From e1bb94633c5d35bf1ab6c76a8e8615749fe80071 Mon Sep 17 00:00:00 2001 From: joshie <93316087+joshieDo@users.noreply.github.com> Date: Tue, 12 Nov 2024 16:41:20 +0900 Subject: [PATCH 1/2] move (Full)NodePrimitives to primitive-traits --- crates/node/types/src/lib.rs | 41 +++------------------------- crates/primitives-traits/src/lib.rs | 4 +++ crates/primitives-traits/src/node.rs | 37 +++++++++++++++++++++++++ 3 files changed, 45 insertions(+), 37 deletions(-) create mode 100644 crates/primitives-traits/src/node.rs diff --git a/crates/node/types/src/lib.rs b/crates/node/types/src/lib.rs index f2bd16280f88..f8770a3c0147 100644 --- a/crates/node/types/src/lib.rs +++ b/crates/node/types/src/lib.rs @@ -9,9 +9,11 @@ #![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))] #![cfg_attr(not(feature = "std"), no_std)] -pub use reth_primitives_traits::{Block, BlockBody, FullBlock, FullReceipt, FullSignedTx}; +pub use reth_primitives_traits::{ + Block, BlockBody, FullBlock, FullNodePrimitives, FullReceipt, FullSignedTx, NodePrimitives, +}; -use core::{fmt, marker::PhantomData}; +use core::marker::PhantomData; use reth_chainspec::EthChainSpec; use reth_db_api::{ @@ -21,41 +23,6 @@ use reth_db_api::{ use reth_engine_primitives::EngineTypes; use reth_trie_db::StateCommitment; -/// Configures all the primitive types of the node. -pub trait NodePrimitives: Send + Sync + Unpin + Clone + Default + fmt::Debug { - /// Block primitive. - type Block: Send + Sync + Unpin + Clone + Default + fmt::Debug + 'static; - /// Signed version of the transaction type. - type SignedTx: Send + Sync + Unpin + Clone + Default + fmt::Debug + 'static; - /// A receipt. - type Receipt: Send + Sync + Unpin + Clone + Default + fmt::Debug + 'static; -} - -impl NodePrimitives for () { - type Block = (); - type SignedTx = (); - type Receipt = (); -} - -/// Helper trait that sets trait bounds on [`NodePrimitives`]. -pub trait FullNodePrimitives: Send + Sync + Unpin + Clone + Default + fmt::Debug { - /// Block primitive. - type Block: FullBlock>; - /// Signed version of the transaction type. - type SignedTx: FullSignedTx; - /// A receipt. - type Receipt: FullReceipt; -} - -impl NodePrimitives for T -where - T: FullNodePrimitives, -{ - type Block = T::Block; - type SignedTx = T::SignedTx; - type Receipt = T::Receipt; -} - /// The type that configures the essential types of an Ethereum-like node. /// /// This includes the primitive types of a node and chain specification. diff --git a/crates/primitives-traits/src/lib.rs b/crates/primitives-traits/src/lib.rs index 6fcb725cfa49..babc0f42e0b0 100644 --- a/crates/primitives-traits/src/lib.rs +++ b/crates/primitives-traits/src/lib.rs @@ -77,3 +77,7 @@ pub mod serde_bincode_compat { /// Heuristic size trait pub mod size; pub use size::InMemorySize; + +/// Node traits +pub mod node; +pub use node::{FullNodePrimitives, NodePrimitives}; diff --git a/crates/primitives-traits/src/node.rs b/crates/primitives-traits/src/node.rs new file mode 100644 index 000000000000..73b790687a8f --- /dev/null +++ b/crates/primitives-traits/src/node.rs @@ -0,0 +1,37 @@ +use crate::{BlockBody, FullBlock, FullReceipt, FullSignedTx}; +use core::fmt; + +/// Configures all the primitive types of the node. +pub trait NodePrimitives: Send + Sync + Unpin + Clone + Default + fmt::Debug { + /// Block primitive. + type Block: Send + Sync + Unpin + Clone + Default + fmt::Debug + 'static; + /// Signed version of the transaction type. + type SignedTx: Send + Sync + Unpin + Clone + Default + fmt::Debug + 'static; + /// A receipt. + type Receipt: Send + Sync + Unpin + Clone + Default + fmt::Debug + 'static; +} + +impl NodePrimitives for () { + type Block = (); + type SignedTx = (); + type Receipt = (); +} + +/// Helper trait that sets trait bounds on [`NodePrimitives`]. +pub trait FullNodePrimitives: Send + Sync + Unpin + Clone + Default + fmt::Debug { + /// Block primitive. + type Block: FullBlock>; + /// Signed version of the transaction type. + type SignedTx: FullSignedTx; + /// A receipt. + type Receipt: FullReceipt; +} + +impl NodePrimitives for T +where + T: FullNodePrimitives, +{ + type Block = T::Block; + type SignedTx = T::SignedTx; + type Receipt = T::Receipt; +} From d519cdecad5af2070f74cd5157f5b405cf857df6 Mon Sep 17 00:00:00 2001 From: joshieDo <93316087+joshieDo@users.noreply.github.com> Date: Tue, 12 Nov 2024 16:44:13 +0700 Subject: [PATCH 2/2] Update crates/primitives-traits/src/node.rs Co-authored-by: Emilia Hane --- crates/primitives-traits/src/node.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/crates/primitives-traits/src/node.rs b/crates/primitives-traits/src/node.rs index 73b790687a8f..921942841d4e 100644 --- a/crates/primitives-traits/src/node.rs +++ b/crates/primitives-traits/src/node.rs @@ -1,6 +1,7 @@ -use crate::{BlockBody, FullBlock, FullReceipt, FullSignedTx}; use core::fmt; +use crate::{BlockBody, FullBlock, FullReceipt, FullSignedTx}; + /// Configures all the primitive types of the node. pub trait NodePrimitives: Send + Sync + Unpin + Clone + Default + fmt::Debug { /// Block primitive.