From d709c8a0d2704b485c10319a3b62377d1aad0d2a Mon Sep 17 00:00:00 2001 From: Matthias Seitz Date: Tue, 28 Jan 2025 11:24:29 +0100 Subject: [PATCH] chore: use BlockNumHash in exex (#14015) --- crates/exex/exex/src/context.rs | 4 +-- crates/exex/exex/src/dyn_context.rs | 8 +++--- crates/exex/exex/src/manager.rs | 35 +++++++++++++------------- crates/exex/exex/src/notifications.rs | 33 ++++++++---------------- crates/exex/test-utils/src/lib.rs | 10 ++------ crates/node/builder/src/launch/exex.rs | 5 ++-- 6 files changed, 39 insertions(+), 56 deletions(-) diff --git a/crates/exex/exex/src/context.rs b/crates/exex/exex/src/context.rs index 9d003dec7..e48abed6d 100644 --- a/crates/exex/exex/src/context.rs +++ b/crates/exex/exex/src/context.rs @@ -1,8 +1,8 @@ use crate::{ExExContextDyn, ExExEvent, ExExNotifications, ExExNotificationsStream}; +use alloy_eips::BlockNumHash; use reth_exex_types::ExExHead; use reth_node_api::{FullNodeComponents, NodePrimitives, NodeTypes, PrimitivesTy}; use reth_node_core::node_config::NodeConfig; -use reth_primitives::Head; use reth_provider::BlockReader; use reth_tasks::TaskExecutor; use std::fmt::Debug; @@ -11,7 +11,7 @@ use tokio::sync::mpsc::UnboundedSender; /// Captures the context that an `ExEx` has access to. pub struct ExExContext { /// The current head of the blockchain at launch. - pub head: Head, + pub head: BlockNumHash, /// The config of the node pub config: NodeConfig<::ChainSpec>, /// The loaded node config diff --git a/crates/exex/exex/src/dyn_context.rs b/crates/exex/exex/src/dyn_context.rs index 0578fbf63..de01f70e5 100644 --- a/crates/exex/exex/src/dyn_context.rs +++ b/crates/exex/exex/src/dyn_context.rs @@ -1,13 +1,13 @@ //! Mirrored version of [`ExExContext`](`crate::ExExContext`) //! without generic abstraction over [Node](`reth_node_api::FullNodeComponents`) -use std::fmt::Debug; - -use reth_chainspec::{EthChainSpec, Head}; +use alloy_eips::BlockNumHash; +use reth_chainspec::EthChainSpec; use reth_node_api::{FullNodeComponents, HeaderTy, NodePrimitives, NodeTypes, PrimitivesTy}; use reth_node_core::node_config::NodeConfig; use reth_primitives::EthPrimitives; use reth_provider::BlockReader; +use std::fmt::Debug; use tokio::sync::mpsc; use crate::{ExExContext, ExExEvent, ExExNotificationsStream}; @@ -16,7 +16,7 @@ use crate::{ExExContext, ExExEvent, ExExNotificationsStream}; /// Captures the context that an `ExEx` has access to. pub struct ExExContextDyn { /// The current head of the blockchain at launch. - pub head: Head, + pub head: BlockNumHash, /// The config of the node pub config: NodeConfig + 'static>>, /// The loaded node config diff --git a/crates/exex/exex/src/manager.rs b/crates/exex/exex/src/manager.rs index 0d232e3ef..967075679 100644 --- a/crates/exex/exex/src/manager.rs +++ b/crates/exex/exex/src/manager.rs @@ -7,7 +7,6 @@ use futures::StreamExt; use itertools::Itertools; use metrics::Gauge; use reth_chain_state::ForkChoiceStream; -use reth_chainspec::Head; use reth_evm::execute::BlockExecutorProvider; use reth_metrics::{metrics::Counter, Metrics}; use reth_node_api::NodePrimitives; @@ -96,7 +95,7 @@ impl ExExHandle { /// [`mpsc::Receiver`] for [`ExExNotification`]s that should be given to the `ExEx`. pub fn new>( id: String, - node_head: Head, + node_head: BlockNumHash, provider: P, executor: E, wal_handle: WalHandle, @@ -685,7 +684,7 @@ mod tests { let (mut exex_handle, event_tx, mut _notification_rx) = ExExHandle::new( "test_exex".to_string(), - Head::default(), + Default::default(), (), MockExecutorProvider::default(), wal.handle(), @@ -705,7 +704,7 @@ mod tests { let (exex_handle_1, _, _) = ExExHandle::new( "test_exex_1".to_string(), - Head::default(), + Default::default(), (), MockExecutorProvider::default(), wal.handle(), @@ -727,7 +726,7 @@ mod tests { let (exex_handle_1, _, _) = ExExHandle::new( "test_exex_1".to_string(), - Head::default(), + Default::default(), (), MockExecutorProvider::default(), wal.handle(), @@ -755,7 +754,7 @@ mod tests { let (exex_handle, _, _) = ExExHandle::new( "test_exex".to_string(), - Head::default(), + Default::default(), (), MockExecutorProvider::default(), wal.handle(), @@ -810,7 +809,7 @@ mod tests { let (exex_handle, _, _) = ExExHandle::new( "test_exex".to_string(), - Head::default(), + Default::default(), (), MockExecutorProvider::default(), wal.handle(), @@ -861,7 +860,7 @@ mod tests { let (exex_handle, event_tx, mut _notification_rx) = ExExHandle::new( "test_exex".to_string(), - Head::default(), + Default::default(), (), MockExecutorProvider::default(), wal.handle(), @@ -916,14 +915,14 @@ mod tests { // Create two `ExExHandle` instances let (exex_handle1, event_tx1, _) = ExExHandle::new( "test_exex1".to_string(), - Head::default(), + Default::default(), (), MockExecutorProvider::default(), wal.handle(), ); let (exex_handle2, event_tx2, _) = ExExHandle::new( "test_exex2".to_string(), - Head::default(), + Default::default(), (), MockExecutorProvider::default(), wal.handle(), @@ -973,14 +972,14 @@ mod tests { // Create two `ExExHandle` instances let (exex_handle1, event_tx1, _) = ExExHandle::new( "test_exex1".to_string(), - Head::default(), + Default::default(), (), MockExecutorProvider::default(), wal.handle(), ); let (exex_handle2, event_tx2, _) = ExExHandle::new( "test_exex2".to_string(), - Head::default(), + Default::default(), (), MockExecutorProvider::default(), wal.handle(), @@ -1036,7 +1035,7 @@ mod tests { let (exex_handle_1, _, _) = ExExHandle::new( "test_exex_1".to_string(), - Head::default(), + Default::default(), (), MockExecutorProvider::default(), wal.handle(), @@ -1105,7 +1104,7 @@ mod tests { let (mut exex_handle, _, mut notifications) = ExExHandle::new( "test_exex".to_string(), - Head::default(), + Default::default(), provider, EthExecutorProvider::mainnet(), wal.handle(), @@ -1160,7 +1159,7 @@ mod tests { let (mut exex_handle, _, mut notifications) = ExExHandle::new( "test_exex".to_string(), - Head::default(), + Default::default(), provider, EthExecutorProvider::mainnet(), wal.handle(), @@ -1210,7 +1209,7 @@ mod tests { let (mut exex_handle, _, mut notifications) = ExExHandle::new( "test_exex".to_string(), - Head::default(), + Default::default(), provider, EthExecutorProvider::mainnet(), wal.handle(), @@ -1253,7 +1252,7 @@ mod tests { let (mut exex_handle, _, mut notifications) = ExExHandle::new( "test_exex".to_string(), - Head::default(), + Default::default(), provider, EthExecutorProvider::mainnet(), wal.handle(), @@ -1313,7 +1312,7 @@ mod tests { let (exex_handle, events_tx, mut notifications) = ExExHandle::new( "test_exex".to_string(), - Head::default(), + Default::default(), provider.clone(), EthExecutorProvider::mainnet(), wal.handle(), diff --git a/crates/exex/exex/src/notifications.rs b/crates/exex/exex/src/notifications.rs index f9f5dfc91..892b48181 100644 --- a/crates/exex/exex/src/notifications.rs +++ b/crates/exex/exex/src/notifications.rs @@ -1,7 +1,7 @@ use crate::{BackfillJobFactory, ExExNotification, StreamBackfillJob, WalHandle}; use alloy_consensus::BlockHeader; +use alloy_eips::BlockNumHash; use futures::{Stream, StreamExt}; -use reth_chainspec::Head; use reth_evm::execute::BlockExecutorProvider; use reth_exex_types::ExExHead; use reth_node_api::NodePrimitives; @@ -84,7 +84,7 @@ where { /// Creates a new stream of [`ExExNotifications`] without a head. pub const fn new( - node_head: Head, + node_head: BlockNumHash, provider: P, executor: E, notifications: Receiver>, @@ -183,7 +183,7 @@ pub struct ExExNotificationsWithoutHead where E: BlockExecutorProvider, { - node_head: Head, + node_head: BlockNumHash, provider: P, executor: E, notifications: Receiver>, @@ -209,7 +209,7 @@ where { /// Creates a new instance of [`ExExNotificationsWithoutHead`]. const fn new( - node_head: Head, + node_head: BlockNumHash, provider: P, executor: E, notifications: Receiver>, @@ -255,7 +255,7 @@ pub struct ExExNotificationsWithHead where E: BlockExecutorProvider, { - node_head: Head, + node_head: BlockNumHash, provider: P, executor: E, notifications: Receiver>, @@ -277,7 +277,7 @@ where { /// Creates a new [`ExExNotificationsWithHead`]. const fn new( - node_head: Head, + node_head: BlockNumHash, provider: P, executor: E, notifications: Receiver>, @@ -477,11 +477,7 @@ mod tests { .insert_block(node_head_block.clone().try_recover()?, StorageLocation::Database)?; provider_rw.commit()?; - let node_head = Head { - number: node_head_block.number, - hash: node_head_block.hash(), - ..Default::default() - }; + let node_head = node_head_block.num_hash(); let exex_head = ExExHead { block: BlockNumHash { number: genesis_block.number, hash: genesis_hash } }; @@ -546,10 +542,8 @@ mod tests { let provider = BlockchainProvider::new(provider_factory)?; - let node_head = - Head { number: genesis_block.number, hash: genesis_hash, ..Default::default() }; - let exex_head = - ExExHead { block: BlockNumHash { number: node_head.number, hash: node_head.hash } }; + let node_head = BlockNumHash { number: genesis_block.number, hash: genesis_hash }; + let exex_head = ExExHead { block: node_head }; let notification = ExExNotification::ChainCommitted { new: Arc::new(Chain::new( @@ -608,11 +602,7 @@ mod tests { BlockParams { parent: Some(genesis_hash), tx_count: Some(0), ..Default::default() }, ) .try_recover()?; - let node_head = Head { - number: node_head_block.number, - hash: node_head_block.hash(), - ..Default::default() - }; + let node_head = node_head_block.num_hash(); let provider_rw = provider.database_provider_rw()?; provider_rw.insert_block(node_head_block, StorageLocation::Database)?; provider_rw.commit()?; @@ -711,8 +701,7 @@ mod tests { }; wal.commit(&exex_head_notification)?; - let node_head = - Head { number: genesis_block.number, hash: genesis_hash, ..Default::default() }; + let node_head = BlockNumHash { number: genesis_block.number, hash: genesis_hash }; let exex_head = ExExHead { block: BlockNumHash { number: exex_head_block.number, hash: exex_head_block.hash() }, }; diff --git a/crates/exex/test-utils/src/lib.rs b/crates/exex/test-utils/src/lib.rs index 60970999b..b29353d15 100644 --- a/crates/exex/test-utils/src/lib.rs +++ b/crates/exex/test-utils/src/lib.rs @@ -45,7 +45,7 @@ use reth_node_ethereum::{ EthEngineTypes, EthEvmConfig, }; use reth_payload_builder::noop::NoopPayloadBuilderService; -use reth_primitives::{EthPrimitives, Head, RecoveredBlock, TransactionSigned}; +use reth_primitives::{EthPrimitives, RecoveredBlock, TransactionSigned}; use reth_primitives_traits::Block as _; use reth_provider::{ providers::{BlockchainProvider, StaticFileProvider}, @@ -308,13 +308,7 @@ pub async fn test_exex_context_with_chain_spec( .seal_slow() .try_recover()?; - let head = Head { - number: genesis.number, - hash: genesis_hash, - difficulty: genesis.difficulty, - timestamp: genesis.timestamp, - total_difficulty: Default::default(), - }; + let head = genesis.num_hash(); let wal_directory = tempfile::tempdir()?; let wal = Wal::new(wal_directory.path())?; diff --git a/crates/node/builder/src/launch/exex.rs b/crates/node/builder/src/launch/exex.rs index de84b68f8..337a92cf5 100644 --- a/crates/node/builder/src/launch/exex.rs +++ b/crates/node/builder/src/launch/exex.rs @@ -1,7 +1,6 @@ //! Support for launching execution extensions. -use std::{fmt, fmt::Debug}; - +use alloy_eips::BlockNumHash; use futures::future; use reth_chain_state::ForkChoiceSubscriptions; use reth_chainspec::EthChainSpec; @@ -13,6 +12,7 @@ use reth_node_api::{FullNodeComponents, NodeTypes, PrimitivesTy}; use reth_primitives::Head; use reth_provider::CanonStateSubscriptions; use reth_tracing::tracing::{debug, info}; +use std::{fmt, fmt::Debug}; use tracing::Instrument; use crate::{common::WithConfigs, exex::BoxedLaunchExEx}; @@ -44,6 +44,7 @@ impl ExExLauncher { self, ) -> eyre::Result>>> { let Self { head, extensions, components, config_container } = self; + let head = BlockNumHash::new(head.number, head.hash); if extensions.is_empty() { // nothing to launch