12
12
// See the License for the specific language governing permissions and
13
13
// limitations under the License.
14
14
15
- use std:: collections:: { hash_map:: Entry , HashMap , HashSet } ;
16
-
17
15
use super :: { provider:: ProviderDb , AlloyDb } ;
18
16
use crate :: MerkleTrie ;
19
17
use alloy:: {
@@ -23,7 +21,10 @@ use alloy::{
23
21
rpc:: types:: EIP1186AccountProofResponse ,
24
22
transports:: Transport ,
25
23
} ;
26
- use alloy_primitives:: { Address , BlockNumber , Bytes , StorageKey , StorageValue , B256 , U256 } ;
24
+ use alloy_primitives:: {
25
+ map:: { hash_map, AddressHashMap , B256HashMap , B256HashSet , HashSet } ,
26
+ Address , BlockNumber , Bytes , StorageKey , StorageValue , B256 , U256 ,
27
+ } ;
27
28
use anyhow:: { ensure, Context , Result } ;
28
29
use revm:: {
29
30
primitives:: { AccountInfo , Bytecode } ,
@@ -32,20 +33,18 @@ use revm::{
32
33
33
34
/// A simple revm [Database] wrapper that records all DB queries.
34
35
pub struct ProofDb < D > {
35
- accounts : HashMap < Address , HashSet < StorageKey > > ,
36
- contracts : HashMap < B256 , Bytes > ,
36
+ accounts : AddressHashMap < B256HashSet > ,
37
+ contracts : B256HashMap < Bytes > ,
37
38
block_hash_numbers : HashSet < BlockNumber > ,
38
-
39
- proofs : HashMap < Address , AccountProof > ,
40
-
39
+ proofs : AddressHashMap < AccountProof > ,
41
40
inner : D ,
42
41
}
43
42
44
43
struct AccountProof {
45
44
/// The inclusion proof for this account.
46
45
account_proof : Vec < Bytes > ,
47
46
/// The MPT inclusion proofs for several storage slots.
48
- storage_proofs : HashMap < StorageKey , StorageProof > ,
47
+ storage_proofs : B256HashMap < StorageProof > ,
49
48
}
50
49
51
50
struct StorageProof {
@@ -59,11 +58,10 @@ impl<D: Database> ProofDb<D> {
59
58
/// Creates a new ProofDb instance, with a [Database].
60
59
pub fn new ( db : D ) -> Self {
61
60
Self {
62
- accounts : HashMap :: new ( ) ,
63
- contracts : HashMap :: new ( ) ,
64
- block_hash_numbers : HashSet :: new ( ) ,
65
-
66
- proofs : HashMap :: new ( ) ,
61
+ accounts : Default :: default ( ) ,
62
+ contracts : Default :: default ( ) ,
63
+ block_hash_numbers : Default :: default ( ) ,
64
+ proofs : Default :: default ( ) ,
67
65
inner : db,
68
66
}
69
67
}
@@ -76,7 +74,7 @@ impl<D: Database> ProofDb<D> {
76
74
}
77
75
78
76
/// Returns the referenced contracts
79
- pub fn contracts ( & self ) -> & HashMap < B256 , Bytes > {
77
+ pub fn contracts ( & self ) -> & B256HashMap < Bytes > {
80
78
& self . contracts
81
79
}
82
80
@@ -176,7 +174,7 @@ impl<T: Transport + Clone, N: Network, P: Provider<T, N>> ProofDb<AlloyDb<T, N,
176
174
. flat_map ( |proof| proof. account_proof . iter ( ) ) ;
177
175
let state_trie = MerkleTrie :: from_rlp_nodes ( state_nodes) . context ( "accountProof invalid" ) ?;
178
176
179
- let mut storage_tries = HashMap :: new ( ) ;
177
+ let mut storage_tries = B256HashMap :: default ( ) ;
180
178
for ( address, storage_keys) in & self . accounts {
181
179
// if no storage keys have been accessed, we don't need to prove anything
182
180
if storage_keys. is_empty ( ) {
@@ -258,7 +256,7 @@ fn filter_existing_keys(account_proof: Option<&AccountProof>) -> impl Fn(&Storag
258
256
}
259
257
260
258
fn add_proof (
261
- proofs : & mut HashMap < Address , AccountProof > ,
259
+ proofs : & mut AddressHashMap < AccountProof > ,
262
260
proof_response : EIP1186AccountProofResponse ,
263
261
) -> Result < ( ) > {
264
262
// convert the response into a StorageProof
@@ -277,15 +275,15 @@ fn add_proof(
277
275
. collect ( ) ;
278
276
279
277
match proofs. entry ( proof_response. address ) {
280
- Entry :: Occupied ( mut entry) => {
278
+ hash_map :: Entry :: Occupied ( mut entry) => {
281
279
let account_proof = entry. get_mut ( ) ;
282
280
ensure ! (
283
281
account_proof. account_proof == proof_response. account_proof,
284
282
"account_proof does not match"
285
283
) ;
286
284
account_proof. storage_proofs . extend ( storage_proofs) ;
287
285
}
288
- Entry :: Vacant ( entry) => {
286
+ hash_map :: Entry :: Vacant ( entry) => {
289
287
entry. insert ( AccountProof {
290
288
account_proof : proof_response. account_proof ,
291
289
storage_proofs,
0 commit comments