feat: add impl From BlockExecutionOutput for ExecutionOutcome (#10507)

This commit is contained in:
nk_ysg
2024-08-26 02:25:27 +08:00
committed by GitHub
parent dfcfe8d271
commit 5254f16e07
7 changed files with 33 additions and 44 deletions

View File

@ -15,7 +15,7 @@ use reth_cli_runner::CliContext;
use reth_consensus::Consensus;
use reth_db::DatabaseEnv;
use reth_errors::RethResult;
use reth_evm::execute::{BlockExecutionOutput, BlockExecutorProvider, Executor};
use reth_evm::execute::{BlockExecutorProvider, Executor};
use reth_execution_types::ExecutionOutcome;
use reth_fs_util as fs;
use reth_node_api::PayloadBuilderAttributes;
@ -273,15 +273,10 @@ impl Command {
let db = StateProviderDatabase::new(blockchain_db.latest()?);
let executor = block_executor!(provider_factory.chain_spec()).executor(db);
let BlockExecutionOutput { state, receipts, requests, .. } =
let block_execution_output =
executor.execute((&block_with_senders.clone().unseal(), U256::MAX).into())?;
let execution_outcome = ExecutionOutcome::new(
state,
receipts.into(),
block.number,
vec![requests.into()],
);
let execution_outcome =
ExecutionOutcome::from((block_execution_output, block.number));
debug!(target: "reth::cli", ?execution_outcome, "Executed block");
let hashed_post_state = execution_outcome.hash_state_slow();

View File

@ -10,7 +10,7 @@ use reth_cli_util::get_secret_key;
use reth_config::Config;
use reth_db::DatabaseEnv;
use reth_errors::BlockValidationError;
use reth_evm::execute::{BlockExecutionOutput, BlockExecutorProvider, Executor};
use reth_evm::execute::{BlockExecutorProvider, Executor};
use reth_execution_types::ExecutionOutcome;
use reth_network::{BlockDownloaderProvider, NetworkHandle};
use reth_network_api::NetworkInfo;
@ -136,7 +136,7 @@ impl Command {
let merkle_block_td =
provider.header_td_by_number(merkle_block_number)?.unwrap_or_default();
let BlockExecutionOutput { state, receipts, requests, .. } = executor.execute(
let block_execution_output = executor.execute(
(
&block
.clone()
@ -147,8 +147,7 @@ impl Command {
)
.into(),
)?;
let execution_outcome =
ExecutionOutcome::new(state, receipts.into(), block.number, vec![requests.into()]);
let execution_outcome = ExecutionOutcome::from((block_execution_output, block.number));
// Unpacked `BundleState::state_root_slow` function
let (in_memory_state_root, in_memory_updates) = StateRoot::overlay_root_with_updates(

View File

@ -11,7 +11,7 @@ use reth_blockchain_tree_api::{
};
use reth_consensus::{Consensus, ConsensusError, PostExecutionInput};
use reth_db_api::database::Database;
use reth_evm::execute::{BlockExecutionOutput, BlockExecutorProvider, Executor};
use reth_evm::execute::{BlockExecutorProvider, Executor};
use reth_execution_errors::BlockExecutionError;
use reth_execution_types::{Chain, ExecutionOutcome};
use reth_primitives::{
@ -210,13 +210,12 @@ impl AppendableChain {
let block = block.unseal();
let state = executor.execute((&block, U256::MAX).into())?;
let BlockExecutionOutput { state, receipts, requests, .. } = state;
externals
.consensus
.validate_block_post_execution(&block, PostExecutionInput::new(&receipts, &requests))?;
externals.consensus.validate_block_post_execution(
&block,
PostExecutionInput::new(&state.receipts, &state.requests),
)?;
let initial_execution_outcome =
ExecutionOutcome::new(state, receipts.into(), block.number, vec![requests.into()]);
let initial_execution_outcome = ExecutionOutcome::from((state, block.number));
// check state root if the block extends the canonical chain __and__ if state root
// validation was requested.

View File

@ -45,7 +45,7 @@ mod task;
pub use crate::client::AutoSealClient;
pub use mode::{FixedBlockTimeMiner, MiningMode, ReadyTransactionMiner};
use reth_evm::execute::{BlockExecutionOutput, BlockExecutorProvider, Executor};
use reth_evm::execute::{BlockExecutorProvider, Executor};
pub use task::MiningTask;
/// A consensus implementation intended for local development and testing purposes.
@ -374,19 +374,10 @@ impl StorageInner {
);
// execute the block
let BlockExecutionOutput {
state,
receipts,
requests: block_execution_requests,
gas_used,
..
} = executor.executor(&mut db).execute((&block, U256::ZERO).into())?;
let execution_outcome = ExecutionOutcome::new(
state,
receipts.into(),
block.number,
vec![block_execution_requests.into()],
);
let block_execution_output =
executor.executor(&mut db).execute((&block, U256::ZERO).into())?;
let gas_used = block_execution_output.gas_used;
let execution_outcome = ExecutionOutcome::from((block_execution_output, block.number));
// todo(onbjerg): we should not pass requests around as this is building a block, which
// means we need to extract the requests from the execution output and compute the requests

View File

@ -23,8 +23,8 @@ use reth_payload_builder::PayloadBuilderHandle;
use reth_payload_primitives::{PayloadAttributes, PayloadBuilderAttributes};
use reth_payload_validator::ExecutionPayloadValidator;
use reth_primitives::{
Block, BlockNumHash, BlockNumber, GotExpected, Header, Receipts, Requests, SealedBlock,
SealedBlockWithSenders, SealedHeader, B256, U256,
Block, BlockNumHash, BlockNumber, GotExpected, Header, SealedBlock, SealedBlockWithSenders,
SealedHeader, B256, U256,
};
use reth_provider::{
BlockReader, ExecutionOutcome, ProviderError, StateProviderBox, StateProviderFactory,
@ -1760,12 +1760,7 @@ where
let executed = ExecutedBlock {
block: sealed_block.clone(),
senders: Arc::new(block.senders),
execution_output: Arc::new(ExecutionOutcome::new(
output.state,
Receipts::from(output.receipts),
block_number,
vec![Requests::from(output.requests)],
)),
execution_output: Arc::new(ExecutionOutcome::from((output, block_number))),
hashed_state: Arc::new(hashed_state),
trie: Arc::new(trie_output),
};

View File

@ -26,8 +26,6 @@ impl<'a, Block> From<(&'a Block, U256)> for BlockExecutionInput<'a, Block> {
/// The output of an ethereum block.
///
/// Contains the state changes, transaction receipts, and total gas used in the block.
///
/// TODO(mattsse): combine with `ExecutionOutcome`
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct BlockExecutionOutput<T> {
/// The changed state of the block after execution.

View File

@ -1,3 +1,4 @@
use crate::BlockExecutionOutput;
use reth_primitives::{
logs_bloom, Account, Address, BlockNumber, Bloom, Bytecode, Log, Receipt, Receipts, Requests,
StorageEntry, B256, U256,
@ -355,6 +356,17 @@ impl ExecutionOutcome {
}
}
impl From<(BlockExecutionOutput<Receipt>, BlockNumber)> for ExecutionOutcome {
fn from(value: (BlockExecutionOutput<Receipt>, BlockNumber)) -> Self {
Self {
bundle: value.0.state,
receipts: Receipts::from(value.0.receipts),
first_block: value.1,
requests: vec![Requests::from(value.0.requests)],
}
}
}
#[cfg(test)]
mod tests {
use super::*;