Skip to content

Commit 5ee3152

Browse files
committed
chore: fix unit test, add integration test to github workflow
1 parent 7c7f9b3 commit 5ee3152

File tree

4 files changed

+30
-18
lines changed

4 files changed

+30
-18
lines changed

.github/workflows/bitcoin-tests.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ jobs:
9797
- tests::nakamoto_integrations::check_block_info
9898
- tests::nakamoto_integrations::check_block_info_rewards
9999
- tests::nakamoto_integrations::continue_tenure_extend
100+
- tests::nakamoto_integrations::multiple_miners
100101
# Do not run this one until we figure out why it fails in CI
101102
# - tests::neon_integrations::bitcoin_reorg_flap
102103
# - tests::neon_integrations::bitcoin_reorg_flap_with_follower

stackslib/src/chainstate/nakamoto/mod.rs

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -455,13 +455,17 @@ impl MaturedMinerPaymentSchedules {
455455
}
456456
}
457457

458+
/// Struct containing information about the miners assigned in the
459+
/// .miners stackerdb config
458460
pub struct MinersDBInformation {
459461
signer_0_sortition: ConsensusHash,
460462
signer_1_sortition: ConsensusHash,
461463
latest_winner: u16,
462464
}
463465

464466
impl MinersDBInformation {
467+
/// What index in the `.miners` stackerdb is the miner who won
468+
/// `sortition`?
465469
pub fn get_signer_index(&self, sortition: &ConsensusHash) -> Option<u16> {
466470
if sortition == &self.signer_0_sortition {
467471
Some(0)
@@ -472,6 +476,12 @@ impl MinersDBInformation {
472476
}
473477
}
474478

479+
/// Get all of the sortitions whose winners are included in .miners
480+
pub fn get_sortitions(&self) -> [&ConsensusHash; 2] {
481+
[&self.signer_0_sortition, &self.signer_1_sortition]
482+
}
483+
484+
/// Get the index of the latest sortition winner in .miners
475485
pub fn get_latest_winner_index(&self) -> u16 {
476486
self.latest_winner
477487
}
@@ -4160,14 +4170,18 @@ impl NakamotoChainState {
41604170
.map(usize::from)
41614171
else {
41624172
warn!("Miner is not in the miners StackerDB config";
4163-
"stackerdb_slots" => format!("{:?}", &stackerdb_config.signers));
4173+
"stackerdb_slots" => ?stackerdb_config.signers,
4174+
"queried_sortition" => %election_sortition,
4175+
"sortition_hashes" => ?miners_info.get_sortitions());
41644176
return Ok(None);
41654177
};
41664178
let mut signer_ranges = stackerdb_config.signer_ranges();
41674179
if signer_ix >= signer_ranges.len() {
41684180
// should be unreachable, but always good to be careful
41694181
warn!("Miner is not in the miners StackerDB config";
4170-
"stackerdb_slots" => format!("{:?}", &stackerdb_config.signers));
4182+
"stackerdb_slots" => ?stackerdb_config.signers,
4183+
"queried_sortition" => %election_sortition,
4184+
"sortition_hashes" => ?miners_info.get_sortitions());
41714185

41724186
return Ok(None);
41734187
}

stackslib/src/chainstate/nakamoto/tests/mod.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2080,9 +2080,8 @@ fn test_make_miners_stackerdb_config() {
20802080
let tip = SortitionDB::get_canonical_burn_chain_tip(sort_db.conn()).unwrap();
20812081
let miner_privkey = &miner_keys[i];
20822082
let miner_pubkey = StacksPublicKey::from_private(miner_privkey);
2083-
let slot_id =
2084-
NakamotoChainState::get_miner_slot(&sort_db, &tip, &block.header.consensus_hash)
2085-
.expect("Failed to get miner slot");
2083+
let slot_id = NakamotoChainState::get_miner_slot(&sort_db, &tip, &tip.consensus_hash)
2084+
.expect("Failed to get miner slot");
20862085
if sortition {
20872086
let slot_id = slot_id.expect("No miner slot exists for this miner").start;
20882087
let slot_version = stackerdbs

testnet/stacks-node/src/tests/nakamoto_integrations.rs

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1571,14 +1571,15 @@ fn mine_multiple_per_tenure_integration() {
15711571

15721572
#[test]
15731573
#[ignore]
1574-
/// This test spins up a nakamoto-neon node.
1574+
/// This test spins up two nakamoto nodes, both configured to mine.
15751575
/// It starts in Epoch 2.0, mines with `neon_node` to Epoch 3.0, and then switches
15761576
/// to Nakamoto operation (activating pox-4 by submitting a stack-stx tx). The BootLoop
15771577
/// struct handles the epoch-2/3 tear-down and spin-up.
15781578
/// This test makes three assertions:
1579-
/// * 5 tenures are mined after 3.0 starts
1580-
/// * Each tenure has 10 blocks (the coinbase block and 9 interim blocks)
1581-
fn multiple_nodes() {
1579+
/// * 15 tenures are mined after 3.0 starts
1580+
/// * Each tenure has 6 blocks (the coinbase block and 5 interim blocks)
1581+
/// * Both nodes see the same chainstate at the end of the test
1582+
fn multiple_miners() {
15821583
if env::var("BITCOIND_TEST") != Ok("1".into()) {
15831584
return;
15841585
}
@@ -1683,7 +1684,7 @@ fn multiple_nodes() {
16831684
let coord_channel = run_loop.coordinator_channels();
16841685
let coord_channel_2 = run_loop_2.coordinator_channels();
16851686

1686-
let run_loop_2_thread = thread::Builder::new()
1687+
let _run_loop_2_thread = thread::Builder::new()
16871688
.name("run_loop_2".into())
16881689
.spawn(move || run_loop_2.start(None, 0))
16891690
.unwrap();
@@ -1733,11 +1734,7 @@ fn multiple_nodes() {
17331734
info!("Neighbors 2"; "neighbors" => ?get_neighbors(&conf_node_2));
17341735

17351736
// Wait one block to confirm the VRF register, wait until a block commit is submitted
1736-
next_block_and(&mut btc_regtest_controller, 60, || {
1737-
let commits_count = commits_submitted.load(Ordering::SeqCst);
1738-
Ok(commits_count >= 1)
1739-
})
1740-
.unwrap();
1737+
wait_for_first_naka_block_commit(60, &commits_submitted);
17411738

17421739
// Mine `tenure_count` nakamoto tenures
17431740
for tenure_ix in 0..tenure_count {
@@ -1799,8 +1796,10 @@ fn multiple_nodes() {
17991796
"is_nakamoto" => tip.anchored_header.as_stacks_nakamoto().is_some(),
18001797
);
18011798

1802-
info!("Peer 1 information"; "chain_info" => ?get_chain_info(&naka_conf).stacks_tip_height);
1803-
info!("Peer 2 information"; "chain_info" => ?get_chain_info(&conf_node_2).stacks_tip_height);
1799+
let peer_1_height = get_chain_info(&naka_conf).stacks_tip_height;
1800+
let peer_2_height = get_chain_info(&conf_node_2).stacks_tip_height;
1801+
info!("Peer height information"; "peer_1" => peer_1_height, "peer_2" => peer_2_height);
1802+
assert_eq!(peer_1_height, peer_2_height);
18041803

18051804
assert!(tip.anchored_header.as_stacks_nakamoto().is_some());
18061805
assert_eq!(
@@ -1821,7 +1820,6 @@ fn multiple_nodes() {
18211820
run_loop_2_stopper.store(false, Ordering::SeqCst);
18221821

18231822
run_loop_thread.join().unwrap();
1824-
// run_loop_2_thread.join().unwrap();
18251823
}
18261824

18271825
#[test]

0 commit comments

Comments
 (0)