Skip to content

Commit

Permalink
test: Fix off-by-one error in sync-test
Browse files Browse the repository at this point in the history
Blocks needed before syncing is `sync_mode_threshold + 1`, not
`sync_mode_threshold`.
  • Loading branch information
Sword-Smith committed Jan 29, 2025
1 parent a54f749 commit fa3dc86
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions src/peer_loop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -639,17 +639,17 @@ impl PeerLoopHandler {
PeerMessage::BlockNotification(block_notification) => {
log_slow_scope!(fn_name!() + "::PeerMessage::BlockNotification");

debug!(
"Got BlockNotification of height {}",
block_notification.height
);
let (tip_header, sync_anchor_is_set) = {
let state = self.global_state_lock.lock_guard().await;
(
*state.chain.light_state().header(),
state.net.sync_anchor.is_some(),
)
};
debug!(
"Got BlockNotification of height {}. Own height is {}",
block_notification.height, tip_header.height
);

let sync_mode_threshold = self.global_state_lock.cli().sync_mode_threshold;
if GlobalState::sync_mode_threshold_stateless(
Expand Down Expand Up @@ -3569,7 +3569,6 @@ mod peer_loop_tests {

mod sync_challenges {
use super::*;
use crate::models::peer::SYNC_CHALLENGE_POW_WITNESS_LENGTH;
use crate::tests::shared::fake_valid_sequence_of_blocks_for_tests_dyn;

#[traced_test]
Expand Down Expand Up @@ -3714,8 +3713,9 @@ mod peer_loop_tests {
let network = Network::Main;
let genesis_block: Block = Block::genesis_block(network);

const ALICE_SYNC_MODE_THRESHOLD: usize = 10;
let alice_cli = cli_args::Args {
sync_mode_threshold: 10,
sync_mode_threshold: ALICE_SYNC_MODE_THRESHOLD,
..Default::default()
};
let (
Expand Down Expand Up @@ -3748,11 +3748,13 @@ mod peer_loop_tests {
alice.set_new_tip(block_1.clone()).await?;
bob.set_new_tip(block_1.clone()).await?;

// produce enough blocks to ensure alice needs to go into sync mode
// with this block notification.
let blocks = fake_valid_sequence_of_blocks_for_tests_dyn(
&block_1,
TARGET_BLOCK_INTERVAL,
rng.gen(),
rng.gen_range(SYNC_CHALLENGE_POW_WITNESS_LENGTH..20),
rng.gen_range(ALICE_SYNC_MODE_THRESHOLD + 1..20),
)
.await;
for block in &blocks {
Expand Down

0 comments on commit fa3dc86

Please sign in to comment.