Skip to content

Commit

Permalink
chore(updater): Allow setting setRandomness gas limit via env var
Browse files Browse the repository at this point in the history
  • Loading branch information
oyyblin committed Oct 31, 2024
1 parent 34d95e4 commit 53f271e
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 23 deletions.
1 change: 1 addition & 0 deletions updater/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ local-run-anvil:
export DRAND_ORACLE_ADDRESS=$(ANVIL_DRAND_ORACLE_ADDRESS) && \
export RPC=$(ANVIL_RPC) && \
export CHAIN_ID=$(ANVIL_CHAIN_ID) && \
export SET_RANDOMNESS_GAS_LIMIT=500000 && \
export SIGNER_PRIVATE_KEY=$(ANVIL_SIGNER_PRIVATE_KEY) && \
export SENDER_PRIVATE_KEY=$(ANVIL_SENDER_PRIVATE_KEY) && \
export GENESIS_ROUND=$(ANVIL_GENESIS_ROUND) && \
Expand Down
1 change: 1 addition & 0 deletions updater/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ The updater requires the following environment variables:
- `DRAND_ORACLE_ADDRESS`: The address of the Drand Oracle contract.
- `RPC`: The RPC URL.
- `CHAIN_ID`: The chain ID.
- `SET_RANDOMNESS_GAS_LIMIT`: The gas limit for the setRandomness transaction.
- `SIGNER_PRIVATE_KEY`: The private key of the signer.
- `SENDER_PRIVATE_KEY`: The private key of the sender.
- `GENESIS_ROUND`: The genesis round.
Expand Down
2 changes: 1 addition & 1 deletion updater/cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ func main() {

// Initialize updater service
log.Info().Msg("Initializing updater service...")
updater, err := service.NewUpdater(drandClient, rpcClient, binding, cfg.GenesisRound, signer, sender)
updater, err := service.NewUpdater(drandClient, rpcClient, cfg.SetRandomnessGasLimit, binding, cfg.GenesisRound, signer, sender)
if err != nil {
log.Fatal().Err(err).Msg("error creating updater")
}
Expand Down
17 changes: 9 additions & 8 deletions updater/config/config.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
package config

type Config struct {
DrandURLs []string `envconfig:"DRAND_URLS" required:"true"`
ChainHash string `envconfig:"CHAIN_HASH" required:"true"`
DrandOracleAddress string `envconfig:"DRAND_ORACLE_ADDRESS" required:"true"`
RPC string `envconfig:"RPC" required:"true"`
ChainID int64 `envconfig:"CHAIN_ID" required:"true"`
SignerPrivateKey string `envconfig:"SIGNER_PRIVATE_KEY" required:"true"`
SenderPrivateKey string `envconfig:"SENDER_PRIVATE_KEY" required:"true"`
GenesisRound uint64 `envconfig:"GENESIS_ROUND" required:"true"`
DrandURLs []string `envconfig:"DRAND_URLS" required:"true"`
ChainHash string `envconfig:"CHAIN_HASH" required:"true"`
DrandOracleAddress string `envconfig:"DRAND_ORACLE_ADDRESS" required:"true"`
RPC string `envconfig:"RPC" required:"true"`
ChainID int64 `envconfig:"CHAIN_ID" required:"true"`
SetRandomnessGasLimit uint64 `envconfig:"SET_RANDOMNESS_GAS_LIMIT" required:"true"`
SignerPrivateKey string `envconfig:"SIGNER_PRIVATE_KEY" required:"true"`
SenderPrivateKey string `envconfig:"SENDER_PRIVATE_KEY" required:"true"`
GenesisRound uint64 `envconfig:"GENESIS_ROUND" required:"true"`
}
29 changes: 15 additions & 14 deletions updater/internal/service/updater.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,6 @@ import (
"golang.org/x/sync/errgroup"
)

const (
setRandomnessGasLimit = 500000 // 500,000 should be more than enough for a setRandomness transaction
)

type Updater struct {
// drandClient is the Drand HTTP client
drandClient client.Client
Expand All @@ -35,6 +31,9 @@ type Updater struct {
// rpcClient is the Ethereum RPC client
rpcClient *ethclient.Client

// setRandomnessGasLimit is the gas limit for the setRandomness transaction
setRandomnessGasLimit uint64

// binding is the Drand Oracle contract binding
binding *binding.Binding

Expand Down Expand Up @@ -68,21 +67,23 @@ type roundData struct {
func NewUpdater(
drandClient client.Client,
rpcClient *ethclient.Client,
setRandomnessGasLimit uint64,
binding *binding.Binding,
genesisRound uint64,
signer *signer.Signer,
sender *sender.Sender,
) (*Updater, error) {
return &Updater{
drandClient: drandClient,
rpcClient: rpcClient,
binding: binding,
genesisRound: genesisRound,
roundChan: make(chan *roundData, 1),
latestOracleRound: 0,
latestDrandRound: 0,
signer: signer,
sender: sender,
drandClient: drandClient,
rpcClient: rpcClient,
setRandomnessGasLimit: setRandomnessGasLimit,
binding: binding,
genesisRound: genesisRound,
roundChan: make(chan *roundData, 1),
latestOracleRound: 0,
latestDrandRound: 0,
signer: signer,
sender: sender,
}, nil
}

Expand Down Expand Up @@ -254,7 +255,7 @@ func (u *Updater) processRound(
&bind.TransactOpts{
From: u.sender.Address(),
Signer: u.sender.SignerFn(),
GasLimit: setRandomnessGasLimit,
GasLimit: u.setRandomnessGasLimit,
GasPrice: gasPrice,
},
binding.IDrandOracleRandom{
Expand Down

0 comments on commit 53f271e

Please sign in to comment.