From a11335da806677daaa3347db5bfe05b0872d3678 Mon Sep 17 00:00:00 2001 From: sprites0 <199826320+sprites0@users.noreply.github.com> Date: Thu, 3 Jul 2025 04:18:03 +0000 Subject: [PATCH] refcator: move logic of execute_transaction_with_result_closure into execute_transaction_with_commit_condition --- src/node/evm/executor.rs | 40 +++++++++++++++++++--------------------- 1 file changed, 19 insertions(+), 21 deletions(-) diff --git a/src/node/evm/executor.rs b/src/node/evm/executor.rs index b8597cbed..0a8cf7337 100644 --- a/src/node/evm/executor.rs +++ b/src/node/evm/executor.rs @@ -133,24 +133,13 @@ where fn execute_transaction_with_commit_condition( &mut self, - _tx: impl ExecutableTx, - _f: impl FnOnce(&ExecutionResult<::HaltReason>) -> CommitChanges, + tx: impl ExecutableTx, + f: impl FnOnce(&ExecutionResult<::HaltReason>) -> CommitChanges, ) -> Result, BlockExecutionError> { - Ok(Some(0)) - } - - fn execute_transaction_with_result_closure( - &mut self, - tx: impl ExecutableTx - + IntoTxEnv<::Tx> - + RecoveredTx, - f: impl for<'b> FnOnce(&'b ExecutionResult<::HaltReason>), - ) -> Result { - // Check if it's a system transaction - // let signer = tx.signer(); - // let is_system_transaction = is_system_transaction(tx.tx()); - + // The sum of the transaction's gas limit, Tg, and the gas utilized in this block prior, + // must be no greater than the block's gasLimit. let block_available_gas = self.evm.block().gas_limit - self.gas_used; + if tx.tx().gas_limit() > block_available_gas { return Err(BlockValidationError::TransactionGasLimitMoreThanAvailableBlockGas { transaction_gas_limit: tx.tx().gas_limit(), @@ -158,25 +147,33 @@ where } .into()); } - let result_and_state = self + + // Execute transaction. + let ResultAndState { result, mut state } = self .evm .transact(tx) .map_err(|err| BlockExecutionError::evm(err, tx.tx().trie_hash()))?; - let ResultAndState { result, mut state } = result_and_state; - f(&result); + + if !f(&result).should_commit() { + return Ok(None); + } + let gas_used = result.gas_used(); + + // append gas used if !is_system_transaction(tx.tx()) { self.gas_used += gas_used; } // apply patches after patch_mainnet_after_tx( - self.evm.block().number, + self.evm.block().number.saturating_to(), self.receipts.len() as u64, is_system_transaction(tx.tx()), &mut state, )?; + // Push transaction changeset and calculate header bloom filter for receipt. self.receipts.push(self.receipt_builder.build_receipt(ReceiptBuilderCtx { tx: tx.tx(), evm: &self.evm, @@ -185,9 +182,10 @@ where cumulative_gas_used: self.gas_used, })); + // Commit the state changes. self.evm.db_mut().commit(state); - Ok(gas_used) + Ok(Some(gas_used)) } fn finish(self) -> Result<(Self::Evm, BlockExecutionResult), BlockExecutionError> {