Skip to content

Commit b8ecf19

Browse files
committed
test: cleanup more flake
1 parent 1287d88 commit b8ecf19

File tree

1 file changed

+43
-13
lines changed
  • testnet/stacks-node/src/tests/signer

1 file changed

+43
-13
lines changed

testnet/stacks-node/src/tests/signer/v0.rs

Lines changed: 43 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15377,19 +15377,10 @@ fn bitcoin_reorg_extended_tenure() {
1537715377
.expect("Timed out waiting for contract-call");
1537815378
}
1537915379

15380-
let tenure_0_stacks_height = get_chain_info(&conf_1).stacks_tip_height;
1538115380
miners.pause_commits_miner_1();
1538215381
miners
1538315382
.mine_bitcoin_blocks_and_confirm(&sortdb, 1, 60)
1538415383
.unwrap();
15385-
miners.signer_test.check_signer_states_normal();
15386-
let tip_sn = SortitionDB::get_canonical_burn_chain_tip(sortdb.conn()).unwrap();
15387-
assert_eq!(tip_sn.miner_pk_hash, Some(mining_pkh_1));
15388-
15389-
wait_for(60, || {
15390-
Ok(get_chain_info(&conf_1).stacks_tip_height > tenure_0_stacks_height)
15391-
})
15392-
.expect("Timed out waiting for Miner 1 to mine the first block of Tenure 1");
1539315384

1539415385
for _ in 0..2 {
1539515386
miners
@@ -15398,6 +15389,10 @@ fn bitcoin_reorg_extended_tenure() {
1539815389
.expect("Timed out waiting for contract-call");
1539915390
}
1540015391

15392+
miners.signer_test.check_signer_states_normal();
15393+
let tip_sn = SortitionDB::get_canonical_burn_chain_tip(sortdb.conn()).unwrap();
15394+
assert_eq!(tip_sn.miner_pk_hash, Some(mining_pkh_1));
15395+
1540115396
let last_active_sortition = get_sortition_info(&conf_1);
1540215397
assert!(last_active_sortition.was_sortition);
1540315398

@@ -15456,20 +15451,37 @@ fn bitcoin_reorg_extended_tenure() {
1545615451
info!("Bitcoin fork triggered"; "ch" => %before_fork, "btc_height" => burn_block_height);
1545715452
info!("Chain info before fork: {:?}", get_chain_info(&conf_1));
1545815453

15454+
let mut after_fork = get_chain_info(&conf_1).pox_consensus;
1545915455
wait_for(60, || {
15460-
let after_fork = get_chain_info(&conf_1).pox_consensus;
15456+
after_fork = get_chain_info(&conf_1).pox_consensus;
1546115457
Ok(after_fork != before_fork)
1546215458
})
1546315459
.unwrap();
1546415460

1546515461
info!("Chain info after fork: {:?}", get_chain_info(&conf_1));
1546615462

15463+
// get at least one block produced before we stall broadcasts
15464+
// to check signer approvals
1546715465
miners
1546815466
.signer_test
1546915467
.submit_burn_block_call_and_wait(&miners.sender_sk)
1547015468
.expect("Timed out waiting for contract-call");
1547115469

15472-
let latest = get_chain_info(&conf_1);
15470+
// stall p2p broadcast and signer block announcements
15471+
// so that we can ensure all the signers approve the proposal
15472+
// before it gets accepted by stacks-nodes
15473+
TEST_P2P_BROADCAST_STALL.set(true);
15474+
stacks_signer::v0::tests::TEST_SKIP_BLOCK_BROADCAST.set(true);
15475+
15476+
// the signer signature hash is the same as the block header hash.
15477+
// we use the latest_signer_sighash to make sure we're getting block responses for the
15478+
// block we expect to be mined after the next contract call is submitted.
15479+
let latest_signer_sighash = Sha512Trunc256Sum(get_chain_info(&conf_1).stacks_tip.0);
15480+
15481+
miners
15482+
.signer_test
15483+
.submit_contract_call(&miners.sender_sk, "burn-height-local", "run-update", &[])
15484+
.unwrap();
1547315485

1547415486
let rc = miners.signer_test.get_current_reward_cycle();
1547515487
let slot_ids = miners.signer_test.get_signer_indices(rc);
@@ -15479,21 +15491,39 @@ fn bitcoin_reorg_extended_tenure() {
1547915491
.iter()
1548015492
.filter_map(|slot_id| {
1548115493
let latest_br = miners.signer_test.get_latest_block_response(slot_id.0);
15482-
if latest_br.get_signer_signature_hash().0 == latest.stacks_tip.0 {
15494+
if latest_br.get_signer_signature_hash() != latest_signer_sighash {
1548315495
Some(latest_br)
1548415496
} else {
1548515497
None
1548615498
}
1548715499
})
1548815500
.collect();
15489-
Ok(block_responses.len() == num_signers)
15501+
let Some(sighash) = block_responses
15502+
.first()
15503+
.map(BlockResponse::get_signer_signature_hash)
15504+
else {
15505+
return Ok(false);
15506+
};
15507+
let all_same_block = block_responses
15508+
.iter()
15509+
.all(|x| x.get_signer_signature_hash() == sighash);
15510+
let all_responded = block_responses.len() == num_signers;
15511+
Ok(all_same_block && all_responded)
1549015512
})
1549115513
.unwrap();
1549215514

1549315515
assert!(block_responses
1549415516
.iter()
1549515517
.all(|resp| resp.as_block_accepted().is_some()));
1549615518

15519+
TEST_P2P_BROADCAST_STALL.set(false);
15520+
stacks_signer::v0::tests::TEST_SKIP_BLOCK_BROADCAST.set(false);
15521+
15522+
miners
15523+
.signer_test
15524+
.submit_burn_block_call_and_wait(&miners.sender_sk)
15525+
.expect("Timed out waiting for contract-call");
15526+
1549715527
miners.submit_commit_miner_1(&sortdb);
1549815528
miners
1549915529
.mine_bitcoin_blocks_and_confirm(&sortdb, 1, 60)

0 commit comments

Comments
 (0)