From c1924f9fd1ca5dbd0bf1594e99f49f1ac23f79e5 Mon Sep 17 00:00:00 2001 From: Ian Shim Date: Wed, 15 Nov 2023 00:04:24 -0800 Subject: [PATCH] pass in ctx when making txn --- common/ethclient.go | 2 +- common/geth/client.go | 5 +++-- common/geth/instrumented_client.go | 1 + common/mock/ethclient.go | 2 +- core/eth/tx.go | 2 +- disperser/eth/confirmer_test.go | 2 +- 6 files changed, 8 insertions(+), 6 deletions(-) diff --git a/common/ethclient.go b/common/ethclient.go index 0da7a0bc2..79a3e9859 100644 --- a/common/ethclient.go +++ b/common/ethclient.go @@ -39,5 +39,5 @@ type EthClient interface { TransactionInBlock(ctx context.Context, blockHash common.Hash, index uint) (*types.Transaction, error) TransactionReceipt(ctx context.Context, txHash common.Hash) (*types.Receipt, error) EstimateGasPriceAndLimitAndSendTx(ctx context.Context, tx *types.Transaction, tag string, value *big.Int) (*types.Receipt, error) - EnsureTransactionEvaled(tx *types.Transaction, tag string) (*types.Receipt, error) + EnsureTransactionEvaled(ctx context.Context, tx *types.Transaction, tag string) (*types.Receipt, error) } diff --git a/common/geth/client.go b/common/geth/client.go index b3146598b..c0d25e84a 100644 --- a/common/geth/client.go +++ b/common/geth/client.go @@ -180,6 +180,7 @@ func (c *EthClient) EstimateGasPriceAndLimitAndSendTx( } receipt, err := c.EnsureTransactionEvaled( + ctx, tx, tag, ) @@ -190,8 +191,8 @@ func (c *EthClient) EstimateGasPriceAndLimitAndSendTx( return receipt, err } -func (c *EthClient) EnsureTransactionEvaled(tx *types.Transaction, tag string) (*types.Receipt, error) { - receipt, err := bind.WaitMined(context.Background(), c.Client, tx) +func (c *EthClient) EnsureTransactionEvaled(ctx context.Context, tx *types.Transaction, tag string) (*types.Receipt, error) { + receipt, err := bind.WaitMined(ctx, c.Client, tx) if err != nil { return nil, fmt.Errorf("EnsureTransactionEvaled: failed to wait for transaction (%s) to mine: %w", tag, err) } diff --git a/common/geth/instrumented_client.go b/common/geth/instrumented_client.go index 20712e384..d0312c3b8 100644 --- a/common/geth/instrumented_client.go +++ b/common/geth/instrumented_client.go @@ -550,6 +550,7 @@ func (c *InstrumentedEthClient) EstimateGasPriceAndLimitAndSendTx( } receipt, err := c.EnsureTransactionEvaled( + ctx, tx, tag, ) diff --git a/common/mock/ethclient.go b/common/mock/ethclient.go index 0a0949515..6696ca5ef 100644 --- a/common/mock/ethclient.go +++ b/common/mock/ethclient.go @@ -187,7 +187,7 @@ func (mock *MockEthClient) EstimateGasPriceAndLimitAndSendTx(ctx context.Context return result.(*types.Receipt), args.Error(1) } -func (mock *MockEthClient) EnsureTransactionEvaled(tx *types.Transaction, tag string) (*types.Receipt, error) { +func (mock *MockEthClient) EnsureTransactionEvaled(ctx context.Context, tx *types.Transaction, tag string) (*types.Receipt, error) { args := mock.Called() result := args.Get(0) return result.(*types.Receipt), args.Error(1) diff --git a/core/eth/tx.go b/core/eth/tx.go index 8f17d7aee..39edb0562 100644 --- a/core/eth/tx.go +++ b/core/eth/tx.go @@ -448,7 +448,7 @@ func (t *Transactor) ConfirmBatch(ctx context.Context, batchHeader core.BatchHea } t.Logger.Info("confirming batch onchain") - receipt, err := t.EthClient.EstimateGasPriceAndLimitAndSendTx(context.Background(), tx, "ConfirmBatch", nil) + receipt, err := t.EthClient.EstimateGasPriceAndLimitAndSendTx(ctx, tx, "ConfirmBatch", nil) if err != nil { t.Logger.Error("Failed to estimate gas price and limit", "err", err) return nil, err diff --git a/disperser/eth/confirmer_test.go b/disperser/eth/confirmer_test.go index 3fe61eb9a..e47c004a0 100644 --- a/disperser/eth/confirmer_test.go +++ b/disperser/eth/confirmer_test.go @@ -39,7 +39,7 @@ func TestConfirmerTimeout(t *testing.T) { tx := coremock.MockTransactor{} confirmer, err := eth.NewBatchConfirmer(&tx, 100*time.Millisecond) assert.Nil(t, err) - tx.On("ConfirmBatch").Return(nil, context.DeadlineExceeded) + tx.On("ConfirmBatch").Return(nil, fmt.Errorf("EnsureTransactionEvaled: failed to wait for transaction (%s) to mine: %w", "123", context.DeadlineExceeded)).Once() _, err = confirmer.ConfirmBatch(context.Background(), &core.BatchHeader{ ReferenceBlockNumber: 100, BatchRoot: [32]byte{},