From b286e581cf21aedafa74f0e4e86a3bc57dd446b5 Mon Sep 17 00:00:00 2001 From: Matthias Seitz Date: Mon, 27 Apr 2026 14:42:43 +0200 Subject: [PATCH] refactor(evm): return gas output from block builder --- crates/engine/util/src/reorg.rs | 2 +- crates/ethereum/payload/src/lib.rs | 2 +- crates/evm/evm/src/execute.rs | 12 ++++++------ crates/rpc/rpc-eth-api/src/helpers/pending_block.rs | 2 +- crates/rpc/rpc/src/testing.rs | 2 +- 5 files changed, 10 insertions(+), 10 deletions(-) diff --git a/crates/engine/util/src/reorg.rs b/crates/engine/util/src/reorg.rs index adfec89ba0e..13390cef433 100644 --- a/crates/engine/util/src/reorg.rs +++ b/crates/engine/util/src/reorg.rs @@ -287,7 +287,7 @@ where let tx_recovered = tx.try_into_recovered().map_err(|_| ProviderError::SenderRecoveryError)?; let gas_used = match builder.execute_transaction(tx_recovered) { - Ok(gas_used) => gas_used, + Ok(gas_used) => gas_used.tx_gas_used(), Err(BlockExecutionError::Validation(BlockValidationError::InvalidTx { hash, error, diff --git a/crates/ethereum/payload/src/lib.rs b/crates/ethereum/payload/src/lib.rs index 894619ea34c..95fbb1e71ab 100644 --- a/crates/ethereum/payload/src/lib.rs +++ b/crates/ethereum/payload/src/lib.rs @@ -342,7 +342,7 @@ where let tx_hash = *tx.tx_hash(); let gas_used = match builder.execute_transaction(tx) { - Ok(gas_used) => gas_used, + Ok(gas_used) => gas_used.tx_gas_used(), Err(BlockExecutionError::Validation(BlockValidationError::InvalidTx { error, .. })) => { diff --git a/crates/evm/evm/src/execute.rs b/crates/evm/evm/src/execute.rs index 46c04b8e796..eb1c70c3deb 100644 --- a/crates/evm/evm/src/execute.rs +++ b/crates/evm/evm/src/execute.rs @@ -4,7 +4,7 @@ use crate::{ConfigureEvm, Database, OnStateHook, TxEnvFor}; use alloc::{boxed::Box, sync::Arc, vec::Vec}; use alloy_consensus::{BlockHeader, Header}; use alloy_eips::eip2718::WithEncoded; -pub use alloy_evm::block::{BlockExecutor, BlockExecutorFactory}; +pub use alloy_evm::block::{BlockExecutor, BlockExecutorFactory, GasOutput}; use alloy_evm::{ block::{CommitChanges, ExecutableTxParts}, Evm, EvmEnv, EvmFactory, RecoveredTx, ToTxEnv, @@ -327,7 +327,7 @@ pub trait BlockBuilder { &mut self, tx: impl ExecutorTx, f: impl FnOnce(&::Result) -> CommitChanges, - ) -> Result, BlockExecutionError>; + ) -> Result, BlockExecutionError>; /// Invokes [`BlockExecutor::execute_transaction_with_result_closure`] and saves the /// transaction in internal state. @@ -335,7 +335,7 @@ pub trait BlockBuilder { &mut self, tx: impl ExecutorTx, f: impl FnOnce(&::Result), - ) -> Result { + ) -> Result { self.execute_transaction_with_commit_condition(tx, |res| { f(res); CommitChanges::Yes @@ -348,7 +348,7 @@ pub trait BlockBuilder { fn execute_transaction( &mut self, tx: impl ExecutorTx, - ) -> Result { + ) -> Result { self.execute_transaction_with_result_closure(tx, |_| ()) } @@ -460,13 +460,13 @@ where &mut self, tx: impl ExecutorTx, f: impl FnOnce(&::Result) -> CommitChanges, - ) -> Result, BlockExecutionError> { + ) -> Result, BlockExecutionError> { let (tx_env, tx) = tx.into_parts(); if let Some(gas_used) = self.executor.execute_transaction_with_commit_condition((tx_env, &tx), f)? { self.transactions.push(tx); - Ok(Some(gas_used.tx_gas_used())) + Ok(Some(gas_used)) } else { Ok(None) } diff --git a/crates/rpc/rpc-eth-api/src/helpers/pending_block.rs b/crates/rpc/rpc-eth-api/src/helpers/pending_block.rs index aa3397ef2ca..9a56a4e7afb 100644 --- a/crates/rpc/rpc-eth-api/src/helpers/pending_block.rs +++ b/crates/rpc/rpc-eth-api/src/helpers/pending_block.rs @@ -338,7 +338,7 @@ pub trait LoadPendingBlock: } let gas_used = match builder.execute_transaction(tx) { - Ok(gas_used) => gas_used, + Ok(gas_used) => gas_used.tx_gas_used(), Err(BlockExecutionError::Validation(BlockValidationError::InvalidTx { error, .. diff --git a/crates/rpc/rpc/src/testing.rs b/crates/rpc/rpc/src/testing.rs index 80dd2b1a06c..e7d2e45826c 100644 --- a/crates/rpc/rpc/src/testing.rs +++ b/crates/rpc/rpc/src/testing.rs @@ -179,7 +179,7 @@ where let tip = tx.effective_tip_per_gas(base_fee).unwrap_or_default(); let gas_used = match builder.execute_transaction(tx) { - Ok(gas_used) => gas_used, + Ok(gas_used) => gas_used.tx_gas_used(), Err(err) => { if skip_invalid_transactions { debug!(