Skip to content

Commit

Permalink
chore: update imports
Browse files Browse the repository at this point in the history
  • Loading branch information
zeapoz committed Oct 5, 2023
1 parent e2ff37f commit 1c62021
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 23 deletions.
44 changes: 22 additions & 22 deletions src/processor/tree/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ use std::path::Path;

use async_trait::async_trait;
use eyre::Result;
use tokio::{sync::mpsc, task::JoinHandle};
use tokio::sync::mpsc;

use crate::{constants::ethereum::STATE_FILE_PATH, types::CommitBlockInfoV1};
use crate::constants::storage::STATE_FILE_PATH;
use crate::types::CommitBlockInfoV1;

use self::{snapshot::StateSnapshot, tree_wrapper::TreeWrapper};

Expand Down Expand Up @@ -36,7 +37,7 @@ impl TreeProcessor<'static> {
// Extract `index_to_key_map` from state snapshot.
let StateSnapshot {
ref index_to_key_map,
..
.. // Ignore the rest of the fields.
} = snapshot;

let tree = TreeWrapper::new(db_dir, index_to_key_map.clone())?;
Expand All @@ -48,27 +49,26 @@ impl TreeProcessor<'static> {
#[async_trait]
impl Processor for TreeProcessor<'static> {
async fn run(mut self, mut rx: mpsc::Receiver<Vec<CommitBlockInfoV1>>) {
while let Some(blocks) = rx.recv().await {
for block in blocks {
// Check if we've already processed this block.
if self.snapshot.latest_l2_block_number >= block.block_number {
println!(
"Block {} has already been processed, skipping.",
block.block_number
);
continue;
}

self.tree.insert_block(&block);

// Update snapshot values.
self.snapshot.latest_l2_block_number = block.block_number;
self.snapshot.index_to_key_map = self.tree.index_to_key_map.clone();
while let Some(blocks) = rx.recv().await {
for block in blocks {
// Check if we've already processed this block.
if self.snapshot.latest_l2_block_number >= block.block_number {
println!(
"Block {} has already been processed, skipping.",
block.block_number
);
continue;
}

// Write the current state to a file.
self.snapshot.write(STATE_FILE_PATH).unwrap();
self.tree.insert_block(&block);

// Update snapshot values.
self.snapshot.latest_l2_block_number = block.block_number;
self.snapshot.index_to_key_map = self.tree.index_to_key_map.clone();
}
})

// Write the current state to a file.
self.snapshot.write(STATE_FILE_PATH).unwrap();
}
}
}
2 changes: 1 addition & 1 deletion src/processor/tree/tree_wrapper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use zksync_merkle_tree::{Database, MerkleTree, RocksDBWrapper};

use eyre::Result;

use crate::{constants::ethereum::INITAL_STATE_PATH, CommitBlockInfoV1};
use crate::{constants::storage::INITAL_STATE_PATH, CommitBlockInfoV1};

pub type RootHash = H256;

Expand Down

0 comments on commit 1c62021

Please sign in to comment.