diff --git a/Cargo.lock b/Cargo.lock index 9dcdc61ea4db9..698ce0320bb33 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -7226,6 +7226,7 @@ dependencies = [ "alloy-rpc-types-engine", "auto_impl", "futures", + "reth-chain-state", "reth-errors", "reth-execution-types", "reth-payload-builder-primitives", diff --git a/crates/engine/primitives/Cargo.toml b/crates/engine/primitives/Cargo.toml index 13ac3612937af..7f5c6c1cb2e57 100644 --- a/crates/engine/primitives/Cargo.toml +++ b/crates/engine/primitives/Cargo.toml @@ -17,6 +17,7 @@ reth-payload-primitives.workspace = true reth-payload-builder-primitives.workspace = true reth-primitives.workspace = true reth-primitives-traits.workspace = true +reth-chain-state.workspace = true reth-trie.workspace = true reth-errors.workspace = true diff --git a/crates/engine/primitives/src/event.rs b/crates/engine/primitives/src/event.rs index 1afed370d1bf8..f5bd56ce1a81e 100644 --- a/crates/engine/primitives/src/event.rs +++ b/crates/engine/primitives/src/event.rs @@ -1,7 +1,7 @@ //! Events emitted by the beacon consensus engine. use crate::ForkchoiceStatus; -use alloc::{boxed::Box, sync::Arc}; +use alloc::boxed::Box; use alloy_consensus::BlockHeader; use alloy_primitives::B256; use alloy_rpc_types_engine::ForkchoiceState; @@ -9,7 +9,8 @@ use core::{ fmt::{Display, Formatter, Result}, time::Duration, }; -use reth_primitives::{EthPrimitives, SealedBlock}; +use reth_chain_state::ExecutedBlock; +use reth_primitives::EthPrimitives; use reth_primitives_traits::{NodePrimitives, SealedHeader}; /// Events emitted by the consensus engine. @@ -18,9 +19,9 @@ pub enum BeaconConsensusEngineEvent { /// The fork choice state was updated, and the current fork choice status ForkchoiceUpdated(ForkchoiceState, ForkchoiceStatus), /// A block was added to the fork chain. - ForkBlockAdded(Arc>, Duration), + ForkBlockAdded(ExecutedBlock, Duration), /// A block was added to the canonical chain, and the elapsed time validating the block - CanonicalBlockAdded(Arc>, Duration), + CanonicalBlockAdded(ExecutedBlock, Duration), /// A canonical chain was committed, and the elapsed time committing the data CanonicalChainCommitted(Box>, Duration), /// The consensus engine is involved in live sync, and has specific progress @@ -48,10 +49,14 @@ where write!(f, "ForkchoiceUpdated({state:?}, {status:?})") } Self::ForkBlockAdded(block, duration) => { - write!(f, "ForkBlockAdded({:?}, {duration:?})", block.num_hash()) + write!(f, "ForkBlockAdded({:?}, {duration:?})", block.recovered_block.num_hash()) } Self::CanonicalBlockAdded(block, duration) => { - write!(f, "CanonicalBlockAdded({:?}, {duration:?})", block.num_hash()) + write!( + f, + "CanonicalBlockAdded({:?}, {duration:?})", + block.recovered_block.num_hash() + ) } Self::CanonicalChainCommitted(block, duration) => { write!(f, "CanonicalChainCommitted({:?}, {duration:?})", block.num_hash()) diff --git a/crates/engine/primitives/src/lib.rs b/crates/engine/primitives/src/lib.rs index 708c83d33395d..394d731bb84bc 100644 --- a/crates/engine/primitives/src/lib.rs +++ b/crates/engine/primitives/src/lib.rs @@ -11,14 +11,21 @@ extern crate alloc; +use alloy_consensus::BlockHeader; +use alloy_eips::{eip7685::Requests, Decodable2718}; use alloy_primitives::B256; -use reth_payload_primitives::{BuiltPayload, PayloadAttributes}; -mod error; - +use alloy_rpc_types_engine::{ExecutionPayloadSidecar, PayloadError}; use core::fmt::{self, Debug}; +use reth_payload_primitives::{ + validate_execution_requests, BuiltPayload, EngineApiMessageVersion, + EngineObjectValidationError, InvalidPayloadAttributesError, PayloadAttributes, + PayloadOrAttributes, PayloadTypes, +}; +use reth_primitives::{NodePrimitives, SealedBlock}; +use reth_primitives_traits::Block; +use serde::{de::DeserializeOwned, Deserialize, Serialize}; -use alloy_consensus::BlockHeader; -use alloy_rpc_types_engine::{ExecutionPayloadSidecar, PayloadError}; +mod error; pub use error::*; mod forkchoice; @@ -33,15 +40,6 @@ pub use event::*; mod invalid_block_hook; pub use invalid_block_hook::InvalidBlockHook; -use alloy_eips::{eip7685::Requests, Decodable2718}; -use reth_payload_primitives::{ - validate_execution_requests, EngineApiMessageVersion, EngineObjectValidationError, - InvalidPayloadAttributesError, PayloadOrAttributes, PayloadTypes, -}; -use reth_primitives::{NodePrimitives, SealedBlock}; -use reth_primitives_traits::Block; -use serde::{de::DeserializeOwned, Deserialize, Serialize}; - /// Struct aggregating [`alloy_rpc_types_engine::ExecutionPayload`] and [`ExecutionPayloadSidecar`] /// and encapsulating complete payload supplied for execution. #[derive(Debug, Clone, Serialize, Deserialize)] diff --git a/crates/engine/tree/src/tree/mod.rs b/crates/engine/tree/src/tree/mod.rs index cbfa51662bc4c..865477dadcda0 100644 --- a/crates/engine/tree/src/tree/mod.rs +++ b/crates/engine/tree/src/tree/mod.rs @@ -1392,12 +1392,11 @@ where self.canonical_in_memory_state.set_pending_block(block.clone()); } - let sealed_block = Arc::new(block.sealed_block().clone()); - self.state.tree_state.insert_executed(block); + self.state.tree_state.insert_executed(block.clone()); self.metrics.engine.inserted_already_executed_blocks.increment(1); self.emit_event(EngineApiEvent::BeaconConsensus( BeaconConsensusEngineEvent::CanonicalBlockAdded( - sealed_block, + block.block, now.elapsed(), ), )); @@ -2409,8 +2408,6 @@ where return Err(e.into()) } - let sealed_block = Arc::new(block.clone_sealed_block()); - // We only run the parallel state root if we are currently persisting blocks that are all // ancestors of the one we are executing. If we're committing ancestor blocks, then: any // trie updates being committed are a subset of the in-memory trie updates collected before @@ -2558,7 +2555,7 @@ where self.handle_state_root_result( state_root_handle, state_root_config, - sealed_block.as_ref(), + block.sealed_block(), &hashed_state, &state_provider, root_time, @@ -2617,8 +2614,7 @@ where // prewarm tasks are still running at this point however drop(prewarm_task_lock.write().unwrap()); // apply state updates to cache and save it (if saving was successful) - self.most_recent_cache = - state_provider.save_cache(sealed_block.hash(), &output.state).ok(); + self.most_recent_cache = state_provider.save_cache(block.hash(), &output.state).ok(); let elapsed = save_cache_start.elapsed(); // record how long it took to save caches @@ -2641,15 +2637,15 @@ where self.canonical_in_memory_state.set_pending_block(executed.clone()); } - self.state.tree_state.insert_executed(executed); + self.state.tree_state.insert_executed(executed.clone()); self.metrics.engine.executed_blocks.set(self.state.tree_state.block_count() as f64); // emit insert event let elapsed = start.elapsed(); let engine_event = if self.is_fork(block_num_hash.hash)? { - BeaconConsensusEngineEvent::ForkBlockAdded(sealed_block, elapsed) + BeaconConsensusEngineEvent::ForkBlockAdded(executed.block, elapsed) } else { - BeaconConsensusEngineEvent::CanonicalBlockAdded(sealed_block, elapsed) + BeaconConsensusEngineEvent::CanonicalBlockAdded(executed.block, elapsed) }; self.emit_event(EngineApiEvent::BeaconConsensus(engine_event));