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 21f07d4
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 26 deletions.
6 changes: 3 additions & 3 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ mod types;
use std::env;

use clap::{arg, value_parser, Command};
use constants::ethereum::{BLOCK_STEP, GENESIS_BLOCK};
use constants::ethereum;
use ethers::types::U64;
use eyre::Result;
use l1_fetcher::L1Fetcher;
Expand All @@ -35,13 +35,13 @@ fn cli() -> Command {
.arg(
arg!(--"start-block" <START_BLOCK>)
.help("Ethereum block number to start state import from")
.default_value(GENESIS_BLOCK.to_string())
.default_value(ethereum::GENESIS_BLOCK.to_string())
.value_parser(value_parser!(u64)),
)
.arg(
arg!(--"block-step" <BLOCK_STEP>)
.help("Number of blocks to filter & process in one step")
.default_value(BLOCK_STEP.to_string())
.default_value(ethereum::BLOCK_STEP.to_string())
.value_parser(value_parser!(u64)),
),
)
Expand Down
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 21f07d4

Please sign in to comment.