From a3015c8a3a0eac4a163ed1f35e366310c44a8800 Mon Sep 17 00:00:00 2001 From: Dan Cline <6798349+Rjected@users.noreply.github.com> Date: Wed, 22 Jan 2025 17:29:33 -0500 Subject: [PATCH] feat(sdk): introduce PrimitivesTy helper type (#13933) --- crates/e2e-test-utils/src/node.rs | 4 ++-- crates/ethereum/node/src/payload.rs | 4 ++-- crates/exex/exex/src/context.rs | 4 ++-- crates/exex/exex/src/dyn_context.rs | 4 ++-- crates/node/builder/src/components/builder.rs | 12 +++++------- crates/node/builder/src/components/consensus.rs | 10 ++++------ crates/node/builder/src/components/execute.rs | 10 +++++----- crates/node/builder/src/components/mod.rs | 10 ++++------ crates/node/builder/src/launch/exex.rs | 4 ++-- crates/node/types/src/lib.rs | 13 ++++++++----- crates/optimism/evm/src/execute.rs | 2 +- crates/optimism/node/src/node.rs | 4 ++-- 12 files changed, 39 insertions(+), 42 deletions(-) diff --git a/crates/e2e-test-utils/src/node.rs b/crates/e2e-test-utils/src/node.rs index e21b85e78..63aaf1bd1 100644 --- a/crates/e2e-test-utils/src/node.rs +++ b/crates/e2e-test-utils/src/node.rs @@ -11,7 +11,7 @@ use eyre::Ok; use futures_util::Future; use reth_chainspec::EthereumHardforks; use reth_network_api::test_utils::PeersHandleProvider; -use reth_node_api::{Block, BlockBody, BlockTy, EngineTypes, FullNodeComponents}; +use reth_node_api::{Block, BlockBody, BlockTy, EngineTypes, FullNodeComponents, PrimitivesTy}; use reth_node_builder::{rpc::RethRpcAddOns, FullNode, NodeTypes, NodeTypesWithEngine}; use reth_node_core::primitives::SignedTransaction; use reth_payload_primitives::{BuiltPayload, PayloadBuilderAttributes}; @@ -41,7 +41,7 @@ where pub engine_api: EngineApiTestContext< ::Engine, ::ChainSpec, - ::Primitives, + PrimitivesTy, >, /// Context for testing RPC features. pub rpc: RpcTestContext, diff --git a/crates/ethereum/node/src/payload.rs b/crates/ethereum/node/src/payload.rs index 9882bdc3b..52d0fe01d 100644 --- a/crates/ethereum/node/src/payload.rs +++ b/crates/ethereum/node/src/payload.rs @@ -8,7 +8,7 @@ use reth_ethereum_engine_primitives::{ use reth_ethereum_payload_builder::EthereumBuilderConfig; use reth_evm::ConfigureEvmFor; use reth_evm_ethereum::EthEvmConfig; -use reth_node_api::{FullNodeTypes, NodeTypesWithEngine, TxTy}; +use reth_node_api::{FullNodeTypes, NodeTypesWithEngine, PrimitivesTy, TxTy}; use reth_node_builder::{ components::PayloadServiceBuilder, BuilderContext, PayloadBuilderConfig, PayloadTypes, }; @@ -33,7 +33,7 @@ impl EthereumPayloadBuilder { where Types: NodeTypesWithEngine, Node: FullNodeTypes, - Evm: ConfigureEvmFor, + Evm: ConfigureEvmFor>, Pool: TransactionPool>> + Unpin + 'static, diff --git a/crates/exex/exex/src/context.rs b/crates/exex/exex/src/context.rs index deb6fa2bd..9d003dec7 100644 --- a/crates/exex/exex/src/context.rs +++ b/crates/exex/exex/src/context.rs @@ -1,6 +1,6 @@ use crate::{ExExContextDyn, ExExEvent, ExExNotifications, ExExNotificationsStream}; use reth_exex_types::ExExHead; -use reth_node_api::{FullNodeComponents, NodePrimitives, NodeTypes}; +use reth_node_api::{FullNodeComponents, NodePrimitives, NodeTypes, PrimitivesTy}; use reth_node_core::node_config::NodeConfig; use reth_primitives::Head; use reth_provider::BlockReader; @@ -62,7 +62,7 @@ where Node::Types: NodeTypes, { /// Returns dynamic version of the context - pub fn into_dyn(self) -> ExExContextDyn<::Primitives> { + pub fn into_dyn(self) -> ExExContextDyn> { ExExContextDyn::from(self) } } diff --git a/crates/exex/exex/src/dyn_context.rs b/crates/exex/exex/src/dyn_context.rs index 94f6ae81f..0578fbf63 100644 --- a/crates/exex/exex/src/dyn_context.rs +++ b/crates/exex/exex/src/dyn_context.rs @@ -4,7 +4,7 @@ use std::fmt::Debug; use reth_chainspec::{EthChainSpec, Head}; -use reth_node_api::{FullNodeComponents, HeaderTy, NodePrimitives, NodeTypes}; +use reth_node_api::{FullNodeComponents, HeaderTy, NodePrimitives, NodeTypes, PrimitivesTy}; use reth_node_core::node_config::NodeConfig; use reth_primitives::EthPrimitives; use reth_provider::BlockReader; @@ -50,7 +50,7 @@ impl Debug for ExExContextDyn { } } -impl From> for ExExContextDyn<::Primitives> +impl From> for ExExContextDyn> where Node: FullNodeComponents>, Node::Provider: Debug + BlockReader, diff --git a/crates/node/builder/src/components/builder.rs b/crates/node/builder/src/components/builder.rs index 84e310e74..a9576d8c1 100644 --- a/crates/node/builder/src/components/builder.rs +++ b/crates/node/builder/src/components/builder.rs @@ -10,7 +10,7 @@ use crate::{ use reth_consensus::{ConsensusError, FullConsensus}; use reth_evm::{execute::BlockExecutorProvider, ConfigureEvmFor}; use reth_network::NetworkPrimitives; -use reth_node_api::{BlockTy, BodyTy, HeaderTy, NodeTypes, NodeTypesWithEngine, TxTy}; +use reth_node_api::{BlockTy, BodyTy, HeaderTy, NodeTypesWithEngine, PrimitivesTy, TxTy}; use reth_payload_builder::PayloadBuilderHandle; use reth_transaction_pool::{PoolTransaction, TransactionPool}; use std::{future::Future, marker::PhantomData}; @@ -405,12 +405,10 @@ where Pool: TransactionPool>> + Unpin + 'static, - EVM: ConfigureEvmFor<::Primitives>, - Executor: BlockExecutorProvider::Primitives>, - Cons: FullConsensus<::Primitives, Error = ConsensusError> - + Clone - + Unpin - + 'static, + EVM: ConfigureEvmFor>, + Executor: BlockExecutorProvider>, + Cons: + FullConsensus, Error = ConsensusError> + Clone + Unpin + 'static, { type Components = Components; diff --git a/crates/node/builder/src/components/consensus.rs b/crates/node/builder/src/components/consensus.rs index 0620b2507..426d932e0 100644 --- a/crates/node/builder/src/components/consensus.rs +++ b/crates/node/builder/src/components/consensus.rs @@ -1,6 +1,6 @@ //! Consensus component for the node builder. use reth_consensus::{ConsensusError, FullConsensus}; -use reth_node_api::NodeTypes; +use reth_node_api::PrimitivesTy; use crate::{BuilderContext, FullNodeTypes}; use std::future::Future; @@ -8,7 +8,7 @@ use std::future::Future; /// A type that knows how to build the consensus implementation. pub trait ConsensusBuilder: Send { /// The consensus implementation to build. - type Consensus: FullConsensus<::Primitives, Error = ConsensusError> + type Consensus: FullConsensus, Error = ConsensusError> + Clone + Unpin + 'static; @@ -23,10 +23,8 @@ pub trait ConsensusBuilder: Send { impl ConsensusBuilder for F where Node: FullNodeTypes, - Consensus: FullConsensus<::Primitives, Error = ConsensusError> - + Clone - + Unpin - + 'static, + Consensus: + FullConsensus, Error = ConsensusError> + Clone + Unpin + 'static, F: FnOnce(&BuilderContext) -> Fut + Send, Fut: Future> + Send, { diff --git a/crates/node/builder/src/components/execute.rs b/crates/node/builder/src/components/execute.rs index 04cb93169..038f647ef 100644 --- a/crates/node/builder/src/components/execute.rs +++ b/crates/node/builder/src/components/execute.rs @@ -1,7 +1,7 @@ //! EVM component for the node builder. use crate::{BuilderContext, FullNodeTypes}; use reth_evm::{execute::BlockExecutorProvider, ConfigureEvmFor}; -use reth_node_api::NodeTypes; +use reth_node_api::PrimitivesTy; use std::future::Future; /// A type that knows how to build the executor types. @@ -9,10 +9,10 @@ pub trait ExecutorBuilder: Send { /// The EVM config to use. /// /// This provides the node with the necessary configuration to configure an EVM. - type EVM: ConfigureEvmFor<::Primitives>; + type EVM: ConfigureEvmFor>; /// The type that knows how to execute blocks. - type Executor: BlockExecutorProvider::Primitives>; + type Executor: BlockExecutorProvider>; /// Creates the EVM config. fn build_evm( @@ -24,8 +24,8 @@ pub trait ExecutorBuilder: Send { impl ExecutorBuilder for F where Node: FullNodeTypes, - EVM: ConfigureEvmFor<::Primitives>, - Executor: BlockExecutorProvider::Primitives>, + EVM: ConfigureEvmFor>, + Executor: BlockExecutorProvider>, F: FnOnce(&BuilderContext) -> Fut + Send, Fut: Future> + Send, { diff --git a/crates/node/builder/src/components/mod.rs b/crates/node/builder/src/components/mod.rs index 384dc6658..538427289 100644 --- a/crates/node/builder/src/components/mod.rs +++ b/crates/node/builder/src/components/mod.rs @@ -28,7 +28,7 @@ use reth_evm::{execute::BlockExecutorProvider, ConfigureEvmFor}; use reth_network::{NetworkHandle, NetworkPrimitives}; use reth_network_api::FullNetwork; use reth_node_api::{ - BlockTy, BodyTy, HeaderTy, NodeTypes, NodeTypesWithEngine, PayloadBuilder, TxTy, + BlockTy, BodyTy, HeaderTy, NodeTypes, NodeTypesWithEngine, PayloadBuilder, PrimitivesTy, TxTy, }; use reth_payload_builder::PayloadBuilderHandle; use reth_transaction_pool::{PoolTransaction, TransactionPool}; @@ -112,11 +112,9 @@ where + Unpin + 'static, EVM: ConfigureEvm
, Transaction = TxTy>, - Executor: BlockExecutorProvider::Primitives>, - Cons: FullConsensus<::Primitives, Error = ConsensusError> - + Clone - + Unpin - + 'static, + Executor: BlockExecutorProvider>, + Cons: + FullConsensus, Error = ConsensusError> + Clone + Unpin + 'static, { type Pool = Pool; type Evm = EVM; diff --git a/crates/node/builder/src/launch/exex.rs b/crates/node/builder/src/launch/exex.rs index 0235dd929..de84b68f8 100644 --- a/crates/node/builder/src/launch/exex.rs +++ b/crates/node/builder/src/launch/exex.rs @@ -9,7 +9,7 @@ use reth_exex::{ ExExContext, ExExHandle, ExExManager, ExExManagerHandle, ExExNotificationSource, Wal, DEFAULT_EXEX_MANAGER_CAPACITY, }; -use reth_node_api::{FullNodeComponents, NodeTypes}; +use reth_node_api::{FullNodeComponents, NodeTypes, PrimitivesTy}; use reth_primitives::Head; use reth_provider::CanonStateSubscriptions; use reth_tracing::tracing::{debug, info}; @@ -42,7 +42,7 @@ impl ExExLauncher { /// installed. pub async fn launch( self, - ) -> eyre::Result::Primitives>>> { + ) -> eyre::Result>>> { let Self { head, extensions, components, config_container } = self; if extensions.is_empty() { diff --git a/crates/node/types/src/lib.rs b/crates/node/types/src/lib.rs index 8cdf9015f..a63257582 100644 --- a/crates/node/types/src/lib.rs +++ b/crates/node/types/src/lib.rs @@ -234,16 +234,19 @@ where } /// Helper adapter type for accessing [`NodePrimitives::Block`] on [`NodeTypes`]. -pub type BlockTy = <::Primitives as NodePrimitives>::Block; +pub type BlockTy = as NodePrimitives>::Block; /// Helper adapter type for accessing [`NodePrimitives::BlockHeader`] on [`NodeTypes`]. -pub type HeaderTy = <::Primitives as NodePrimitives>::BlockHeader; +pub type HeaderTy = as NodePrimitives>::BlockHeader; /// Helper adapter type for accessing [`NodePrimitives::BlockBody`] on [`NodeTypes`]. -pub type BodyTy = <::Primitives as NodePrimitives>::BlockBody; +pub type BodyTy = as NodePrimitives>::BlockBody; /// Helper adapter type for accessing [`NodePrimitives::SignedTx`] on [`NodeTypes`]. -pub type TxTy = <::Primitives as NodePrimitives>::SignedTx; +pub type TxTy = as NodePrimitives>::SignedTx; /// Helper adapter type for accessing [`NodePrimitives::Receipt`] on [`NodeTypes`]. -pub type ReceiptTy = <::Primitives as NodePrimitives>::Receipt; +pub type ReceiptTy = as NodePrimitives>::Receipt; + +/// Helper type for getting the `Primitives` associated type from a [`NodeTypes`]. +pub type PrimitivesTy = ::Primitives; diff --git a/crates/optimism/evm/src/execute.rs b/crates/optimism/evm/src/execute.rs index 2b222ee4f..b453dfbbf 100644 --- a/crates/optimism/evm/src/execute.rs +++ b/crates/optimism/evm/src/execute.rs @@ -73,7 +73,7 @@ where Receipt = OpReceipt, SignedTx: OpTransaction, >, - EvmConfig: Clone + Unpin + Sync + Send + 'static + ConfigureEvmFor, + EvmConfig: ConfigureEvmFor + Clone + Unpin + Sync + Send + 'static, { type Primitives = N; type Strategy + Display>> = diff --git a/crates/optimism/node/src/node.rs b/crates/optimism/node/src/node.rs index 32507347a..831fa78f5 100644 --- a/crates/optimism/node/src/node.rs +++ b/crates/optimism/node/src/node.rs @@ -11,7 +11,7 @@ use reth_basic_payload_builder::{BasicPayloadJobGenerator, BasicPayloadJobGenera use reth_chainspec::{EthChainSpec, Hardforks}; use reth_evm::{execute::BasicBlockExecutorProvider, ConfigureEvmFor}; use reth_network::{NetworkConfig, NetworkHandle, NetworkManager, NetworkPrimitives, PeersInfo}; -use reth_node_api::{AddOnsContext, FullNodeComponents, NodeAddOns, TxTy}; +use reth_node_api::{AddOnsContext, FullNodeComponents, NodeAddOns, PrimitivesTy, TxTy}; use reth_node_builder::{ components::{ ComponentsBuilder, ConsensusBuilder, ExecutorBuilder, NetworkBuilder, @@ -484,7 +484,7 @@ where Pool: TransactionPool>> + Unpin + 'static, - Evm: ConfigureEvmFor<::Primitives>, + Evm: ConfigureEvmFor>, { let payload_builder = reth_optimism_payload_builder::OpPayloadBuilder::with_builder_config( evm_config,