From 6a104cc17461bac28164f3c2f08e7e1889708ab6 Mon Sep 17 00:00:00 2001 From: Matthias Seitz Date: Mon, 8 Apr 2024 19:28:17 +0200 Subject: [PATCH] chore: rm unused execute function (#7513) --- crates/revm/src/optimism/processor.rs | 27 +++++++++---------- crates/revm/src/processor.rs | 15 +++-------- .../provider/src/test_utils/executor.rs | 11 -------- .../storage/provider/src/traits/executor.rs | 19 +++++++------ 4 files changed, 24 insertions(+), 48 deletions(-) diff --git a/crates/revm/src/optimism/processor.rs b/crates/revm/src/optimism/processor.rs index f59da9abf..9fdbe45c9 100644 --- a/crates/revm/src/optimism/processor.rs +++ b/crates/revm/src/optimism/processor.rs @@ -45,15 +45,6 @@ where { type Error = BlockExecutionError; - fn execute( - &mut self, - block: &BlockWithSenders, - total_difficulty: U256, - ) -> Result<(), BlockExecutionError> { - let receipts = self.execute_inner(block, total_difficulty)?; - self.save_receipts(receipts) - } - fn execute_and_verify_receipt( &mut self, block: &BlockWithSenders, @@ -216,8 +207,8 @@ mod tests { test_utils::{StateProviderTest, TestEvmConfig}, }; use reth_primitives::{ - Account, Address, Block, ChainSpecBuilder, Header, Signature, StorageKey, StorageValue, - Transaction, TransactionKind, TransactionSigned, TxEip1559, BASE_MAINNET, + b256, Account, Address, Block, ChainSpecBuilder, Header, Signature, StorageKey, + StorageValue, Transaction, TransactionKind, TransactionSigned, TxEip1559, BASE_MAINNET, }; use revm::L1_BLOCK_CONTRACT; use std::{collections::HashMap, str::FromStr, sync::Arc}; @@ -269,7 +260,10 @@ mod tests { number: 1, gas_limit: 1_000_000, gas_used: 42_000, - ..Header::default() + receipts_root: b256!( + "83465d1e7d01578c0d609be33570f91242f013e9e295b0879905346abbd63731" + ), + ..Default::default() }; let mut db = create_op_state_provider(); @@ -306,7 +300,7 @@ mod tests { // Attempt to execute a block with one deposit and one non-deposit transaction executor - .execute( + .execute_and_verify_receipt( &BlockWithSenders { block: Block { header, @@ -340,7 +334,10 @@ mod tests { number: 1, gas_limit: 1_000_000, gas_used: 42_000, - ..Header::default() + receipts_root: b256!( + "fffc85c4004fd03c7bfbe5491fae98a7473126c099ac11e8286fd0013f15f908" + ), + ..Default::default() }; let mut db = create_op_state_provider(); @@ -377,7 +374,7 @@ mod tests { // attempt to execute an empty block with parent beacon block root, this should not fail executor - .execute( + .execute_and_verify_receipt( &BlockWithSenders { block: Block { header, diff --git a/crates/revm/src/processor.rs b/crates/revm/src/processor.rs index 198c80b04..1101eeaed 100644 --- a/crates/revm/src/processor.rs +++ b/crates/revm/src/processor.rs @@ -408,15 +408,6 @@ where { type Error = BlockExecutionError; - fn execute( - &mut self, - block: &BlockWithSenders, - total_difficulty: U256, - ) -> Result<(), BlockExecutionError> { - let receipts = self.execute_inner(block, total_difficulty)?; - self.save_receipts(receipts) - } - fn execute_and_verify_receipt( &mut self, block: &BlockWithSenders, @@ -660,7 +651,7 @@ mod tests { // Now execute a block with the fixed header, ensure that it does not fail executor - .execute( + .execute_and_verify_receipt( &BlockWithSenders { block: Block { header: header.clone(), @@ -854,7 +845,7 @@ mod tests { // now try to process the genesis block again, this time ensuring that a system contract // call does not occur executor - .execute( + .execute_and_verify_receipt( &BlockWithSenders { block: Block { header: header.clone(), @@ -913,7 +904,7 @@ mod tests { // Now execute a block with the fixed header, ensure that it does not fail executor - .execute( + .execute_and_verify_receipt( &BlockWithSenders { block: Block { header: header.clone(), diff --git a/crates/storage/provider/src/test_utils/executor.rs b/crates/storage/provider/src/test_utils/executor.rs index 99e65b0ec..8ac963e93 100644 --- a/crates/storage/provider/src/test_utils/executor.rs +++ b/crates/storage/provider/src/test_utils/executor.rs @@ -13,17 +13,6 @@ pub struct TestExecutor(pub Option); impl BlockExecutor for TestExecutor { type Error = BlockExecutionError; - fn execute( - &mut self, - _block: &BlockWithSenders, - _total_difficulty: U256, - ) -> Result<(), BlockExecutionError> { - if self.0.is_none() { - return Err(BlockExecutionError::UnavailableForTest) - } - Ok(()) - } - fn execute_and_verify_receipt( &mut self, _block: &BlockWithSenders, diff --git a/crates/storage/provider/src/traits/executor.rs b/crates/storage/provider/src/traits/executor.rs index 7a5f1c3cd..d36913da4 100644 --- a/crates/storage/provider/src/traits/executor.rs +++ b/crates/storage/provider/src/traits/executor.rs @@ -18,20 +18,18 @@ pub trait ExecutorFactory: Send + Sync + 'static { } /// An executor capable of executing a block. +/// +/// This type is capable of executing (multiple) blocks by applying the state changes made by each +/// block. The final state of the executor can extracted using +/// [take_output_state](BlockExecutor::take_output_state). pub trait BlockExecutor { /// The error type returned by the executor. type Error; - /// Execute a block. - fn execute( - &mut self, - block: &BlockWithSenders, - total_difficulty: U256, - ) -> Result<(), Self::Error>; - - /// Executes the block and checks receipts. + /// Executes the entire block and verifies: + /// - receipts (receipts root) /// - /// See [execute](BlockExecutor::execute) for more details. + /// This will update the state of the executor with the changes made by the block. fn execute_and_verify_receipt( &mut self, block: &BlockWithSenders, @@ -49,7 +47,8 @@ pub trait BlockExecutor { /// /// The second returned value represents the total gas used by this block of transactions. /// - /// See [execute](BlockExecutor::execute) for more details. + /// See [execute_and_verify_receipt](BlockExecutor::execute_and_verify_receipt) for more + /// details. fn execute_transactions( &mut self, block: &BlockWithSenders,