Skip to content

Commit

Permalink
Use binary search without evm estimate mode (#39)
Browse files Browse the repository at this point in the history
  • Loading branch information
tgmichel authored Feb 7, 2022
1 parent 7e4fd79 commit 32b7cf4
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions client/rpc/src/eth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1482,7 +1482,7 @@ where

// Create a helper to check if a gas allowance results in an executable transaction
let executable =
move |request: CallRequest, gas_limit, api_version| -> Result<ExecutableResult> {
move |request: CallRequest, gas_limit, api_version, estimate_mode| -> Result<ExecutableResult> {
let CallRequest {
from,
to,
Expand Down Expand Up @@ -1516,7 +1516,7 @@ where
gas_limit,
gas_price,
nonce,
true,
estimate_mode,
)
.map_err(|err| internal_err(format!("runtime error: {:?}", err)))?
.map_err(|err| internal_err(format!("execution fatal: {:?}", err)))?
Expand All @@ -1533,7 +1533,7 @@ where
max_fee_per_gas,
max_priority_fee_per_gas,
nonce,
true,
estimate_mode,
)
.map_err(|err| internal_err(format!("runtime error: {:?}", err)))?
.map_err(|err| internal_err(format!("execution fatal: {:?}", err)))?
Expand All @@ -1550,7 +1550,7 @@ where
max_fee_per_gas,
max_priority_fee_per_gas,
nonce,
true,
estimate_mode,
Some(
access_list
.into_iter()
Expand All @@ -1576,7 +1576,7 @@ where
gas_limit,
gas_price,
nonce,
true,
estimate_mode,
)
.map_err(|err| internal_err(format!("runtime error: {:?}", err)))?
.map_err(|err| internal_err(format!("execution fatal: {:?}", err)))?
Expand All @@ -1592,7 +1592,7 @@ where
max_fee_per_gas,
max_priority_fee_per_gas,
nonce,
true,
estimate_mode,
)
.map_err(|err| internal_err(format!("runtime error: {:?}", err)))?
.map_err(|err| internal_err(format!("execution fatal: {:?}", err)))?
Expand All @@ -1608,7 +1608,7 @@ where
max_fee_per_gas,
max_priority_fee_per_gas,
nonce,
true,
estimate_mode,
Some(
access_list
.into_iter()
Expand Down Expand Up @@ -1643,11 +1643,12 @@ where

// Verify that the transaction succeed with highest capacity
let cap = highest;
let estimate_mode = true;
let ExecutableResult {
data,
exit_reason,
used_gas,
} = executable(request.clone(), highest, api_version)?;
} = executable(request.clone(), highest, api_version, estimate_mode)?;
match exit_reason {
ExitReason::Succeed(_) => (),
ExitReason::Error(ExitError::OutOfGas) => {
Expand All @@ -1668,7 +1669,7 @@ where
data,
exit_reason,
used_gas: _,
} = executable(request.clone(), get_current_block_gas_limit()?, api_version)?;
} = executable(request.clone(), get_current_block_gas_limit()?, api_version, estimate_mode)?;
match exit_reason {
ExitReason::Succeed(_) => {
return Err(internal_err(format!(
Expand All @@ -1693,6 +1694,8 @@ where
}
#[cfg(feature = "rpc_binary_search_estimate")]
{
// On binary search, evm estimate mode is disabled
let estimate_mode = false;
// Define the lower bound of the binary search
let mut lowest = MIN_GAS_PER_TX;

Expand All @@ -1706,7 +1709,7 @@ where
data,
exit_reason,
used_gas: _,
} = executable(request.clone(), mid, api_version)?;
} = executable(request.clone(), mid, api_version, estimate_mode)?;
match exit_reason {
ExitReason::Succeed(_) => {
highest = mid;
Expand Down

0 comments on commit 32b7cf4

Please sign in to comment.