Add last_checkpoint argument to zebra-checkpoints (#793)
This commit is contained in:
parent
e74ff18708
commit
917a4fbdbe
|
|
@ -14,6 +14,11 @@ pub struct Args {
|
||||||
#[structopt(default_value = "zcash-cli", short, long)]
|
#[structopt(default_value = "zcash-cli", short, long)]
|
||||||
pub cli: String,
|
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<u32>,
|
||||||
|
|
||||||
/// Passthrough args for `zcash-cli`
|
/// Passthrough args for `zcash-cli`
|
||||||
#[structopt(last = true)]
|
#[structopt(last = true)]
|
||||||
pub zcli_args: Vec<String>,
|
pub zcli_args: Vec<String>,
|
||||||
|
|
|
||||||
|
|
@ -89,19 +89,34 @@ fn main() -> Result<()> {
|
||||||
cmd.arg("getblockcount");
|
cmd.arg("getblockcount");
|
||||||
// calculate the maximum height
|
// calculate the maximum height
|
||||||
let height_limit: BlockHeight = cmd_output(&mut cmd)?.trim().parse()?;
|
let height_limit: BlockHeight = cmd_output(&mut cmd)?.trim().parse()?;
|
||||||
|
assert!(height_limit <= BlockHeight::MAX);
|
||||||
let height_limit = height_limit
|
let height_limit = height_limit
|
||||||
.0
|
.0
|
||||||
.checked_sub(BLOCK_REORG_LIMIT.0)
|
.checked_sub(BLOCK_REORG_LIMIT.0)
|
||||||
.map(BlockHeight)
|
.map(BlockHeight)
|
||||||
.expect("zcashd has some mature blocks: wait for zcashd to sync more blocks");
|
.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
|
// set up counters
|
||||||
let mut cumulative_bytes: u64 = 0;
|
let mut cumulative_bytes: u64 = 0;
|
||||||
let mut height_gap: BlockHeight = BlockHeight(0);
|
let mut height_gap: BlockHeight = BlockHeight(0);
|
||||||
|
|
||||||
// loop through all blocks
|
// loop through all blocks
|
||||||
for x in 0..height_limit.0 {
|
for x in starting_height..height_limit.0 {
|
||||||
// unfortunatly we need to create a process for each block
|
// unfortunately we need to create a process for each block
|
||||||
let mut cmd = passthrough_cmd();
|
let mut cmd = passthrough_cmd();
|
||||||
|
|
||||||
// get block data
|
// get block data
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue