feat(sdk): introduce PrimitivesTy helper type (#13933)

This commit is contained in:
Dan Cline
2025-01-22 17:29:33 -05:00
committed by GitHub
parent 05b4205243
commit a3015c8a3a
12 changed files with 39 additions and 42 deletions

View File

@ -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<Transaction: PoolTransaction<Consensus = TxTy<Node::Types>>>
+ Unpin
+ 'static,
EVM: ConfigureEvmFor<<Node::Types as NodeTypes>::Primitives>,
Executor: BlockExecutorProvider<Primitives = <Node::Types as NodeTypes>::Primitives>,
Cons: FullConsensus<<Node::Types as NodeTypes>::Primitives, Error = ConsensusError>
+ Clone
+ Unpin
+ 'static,
EVM: ConfigureEvmFor<PrimitivesTy<Node::Types>>,
Executor: BlockExecutorProvider<Primitives = PrimitivesTy<Node::Types>>,
Cons:
FullConsensus<PrimitivesTy<Node::Types>, Error = ConsensusError> + Clone + Unpin + 'static,
{
type Components = Components<Node, N, Pool, EVM, Executor, Cons>;

View File

@ -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<Node: FullNodeTypes>: Send {
/// The consensus implementation to build.
type Consensus: FullConsensus<<Node::Types as NodeTypes>::Primitives, Error = ConsensusError>
type Consensus: FullConsensus<PrimitivesTy<Node::Types>, Error = ConsensusError>
+ Clone
+ Unpin
+ 'static;
@ -23,10 +23,8 @@ pub trait ConsensusBuilder<Node: FullNodeTypes>: Send {
impl<Node, F, Fut, Consensus> ConsensusBuilder<Node> for F
where
Node: FullNodeTypes,
Consensus: FullConsensus<<Node::Types as NodeTypes>::Primitives, Error = ConsensusError>
+ Clone
+ Unpin
+ 'static,
Consensus:
FullConsensus<PrimitivesTy<Node::Types>, Error = ConsensusError> + Clone + Unpin + 'static,
F: FnOnce(&BuilderContext<Node>) -> Fut + Send,
Fut: Future<Output = eyre::Result<Consensus>> + Send,
{

View File

@ -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<Node: FullNodeTypes>: Send {
/// The EVM config to use.
///
/// This provides the node with the necessary configuration to configure an EVM.
type EVM: ConfigureEvmFor<<Node::Types as NodeTypes>::Primitives>;
type EVM: ConfigureEvmFor<PrimitivesTy<Node::Types>>;
/// The type that knows how to execute blocks.
type Executor: BlockExecutorProvider<Primitives = <Node::Types as NodeTypes>::Primitives>;
type Executor: BlockExecutorProvider<Primitives = PrimitivesTy<Node::Types>>;
/// Creates the EVM config.
fn build_evm(
@ -24,8 +24,8 @@ pub trait ExecutorBuilder<Node: FullNodeTypes>: Send {
impl<Node, F, Fut, EVM, Executor> ExecutorBuilder<Node> for F
where
Node: FullNodeTypes,
EVM: ConfigureEvmFor<<Node::Types as NodeTypes>::Primitives>,
Executor: BlockExecutorProvider<Primitives = <Node::Types as NodeTypes>::Primitives>,
EVM: ConfigureEvmFor<PrimitivesTy<Node::Types>>,
Executor: BlockExecutorProvider<Primitives = PrimitivesTy<Node::Types>>,
F: FnOnce(&BuilderContext<Node>) -> Fut + Send,
Fut: Future<Output = eyre::Result<(EVM, Executor)>> + Send,
{

View File

@ -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<Header = HeaderTy<Node::Types>, Transaction = TxTy<Node::Types>>,
Executor: BlockExecutorProvider<Primitives = <Node::Types as NodeTypes>::Primitives>,
Cons: FullConsensus<<Node::Types as NodeTypes>::Primitives, Error = ConsensusError>
+ Clone
+ Unpin
+ 'static,
Executor: BlockExecutorProvider<Primitives = PrimitivesTy<Node::Types>>,
Cons:
FullConsensus<PrimitivesTy<Node::Types>, Error = ConsensusError> + Clone + Unpin + 'static,
{
type Pool = Pool;
type Evm = EVM;

View File

@ -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<Node: FullNodeComponents + Clone> ExExLauncher<Node> {
/// installed.
pub async fn launch(
self,
) -> eyre::Result<Option<ExExManagerHandle<<Node::Types as NodeTypes>::Primitives>>> {
) -> eyre::Result<Option<ExExManagerHandle<PrimitivesTy<Node::Types>>>> {
let Self { head, extensions, components, config_container } = self;
if extensions.is_empty() {

View File

@ -234,16 +234,19 @@ where
}
/// Helper adapter type for accessing [`NodePrimitives::Block`] on [`NodeTypes`].
pub type BlockTy<N> = <<N as NodeTypes>::Primitives as NodePrimitives>::Block;
pub type BlockTy<N> = <PrimitivesTy<N> as NodePrimitives>::Block;
/// Helper adapter type for accessing [`NodePrimitives::BlockHeader`] on [`NodeTypes`].
pub type HeaderTy<N> = <<N as NodeTypes>::Primitives as NodePrimitives>::BlockHeader;
pub type HeaderTy<N> = <PrimitivesTy<N> as NodePrimitives>::BlockHeader;
/// Helper adapter type for accessing [`NodePrimitives::BlockBody`] on [`NodeTypes`].
pub type BodyTy<N> = <<N as NodeTypes>::Primitives as NodePrimitives>::BlockBody;
pub type BodyTy<N> = <PrimitivesTy<N> as NodePrimitives>::BlockBody;
/// Helper adapter type for accessing [`NodePrimitives::SignedTx`] on [`NodeTypes`].
pub type TxTy<N> = <<N as NodeTypes>::Primitives as NodePrimitives>::SignedTx;
pub type TxTy<N> = <PrimitivesTy<N> as NodePrimitives>::SignedTx;
/// Helper adapter type for accessing [`NodePrimitives::Receipt`] on [`NodeTypes`].
pub type ReceiptTy<N> = <<N as NodeTypes>::Primitives as NodePrimitives>::Receipt;
pub type ReceiptTy<N> = <PrimitivesTy<N> as NodePrimitives>::Receipt;
/// Helper type for getting the `Primitives` associated type from a [`NodeTypes`].
pub type PrimitivesTy<N> = <N as NodeTypes>::Primitives;