Replace the lookahead limit panic with a warning (#4662)

And decrease the minimum to 400 blocks
This commit is contained in:
teor 2022-06-21 21:07:32 +10:00 committed by GitHub
parent ee50f3ae45
commit 3a7c2c8926
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 14 additions and 11 deletions

View File

@ -57,8 +57,8 @@ const BLOCK_DOWNLOAD_RETRY_LIMIT: usize = 3;
/// A lower bound on the user-specified lookahead limit. /// A lower bound on the user-specified lookahead limit.
/// ///
/// Set to two checkpoint intervals, so that we're sure that the lookahead /// Set to the maximum checkpoint interval, so the pipeline holds at least one checkpoint's
/// limit always contains at least one complete checkpoint. /// worth of blocks.
/// ///
/// ## Security /// ## Security
/// ///
@ -74,7 +74,7 @@ const BLOCK_DOWNLOAD_RETRY_LIMIT: usize = 3;
/// Once these malicious blocks start failing validation, the syncer will cancel all /// Once these malicious blocks start failing validation, the syncer will cancel all
/// the pending download and verify tasks, drop all the blocks, and start a new /// the pending download and verify tasks, drop all the blocks, and start a new
/// ObtainTips with a new set of peers. /// ObtainTips with a new set of peers.
pub const MIN_LOOKAHEAD_LIMIT: usize = zebra_consensus::MAX_CHECKPOINT_HEIGHT_GAP * 2; pub const MIN_LOOKAHEAD_LIMIT: usize = zebra_consensus::MAX_CHECKPOINT_HEIGHT_GAP;
/// The default for the user-specified lookahead limit. /// The default for the user-specified lookahead limit.
/// ///
@ -318,24 +318,27 @@ where
// We apply a timeout to the verifier to avoid hangs due to missing earlier blocks. // We apply a timeout to the verifier to avoid hangs due to missing earlier blocks.
let verifier = Timeout::new(verifier, BLOCK_VERIFY_TIMEOUT); let verifier = Timeout::new(verifier, BLOCK_VERIFY_TIMEOUT);
assert!( let mut lookahead_limit = config.sync.lookahead_limit;
config.sync.lookahead_limit >= MIN_LOOKAHEAD_LIMIT, if lookahead_limit < MIN_LOOKAHEAD_LIMIT {
"configured lookahead limit {} too low, must be at least {}", warn!(
config.sync.lookahead_limit, "configured lookahead limit {} too low, increasing to {}",
MIN_LOOKAHEAD_LIMIT config.sync.lookahead_limit, MIN_LOOKAHEAD_LIMIT,
); );
lookahead_limit = MIN_LOOKAHEAD_LIMIT;
}
let (sync_status, recent_syncs) = SyncStatus::new(); let (sync_status, recent_syncs) = SyncStatus::new();
let new_syncer = Self { let new_syncer = Self {
genesis_hash: genesis_hash(config.network.network), genesis_hash: genesis_hash(config.network.network),
lookahead_limit: config.sync.lookahead_limit, lookahead_limit,
tip_network, tip_network,
downloads: Box::pin(Downloads::new( downloads: Box::pin(Downloads::new(
block_network, block_network,
verifier, verifier,
latest_chain_tip.clone(), latest_chain_tip.clone(),
config.sync.lookahead_limit, lookahead_limit,
)), )),
state, state,
latest_chain_tip, latest_chain_tip,