Skip to content
Draft
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
46 changes: 19 additions & 27 deletions crates/evm/src/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1098,7 +1098,7 @@ impl<C: sov_modules_api::Context> Evm<C> {
cfg_env.clone(),
block_env.clone(),
inspect_tx_env.clone(),
l1_fee_rate,
0, // run with l1 fee rate = 0, so that we don't get "Not enough funds for L1 fee"
TracingInspector::new(TracingInspectorConfig::none()),
);

Expand All @@ -1109,16 +1109,13 @@ impl<C: sov_modules_api::Context> Evm<C> {
// One with 0 value and the other with the remaining balance that extract from the current balance after the gas fee is deducted
// This causes the diff size to be lower than the actual diff size, and the tx to fail due to not enough l1 fee
let mut diff_size = tx_info.l1_diff_size;
let mut l1_fee = tx_info.l1_fee;
if tx_env.value.is_zero() {
// Calculation taken from diff size calculation in handler.rs
let balance_diff_size = diff_size_send_eth_eoa() as u64;

diff_size += balance_diff_size;
l1_fee = l1_fee.saturating_add(
U256::from(l1_fee_rate) * (U256::from(balance_diff_size)),
);
}
let l1_fee = U256::from(l1_fee_rate) * (U256::from(diff_size));
return Ok(EstimatedTxExpenses {
gas_used: U64::from(MIN_TRANSACTION_GAS),
block_gas_limit,
Expand Down Expand Up @@ -1153,7 +1150,7 @@ impl<C: sov_modules_api::Context> Evm<C> {
cfg_env.clone(),
block_env.clone(),
tx_env.clone(),
l1_fee_rate,
0, // run with l1 fee rate = 0, so that we don't get "Not enough funds for L1 fee"
TracingInspector::new(TracingInspectorConfig::none()),
);

Expand All @@ -1168,14 +1165,9 @@ impl<C: sov_modules_api::Context> Evm<C> {
if let Some(ref state_overrides) = state_overrides {
apply_state_overrides(state_overrides.clone(), &mut evm_db)?;
}
return Err(map_out_of_gas_err(
block_env.clone(),
tx_env.clone(),
cfg_env,
evm_db,
l1_fee_rate,
)
.into());
return Err(
map_out_of_gas_err(block_env.clone(), tx_env.clone(), cfg_env, evm_db).into(),
);
}
} else if let Err(EVMError::Transaction(
InvalidTransaction::CallGasCostMoreThanGasLimit { .. },
Expand All @@ -1194,7 +1186,9 @@ impl<C: sov_modules_api::Context> Evm<C> {
let (result, mut l1_fee, mut diff_size) = match result {
Ok((result, tx_info)) => match result.result {
ExecutionResult::Success { .. } => {
(result.result, tx_info.l1_fee, tx_info.l1_diff_size)
let TxInfo { l1_diff_size, .. } = tx_info;
let l1_fee = U256::from(l1_fee_rate) * (U256::from(l1_diff_size));
(result.result, l1_fee, l1_diff_size)
}
ExecutionResult::Halt { reason, gas_used } => {
return Err(RpcInvalidTransactionError::halt(reason, gas_used).into())
Expand All @@ -1207,14 +1201,10 @@ impl<C: sov_modules_api::Context> Evm<C> {
if let Some(ref state_overrides) = state_overrides {
apply_state_overrides(state_overrides.clone(), &mut evm_db)?;
}
Err(map_out_of_gas_err(
block_env.clone(),
tx_env.clone(),
cfg_env,
evm_db,
l1_fee_rate,
Err(
map_out_of_gas_err(block_env.clone(), tx_env.clone(), cfg_env, evm_db)
.into(),
)
.into())
} else {
// the transaction did revert
Err(RpcInvalidTransactionError::Revert(RevertError::new(output)).into())
Expand Down Expand Up @@ -1255,7 +1245,7 @@ impl<C: sov_modules_api::Context> Evm<C> {
cfg_env.clone(),
block_env.clone(),
tx_env.clone(),
l1_fee_rate,
0, // run with l1 fee rate = 0, so that we don't get "Not enough funds for L1 fee"
TracingInspector::new(TracingInspectorConfig::none()),
);
let (curr_result, tx_info) = match curr_result {
Expand All @@ -1270,6 +1260,7 @@ impl<C: sov_modules_api::Context> Evm<C> {
&mut l1_fee,
&mut diff_size,
tx_info,
l1_fee_rate,
)?;
};

Expand Down Expand Up @@ -1332,6 +1323,7 @@ impl<C: sov_modules_api::Context> Evm<C> {
&mut l1_fee,
&mut diff_size,
tx_info,
l1_fee_rate,
)?;
}

Expand Down Expand Up @@ -2113,7 +2105,6 @@ fn map_out_of_gas_err<C: sov_modules_api::Context>(
mut tx_env: revm::context::TxEnv,
cfg_env: CfgEnv,
db: EvmDb<'_, C>,
l1_fee_rate: u128,
) -> EthApiError {
let req_gas_limit = tx_env.gas_limit;
tx_env.gas_limit = block_env.gas_limit;
Expand All @@ -2123,7 +2114,7 @@ fn map_out_of_gas_err<C: sov_modules_api::Context>(
cfg_env,
block_env,
tx_env,
l1_fee_rate,
/* l1_fee_rate */ 0,
TracingInspector::new(TracingInspectorConfig::none()),
) {
Ok((res, _tx_info)) => match res.result {
Expand Down Expand Up @@ -2155,19 +2146,20 @@ fn update_estimated_gas_range(
l1_fee: &mut U256,
diff_size: &mut u64,
tx_info: TxInfo,
l1_fee_rate: u128,
) -> EthResult<()> {
match result {
ExecutionResult::Success { .. } => {
// cap the highest gas limit with succeeding gas limit
*highest_gas_limit = tx_gas_limit;
*l1_fee = tx_info.l1_fee;
*l1_fee = U256::from(tx_info.l1_diff_size) * U256::from(l1_fee_rate);
*diff_size = tx_info.l1_diff_size;
}
ExecutionResult::Revert { .. } => {
// increase the lowest gas limit
*lowest_gas_limit = tx_gas_limit;

*l1_fee = tx_info.l1_fee;
*l1_fee = U256::from(tx_info.l1_diff_size) * U256::from(l1_fee_rate);
*diff_size = tx_info.l1_diff_size;
}
ExecutionResult::Halt { reason, .. } => {
Expand Down
Loading