From c88c260069735fc31e0854222883038c5a0c8a71 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tuomas=20M=C3=A4kinen?= Date: Fri, 29 Sep 2023 10:05:34 +0300 Subject: [PATCH 1/4] Introduce CLI command This is first step towards CLI command of state reconstruction tool. --- Cargo.toml | 1 + src/main.rs | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+) create mode 100644 src/main.rs diff --git a/Cargo.toml b/Cargo.toml index fc2a701..8869425 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,6 +6,7 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] +clap = "4.4.0" ethers = "2.0.10" eyre = "0.6.8" serde_json = "1.0.107" diff --git a/src/main.rs b/src/main.rs new file mode 100644 index 0000000..ed8eb4b --- /dev/null +++ b/src/main.rs @@ -0,0 +1,48 @@ +use clap::{arg, value_parser, Command}; + +fn cli() -> Command { + Command::new("state-reconstruct") + .about("zkSync state reconstruction tool") + .subcommand_required(true) + .arg_required_else_help(false) + .subcommand( + Command::new("import") + .about("Import state") + .subcommand_required(true) + .subcommand( + Command::new("l1") + .about("Import state from Ethereum L1") + .arg( + arg!(--"start-block" ) + .help("Ethereum block number to start state import from") + .default_value("16627460") + .value_parser(value_parser!(u64)), + ) + .arg( + arg!(--"block-step" ) + .help("Number of blocks to filter & process in one step") + .default_value("128") + .value_parser(value_parser!(u64)), + ), + ), + ) +} + +fn main() { + let matches = cli().get_matches(); + + match matches.subcommand() { + Some(("import", sub_matches)) => { + match sub_matches.subcommand() { + Some(("l1", args)) => { + let start_block = args.get_one::("start-block").expect("required"); + let block_step = args.get_one::("block-step").expect("required"); + println!("import from L1, starting from block number {}, processing {} blocks at a time", start_block, block_step); + // TODO(tuommaki): Implement block fetch logic. + } + _ => unreachable!(), + } + } + _ => unreachable!(), + } +} From 6abb2fd5f0613c14664a66ae26fa2e2e55e95e37 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tuomas=20M=C3=A4kinen?= Date: Fri, 29 Sep 2023 10:14:23 +0300 Subject: [PATCH 2/4] Add file import support to CLI args --- src/main.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/main.rs b/src/main.rs index ed8eb4b..6134940 100644 --- a/src/main.rs +++ b/src/main.rs @@ -24,6 +24,12 @@ fn cli() -> Command { .default_value("128") .value_parser(value_parser!(u64)), ), + ) + .subcommand( + Command::new("file") + .about("Import state from file") + .arg(arg!( "File to import state from")) + .arg_required_else_help(true), ), ) } @@ -40,6 +46,10 @@ fn main() { println!("import from L1, starting from block number {}, processing {} blocks at a time", start_block, block_step); // TODO(tuommaki): Implement block fetch logic. } + Some(("file", args)) => { + let input_file = args.get_one::("FILE").expect("required"); + println!("import from file (path: \"{}\")", input_file); + } _ => unreachable!(), } } From e83f31b65afd6146e28c0ff7500994597e764bfd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tuomas=20M=C3=A4kinen?= Date: Fri, 29 Sep 2023 12:09:49 +0300 Subject: [PATCH 3/4] Use constants for default values --- Cargo.toml | 2 +- src/main.rs | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 8869425..4331cde 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,7 +6,7 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -clap = "4.4.0" +clap = { version = "4.4.0", features = ["string"] } ethers = "2.0.10" eyre = "0.6.8" serde_json = "1.0.107" diff --git a/src/main.rs b/src/main.rs index 6134940..50272b4 100644 --- a/src/main.rs +++ b/src/main.rs @@ -15,13 +15,13 @@ fn cli() -> Command { .arg( arg!(--"start-block" ) .help("Ethereum block number to start state import from") - .default_value("16627460") + .default_value(state_reconstruct::GENESIS_BLOCK.to_string()) .value_parser(value_parser!(u64)), ) .arg( arg!(--"block-step" ) .help("Number of blocks to filter & process in one step") - .default_value("128") + .default_value(state_reconstruct::BLOCK_STEP.to_string()) .value_parser(value_parser!(u64)), ), ) From 06fe3d2055c2618c02e6a008173e0e1d8f5391be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tuomas=20M=C3=A4kinen?= Date: Fri, 29 Sep 2023 12:27:21 +0300 Subject: [PATCH 4/4] import -> reconstruct --- src/main.rs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/main.rs b/src/main.rs index 50272b4..3fca38c 100644 --- a/src/main.rs +++ b/src/main.rs @@ -6,12 +6,12 @@ fn cli() -> Command { .subcommand_required(true) .arg_required_else_help(false) .subcommand( - Command::new("import") - .about("Import state") + Command::new("reconstruct") + .about("Reconstruct L2 state") .subcommand_required(true) .subcommand( Command::new("l1") - .about("Import state from Ethereum L1") + .about("Read state from Ethereum L1") .arg( arg!(--"start-block" ) .help("Ethereum block number to start state import from") @@ -27,7 +27,7 @@ fn cli() -> Command { ) .subcommand( Command::new("file") - .about("Import state from file") + .about("Read state from file") .arg(arg!( "File to import state from")) .arg_required_else_help(true), ), @@ -38,17 +38,17 @@ fn main() { let matches = cli().get_matches(); match matches.subcommand() { - Some(("import", sub_matches)) => { + Some(("reconstruct", sub_matches)) => { match sub_matches.subcommand() { Some(("l1", args)) => { let start_block = args.get_one::("start-block").expect("required"); let block_step = args.get_one::("block-step").expect("required"); - println!("import from L1, starting from block number {}, processing {} blocks at a time", start_block, block_step); + println!("reconstruct from L1, starting from block number {}, processing {} blocks at a time", start_block, block_step); // TODO(tuommaki): Implement block fetch logic. } Some(("file", args)) => { let input_file = args.get_one::("FILE").expect("required"); - println!("import from file (path: \"{}\")", input_file); + println!("reconstruct from file (path: \"{}\")", input_file); } _ => unreachable!(), }