Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use existing context when submitting transaction #33

Merged
merged 1 commit into from
Nov 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)).Once()
_, err = confirmer.ConfirmBatch(context.Background(), &core.BatchHeader{
ReferenceBlockNumber: 100,
BatchRoot: [32]byte{},
Expand Down
Loading