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

fix: estimateGas edge case #11764

Merged
merged 2 commits into from
Oct 15, 2024
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
6 changes: 5 additions & 1 deletion crates/rpc/rpc-eth-api/src/helpers/call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -888,7 +888,11 @@ pub trait Call: LoadState + SpawnBlocking {
// Execute transaction and handle potential gas errors, adjusting limits accordingly.
match self.transact(&mut db, env.clone()) {
Err(err) if err.is_gas_too_high() => {
// Increase the lowest gas limit if gas is too high
// Decrease the highest gas limit if gas is too high
highest_gas_limit = mid_gas_limit;
}
Err(err) if err.is_gas_too_low() => {
// Increase the lowest gas limit if gas is too low
lowest_gas_limit = mid_gas_limit;
}
// Handle other cases, including successful transactions.
Expand Down
10 changes: 10 additions & 0 deletions crates/rpc/rpc-eth-api/src/helpers/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,16 @@ pub trait AsEthApiError {

false
}

/// Returns `true` if error is
/// [`RpcInvalidTransactionError::GasTooLow`](reth_rpc_eth_types::RpcInvalidTransactionError::GasTooLow).
fn is_gas_too_low(&self) -> bool {
if let Some(err) = self.as_err() {
return err.is_gas_too_low()
}

false
}
}

impl AsEthApiError for EthApiError {
Expand Down
5 changes: 5 additions & 0 deletions crates/rpc/rpc-eth-types/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,11 @@ impl EthApiError {
pub const fn is_gas_too_high(&self) -> bool {
matches!(self, Self::InvalidTransaction(RpcInvalidTransactionError::GasTooHigh))
}

/// Returns `true` if error is [`RpcInvalidTransactionError::GasTooLow`]
pub const fn is_gas_too_low(&self) -> bool {
matches!(self, Self::InvalidTransaction(RpcInvalidTransactionError::GasTooLow))
}
}

impl From<EthApiError> for jsonrpsee_types::error::ErrorObject<'static> {
Expand Down
Loading