Skip to content

Commit

Permalink
pass in ctx when making txn
Browse files Browse the repository at this point in the history
  • Loading branch information
ian-shim committed Nov 15, 2023
1 parent 423ddd3 commit 7854c1c
Show file tree
Hide file tree
Showing 6 changed files with 8 additions and 6 deletions.
2 changes: 1 addition & 1 deletion common/ethclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
5 changes: 3 additions & 2 deletions common/geth/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ func (c *EthClient) EstimateGasPriceAndLimitAndSendTx(
}

receipt, err := c.EnsureTransactionEvaled(
ctx,
tx,
tag,
)
Expand All @@ -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)
}
Expand Down
1 change: 1 addition & 0 deletions common/geth/instrumented_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -550,6 +550,7 @@ func (c *InstrumentedEthClient) EstimateGasPriceAndLimitAndSendTx(
}

receipt, err := c.EnsureTransactionEvaled(
ctx,
tx,
tag,
)
Expand Down
2 changes: 1 addition & 1 deletion common/mock/ethclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion core/eth/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion disperser/eth/confirmer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
_, err = confirmer.ConfirmBatch(context.Background(), &core.BatchHeader{
ReferenceBlockNumber: 100,
BatchRoot: [32]byte{},
Expand Down

0 comments on commit 7854c1c

Please sign in to comment.