@@ -103,8 +103,8 @@ func init() {
103103}
104104
105105type registryContractClient interface {
106- RegisterVoter (nextRewardEpochId * big.Int , address common.Address ) <- chan shared.ExecuteStatus [any ]
107- PreregisterVoter (nextRewardEpochId * big.Int , address common.Address ) <- chan shared.ExecuteStatus [any ]
106+ RegisterVoter (ctx context. Context , nextRewardEpochId * big.Int , address common.Address ) <- chan shared.ExecuteStatus [any ]
107+ PreregisterVoter (ctx context. Context , nextRewardEpochId * big.Int , address common.Address ) <- chan shared.ExecuteStatus [any ]
108108}
109109
110110type registryContractClientImpl struct {
@@ -153,9 +153,9 @@ func NewRegistryContractClient(
153153}
154154
155155// RegisterVoter tries to register voter on VoterRegistry smart contract.
156- func (r * registryContractClientImpl ) RegisterVoter (nextRewardEpochID * big.Int , address common.Address ) <- chan shared.ExecuteStatus [any ] {
156+ func (r * registryContractClientImpl ) RegisterVoter (ctx context. Context , nextRewardEpochID * big.Int , address common.Address ) <- chan shared.ExecuteStatus [any ] {
157157 return shared .ExecuteWithRetryChan (func () (any , error ) {
158- err := r .sendRegisterVoter (nextRewardEpochID , address )
158+ err := r .sendRegisterVoter (ctx , nextRewardEpochID , address )
159159 if err != nil {
160160 if shared .ExistsAsSubstring (nonFatalRegisterErrors , err .Error ()) {
161161 logger .Debugf ("Non fatal error sending register voter: %v" , err )
@@ -167,7 +167,7 @@ func (r *registryContractClientImpl) RegisterVoter(nextRewardEpochID *big.Int, a
167167 }, shared .MaxTxSendRetriesLong , shared .TxRetryIntervalLong )
168168}
169169
170- func (r * registryContractClientImpl ) sendRegisterVoter (nextRewardEpochID * big.Int , address common.Address ) error {
170+ func (r * registryContractClientImpl ) sendRegisterVoter (ctx context. Context , nextRewardEpochID * big.Int , address common.Address ) error {
171171 epochID := uint32 (nextRewardEpochID .Uint64 ())
172172
173173 var (
@@ -193,12 +193,13 @@ func (r *registryContractClientImpl) sendRegisterVoter(nextRewardEpochID *big.In
193193 V : signature [64 ] + 27 ,
194194 }
195195
196- err = SetGas (r .senderTxOpts , r .ethClient , r .gasCfg )
196+ err = SetGas (ctx , r .senderTxOpts , r .ethClient , r .gasCfg )
197197 if err != nil {
198198 return err
199199 }
200200
201201 estimatedGasLimit , err := chain .DryRunTxAbi (
202+ ctx ,
202203 r .ethClient ,
203204 chain .DefaultTxTimeout ,
204205 r .senderTxOpts .From ,
@@ -224,7 +225,7 @@ func (r *registryContractClientImpl) sendRegisterVoter(nextRewardEpochID *big.In
224225 return fmt .Errorf ("sending registry tx: %w" , err )
225226 }
226227
227- err = r .txVerifier .WaitUntilMined (r .senderTxOpts .From , tx , chain .DefaultTxTimeout )
228+ err = r .txVerifier .WaitUntilMined (ctx , r .senderTxOpts .From , tx , chain .DefaultTxTimeout )
228229 if err != nil {
229230 return err
230231 }
@@ -233,9 +234,9 @@ func (r *registryContractClientImpl) sendRegisterVoter(nextRewardEpochID *big.In
233234}
234235
235236// PreregisterVoter tries to pre-register voter on VoterPreRegistry smart contract.
236- func (r * registryContractClientImpl ) PreregisterVoter (nextRewardEpochId * big.Int , address common.Address ) <- chan shared.ExecuteStatus [any ] {
237+ func (r * registryContractClientImpl ) PreregisterVoter (ctx context. Context , nextRewardEpochId * big.Int , address common.Address ) <- chan shared.ExecuteStatus [any ] {
237238 return shared .ExecuteWithRetryChan (func () (any , error ) {
238- err := r .sendPreRegisterVoter (nextRewardEpochId , address )
239+ err := r .sendPreRegisterVoter (ctx , nextRewardEpochId , address )
239240 if err != nil {
240241 if shared .ExistsAsSubstring (nonFatalPreregisterErrors , err .Error ()) {
241242 logger .Debugf ("Non fatal error sending pre-register voter: %v" , err )
@@ -247,7 +248,7 @@ func (r *registryContractClientImpl) PreregisterVoter(nextRewardEpochId *big.Int
247248 }, shared .MaxTxSendRetries , shared .TxRetryInterval )
248249}
249250
250- func (r * registryContractClientImpl ) sendPreRegisterVoter (nextRewardEpochID * big.Int , address common.Address ) error {
251+ func (r * registryContractClientImpl ) sendPreRegisterVoter (ctx context. Context , nextRewardEpochID * big.Int , address common.Address ) error {
251252 epochID := uint32 (nextRewardEpochID .Uint64 ())
252253
253254 var (
@@ -273,12 +274,13 @@ func (r *registryContractClientImpl) sendPreRegisterVoter(nextRewardEpochID *big
273274 V : signature [64 ] + 27 ,
274275 }
275276
276- err = SetGas (r .senderTxOpts , r .ethClient , r .gasCfg )
277+ err = SetGas (ctx , r .senderTxOpts , r .ethClient , r .gasCfg )
277278 if err != nil {
278279 return fmt .Errorf ("setting gas pre registry:%w" , err )
279280 }
280281
281282 estimatedGasLimit , err := chain .DryRunTxAbi (
283+ ctx ,
282284 r .ethClient ,
283285 chain .DefaultTxTimeout ,
284286 r .senderTxOpts .From ,
@@ -304,7 +306,7 @@ func (r *registryContractClientImpl) sendPreRegisterVoter(nextRewardEpochID *big
304306 return fmt .Errorf ("sending preregistry tx: %w" , err )
305307 }
306308
307- err = r .txVerifier .WaitUntilMined (r .senderTxOpts .From , tx , chain .DefaultTxTimeout )
309+ err = r .txVerifier .WaitUntilMined (ctx , r .senderTxOpts .From , tx , chain .DefaultTxTimeout )
308310 if err != nil {
309311 return err
310312 }
@@ -335,19 +337,19 @@ func (r *registryContractClientImpl) createSignatureNew(chainID int, nextRewardE
335337}
336338
337339// SetGas sets gas parameters in txOptions according to the gasConfig.
338- func SetGas (txOptions * bind.TransactOpts , client * ethclient.Client , gasConfig * config.Gas ) error {
340+ func SetGas (ctx context. Context , txOptions * bind.TransactOpts , client * ethclient.Client , gasConfig * config.Gas ) error {
339341 switch gasConfig .TxType {
340342 case 0 :
341- gasPrice , err := chain .GetGasPrice (gasConfig , client , chain .DefaultTxTimeout )
343+ gasPrice , err := chain .GetGasPrice (ctx , gasConfig , client , chain .DefaultTxTimeout )
342344 if err != nil {
343345 logger .Warnf ("Unable to obtain gas price: %v, using fallback %d" , err , fallbackGasPrice )
344346 gasPrice = new (big.Int ).Set (fallbackGasPrice )
345347 }
346348 txOptions .GasPrice = gasPrice
347349 return nil
348350 case 2 :
349- ctx , cancelFunc := context .WithTimeout (context . Background (), timeout )
350- baseFeePerGas , err := chain .BaseFee (ctx , client )
351+ feeCtx , cancelFunc := context .WithTimeout (ctx , chain . DefaultTxTimeout )
352+ baseFeePerGas , err := chain .BaseFee (feeCtx , client )
351353 cancelFunc ()
352354
353355 if err != nil {
0 commit comments