Skip to content

Commit faa4b28

Browse files
Merge pull request stacks-network#6968 from jacinta-stacks/fix/flakey-tenure-extend-tests
Fix flakiness in a bunch of tests
2 parents d929c52 + 3aa237a commit faa4b28

19 files changed

+1154
-1613
lines changed

stacks-node/src/nakamoto_node/relayer.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1702,7 +1702,7 @@ impl RelayerThread {
17021702

17031703
#[cfg(test)]
17041704
fn fault_injection_skip_block_commit(&self) -> bool {
1705-
self.globals.counters.naka_skip_commit_op.get()
1705+
self.globals.counters.skip_commit_op.get()
17061706
}
17071707

17081708
#[cfg(not(test))]

stacks-node/src/neon_node.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2645,6 +2645,11 @@ impl BlockMinerThread {
26452645
);
26462646

26472647
// let's commit
2648+
#[cfg(test)]
2649+
if self.globals.counters.skip_commit_op.get() {
2650+
debug!("Relayer: fault injection: skip block commit");
2651+
return None;
2652+
}
26482653
let op = self.make_block_commit(
26492654
&mut burn_db,
26502655
&mut chain_state,

stacks-node/src/run_loop/neon.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ pub struct Counters {
135135
pub naka_miner_current_rejections_timeout_secs: RunLoopCounter,
136136

137137
#[cfg(test)]
138-
pub naka_skip_commit_op: TestFlag<bool>,
138+
pub skip_commit_op: TestFlag<bool>,
139139
}
140140

141141
impl Counters {

stacks-node/src/tests/nakamoto_integrations.rs

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5402,7 +5402,7 @@ fn bad_commit_does_not_trigger_fork() {
54025402
blocks_processed,
54035403
naka_submitted_commits: commits_submitted,
54045404
naka_mined_blocks: mined_blocks,
5405-
naka_skip_commit_op: test_skip_commit_op,
5405+
skip_commit_op: test_skip_commit_op,
54065406
..
54075407
} = run_loop.counters();
54085408
let counters = run_loop.counters();
@@ -6186,7 +6186,7 @@ fn nakamoto_attempt_time() {
61866186
privk: Secp256k1PrivateKey,
61876187
_address: StacksAddress,
61886188
}
6189-
let num_accounts = 1_000;
6189+
let num_accounts = 100;
61906190
let init_account_balance = 1_000_000_000;
61916191
let account_keys = add_initial_balances(&mut naka_conf, num_accounts, init_account_balance);
61926192
let mut account = account_keys
@@ -6402,7 +6402,7 @@ fn nakamoto_attempt_time() {
64026402
.expect("Mutex poisoned")
64036403
.get_stacks_blocks_processed();
64046404

6405-
let tx_limit = 10000;
6405+
let tx_limit = 1000;
64066406
let tx_fee = 500;
64076407
let amount = 500;
64086408
let mut tx_total_size = 0;
@@ -9651,7 +9651,7 @@ fn run_mock_mining_ongoing_tenure_boot_test(check_empty_sortition_recovery: bool
96519651
let follower_mined_before_empty_sortition = follower_mined_blocks.load(Ordering::SeqCst);
96529652

96539653
// Force an empty sortition and ensure the restarted mock miner keeps mining afterwards.
9654-
counters.naka_skip_commit_op.set(true);
9654+
counters.skip_commit_op.set(true);
96559655
let miner_burn_height_before = get_chain_info(&naka_conf).burn_block_height;
96569656
let follower_burn_height_before = get_chain_info(&follower_conf).burn_block_height;
96579657

@@ -9678,7 +9678,7 @@ fn run_mock_mining_ongoing_tenure_boot_test(check_empty_sortition_recovery: bool
96789678
})
96799679
.expect("Mock miner did not continue mining after empty sortition");
96809680
TEST_P2P_BROADCAST_STALL.set(false);
9681-
counters.naka_skip_commit_op.set(false);
9681+
counters.skip_commit_op.set(false);
96829682
} else {
96839683
// Confirm the restarted follower can start mining in the middle of an ongoing tenure.
96849684
let follower_mined_before_mid_tenure = follower_mined_blocks.load(Ordering::SeqCst);
@@ -9702,7 +9702,7 @@ fn run_mock_mining_ongoing_tenure_boot_test(check_empty_sortition_recovery: bool
97029702

97039703
// Best-effort reset for test globals before teardown.
97049704
TEST_P2P_BROADCAST_STALL.set(false);
9705-
counters.naka_skip_commit_op.set(false);
9705+
counters.skip_commit_op.set(false);
97069706

97079707
coord_channel
97089708
.lock()
@@ -11373,7 +11373,7 @@ fn test_tenure_extend_from_flashblocks() {
1137311373
next_block_and_mine_commit(btc_regtest_controller, 60, &naka_conf, &counters).unwrap();
1137411374

1137511375
// prevent the miner from sending another block-commit
11376-
counters.naka_skip_commit_op.set(true);
11376+
counters.skip_commit_op.set(true);
1137711377

1137811378
let info_before = get_chain_info(&naka_conf);
1137911379

@@ -11465,7 +11465,7 @@ fn test_tenure_extend_from_flashblocks() {
1146511465
}
1146611466

1146711467
// unstall miner thread and allow block-commits again
11468-
counters.naka_skip_commit_op.set(false);
11468+
counters.skip_commit_op.set(false);
1146911469
fault_injection_unstall_miner();
1147011470

1147111471
// wait for the miner directive to be processed
@@ -16217,7 +16217,6 @@ fn check_sip040_post_conditions() {
1621716217
get_tx_result_by_id(&mint_and_send_as_contract_originator_txid),
1621816218
Some(Value::okay_true())
1621916219
);
16220-
sender_nonce += 1;
1622116220

1622216221
coord_channel
1622316222
.lock()
@@ -19321,7 +19320,7 @@ fn tenure_extend_no_commits() {
1932119320
test_observer::clear();
1932219321

1932319322
// Skip block commits so that for the next block, there is no new commit
19324-
counters.naka_skip_commit_op.set(true);
19323+
counters.skip_commit_op.set(true);
1932519324

1932619325
// Mine an empty Bitcoin block (no commits)
1932719326
info!("1. Mining an empty Bitcoin block, even though the miner had submitted a valid commit");

0 commit comments

Comments
 (0)