From fbeae993283015f4884dce52e4f8634d3d621e7e Mon Sep 17 00:00:00 2001 From: teor Date: Wed, 29 Jul 2020 16:21:50 +1000 Subject: [PATCH] fix: Only warn on unexpected high blocks High blocks are expected when we restart with most of the chain in our state. Also downgrade the message from warn to info. --- zebra-consensus/src/chain.rs | 22 ++++++++++++---------- zebra-consensus/src/chain/tests.rs | 8 ++++++-- 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/zebra-consensus/src/chain.rs b/zebra-consensus/src/chain.rs index be811bc59..062c451e3 100644 --- a/zebra-consensus/src/chain.rs +++ b/zebra-consensus/src/chain.rs @@ -98,7 +98,7 @@ where ); let height = block.coinbase_height(); - // Log a warning on unexpected high blocks + // Log an info-level message on unexpected high blocks let is_unexpected_high_block = match height { Some(BlockHeight(height)) if (height > self.last_block_height.0 + MAX_EXPECTED_BLOCK_GAP) => @@ -114,7 +114,7 @@ where }; async move { - // TODO(teor): for post-sapling checkpoint blocks, allow callers + // TODO(teor): in the post-sapling checkpoint range, allow callers // to use BlockVerifier, CheckpointVerifier, or both. // Call a verifier based on the block height and checkpoints. @@ -127,10 +127,11 @@ where .await? } _ => { - // Temporary trace, for identifying early high blocks. - // We think the downloader or sync service should reject these blocks + // Log an info-level message on early high blocks. + // The sync service rejects most of these blocks, but we + // still want to know if a large number get through. if is_unexpected_high_block { - tracing::warn!(?height, "unexpected high block"); + tracing::info!(?height, "unexpected high block"); } block_verifier @@ -205,11 +206,11 @@ where let block_verifier = crate::block::init(state_service.clone()); let checkpoint_verifier = CheckpointVerifier::new(network, initial_tip); - init_from_verifiers(block_verifier, checkpoint_verifier, state_service) + init_from_verifiers(block_verifier, checkpoint_verifier, state_service, height) } -/// Return a chain verification service, using the provided verifier and state -/// services. +/// Return a chain verification service, using the provided verifier, state +/// services, and initial tip height. /// /// The chain verifier holds a state service of type `S`, used as context for /// block validation and to which newly verified blocks will be committed. This @@ -227,6 +228,7 @@ pub fn init_from_verifiers( block_verifier: BV, checkpoint_verifier: CheckpointVerifier, state_service: S, + initial_tip_height: Option, ) -> impl Service< Arc, Response = BlockHeaderHash, @@ -259,10 +261,10 @@ where checkpoint_verifier, max_checkpoint_height, state_service, - // We haven't actually got the genesis block yet, but that's ok, + // We might not have the genesis block yet, but that's ok, // because this field is only used for debugging unexpected high // blocks. - last_block_height: BlockHeight(0), + last_block_height: initial_tip_height.unwrap_or(BlockHeight(0)), }, 1, ) diff --git a/zebra-consensus/src/chain/tests.rs b/zebra-consensus/src/chain/tests.rs index bccc53b0f..bc2877613 100644 --- a/zebra-consensus/src/chain/tests.rs +++ b/zebra-consensus/src/chain/tests.rs @@ -67,8 +67,12 @@ fn verifiers_from_checkpoint_list( let block_verifier = crate::block::init(state_service.clone()); let checkpoint_verifier = crate::checkpoint::CheckpointVerifier::from_checkpoint_list(checkpoint_list, None); - let chain_verifier = - super::init_from_verifiers(block_verifier, checkpoint_verifier, state_service.clone()); + let chain_verifier = super::init_from_verifiers( + block_verifier, + checkpoint_verifier, + state_service.clone(), + None, + ); (chain_verifier, state_service) }