Skip to content

Commit 53f271e

Browse files
committed
chore(updater): Allow setting setRandomness gas limit via env var
1 parent 34d95e4 commit 53f271e

File tree

5 files changed

+27
-23
lines changed

5 files changed

+27
-23
lines changed

updater/Makefile

+1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ local-run-anvil:
2828
export DRAND_ORACLE_ADDRESS=$(ANVIL_DRAND_ORACLE_ADDRESS) && \
2929
export RPC=$(ANVIL_RPC) && \
3030
export CHAIN_ID=$(ANVIL_CHAIN_ID) && \
31+
export SET_RANDOMNESS_GAS_LIMIT=500000 && \
3132
export SIGNER_PRIVATE_KEY=$(ANVIL_SIGNER_PRIVATE_KEY) && \
3233
export SENDER_PRIVATE_KEY=$(ANVIL_SENDER_PRIVATE_KEY) && \
3334
export GENESIS_ROUND=$(ANVIL_GENESIS_ROUND) && \

updater/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ The updater requires the following environment variables:
2727
- `DRAND_ORACLE_ADDRESS`: The address of the Drand Oracle contract.
2828
- `RPC`: The RPC URL.
2929
- `CHAIN_ID`: The chain ID.
30+
- `SET_RANDOMNESS_GAS_LIMIT`: The gas limit for the setRandomness transaction.
3031
- `SIGNER_PRIVATE_KEY`: The private key of the signer.
3132
- `SENDER_PRIVATE_KEY`: The private key of the sender.
3233
- `GENESIS_ROUND`: The genesis round.

updater/cmd/main.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ func main() {
8383

8484
// Initialize updater service
8585
log.Info().Msg("Initializing updater service...")
86-
updater, err := service.NewUpdater(drandClient, rpcClient, binding, cfg.GenesisRound, signer, sender)
86+
updater, err := service.NewUpdater(drandClient, rpcClient, cfg.SetRandomnessGasLimit, binding, cfg.GenesisRound, signer, sender)
8787
if err != nil {
8888
log.Fatal().Err(err).Msg("error creating updater")
8989
}

updater/config/config.go

+9-8
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
package config
22

33
type Config struct {
4-
DrandURLs []string `envconfig:"DRAND_URLS" required:"true"`
5-
ChainHash string `envconfig:"CHAIN_HASH" required:"true"`
6-
DrandOracleAddress string `envconfig:"DRAND_ORACLE_ADDRESS" required:"true"`
7-
RPC string `envconfig:"RPC" required:"true"`
8-
ChainID int64 `envconfig:"CHAIN_ID" required:"true"`
9-
SignerPrivateKey string `envconfig:"SIGNER_PRIVATE_KEY" required:"true"`
10-
SenderPrivateKey string `envconfig:"SENDER_PRIVATE_KEY" required:"true"`
11-
GenesisRound uint64 `envconfig:"GENESIS_ROUND" required:"true"`
4+
DrandURLs []string `envconfig:"DRAND_URLS" required:"true"`
5+
ChainHash string `envconfig:"CHAIN_HASH" required:"true"`
6+
DrandOracleAddress string `envconfig:"DRAND_ORACLE_ADDRESS" required:"true"`
7+
RPC string `envconfig:"RPC" required:"true"`
8+
ChainID int64 `envconfig:"CHAIN_ID" required:"true"`
9+
SetRandomnessGasLimit uint64 `envconfig:"SET_RANDOMNESS_GAS_LIMIT" required:"true"`
10+
SignerPrivateKey string `envconfig:"SIGNER_PRIVATE_KEY" required:"true"`
11+
SenderPrivateKey string `envconfig:"SENDER_PRIVATE_KEY" required:"true"`
12+
GenesisRound uint64 `envconfig:"GENESIS_ROUND" required:"true"`
1213
}

updater/internal/service/updater.go

+15-14
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,6 @@ import (
2121
"golang.org/x/sync/errgroup"
2222
)
2323

24-
const (
25-
setRandomnessGasLimit = 500000 // 500,000 should be more than enough for a setRandomness transaction
26-
)
27-
2824
type Updater struct {
2925
// drandClient is the Drand HTTP client
3026
drandClient client.Client
@@ -35,6 +31,9 @@ type Updater struct {
3531
// rpcClient is the Ethereum RPC client
3632
rpcClient *ethclient.Client
3733

34+
// setRandomnessGasLimit is the gas limit for the setRandomness transaction
35+
setRandomnessGasLimit uint64
36+
3837
// binding is the Drand Oracle contract binding
3938
binding *binding.Binding
4039

@@ -68,21 +67,23 @@ type roundData struct {
6867
func NewUpdater(
6968
drandClient client.Client,
7069
rpcClient *ethclient.Client,
70+
setRandomnessGasLimit uint64,
7171
binding *binding.Binding,
7272
genesisRound uint64,
7373
signer *signer.Signer,
7474
sender *sender.Sender,
7575
) (*Updater, error) {
7676
return &Updater{
77-
drandClient: drandClient,
78-
rpcClient: rpcClient,
79-
binding: binding,
80-
genesisRound: genesisRound,
81-
roundChan: make(chan *roundData, 1),
82-
latestOracleRound: 0,
83-
latestDrandRound: 0,
84-
signer: signer,
85-
sender: sender,
77+
drandClient: drandClient,
78+
rpcClient: rpcClient,
79+
setRandomnessGasLimit: setRandomnessGasLimit,
80+
binding: binding,
81+
genesisRound: genesisRound,
82+
roundChan: make(chan *roundData, 1),
83+
latestOracleRound: 0,
84+
latestDrandRound: 0,
85+
signer: signer,
86+
sender: sender,
8687
}, nil
8788
}
8889

@@ -254,7 +255,7 @@ func (u *Updater) processRound(
254255
&bind.TransactOpts{
255256
From: u.sender.Address(),
256257
Signer: u.sender.SignerFn(),
257-
GasLimit: setRandomnessGasLimit,
258+
GasLimit: u.setRandomnessGasLimit,
258259
GasPrice: gasPrice,
259260
},
260261
binding.IDrandOracleRandom{

0 commit comments

Comments
 (0)