Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ref: move library code to subcrate #38

Merged
merged 2 commits into from
Oct 27, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 41 additions & 28 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 11 additions & 10 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,21 @@ version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[workspace]
members = ["state-reconstruct-fetcher"]

[dependencies]
async-trait = "0.1.73"
async-trait = "0.1.74"
blake2 = "0.10.6"
clap = { version = "4.4.0", features = ["derive", "env"] }
ethers = "1"
clap = { version = "4.4.7", features = ["derive", "env"] }
ethers = "1.0.2"
eyre = "0.6.8"
hex = "0.4.3"
indexmap = { version = "2.0.1", features = ["serde"] }
rand = "0.8.0"
serde = { version = "1.0.188", features = ["derive"] }
indexmap = { version = "2.0.2" }
serde = { version = "1.0.189", features = ["derive"] }
serde_json = { version = "1.0.107", features = ["std"] }
serde_json_any_key = "2.0.0"
thiserror = "1.0"
tokio = { version = "1.32.0", features = ["macros", "signal"] }
tracing = "0.1.37"
state-reconstruct-fetcher = { path = "./state-reconstruct-fetcher" }
tokio = { version = "1.33.0", features = ["macros"] }
tracing = "0.1.40"
tracing-subscriber = "0.3.17"
zksync_merkle_tree = { git = "https://github.com/matter-labs/zksync-era.git" }
3 changes: 1 addition & 2 deletions src/cli.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use clap::{Args, Parser, Subcommand, ValueEnum};

use crate::constants::ethereum;
use state_reconstruct_fetcher::constants::ethereum;

#[derive(Args)]
pub struct L1FetcherOptions {
Expand Down
37 changes: 24 additions & 13 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,8 @@
#![feature(array_chunks)]
#![feature(iter_next_chunk)]
#![warn(clippy::pedantic)]
#![allow(clippy::module_name_repetitions)]

mod cli;
mod constants;
mod l1_fetcher;
mod processor;
mod snapshot;
mod types;
mod util;

use std::{
Expand All @@ -21,20 +15,22 @@ use std::{

use clap::Parser;
use cli::{Cli, Command, ReconstructSource};
use constants::storage;
use eyre::Result;
use snapshot::StateSnapshot;
use state_reconstruct_fetcher::{
constants::storage,
l1_fetcher::{L1Fetcher, L1FetcherOptions},
snapshot::StateSnapshot,
types::CommitBlockInfoV1,
};
use tokio::sync::{mpsc, Mutex};
use tracing_subscriber::{filter::LevelFilter, EnvFilter};

use crate::{
l1_fetcher::L1Fetcher,
processor::{
json::JsonSerializationProcessor,
tree::{query_tree::QueryTree, TreeProcessor},
Processor,
},
types::CommitBlockInfoV1,
util::json,
};

Expand Down Expand Up @@ -71,8 +67,15 @@ async fn main() -> Result<()> {
match source {
ReconstructSource::L1 { l1_fetcher_options } => {
let snapshot = Arc::new(Mutex::new(StateSnapshot::default()));

let fetcher = L1Fetcher::new(l1_fetcher_options, Some(snapshot.clone()))?;
let fetcher_options = L1FetcherOptions {
http_url: l1_fetcher_options.http_url,
start_block: l1_fetcher_options.start_block,
block_step: l1_fetcher_options.block_step,
block_count: l1_fetcher_options.block_count,
disable_polling: l1_fetcher_options.disable_polling,
};

let fetcher = L1Fetcher::new(fetcher_options, Some(snapshot.clone()))?;
let processor = TreeProcessor::new(db_path, snapshot.clone()).await?;
let (tx, rx) = mpsc::channel::<CommitBlockInfoV1>(5);

Expand Down Expand Up @@ -109,7 +112,15 @@ async fn main() -> Result<()> {
l1_fetcher_options,
file,
} => {
let fetcher = L1Fetcher::new(l1_fetcher_options, None)?;
let fetcher_options = L1FetcherOptions {
http_url: l1_fetcher_options.http_url,
start_block: l1_fetcher_options.start_block,
block_step: l1_fetcher_options.block_step,
block_count: l1_fetcher_options.block_count,
disable_polling: l1_fetcher_options.disable_polling,
};

let fetcher = L1Fetcher::new(fetcher_options, None)?;
let processor = JsonSerializationProcessor::new(Path::new(&file))?;
let (tx, rx) = mpsc::channel::<CommitBlockInfoV1>(5);

Expand Down
2 changes: 1 addition & 1 deletion src/processor/json/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ use std::{fs::File, path::Path};

use async_trait::async_trait;
use eyre::Result;
use state_reconstruct_fetcher::types::CommitBlockInfoV1;
use serde::ser::{SerializeSeq, Serializer};
use serde_json;
use tokio::sync::mpsc;

use super::Processor;
use crate::types::CommitBlockInfoV1;

pub struct JsonSerializationProcessor {
serializer: serde_json::Serializer<File>,
Expand Down
3 changes: 1 addition & 2 deletions src/processor/mod.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
use async_trait::async_trait;
use state_reconstruct_fetcher::types::CommitBlockInfoV1;
use tokio::sync::mpsc;

use crate::types::CommitBlockInfoV1;

pub mod json;
pub mod tree;

Expand Down
6 changes: 3 additions & 3 deletions src/processor/tree/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ use std::{io, path::PathBuf, sync::Arc};
use async_trait::async_trait;
use ethers::types::H256;
use eyre::Result;
use state_reconstruct_fetcher::{
constants::storage::STATE_FILE_NAME, snapshot::StateSnapshot, types::CommitBlockInfoV1,
};
use tokio::sync::{mpsc, Mutex};

use self::tree_wrapper::TreeWrapper;
use super::Processor;
use crate::{
constants::storage::STATE_FILE_NAME, snapshot::StateSnapshot, types::CommitBlockInfoV1,
};

pub type RootHash = H256;

Expand Down
2 changes: 1 addition & 1 deletion src/processor/tree/tree_wrapper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ use std::{fs, path::Path, str::FromStr};
use blake2::{Blake2s256, Digest};
use ethers::types::{Address, H256, U256};
use eyre::Result;
use state_reconstruct_fetcher::{constants::storage::INITAL_STATE_PATH, types::CommitBlockInfoV1};
use indexmap::IndexSet;
use zksync_merkle_tree::{Database, MerkleTree, RocksDBWrapper};

use super::RootHash;
use crate::{constants::storage::INITAL_STATE_PATH, CommitBlockInfoV1};

pub struct TreeWrapper<'a> {
tree: MerkleTree<'a, RocksDBWrapper>,
Expand Down
16 changes: 16 additions & 0 deletions state-reconstruct-fetcher/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
[package]
name = "state-reconstruct-fetcher"
version = "0.1.0"
edition = "2021"

[dependencies]
ethers = "1.0.2"
eyre = "0.6.8"
indexmap = { version = "2.0.2", features = ["serde"] }
rand = "0.8.5"
serde = { version = "1.0.189", features = ["derive"] }
serde_json = { version = "1.0.107", features = ["std"] }
serde_json_any_key = "2.0.0"
thiserror = "1.0.50"
tokio = { version = "1.33.0", features = ["signal"] }
tracing = "0.1.40"
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ use tokio::{
};

use crate::{
cli::L1FetcherOptions,
constants::ethereum::{BLOCK_STEP, GENESIS_BLOCK, ZK_SYNC_ADDR},
snapshot::StateSnapshot,
types::{CommitBlockInfoV1, ParseError},
Expand All @@ -37,6 +36,19 @@ pub enum L1FetchError {
GetTx,
}

pub struct L1FetcherOptions {
/// The Ethereum JSON-RPC HTTP URL to use.
pub http_url: String,
/// Ethereum block number to start state import from.
pub start_block: u64,
/// The number of blocks to filter & process in one step over.
pub block_step: u64,
/// The number of blocks to process from Ethereum.
pub block_count: Option<u64>,
/// If present, don't poll for new blocks after reaching the end.
pub disable_polling: bool,
}

#[derive(Default)]
struct L1Metrics {
// Metrics variables.
Expand Down
Loading
Loading