diff --git a/src/processor/tree/tree_wrapper.rs b/src/processor/tree/tree_wrapper.rs index 8359571..3106bca 100644 --- a/src/processor/tree/tree_wrapper.rs +++ b/src/processor/tree/tree_wrapper.rs @@ -1,9 +1,8 @@ -use std::{fs, path::Path, str::FromStr}; +use std::{collections::VecDeque, fs, path::Path, str::FromStr}; use blake2::{Blake2s256, Digest}; use ethers::types::{Address, H256, U256}; use eyre::Result; -use indexmap::IndexSet; use state_reconstruct_fetcher::{constants::storage::INITAL_STATE_PATH, types::CommitBlock}; use zksync_merkle_tree::{Database, MerkleTree, RocksDBWrapper}; @@ -11,12 +10,12 @@ use super::RootHash; pub struct TreeWrapper { tree: MerkleTree, - pub index_to_key_map: IndexSet, + pub index_to_key_map: VecDeque, } impl TreeWrapper { /// Attempts to create a new [`TreeWrapper`]. - pub fn new(db_path: &Path, mut index_to_key_map: IndexSet) -> Result { + pub fn new(db_path: &Path, mut index_to_key_map: VecDeque) -> Result { let db = RocksDBWrapper::new(db_path); let mut tree = MerkleTree::new(db); @@ -42,14 +41,14 @@ impl TreeWrapper { let value = H256::from(value); key_value_pairs.push((key, value)); - self.index_to_key_map.insert(key); + self.index_to_key_map.push_back(key); } // REPEATED CALLDATA. for (index, value) in &block.repeated_storage_changes { let index = usize::try_from(*index).expect("truncation failed"); // Index is 1-based so we subtract 1. - let key = *self.index_to_key_map.get_index(index - 1).unwrap(); + let key = self.index_to_key_map[index - 1]; let value = H256::from(value); key_value_pairs.push((key, value)); @@ -74,7 +73,7 @@ impl TreeWrapper { /// Attempts to reconstruct the genesis state from a CSV file. fn reconstruct_genesis_state( tree: &mut MerkleTree, - index_to_key: &mut IndexSet, + index_to_key: &mut VecDeque, path: &str, ) -> Result<()> { fn cleanup_encoding(input: &'_ str) -> &'_ str { @@ -167,7 +166,7 @@ fn reconstruct_genesis_state( let key = U256::from_little_endian(&derived_key); let value = H256::from(tmp); key_value_pairs.push((key, value)); - index_to_key.insert(key); + index_to_key.push_back(key); } let output = tree.extend(key_value_pairs); diff --git a/state-reconstruct-fetcher/src/snapshot.rs b/state-reconstruct-fetcher/src/snapshot.rs index 281b635..373d653 100644 --- a/state-reconstruct-fetcher/src/snapshot.rs +++ b/state-reconstruct-fetcher/src/snapshot.rs @@ -1,7 +1,6 @@ -use std::{fs, io, path::Path}; +use std::{collections::VecDeque, fs, io, path::Path}; use ethers::types::{U256, U64}; -use indexmap::IndexSet; use serde::{Deserialize, Serialize}; /// Struct containing the fields used for restoring the tree state. @@ -12,7 +11,7 @@ pub struct StateSnapshot { /// The latest l2 block number that was processed. pub latest_l2_block_number: u64, /// The mappings of index to key values. - pub index_to_key_map: IndexSet, + pub index_to_key_map: VecDeque, } impl StateSnapshot {