reth_rpc_eth_types/cache/
db.rs1use alloy_primitives::{Address, B256, U256};
6use reth_errors::ProviderResult;
7use reth_revm::database::StateProviderDatabase;
8use reth_storage_api::{BytecodeReader, HashedPostStateProvider, StateProvider, StateProviderBox};
9use reth_trie::{HashedStorage, MultiProofTargets};
10use revm::database::{BundleState, State};
11
12pub type StateCacheDb = State<StateProviderDatabase<StateProviderTraitObjWrapper>>;
14
15#[expect(missing_debug_implementations)]
22pub struct StateProviderTraitObjWrapper(pub StateProviderBox);
23
24impl reth_storage_api::StateRootProvider for StateProviderTraitObjWrapper {
25 fn state_root(
26 &self,
27 hashed_state: reth_trie::HashedPostState,
28 ) -> reth_errors::ProviderResult<B256> {
29 self.0.state_root(hashed_state)
30 }
31
32 fn state_root_from_nodes(
33 &self,
34 input: reth_trie::TrieInput,
35 ) -> reth_errors::ProviderResult<B256> {
36 self.0.state_root_from_nodes(input)
37 }
38
39 fn state_root_with_updates(
40 &self,
41 hashed_state: reth_trie::HashedPostState,
42 ) -> reth_errors::ProviderResult<(B256, reth_trie::updates::TrieUpdates)> {
43 self.0.state_root_with_updates(hashed_state)
44 }
45
46 fn state_root_from_nodes_with_updates(
47 &self,
48 input: reth_trie::TrieInput,
49 ) -> reth_errors::ProviderResult<(B256, reth_trie::updates::TrieUpdates)> {
50 self.0.state_root_from_nodes_with_updates(input)
51 }
52}
53
54impl reth_storage_api::StorageRootProvider for StateProviderTraitObjWrapper {
55 fn storage_root(
56 &self,
57 address: Address,
58 hashed_storage: HashedStorage,
59 ) -> ProviderResult<B256> {
60 self.0.storage_root(address, hashed_storage)
61 }
62
63 fn storage_proof(
64 &self,
65 address: Address,
66 slot: B256,
67 hashed_storage: HashedStorage,
68 ) -> ProviderResult<reth_trie::StorageProof> {
69 self.0.storage_proof(address, slot, hashed_storage)
70 }
71
72 fn storage_multiproof(
73 &self,
74 address: Address,
75 slots: &[B256],
76 hashed_storage: HashedStorage,
77 ) -> ProviderResult<reth_trie::StorageMultiProof> {
78 self.0.storage_multiproof(address, slots, hashed_storage)
79 }
80}
81
82impl reth_storage_api::StateProofProvider for StateProviderTraitObjWrapper {
83 fn proof(
84 &self,
85 input: reth_trie::TrieInput,
86 address: Address,
87 slots: &[B256],
88 ) -> reth_errors::ProviderResult<reth_trie::AccountProof> {
89 self.0.proof(input, address, slots)
90 }
91
92 fn multiproof(
93 &self,
94 input: reth_trie::TrieInput,
95 targets: MultiProofTargets,
96 ) -> ProviderResult<reth_trie::MultiProof> {
97 self.0.multiproof(input, targets)
98 }
99
100 fn witness(
101 &self,
102 input: reth_trie::TrieInput,
103 target: reth_trie::HashedPostState,
104 ) -> reth_errors::ProviderResult<Vec<alloy_primitives::Bytes>> {
105 self.0.witness(input, target)
106 }
107}
108
109impl reth_storage_api::AccountReader for StateProviderTraitObjWrapper {
110 fn basic_account(
111 &self,
112 address: &Address,
113 ) -> reth_errors::ProviderResult<Option<reth_primitives_traits::Account>> {
114 self.0.basic_account(address)
115 }
116}
117
118impl reth_storage_api::BlockHashReader for StateProviderTraitObjWrapper {
119 fn block_hash(
120 &self,
121 block_number: alloy_primitives::BlockNumber,
122 ) -> reth_errors::ProviderResult<Option<B256>> {
123 self.0.block_hash(block_number)
124 }
125
126 fn convert_block_hash(
127 &self,
128 hash_or_number: alloy_rpc_types_eth::BlockHashOrNumber,
129 ) -> reth_errors::ProviderResult<Option<B256>> {
130 self.0.convert_block_hash(hash_or_number)
131 }
132
133 fn canonical_hashes_range(
134 &self,
135 start: alloy_primitives::BlockNumber,
136 end: alloy_primitives::BlockNumber,
137 ) -> reth_errors::ProviderResult<Vec<B256>> {
138 self.0.canonical_hashes_range(start, end)
139 }
140}
141
142impl HashedPostStateProvider for StateProviderTraitObjWrapper {
143 fn hashed_post_state(&self, bundle_state: &BundleState) -> reth_trie::HashedPostState {
144 self.0.hashed_post_state(bundle_state)
145 }
146}
147
148impl StateProvider for StateProviderTraitObjWrapper {
149 fn storage(
150 &self,
151 account: Address,
152 storage_key: alloy_primitives::StorageKey,
153 ) -> reth_errors::ProviderResult<Option<alloy_primitives::StorageValue>> {
154 self.0.storage(account, storage_key)
155 }
156
157 fn account_code(
158 &self,
159 addr: &Address,
160 ) -> reth_errors::ProviderResult<Option<reth_primitives_traits::Bytecode>> {
161 self.0.account_code(addr)
162 }
163
164 fn account_balance(&self, addr: &Address) -> reth_errors::ProviderResult<Option<U256>> {
165 self.0.account_balance(addr)
166 }
167
168 fn account_nonce(&self, addr: &Address) -> reth_errors::ProviderResult<Option<u64>> {
169 self.0.account_nonce(addr)
170 }
171}
172
173impl BytecodeReader for StateProviderTraitObjWrapper {
174 fn bytecode_by_hash(
175 &self,
176 code_hash: &B256,
177 ) -> reth_errors::ProviderResult<Option<reth_primitives_traits::Bytecode>> {
178 self.0.bytecode_by_hash(code_hash)
179 }
180}