From 639f4be255eda93f9950d052f6e4b83904817d06 Mon Sep 17 00:00:00 2001 From: maskpp Date: Fri, 1 Nov 2024 09:10:35 +0800 Subject: [PATCH] update BlockExecutionInput struct --- .../src/commands/debug_cmd/build_block.rs | 2 +- .../commands/debug_cmd/in_memory_merkle.rs | 2 +- bin/reth/src/commands/debug_cmd/merkle.rs | 2 +- crates/blockchain-tree/src/chain.rs | 4 +-- crates/consensus/auto-seal/src/lib.rs | 4 +-- crates/engine/tree/src/tree/mod.rs | 4 +-- crates/ethereum/evm/src/execute.rs | 8 +++--- crates/evm/execution-types/src/execute.rs | 28 +++++++++++++++---- crates/evm/src/execute.rs | 2 +- crates/evm/src/metrics.rs | 12 ++++++-- crates/exex/exex/src/backfill/job.rs | 8 +++--- crates/exex/exex/src/backfill/test_utils.rs | 18 ++++++++---- crates/optimism/evm/src/execute.rs | 8 +++--- crates/rpc/rpc/src/debug.rs | 2 +- crates/stages/stages/src/stages/execution.rs | 4 +-- 15 files changed, 71 insertions(+), 37 deletions(-) diff --git a/bin/reth/src/commands/debug_cmd/build_block.rs b/bin/reth/src/commands/debug_cmd/build_block.rs index 455d8356aff9..20edaf28753b 100644 --- a/bin/reth/src/commands/debug_cmd/build_block.rs +++ b/bin/reth/src/commands/debug_cmd/build_block.rs @@ -261,7 +261,7 @@ impl> Command { EthExecutorProvider::ethereum(provider_factory.chain_spec()).executor(db); let block_execution_output = - executor.execute((&block_with_senders.clone().unseal(), U256::MAX).into())?; + executor.execute((&mut block_with_senders.clone().unseal(), U256::MAX).into())?; let execution_outcome = ExecutionOutcome::from((block_execution_output, block.number)); debug!(target: "reth::cli", ?execution_outcome, "Executed block"); diff --git a/bin/reth/src/commands/debug_cmd/in_memory_merkle.rs b/bin/reth/src/commands/debug_cmd/in_memory_merkle.rs index 51851c0b0ad2..2305868ed147 100644 --- a/bin/reth/src/commands/debug_cmd/in_memory_merkle.rs +++ b/bin/reth/src/commands/debug_cmd/in_memory_merkle.rs @@ -142,7 +142,7 @@ impl> Command { provider.header_td_by_number(merkle_block_number)?.unwrap_or_default(); let block_execution_output = executor.execute( ( - &block + &mut block .clone() .unseal() .with_recovered_senders() diff --git a/bin/reth/src/commands/debug_cmd/merkle.rs b/bin/reth/src/commands/debug_cmd/merkle.rs index 8e02a52eaf07..c1229ec4c3f3 100644 --- a/bin/reth/src/commands/debug_cmd/merkle.rs +++ b/bin/reth/src/commands/debug_cmd/merkle.rs @@ -158,7 +158,7 @@ impl> Command { provider_rw.static_file_provider().clone(), ), )); - executor.execute_and_verify_one((&sealed_block.clone().unseal(), td).into())?; + executor.execute_and_verify_one((&mut sealed_block.clone().unseal(), td).into())?; let execution_outcome = executor.finalize(); let mut storage_writer = UnifiedStorageWriter::from_database(&provider_rw); diff --git a/crates/blockchain-tree/src/chain.rs b/crates/blockchain-tree/src/chain.rs index 393e525d5ae2..f2657f235035 100644 --- a/crates/blockchain-tree/src/chain.rs +++ b/crates/blockchain-tree/src/chain.rs @@ -206,9 +206,9 @@ impl AppendableChain { let db = StateProviderDatabase::new(&provider); let executor = externals.executor_factory.executor(db); let block_hash = block.hash(); - let block = block.unseal(); + let mut block = block.unseal(); - let state = executor.execute((&block, U256::MAX).into())?; + let state = executor.execute((&mut block, U256::MAX).into())?; externals.consensus.validate_block_post_execution( &block, PostExecutionInput::new(&state.receipts, &state.requests), diff --git a/crates/consensus/auto-seal/src/lib.rs b/crates/consensus/auto-seal/src/lib.rs index f1ef64c8c0fa..634762710c99 100644 --- a/crates/consensus/auto-seal/src/lib.rs +++ b/crates/consensus/auto-seal/src/lib.rs @@ -368,7 +368,7 @@ impl StorageInner { &chain_spec, ); - let block = Block { + let mut block = Block { header, body: BlockBody { transactions, @@ -388,7 +388,7 @@ impl StorageInner { // execute the block let block_execution_output = - executor.executor(&mut db).execute((&block, U256::ZERO).into())?; + executor.executor(&mut db).execute((&mut block, U256::ZERO).into())?; let gas_used = block_execution_output.gas_used; let execution_outcome = ExecutionOutcome::from((block_execution_output, block.number)); let hashed_state = HashedPostState::from_bundle_state(&execution_outcome.state().state); diff --git a/crates/engine/tree/src/tree/mod.rs b/crates/engine/tree/src/tree/mod.rs index 3eadbbd522db..9a0c0c7382c1 100644 --- a/crates/engine/tree/src/tree/mod.rs +++ b/crates/engine/tree/src/tree/mod.rs @@ -2174,10 +2174,10 @@ where let block_number = block.number; let block_hash = block.hash(); let sealed_block = Arc::new(block.block.clone()); - let block = block.unseal(); + let mut block = block.unseal(); let exec_time = Instant::now(); - let output = self.metrics.executor.execute_metered(executor, (&block, U256::MAX).into())?; + let output = self.metrics.executor.execute_metered(executor, (&mut block, U256::MAX).into())?; trace!(target: "engine::tree", elapsed=?exec_time.elapsed(), ?block_number, "Executed block"); if let Err(err) = self.consensus.validate_block_post_execution( diff --git a/crates/ethereum/evm/src/execute.rs b/crates/ethereum/evm/src/execute.rs index 6513cf75fad5..31411924364d 100644 --- a/crates/ethereum/evm/src/execute.rs +++ b/crates/ethereum/evm/src/execute.rs @@ -362,7 +362,7 @@ where /// /// Returns an error if the block could not be executed or failed verification. fn execute(mut self, input: Self::Input<'_>) -> Result { - let BlockExecutionInput { block, total_difficulty } = input; + let BlockExecutionInput { block, total_difficulty, .. } = input; let EthExecuteOutput { receipts, requests, gas_used } = self.execute_without_verification(block, total_difficulty)?; @@ -380,7 +380,7 @@ where where F: FnMut(&State), { - let BlockExecutionInput { block, total_difficulty } = input; + let BlockExecutionInput { block, total_difficulty, .. } = input; let EthExecuteOutput { receipts, requests, gas_used } = self.execute_without_verification(block, total_difficulty)?; @@ -398,7 +398,7 @@ where where F: OnStateHook, { - let BlockExecutionInput { block, total_difficulty } = input; + let BlockExecutionInput { block, total_difficulty, .. } = input; let EthExecuteOutput { receipts, requests, gas_used } = self .execute_without_verification_with_state_hook( block, @@ -442,7 +442,7 @@ where type Error = BlockExecutionError; fn execute_and_verify_one(&mut self, input: Self::Input<'_>) -> Result<(), Self::Error> { - let BlockExecutionInput { block, total_difficulty } = input; + let BlockExecutionInput { block, total_difficulty, .. } = input; if self.batch_record.first_block().is_none() { self.batch_record.set_first_block(block.number); diff --git a/crates/evm/execution-types/src/execute.rs b/crates/evm/execution-types/src/execute.rs index 0cf5d7050793..22ee3fd5b581 100644 --- a/crates/evm/execution-types/src/execute.rs +++ b/crates/evm/execution-types/src/execute.rs @@ -6,20 +6,38 @@ use revm::db::BundleState; #[derive(Debug)] pub struct BlockExecutionInput<'a, Block> { /// The block to execute. - pub block: &'a Block, + pub block: &'a mut Block, /// The total difficulty of the block. pub total_difficulty: U256, + /// Enable anchor transaction. + pub enable_anchor: bool, + /// Enable skip invalid transaction. + pub enable_skip: bool, + /// Enable build transaction lists. + pub enable_build: bool, + /// Max compressed bytes. + pub max_bytes_per_tx_list: u64, + /// Max length of transactions list. + pub max_transactions_lists: u64, } impl<'a, Block> BlockExecutionInput<'a, Block> { /// Creates a new input. - pub const fn new(block: &'a Block, total_difficulty: U256) -> Self { - Self { block, total_difficulty } + pub fn new(block: &'a mut Block, total_difficulty: U256) -> Self { + Self { + block, + total_difficulty, + enable_anchor: false, + enable_skip: false, + enable_build: false, + max_bytes_per_tx_list: 0, + max_transactions_lists: 0, + } } } -impl<'a, Block> From<(&'a Block, U256)> for BlockExecutionInput<'a, Block> { - fn from((block, total_difficulty): (&'a Block, U256)) -> Self { +impl<'a, Block> From<(&'a mut Block, U256)> for BlockExecutionInput<'a, Block> { + fn from((block, total_difficulty): (&'a mut Block, U256)) -> Self { Self::new(block, total_difficulty) } } diff --git a/crates/evm/src/execute.rs b/crates/evm/src/execute.rs index 145eca29c92b..28e97bf76d0d 100644 --- a/crates/evm/src/execute.rs +++ b/crates/evm/src/execute.rs @@ -257,6 +257,6 @@ mod tests { let provider = TestExecutorProvider; let db = CacheDB::>::default(); let executor = provider.executor(db); - let _ = executor.execute(BlockExecutionInput::new(&Default::default(), U256::ZERO)); + let _ = executor.execute(BlockExecutionInput::new(&mut Default::default(), U256::ZERO)); } } diff --git a/crates/evm/src/metrics.rs b/crates/evm/src/metrics.rs index fbb2b858b158..7a5be3511d85 100644 --- a/crates/evm/src/metrics.rs +++ b/crates/evm/src/metrics.rs @@ -78,7 +78,7 @@ impl ExecutorMetrics { Error = Error, >, { - let output = self.metered(input.block, || { + let output = self.metered(&input.block.clone(), || { executor.execute_with_state_closure(input, |state: &revm::db::State| { // Update the metrics for the number of accounts, storage slots and bytecodes // loaded @@ -120,6 +120,14 @@ impl ExecutorMetrics { where F: FnOnce(BlockExecutionInput<'_, BlockWithSenders>) -> R, { - self.metered(input.block, || f(input)) + self.metered(input.block, || f(BlockExecutionInput { + block: &mut input.block.clone(), + total_difficulty: Default::default(), + enable_anchor: false, + enable_skip: false, + enable_build: false, + max_bytes_per_tx_list: 0, + max_transactions_lists: 0, + })) } } diff --git a/crates/exex/exex/src/backfill/job.rs b/crates/exex/exex/src/backfill/job.rs index 77a7b50477b0..542ca165a837 100644 --- a/crates/exex/exex/src/backfill/job.rs +++ b/crates/exex/exex/src/backfill/job.rs @@ -111,10 +111,10 @@ where // Unseal the block for execution let (block, senders) = block.into_components(); let (unsealed_header, hash) = block.header.split(); - let block = + let mut block = Block { header: unsealed_header, body: block.body }.with_senders_unchecked(senders); - executor.execute_and_verify_one((&block, td).into())?; + executor.execute_and_verify_one((&mut block, td).into())?; execution_duration += execute_start.elapsed(); // TODO(alexey): report gas metrics using `block.header.gas_used` @@ -196,7 +196,7 @@ where .ok_or_else(|| ProviderError::HeaderNotFound(block_number.into()))?; // Fetch the block with senders for execution. - let block_with_senders = self + let mut block_with_senders = self .provider .block_with_senders(block_number.into(), TransactionVariant::WithHash)? .ok_or_else(|| ProviderError::HeaderNotFound(block_number.into()))?; @@ -208,7 +208,7 @@ where trace!(target: "exex::backfill", number = block_number, txs = block_with_senders.block.body.transactions.len(), "Executing block"); - let block_execution_output = executor.execute((&block_with_senders, td).into())?; + let block_execution_output = executor.execute((&mut block_with_senders, td).into())?; Ok((block_with_senders, block_execution_output)) } diff --git a/crates/exex/exex/src/backfill/test_utils.rs b/crates/exex/exex/src/backfill/test_utils.rs index 1c793975c755..f43ccdc31764 100644 --- a/crates/exex/exex/src/backfill/test_utils.rs +++ b/crates/exex/exex/src/backfill/test_utils.rs @@ -55,7 +55,7 @@ pub(crate) fn chain_spec(address: Address) -> Arc { pub(crate) fn execute_block_and_commit_to_database( provider_factory: &ProviderFactory, chain_spec: Arc, - block: &BlockWithSenders, + block: &mut BlockWithSenders, ) -> eyre::Result> where N: ProviderNodeTypes, @@ -68,7 +68,15 @@ where provider.tx_ref(), provider.static_file_provider(), ))) - .execute(BlockExecutionInput { block, total_difficulty: U256::ZERO })?; + .execute(BlockExecutionInput { + block, + total_difficulty: U256::ZERO, + enable_anchor: false, + enable_skip: false, + enable_build: false, + max_bytes_per_tx_list: 0, + max_transactions_lists: 0, + })?; block_execution_output.state.reverts.sort(); // Convert the block execution output to an execution outcome for committing to the database @@ -167,12 +175,12 @@ pub(crate) fn blocks_and_execution_outputs( where N: ProviderNodeTypes, { - let (block1, block2) = blocks(chain_spec.clone(), key_pair)?; + let (mut block1, mut block2) = blocks(chain_spec.clone(), key_pair)?; let block_output1 = - execute_block_and_commit_to_database(&provider_factory, chain_spec.clone(), &block1)?; + execute_block_and_commit_to_database(&provider_factory, chain_spec.clone(), &mut block1)?; let block_output2 = - execute_block_and_commit_to_database(&provider_factory, chain_spec, &block2)?; + execute_block_and_commit_to_database(&provider_factory, chain_spec, &mut block2)?; let block1 = block1.seal_slow(); let block2 = block2.seal_slow(); diff --git a/crates/optimism/evm/src/execute.rs b/crates/optimism/evm/src/execute.rs index 2491e99b5038..3a66c4cb9133 100644 --- a/crates/optimism/evm/src/execute.rs +++ b/crates/optimism/evm/src/execute.rs @@ -367,7 +367,7 @@ where /// /// State changes are committed to the database. fn execute(mut self, input: Self::Input<'_>) -> Result { - let BlockExecutionInput { block, total_difficulty } = input; + let BlockExecutionInput { block, total_difficulty, .. } = input; let (receipts, gas_used) = self.execute_without_verification(block, total_difficulty)?; // NOTE: we need to merge keep the reverts for the bundle retention @@ -389,7 +389,7 @@ where where F: FnMut(&State), { - let BlockExecutionInput { block, total_difficulty } = input; + let BlockExecutionInput { block, total_difficulty, .. } = input; let (receipts, gas_used) = self.execute_without_verification(block, total_difficulty)?; // NOTE: we need to merge keep the reverts for the bundle retention @@ -412,7 +412,7 @@ where where F: OnStateHook, { - let BlockExecutionInput { block, total_difficulty } = input; + let BlockExecutionInput { block, total_difficulty, .. } = input; let (receipts, gas_used) = self.execute_without_verification_with_state_hook( block, total_difficulty, @@ -464,7 +464,7 @@ where type Error = BlockExecutionError; fn execute_and_verify_one(&mut self, input: Self::Input<'_>) -> Result<(), Self::Error> { - let BlockExecutionInput { block, total_difficulty } = input; + let BlockExecutionInput { block, total_difficulty, .. } = input; if self.batch_record.first_block().is_none() { self.batch_record.set_first_block(block.number); diff --git a/crates/rpc/rpc/src/debug.rs b/crates/rpc/rpc/src/debug.rs index b26459c4f040..6bd73806f2d7 100644 --- a/crates/rpc/rpc/src/debug.rs +++ b/crates/rpc/rpc/src/debug.rs @@ -613,7 +613,7 @@ where let _ = block_executor .execute_with_state_closure( - (&block.clone().unseal(), block.difficulty).into(), + (&mut block.clone().unseal(), block.difficulty).into(), |statedb| { codes = statedb .cache diff --git a/crates/stages/stages/src/stages/execution.rs b/crates/stages/stages/src/stages/execution.rs index 7bb6ebc59e09..e43166cbf1e8 100644 --- a/crates/stages/stages/src/stages/execution.rs +++ b/crates/stages/stages/src/stages/execution.rs @@ -275,8 +275,8 @@ where // Execute the block let execute_start = Instant::now(); - self.metrics.metered_one((&block, td).into(), |input| { - let sealed = block.header.clone().seal_slow(); + self.metrics.metered_one((&mut block.clone(), td).into(), |input| { + let sealed = block.clone().header.clone().seal_slow(); let (header, seal) = sealed.into_parts(); executor.execute_and_verify_one(input).map_err(|error| StageError::Block {