From 917a4fbdbedb370c6b62ee5428d6453442060d20 Mon Sep 17 00:00:00 2001 From: Alfredo Garcia Date: Thu, 30 Jul 2020 19:33:00 -0300 Subject: [PATCH] Add last_checkpoint argument to zebra-checkpoints (#793) --- zebra-utils/src/bin/zebra-checkpoints/args.rs | 5 +++++ zebra-utils/src/bin/zebra-checkpoints/main.rs | 19 +++++++++++++++++-- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/zebra-utils/src/bin/zebra-checkpoints/args.rs b/zebra-utils/src/bin/zebra-checkpoints/args.rs index f0e3a21c..283b5f55 100644 --- a/zebra-utils/src/bin/zebra-checkpoints/args.rs +++ b/zebra-utils/src/bin/zebra-checkpoints/args.rs @@ -14,6 +14,11 @@ pub struct Args { #[structopt(default_value = "zcash-cli", short, long)] pub cli: String, + /// Start looking for checkpoints after this height. + /// If there is no last checkpoint, we start looking at the Genesis block (height 0). + #[structopt(short, long)] + pub last_checkpoint: Option, + /// Passthrough args for `zcash-cli` #[structopt(last = true)] pub zcli_args: Vec, diff --git a/zebra-utils/src/bin/zebra-checkpoints/main.rs b/zebra-utils/src/bin/zebra-checkpoints/main.rs index 90503381..79ddfd1c 100644 --- a/zebra-utils/src/bin/zebra-checkpoints/main.rs +++ b/zebra-utils/src/bin/zebra-checkpoints/main.rs @@ -89,19 +89,34 @@ fn main() -> Result<()> { cmd.arg("getblockcount"); // calculate the maximum height let height_limit: BlockHeight = cmd_output(&mut cmd)?.trim().parse()?; + assert!(height_limit <= BlockHeight::MAX); let height_limit = height_limit .0 .checked_sub(BLOCK_REORG_LIMIT.0) .map(BlockHeight) .expect("zcashd has some mature blocks: wait for zcashd to sync more blocks"); + let starting_height = args::Args::from_args().last_checkpoint.map(BlockHeight); + if starting_height.is_some() { + // Since we're about to add 1, height needs to be strictly less than the maximum + assert!(starting_height.unwrap() < BlockHeight::MAX); + } + // Start at the next block after the last checkpoint. + // If there is no last checkpoint, start at genesis (height 0). + let starting_height = starting_height.map_or(0, |BlockHeight(h)| h + 1); + + assert!( + starting_height < height_limit.0, + "No mature blocks after the last checkpoint: wait for zcashd to sync more blocks" + ); + // set up counters let mut cumulative_bytes: u64 = 0; let mut height_gap: BlockHeight = BlockHeight(0); // loop through all blocks - for x in 0..height_limit.0 { - // unfortunatly we need to create a process for each block + for x in starting_height..height_limit.0 { + // unfortunately we need to create a process for each block let mut cmd = passthrough_cmd(); // get block data