Skip to content

Commit f4fdae8

Browse files
ian-shimjianoaix
authored andcommitted
Use existing context when submitting transaction (#33)
1 parent f08ac71 commit f4fdae8

File tree

6 files changed

+8
-6
lines changed

6 files changed

+8
-6
lines changed

common/ethclient.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,5 +39,5 @@ type EthClient interface {
3939
TransactionInBlock(ctx context.Context, blockHash common.Hash, index uint) (*types.Transaction, error)
4040
TransactionReceipt(ctx context.Context, txHash common.Hash) (*types.Receipt, error)
4141
EstimateGasPriceAndLimitAndSendTx(ctx context.Context, tx *types.Transaction, tag string, value *big.Int) (*types.Receipt, error)
42-
EnsureTransactionEvaled(tx *types.Transaction, tag string) (*types.Receipt, error)
42+
EnsureTransactionEvaled(ctx context.Context, tx *types.Transaction, tag string) (*types.Receipt, error)
4343
}

common/geth/client.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,7 @@ func (c *EthClient) EstimateGasPriceAndLimitAndSendTx(
180180
}
181181

182182
receipt, err := c.EnsureTransactionEvaled(
183+
ctx,
183184
tx,
184185
tag,
185186
)
@@ -190,8 +191,8 @@ func (c *EthClient) EstimateGasPriceAndLimitAndSendTx(
190191
return receipt, err
191192
}
192193

193-
func (c *EthClient) EnsureTransactionEvaled(tx *types.Transaction, tag string) (*types.Receipt, error) {
194-
receipt, err := bind.WaitMined(context.Background(), c.Client, tx)
194+
func (c *EthClient) EnsureTransactionEvaled(ctx context.Context, tx *types.Transaction, tag string) (*types.Receipt, error) {
195+
receipt, err := bind.WaitMined(ctx, c.Client, tx)
195196
if err != nil {
196197
return nil, fmt.Errorf("EnsureTransactionEvaled: failed to wait for transaction (%s) to mine: %w", tag, err)
197198
}

common/geth/instrumented_client.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -550,6 +550,7 @@ func (c *InstrumentedEthClient) EstimateGasPriceAndLimitAndSendTx(
550550
}
551551

552552
receipt, err := c.EnsureTransactionEvaled(
553+
ctx,
553554
tx,
554555
tag,
555556
)

common/mock/ethclient.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ func (mock *MockEthClient) EstimateGasPriceAndLimitAndSendTx(ctx context.Context
187187
return result.(*types.Receipt), args.Error(1)
188188
}
189189

190-
func (mock *MockEthClient) EnsureTransactionEvaled(tx *types.Transaction, tag string) (*types.Receipt, error) {
190+
func (mock *MockEthClient) EnsureTransactionEvaled(ctx context.Context, tx *types.Transaction, tag string) (*types.Receipt, error) {
191191
args := mock.Called()
192192
result := args.Get(0)
193193
return result.(*types.Receipt), args.Error(1)

core/eth/tx.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -448,7 +448,7 @@ func (t *Transactor) ConfirmBatch(ctx context.Context, batchHeader core.BatchHea
448448
}
449449

450450
t.Logger.Info("confirming batch onchain")
451-
receipt, err := t.EthClient.EstimateGasPriceAndLimitAndSendTx(context.Background(), tx, "ConfirmBatch", nil)
451+
receipt, err := t.EthClient.EstimateGasPriceAndLimitAndSendTx(ctx, tx, "ConfirmBatch", nil)
452452
if err != nil {
453453
t.Logger.Error("Failed to estimate gas price and limit", "err", err)
454454
return nil, err

disperser/eth/confirmer_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ func TestConfirmerTimeout(t *testing.T) {
3939
tx := coremock.MockTransactor{}
4040
confirmer, err := eth.NewBatchConfirmer(&tx, 100*time.Millisecond)
4141
assert.Nil(t, err)
42-
tx.On("ConfirmBatch").Return(nil, context.DeadlineExceeded)
42+
tx.On("ConfirmBatch").Return(nil, fmt.Errorf("EnsureTransactionEvaled: failed to wait for transaction (%s) to mine: %w", "123", context.DeadlineExceeded)).Once()
4343
_, err = confirmer.ConfirmBatch(context.Background(), &core.BatchHeader{
4444
ReferenceBlockNumber: 100,
4545
BatchRoot: [32]byte{},

0 commit comments

Comments
 (0)