From 8d97ea31445e7801834246c62ce4db64a159f02f Mon Sep 17 00:00:00 2001 From: rakita Date: Wed, 27 Sep 2023 12:01:20 +0200 Subject: [PATCH] remove USE_GAS from handlers --- .github/workflows/ci.yml | 3 + crates/revm/src/handler/mainnet.rs | 18 +++--- crates/revm/src/handler/optimism.rs | 87 ++++++++++++++--------------- 3 files changed, 53 insertions(+), 55 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b67c05895b..02d613b233 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -25,6 +25,9 @@ jobs: cache-on-failure: true - name: cargo test + run: cargo test --workspace + + - name: cargo test all features run: cargo test --workspace --all-features - name: cargo check no_std diff --git a/crates/revm/src/handler/mainnet.rs b/crates/revm/src/handler/mainnet.rs index 2e87f76100..81f12fdb6c 100644 --- a/crates/revm/src/handler/mainnet.rs +++ b/crates/revm/src/handler/mainnet.rs @@ -18,17 +18,15 @@ pub fn handle_call_return( let mut gas = Gas::new(tx_gas_limit); gas.record_cost(tx_gas_limit); - if crate::USE_GAS { - match call_result { - return_ok!() => { - gas.erase_cost(returned_gas.remaining()); - gas.record_refund(returned_gas.refunded()); - } - return_revert!() => { - gas.erase_cost(returned_gas.remaining()); - } - _ => {} + match call_result { + return_ok!() => { + gas.erase_cost(returned_gas.remaining()); + gas.record_refund(returned_gas.refunded()); } + return_revert!() => { + gas.erase_cost(returned_gas.remaining()); + } + _ => {} } gas } diff --git a/crates/revm/src/handler/optimism.rs b/crates/revm/src/handler/optimism.rs index b64d18edab..bccab5608d 100644 --- a/crates/revm/src/handler/optimism.rs +++ b/crates/revm/src/handler/optimism.rs @@ -11,7 +11,6 @@ use crate::{ }; /// Handle output of the transaction -#[cfg(feature = "optimism")] pub fn handle_call_return( env: &Env, call_result: InstructionResult, @@ -26,52 +25,50 @@ pub fn handle_call_return( let mut gas = Gas::new(tx_gas_limit); gas.record_cost(tx_gas_limit); - if crate::USE_GAS { - match call_result { - return_ok!() => { - // On Optimism, deposit transactions report gas usage uniquely to other - // transactions due to them being pre-paid on L1. - // - // Hardfork Behavior: - // - Bedrock (success path): - // - Deposit transactions (non-system) report their gas limit as the usage. - // No refunds. - // - Deposit transactions (system) report 0 gas used. No refunds. - // - Regular transactions report gas usage as normal. - // - Regolith (success path): - // - Deposit transactions (all) report their gas used as normal. Refunds - // enabled. - // - Regular transactions report their gas used as normal. - if is_optimism && (!is_deposit || is_regolith) { - // For regular transactions prior to Regolith and all transactions after - // Regolith, gas is reported as normal. - gas.erase_cost(returned_gas.remaining()); - gas.record_refund(returned_gas.refunded()); - } else if is_deposit && tx_system.unwrap_or(false) { - // System transactions were a special type of deposit transaction in - // the Bedrock hardfork that did not incur any gas costs. - gas.erase_cost(tx_gas_limit); - } + match call_result { + return_ok!() => { + // On Optimism, deposit transactions report gas usage uniquely to other + // transactions due to them being pre-paid on L1. + // + // Hardfork Behavior: + // - Bedrock (success path): + // - Deposit transactions (non-system) report their gas limit as the usage. + // No refunds. + // - Deposit transactions (system) report 0 gas used. No refunds. + // - Regular transactions report gas usage as normal. + // - Regolith (success path): + // - Deposit transactions (all) report their gas used as normal. Refunds + // enabled. + // - Regular transactions report their gas used as normal. + if is_optimism && (!is_deposit || is_regolith) { + // For regular transactions prior to Regolith and all transactions after + // Regolith, gas is reported as normal. + gas.erase_cost(returned_gas.remaining()); + gas.record_refund(returned_gas.refunded()); + } else if is_deposit && tx_system.unwrap_or(false) { + // System transactions were a special type of deposit transaction in + // the Bedrock hardfork that did not incur any gas costs. + gas.erase_cost(tx_gas_limit); } - return_revert!() => { - // On Optimism, deposit transactions report gas usage uniquely to other - // transactions due to them being pre-paid on L1. - // - // Hardfork Behavior: - // - Bedrock (revert path): - // - Deposit transactions (all) report the gas limit as the amount of gas - // used on failure. No refunds. - // - Regular transactions receive a refund on remaining gas as normal. - // - Regolith (revert path): - // - Deposit transactions (all) report the actual gas used as the amount of - // gas used on failure. Refunds on remaining gas enabled. - // - Regular transactions receive a refund on remaining gas as normal. - if is_optimism && (!is_deposit || is_regolith) { - gas.erase_cost(returned_gas.remaining()); - } + } + return_revert!() => { + // On Optimism, deposit transactions report gas usage uniquely to other + // transactions due to them being pre-paid on L1. + // + // Hardfork Behavior: + // - Bedrock (revert path): + // - Deposit transactions (all) report the gas limit as the amount of gas + // used on failure. No refunds. + // - Regular transactions receive a refund on remaining gas as normal. + // - Regolith (revert path): + // - Deposit transactions (all) report the actual gas used as the amount of + // gas used on failure. Refunds on remaining gas enabled. + // - Regular transactions receive a refund on remaining gas as normal. + if is_optimism && (!is_deposit || is_regolith) { + gas.erase_cost(returned_gas.remaining()); } - _ => {} } + _ => {} } gas } @@ -141,7 +138,7 @@ pub fn reward_beneficiary( Ok(()) } -#[cfg(feature = "optimism")] + #[cfg(test)] mod tests { use crate::primitives::{BedrockSpec, RegolithSpec};