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/SeismicSystems/seismic-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::{
19 database_metrics::{DatabaseMetadata, DatabaseMetrics},
20 Database,
21};
22use reth_engine_primitives::EngineTypes;
23use reth_trie_db::StateCommitment;
24
25pub trait NodeTypes: Send + Sync + Unpin + 'static {
31 type Primitives: NodePrimitives;
33 type ChainSpec: EthChainSpec<Header = <Self::Primitives as NodePrimitives>::BlockHeader>;
35 type StateCommitment: StateCommitment;
37 type Storage: Default + Send + Sync + Unpin + Debug + 'static;
39}
40
41pub trait NodeTypesWithEngine: NodeTypes {
43 type Engine: EngineTypes;
45}
46
47pub trait NodeTypesWithDB: NodeTypes {
52 type DB: Database + DatabaseMetrics + DatabaseMetadata + Clone + Unpin + 'static;
54}
55
56#[derive(Debug)]
58pub struct NodeTypesWithDBAdapter<Types, DB> {
59 types: PhantomData<Types>,
60 db: PhantomData<DB>,
61}
62
63impl<Types, DB> NodeTypesWithDBAdapter<Types, DB> {
64 pub fn new() -> Self {
66 Self { types: Default::default(), db: Default::default() }
67 }
68}
69
70impl<Types, DB> Default for NodeTypesWithDBAdapter<Types, DB> {
71 fn default() -> Self {
72 Self::new()
73 }
74}
75
76impl<Types, DB> Clone for NodeTypesWithDBAdapter<Types, DB> {
77 fn clone(&self) -> Self {
78 Self { types: self.types, db: self.db }
79 }
80}
81
82impl<Types, DB> NodeTypes for NodeTypesWithDBAdapter<Types, DB>
83where
84 Types: NodeTypes,
85 DB: Send + Sync + Unpin + 'static,
86{
87 type Primitives = Types::Primitives;
88 type ChainSpec = Types::ChainSpec;
89 type StateCommitment = Types::StateCommitment;
90 type Storage = Types::Storage;
91}
92
93impl<Types, DB> NodeTypesWithEngine for NodeTypesWithDBAdapter<Types, DB>
94where
95 Types: NodeTypesWithEngine,
96 DB: Send + Sync + Unpin + 'static,
97{
98 type Engine = Types::Engine;
99}
100
101impl<Types, DB> NodeTypesWithDB for NodeTypesWithDBAdapter<Types, DB>
102where
103 Types: NodeTypes,
104 DB: Database + DatabaseMetrics + DatabaseMetadata + Clone + Unpin + 'static,
105{
106 type DB = DB;
107}
108
109#[derive(Debug)]
111pub struct AnyNodeTypes<P = (), C = (), SC = (), S = ()>(
112 PhantomData<P>,
113 PhantomData<C>,
114 PhantomData<SC>,
115 PhantomData<S>,
116);
117
118impl<P, C, SC, S> Default for AnyNodeTypes<P, C, SC, S> {
119 fn default() -> Self {
120 Self::new()
121 }
122}
123
124impl<P, C, SC, S> AnyNodeTypes<P, C, SC, S> {
125 pub const fn new() -> Self {
127 Self(PhantomData, PhantomData, PhantomData, PhantomData)
128 }
129
130 pub const fn primitives<T>(self) -> AnyNodeTypes<T, C, SC, S> {
132 AnyNodeTypes::new()
133 }
134
135 pub const fn chain_spec<T>(self) -> AnyNodeTypes<P, T, SC, S> {
137 AnyNodeTypes::new()
138 }
139
140 pub const fn state_commitment<T>(self) -> AnyNodeTypes<P, C, T, S> {
142 AnyNodeTypes::new()
143 }
144
145 pub const fn storage<T>(self) -> AnyNodeTypes<P, C, SC, T> {
147 AnyNodeTypes::new()
148 }
149}
150
151impl<P, C, SC, S> NodeTypes for AnyNodeTypes<P, C, SC, S>
152where
153 P: NodePrimitives + Send + Sync + Unpin + 'static,
154 C: EthChainSpec<Header = P::BlockHeader> + 'static,
155 SC: StateCommitment,
156 S: Default + Send + Sync + Unpin + Debug + 'static,
157{
158 type Primitives = P;
159 type ChainSpec = C;
160 type StateCommitment = SC;
161 type Storage = S;
162}
163
164#[derive(Debug)]
166pub struct AnyNodeTypesWithEngine<P = (), E = (), C = (), SC = (), S = ()> {
167 _base: AnyNodeTypes<P, C, SC, S>,
169 _engine: PhantomData<E>,
171}
172
173impl<P, E, C, SC, S> Default for AnyNodeTypesWithEngine<P, E, C, SC, S> {
174 fn default() -> Self {
175 Self::new()
176 }
177}
178
179impl<P, E, C, SC, S> AnyNodeTypesWithEngine<P, E, C, SC, S> {
180 pub const fn new() -> Self {
182 Self { _base: AnyNodeTypes::new(), _engine: PhantomData }
183 }
184
185 pub const fn primitives<T>(self) -> AnyNodeTypesWithEngine<T, E, C, SC, S> {
187 AnyNodeTypesWithEngine::new()
188 }
189
190 pub const fn engine<T>(self) -> AnyNodeTypesWithEngine<P, T, C, SC, S> {
192 AnyNodeTypesWithEngine::new()
193 }
194
195 pub const fn chain_spec<T>(self) -> AnyNodeTypesWithEngine<P, E, T, SC, S> {
197 AnyNodeTypesWithEngine::new()
198 }
199
200 pub const fn state_commitment<T>(self) -> AnyNodeTypesWithEngine<P, E, C, T, S> {
202 AnyNodeTypesWithEngine::new()
203 }
204
205 pub const fn storage<T>(self) -> AnyNodeTypesWithEngine<P, E, C, SC, T> {
207 AnyNodeTypesWithEngine::new()
208 }
209}
210
211impl<P, E, C, SC, S> NodeTypes for AnyNodeTypesWithEngine<P, E, C, SC, S>
212where
213 P: NodePrimitives + Send + Sync + Unpin + 'static,
214 E: EngineTypes + Send + Sync + Unpin,
215 C: EthChainSpec<Header = P::BlockHeader> + 'static,
216 SC: StateCommitment,
217 S: Default + Send + Sync + Unpin + Debug + 'static,
218{
219 type Primitives = P;
220 type ChainSpec = C;
221 type StateCommitment = SC;
222 type Storage = S;
223}
224
225impl<P, E, C, SC, S> NodeTypesWithEngine for AnyNodeTypesWithEngine<P, E, C, SC, S>
226where
227 P: NodePrimitives + Send + Sync + Unpin + 'static,
228 E: EngineTypes + Send + Sync + Unpin,
229 C: EthChainSpec<Header = P::BlockHeader> + 'static,
230 SC: StateCommitment,
231 S: Default + Send + Sync + Unpin + Debug + 'static,
232{
233 type Engine = E;
234}
235
236pub type BlockTy<N> = <<N as NodeTypes>::Primitives as NodePrimitives>::Block;
238
239pub type HeaderTy<N> = <<N as NodeTypes>::Primitives as NodePrimitives>::BlockHeader;
241
242pub type BodyTy<N> = <<N as NodeTypes>::Primitives as NodePrimitives>::BlockBody;
244
245pub type TxTy<N> = <<N as NodeTypes>::Primitives as NodePrimitives>::SignedTx;
247
248pub type ReceiptTy<N> = <<N as NodeTypes>::Primitives as NodePrimitives>::Receipt;