1#![doc(
4 html_logo_url = "https://raw.githubusercontent.com/paradigmxyz/reth/main/assets/reth-docs.png",
5 html_favicon_url = "https://avatars0.githubusercontent.com/u/97369466?s=256",
6 issue_tracker_base_url = "https://github.com/paradigmxyz/reth/issues/"
7)]
8#![cfg_attr(not(test), warn(unused_crate_dependencies))]
9#![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))]
10#![cfg_attr(not(feature = "std"), no_std)]
11
12use core::{fmt::Debug, marker::PhantomData};
13pub use reth_primitives_traits::{
14 Block, BlockBody, FullBlock, FullNodePrimitives, FullReceipt, FullSignedTx, NodePrimitives,
15};
16
17use reth_chainspec::EthChainSpec;
18use reth_db_api::{database_metrics::DatabaseMetrics, Database};
19use reth_engine_primitives::EngineTypes;
20use reth_payload_primitives::{BuiltPayload, PayloadTypes};
21use reth_trie_db::StateCommitment;
22
23pub trait NodeTypes: Clone + Debug + Send + Sync + Unpin + 'static {
29 type Primitives: NodePrimitives;
31 type ChainSpec: EthChainSpec<Header = <Self::Primitives as NodePrimitives>::BlockHeader>;
33 type StateCommitment: StateCommitment;
35 type Storage: Default + Send + Sync + Unpin + Debug + 'static;
37 type Payload: PayloadTypes<BuiltPayload: BuiltPayload<Primitives = Self::Primitives>>;
39}
40
41pub trait NodeTypesWithDB: NodeTypes {
46 type DB: Database + DatabaseMetrics + Clone + Unpin + 'static;
48}
49
50#[derive(Clone, Debug, Default)]
52pub struct NodeTypesWithDBAdapter<Types, DB> {
53 types: PhantomData<Types>,
54 db: PhantomData<DB>,
55}
56
57impl<Types, DB> NodeTypesWithDBAdapter<Types, DB> {
58 pub fn new() -> Self {
60 Self { types: Default::default(), db: Default::default() }
61 }
62}
63
64impl<Types, DB> NodeTypes for NodeTypesWithDBAdapter<Types, DB>
65where
66 Types: NodeTypes,
67 DB: Clone + Debug + Send + Sync + Unpin + 'static,
68{
69 type Primitives = Types::Primitives;
70 type ChainSpec = Types::ChainSpec;
71 type StateCommitment = Types::StateCommitment;
72 type Storage = Types::Storage;
73 type Payload = Types::Payload;
74}
75
76impl<Types, DB> NodeTypesWithDB for NodeTypesWithDBAdapter<Types, DB>
77where
78 Types: NodeTypes,
79 DB: Database + DatabaseMetrics + Clone + Unpin + 'static,
80{
81 type DB = DB;
82}
83
84#[derive(Clone, Debug, Default)]
86pub struct AnyNodeTypes<P = (), C = (), SC = (), S = (), PL = ()>(
87 PhantomData<P>,
88 PhantomData<C>,
89 PhantomData<SC>,
90 PhantomData<S>,
91 PhantomData<PL>,
92);
93
94impl<P, C, SC, S, PL> AnyNodeTypes<P, C, SC, S, PL> {
95 pub const fn new() -> Self {
97 Self(PhantomData, PhantomData, PhantomData, PhantomData, PhantomData)
98 }
99
100 pub const fn primitives<T>(self) -> AnyNodeTypes<T, C, SC, S, PL> {
102 AnyNodeTypes::new()
103 }
104
105 pub const fn chain_spec<T>(self) -> AnyNodeTypes<P, T, SC, S, PL> {
107 AnyNodeTypes::new()
108 }
109
110 pub const fn state_commitment<T>(self) -> AnyNodeTypes<P, C, T, S, PL> {
112 AnyNodeTypes::new()
113 }
114
115 pub const fn storage<T>(self) -> AnyNodeTypes<P, C, SC, T, PL> {
117 AnyNodeTypes::new()
118 }
119
120 pub const fn payload<T>(self) -> AnyNodeTypes<P, C, SC, S, T> {
122 AnyNodeTypes::new()
123 }
124}
125
126impl<P, C, SC, S, PL> NodeTypes for AnyNodeTypes<P, C, SC, S, PL>
127where
128 P: NodePrimitives + Send + Sync + Unpin + 'static,
129 C: EthChainSpec<Header = P::BlockHeader> + Clone + 'static,
130 SC: StateCommitment,
131 S: Default + Clone + Send + Sync + Unpin + Debug + 'static,
132 PL: PayloadTypes<BuiltPayload: BuiltPayload<Primitives = P>> + Send + Sync + Unpin + 'static,
133{
134 type Primitives = P;
135 type ChainSpec = C;
136 type StateCommitment = SC;
137 type Storage = S;
138 type Payload = PL;
139}
140
141#[derive(Clone, Debug, Default)]
143pub struct AnyNodeTypesWithEngine<P = (), E = (), C = (), SC = (), S = (), PL = ()> {
144 _base: AnyNodeTypes<P, C, SC, S, PL>,
146 _engine: PhantomData<E>,
148}
149
150impl<P, E, C, SC, S, PL> AnyNodeTypesWithEngine<P, E, C, SC, S, PL> {
151 pub const fn new() -> Self {
153 Self { _base: AnyNodeTypes::new(), _engine: PhantomData }
154 }
155
156 pub const fn primitives<T>(self) -> AnyNodeTypesWithEngine<T, E, C, SC, S, PL> {
158 AnyNodeTypesWithEngine::new()
159 }
160
161 pub const fn engine<T>(self) -> AnyNodeTypesWithEngine<P, T, C, SC, S, PL> {
163 AnyNodeTypesWithEngine::new()
164 }
165
166 pub const fn chain_spec<T>(self) -> AnyNodeTypesWithEngine<P, E, T, SC, S, PL> {
168 AnyNodeTypesWithEngine::new()
169 }
170
171 pub const fn state_commitment<T>(self) -> AnyNodeTypesWithEngine<P, E, C, T, S, PL> {
173 AnyNodeTypesWithEngine::new()
174 }
175
176 pub const fn storage<T>(self) -> AnyNodeTypesWithEngine<P, E, C, SC, T, PL> {
178 AnyNodeTypesWithEngine::new()
179 }
180
181 pub const fn payload<T>(self) -> AnyNodeTypesWithEngine<P, E, C, SC, S, T> {
183 AnyNodeTypesWithEngine::new()
184 }
185}
186
187impl<P, E, C, SC, S, PL> NodeTypes for AnyNodeTypesWithEngine<P, E, C, SC, S, PL>
188where
189 P: NodePrimitives + Send + Sync + Unpin + 'static,
190 E: EngineTypes + Send + Sync + Unpin,
191 C: EthChainSpec<Header = P::BlockHeader> + Clone + 'static,
192 SC: StateCommitment,
193 S: Default + Clone + Send + Sync + Unpin + Debug + 'static,
194 PL: PayloadTypes<BuiltPayload: BuiltPayload<Primitives = P>> + Send + Sync + Unpin + 'static,
195{
196 type Primitives = P;
197 type ChainSpec = C;
198 type StateCommitment = SC;
199 type Storage = S;
200 type Payload = PL;
201}
202
203pub type BlockTy<N> = <PrimitivesTy<N> as NodePrimitives>::Block;
205
206pub type HeaderTy<N> = <PrimitivesTy<N> as NodePrimitives>::BlockHeader;
208
209pub type BodyTy<N> = <PrimitivesTy<N> as NodePrimitives>::BlockBody;
211
212pub type TxTy<N> = <PrimitivesTy<N> as NodePrimitives>::SignedTx;
214
215pub type ReceiptTy<N> = <PrimitivesTy<N> as NodePrimitives>::Receipt;
217
218pub type PrimitivesTy<N> = <N as NodeTypes>::Primitives;
220
221pub type KeyHasherTy<N> = <<N as NodeTypes>::StateCommitment as StateCommitment>::KeyHasher;