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 mode: reth_trie::ExecutionWitnessMode,
105 ) -> reth_errors::ProviderResult<Vec<alloy_primitives::Bytes>> {
106 self.0.witness(input, target, mode)
107 }
108}
109
110impl reth_storage_api::AccountReader for StateProviderTraitObjWrapper {
111 fn basic_account(
112 &self,
113 address: &Address,
114 ) -> reth_errors::ProviderResult<Option<reth_primitives_traits::Account>> {
115 self.0.basic_account(address)
116 }
117}
118
119impl reth_storage_api::BlockHashReader for StateProviderTraitObjWrapper {
120 fn block_hash(
121 &self,
122 block_number: alloy_primitives::BlockNumber,
123 ) -> reth_errors::ProviderResult<Option<B256>> {
124 self.0.block_hash(block_number)
125 }
126
127 fn convert_block_hash(
128 &self,
129 hash_or_number: alloy_rpc_types_eth::BlockHashOrNumber,
130 ) -> reth_errors::ProviderResult<Option<B256>> {
131 self.0.convert_block_hash(hash_or_number)
132 }
133
134 fn canonical_hashes_range(
135 &self,
136 start: alloy_primitives::BlockNumber,
137 end: alloy_primitives::BlockNumber,
138 ) -> reth_errors::ProviderResult<Vec<B256>> {
139 self.0.canonical_hashes_range(start, end)
140 }
141}
142
143impl HashedPostStateProvider for StateProviderTraitObjWrapper {
144 fn hashed_post_state(&self, bundle_state: &BundleState) -> reth_trie::HashedPostState {
145 self.0.hashed_post_state(bundle_state)
146 }
147}
148
149impl StateProvider for StateProviderTraitObjWrapper {
150 fn storage(
151 &self,
152 account: Address,
153 storage_key: alloy_primitives::StorageKey,
154 ) -> reth_errors::ProviderResult<Option<alloy_primitives::StorageValue>> {
155 self.0.storage(account, storage_key)
156 }
157
158 fn account_code(
159 &self,
160 addr: &Address,
161 ) -> reth_errors::ProviderResult<Option<reth_primitives_traits::Bytecode>> {
162 self.0.account_code(addr)
163 }
164
165 fn account_balance(&self, addr: &Address) -> reth_errors::ProviderResult<Option<U256>> {
166 self.0.account_balance(addr)
167 }
168
169 fn account_nonce(&self, addr: &Address) -> reth_errors::ProviderResult<Option<u64>> {
170 self.0.account_nonce(addr)
171 }
172}
173
174impl BytecodeReader for StateProviderTraitObjWrapper {
175 fn bytecode_by_hash(
176 &self,
177 code_hash: &B256,
178 ) -> reth_errors::ProviderResult<Option<reth_primitives_traits::Bytecode>> {
179 self.0.bytecode_by_hash(code_hash)
180 }
181}