Skip to content
This repository has been archived by the owner on Aug 22, 2024. It is now read-only.

Commit

Permalink
chore: add unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
jcnelson committed May 6, 2024
1 parent d6f5ce6 commit 07c6ac8
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 4 deletions.
10 changes: 6 additions & 4 deletions stackslib/src/net/inv/epoch2x.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1753,7 +1753,7 @@ impl PeerNetwork {
}

/// Determine at which reward cycle to begin scanning inventories
fn get_block_scan_start(&self, sortdb: &SortitionDB) -> u64 {
pub(crate) fn get_block_scan_start(&self, sortdb: &SortitionDB) -> u64 {
// see if the stacks tip affirmation map and heaviest affirmation map diverge. If so, then
// start scaning at the reward cycle just before that.
let am_rescan_rc = self
Expand Down Expand Up @@ -1786,10 +1786,12 @@ impl PeerNetwork {
let rescan_rc = cmp::min(am_rescan_rc, start_reward_cycle);

test_debug!(
"begin blocks inv scan at {} = min({},{})",
"begin blocks inv scan at {} = min({},{}) stacks_tip_am={} heaviest_am={}",
rescan_rc,
stacks_tip_rc,
am_rescan_rc
am_rescan_rc,
start_reward_cycle,
&self.stacks_tip_affirmation_map,
&self.heaviest_affirmation_map
);
rescan_rc
}
Expand Down
50 changes: 50 additions & 0 deletions stackslib/src/net/tests/inv/epoch2x.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1241,6 +1241,56 @@ fn test_sync_inv_diagnose_nack() {
);
}

#[test]
fn test_inv_sync_start_reward_cycle() {
let mut peer_1_config = TestPeerConfig::new(function_name!(), 0, 0);
peer_1_config.connection_opts.inv_reward_cycles = 0;

let mut peer_1 = TestPeer::new(peer_1_config);

let num_blocks = (GETPOXINV_MAX_BITLEN * 2) as u64;
for i in 0..num_blocks {
let (burn_ops, stacks_block, microblocks) = peer_1.make_default_tenure();
peer_1.next_burnchain_block(burn_ops.clone());
peer_1.process_stacks_epoch_at_tip(&stacks_block, &microblocks);
}

let _ = peer_1.step();

let block_scan_start = peer_1
.network
.get_block_scan_start(peer_1.sortdb.as_ref().unwrap());
assert_eq!(block_scan_start, 7);

peer_1.network.connection_opts.inv_reward_cycles = 1;

let block_scan_start = peer_1
.network
.get_block_scan_start(peer_1.sortdb.as_ref().unwrap());
assert_eq!(block_scan_start, 7);

peer_1.network.connection_opts.inv_reward_cycles = 2;

let block_scan_start = peer_1
.network
.get_block_scan_start(peer_1.sortdb.as_ref().unwrap());
assert_eq!(block_scan_start, 6);

peer_1.network.connection_opts.inv_reward_cycles = 3;

let block_scan_start = peer_1
.network
.get_block_scan_start(peer_1.sortdb.as_ref().unwrap());
assert_eq!(block_scan_start, 5);

peer_1.network.connection_opts.inv_reward_cycles = 300;

let block_scan_start = peer_1
.network
.get_block_scan_start(peer_1.sortdb.as_ref().unwrap());
assert_eq!(block_scan_start, 0);
}

#[test]
#[ignore]
fn test_sync_inv_2_peers_plain() {
Expand Down

0 comments on commit 07c6ac8

Please sign in to comment.