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

[txmgr] Call estimate gas twice #6056

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
19 changes: 16 additions & 3 deletions op-service/txmgr/txmgr.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,17 +192,30 @@ func (m *SimpleTxManager) craftTx(ctx context.Context, candidate TxCandidate) (*
rawTx.Gas = candidate.GasLimit
} else {
// Calculate the intrinsic gas for the transaction
gas, err := m.backend.EstimateGas(ctx, ethereum.CallMsg{
call := ethereum.CallMsg{
From: m.cfg.From,
To: candidate.To,
GasFeeCap: gasFeeCap,
GasTipCap: gasTipCap,
Data: rawTx.Data,
})
}
// Some implementations of EstimateGas have a race condition that can cause extremely high
// estimates for contract interactions. This can cause stuck transactions, because the
// returned estimated gas is close to the block limit, and nodes will ignore the tx. Here
// we call EstimateGas twice, and use the minimum of the two values.
gas, err := m.backend.EstimateGas(ctx, call)
if err != nil {
return nil, fmt.Errorf("failed to estimate gas: %w", err)
}
rawTx.Gas = gas
gas2, err := m.backend.EstimateGas(ctx, call)
if err != nil {
return nil, fmt.Errorf("failed to estimate gas: %w", err)
}
if gas < gas2 {
rawTx.Gas = gas
} else {
rawTx.Gas = gas2
}
}

ctx, cancel := context.WithTimeout(ctx, m.cfg.NetworkTimeout)
Expand Down