reth_provider/providers/database/
chain.rs

1use crate::{providers::NodeTypesForProvider, DatabaseProvider};
2use reth_db_api::transaction::{DbTx, DbTxMut};
3use reth_node_types::FullNodePrimitives;
4
5use reth_primitives_traits::{FullBlockHeader, FullSignedTx};
6use reth_storage_api::{ChainStorageReader, ChainStorageWriter, EmptyBodyStorage, EthStorage};
7
8/// Trait that provides access to implementations of [`ChainStorage`]
9pub trait ChainStorage<Primitives: FullNodePrimitives>: Send + Sync {
10    /// Provides access to the chain reader.
11    fn reader<TX, Types>(&self) -> impl ChainStorageReader<DatabaseProvider<TX, Types>, Primitives>
12    where
13        TX: DbTx + 'static,
14        Types: NodeTypesForProvider<Primitives = Primitives>;
15
16    /// Provides access to the chain writer.
17    fn writer<TX, Types>(&self) -> impl ChainStorageWriter<DatabaseProvider<TX, Types>, Primitives>
18    where
19        TX: DbTxMut + DbTx + 'static,
20        Types: NodeTypesForProvider<Primitives = Primitives>;
21}
22
23impl<N, T, H> ChainStorage<N> for EthStorage<T, H>
24where
25    T: FullSignedTx,
26    H: FullBlockHeader,
27    N: FullNodePrimitives<
28        Block = alloy_consensus::Block<T, H>,
29        BlockHeader = H,
30        BlockBody = alloy_consensus::BlockBody<T, H>,
31        SignedTx = T,
32    >,
33{
34    fn reader<TX, Types>(&self) -> impl ChainStorageReader<DatabaseProvider<TX, Types>, N>
35    where
36        TX: DbTx + 'static,
37        Types: NodeTypesForProvider<Primitives = N>,
38    {
39        self
40    }
41
42    fn writer<TX, Types>(&self) -> impl ChainStorageWriter<DatabaseProvider<TX, Types>, N>
43    where
44        TX: DbTxMut + DbTx + 'static,
45        Types: NodeTypesForProvider<Primitives = N>,
46    {
47        self
48    }
49}
50
51impl<N, T, H> ChainStorage<N> for EmptyBodyStorage<T, H>
52where
53    T: FullSignedTx,
54    H: FullBlockHeader,
55    N: FullNodePrimitives<
56        Block = alloy_consensus::Block<T, H>,
57        BlockHeader = H,
58        BlockBody = alloy_consensus::BlockBody<T, H>,
59        SignedTx = T,
60    >,
61{
62    fn reader<TX, Types>(&self) -> impl ChainStorageReader<DatabaseProvider<TX, Types>, N>
63    where
64        TX: DbTx + 'static,
65        Types: NodeTypesForProvider<Primitives = N>,
66    {
67        self
68    }
69
70    fn writer<TX, Types>(&self) -> impl ChainStorageWriter<DatabaseProvider<TX, Types>, N>
71    where
72        TX: DbTxMut + DbTx + 'static,
73        Types: NodeTypesForProvider<Primitives = N>,
74    {
75        self
76    }
77}