fix: estimateGas edge case (#11764)

This commit is contained in:
Arsenii Kulikov
2024-10-15 22:43:56 +04:00
committed by GitHub
parent 7b1b1fcb3b
commit 7f92760655
3 changed files with 20 additions and 1 deletions

View File

@@ -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.

View File

@@ -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 {

View File

@@ -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> {