Skip to content

Commit cc2af4e

Browse files
committed
Should not use the nakamoto blocks mined test observer heuristic in multi miner tests
Signed-off-by: Jacinta Ferrant <[email protected]>
1 parent 66bc4ab commit cc2af4e

File tree

2 files changed

+28
-22
lines changed

2 files changed

+28
-22
lines changed

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,8 @@ impl<S: Signer<T> + Send + 'static, T: SignerEventTrait + 'static> SignerTest<Sp
310310
}
311311

312312
/// Mine a BTC block and wait for a new Stacks block to be mined
313-
fn mine_nakamoto_block(&mut self, timeout: Duration) {
313+
/// Note: do not use nakamoto blocks mined heuristic if running a test with multiple miners
314+
fn mine_nakamoto_block(&mut self, timeout: Duration, use_nakamoto_blocks_mined: bool) {
314315
let commits_submitted = self.running_nodes.commits_submitted.clone();
315316
let mined_block_time = Instant::now();
316317
let mined_before = self.running_nodes.nakamoto_blocks_mined.get();
@@ -327,7 +328,7 @@ impl<S: Signer<T> + Send + 'static, T: SignerEventTrait + 'static> SignerTest<Sp
327328
let info_after = self.get_peer_info();
328329
let blocks_mined = self.running_nodes.nakamoto_blocks_mined.get();
329330
Ok(info_after.stacks_tip_height > info_before.stacks_tip_height
330-
&& blocks_mined > mined_before)
331+
&& (!use_nakamoto_blocks_mined || blocks_mined > mined_before))
331332
})
332333
.unwrap();
333334
let mined_block_elapsed_time = mined_block_time.elapsed();

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

Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ impl SignerTest<SpawnedSigner> {
280280
// could be other miners mining blocks.
281281
let height_before = get_chain_info(&self.running_nodes.conf).stacks_tip_height;
282282
info!("Waiting for first Nakamoto block: {}", height_before + 1);
283-
self.mine_nakamoto_block(Duration::from_secs(30));
283+
self.mine_nakamoto_block(Duration::from_secs(30), false);
284284
wait_for(30, || {
285285
Ok(get_chain_info(&self.running_nodes.conf).stacks_tip_height > height_before)
286286
})
@@ -289,12 +289,17 @@ impl SignerTest<SpawnedSigner> {
289289
}
290290

291291
// Only call after already past the epoch 3.0 boundary
292-
fn mine_and_verify_confirmed_naka_block(&mut self, timeout: Duration, num_signers: usize) {
292+
fn mine_and_verify_confirmed_naka_block(
293+
&mut self,
294+
timeout: Duration,
295+
num_signers: usize,
296+
use_nakamoto_blocks_mined: bool,
297+
) {
293298
info!("------------------------- Try mining one block -------------------------");
294299

295300
let reward_cycle = self.get_current_reward_cycle();
296301

297-
self.mine_nakamoto_block(timeout);
302+
self.mine_nakamoto_block(timeout, use_nakamoto_blocks_mined);
298303

299304
// Verify that the signers accepted the proposed block, sending back a validate ok response
300305
let proposed_signer_signature_hash = self
@@ -377,7 +382,7 @@ impl SignerTest<SpawnedSigner> {
377382
let total_nmb_blocks_to_mine = burnchain_height.saturating_sub(current_block_height);
378383
debug!("Mining {total_nmb_blocks_to_mine} Nakamoto block(s) to reach burnchain height {burnchain_height}");
379384
for _ in 0..total_nmb_blocks_to_mine {
380-
self.mine_and_verify_confirmed_naka_block(timeout, num_signers);
385+
self.mine_and_verify_confirmed_naka_block(timeout, num_signers, false);
381386
}
382387
}
383388

@@ -590,7 +595,7 @@ fn miner_gather_signatures() {
590595
signer_test.boot_to_epoch_3();
591596

592597
info!("------------------------- Test Mine and Verify Confirmed Nakamoto Block -------------------------");
593-
signer_test.mine_and_verify_confirmed_naka_block(timeout, num_signers);
598+
signer_test.mine_and_verify_confirmed_naka_block(timeout, num_signers, true);
594599

595600
// Test prometheus metrics response
596601
#[cfg(feature = "monitoring_prom")]
@@ -1327,7 +1332,7 @@ fn bitcoind_forking_test() {
13271332

13281333
for i in 0..pre_fork_tenures {
13291334
info!("Mining pre-fork tenure {} of {pre_fork_tenures}", i + 1);
1330-
signer_test.mine_nakamoto_block(Duration::from_secs(30));
1335+
signer_test.mine_nakamoto_block(Duration::from_secs(30), true);
13311336
}
13321337

13331338
let pre_fork_1_nonce = get_account(&http_origin, &miner_address).nonce;
@@ -1399,7 +1404,7 @@ fn bitcoind_forking_test() {
13991404

14001405
for i in 0..5 {
14011406
info!("Mining post-fork tenure {} of 5", i + 1);
1402-
signer_test.mine_nakamoto_block(Duration::from_secs(30));
1407+
signer_test.mine_nakamoto_block(Duration::from_secs(30), true);
14031408
}
14041409

14051410
let pre_fork_2_nonce = get_account(&http_origin, &miner_address).nonce;
@@ -1475,7 +1480,7 @@ fn bitcoind_forking_test() {
14751480

14761481
for i in 0..5 {
14771482
info!("Mining post-fork tenure {} of 5", i + 1);
1478-
signer_test.mine_nakamoto_block(Duration::from_secs(30));
1483+
signer_test.mine_nakamoto_block(Duration::from_secs(30), true);
14791484
}
14801485

14811486
let test_end_nonce = get_account(&http_origin, &miner_address).nonce;
@@ -2508,7 +2513,7 @@ fn signers_broadcast_signed_blocks() {
25082513
.running_nodes
25092514
.nakamoto_blocks_mined
25102515
.load(Ordering::SeqCst);
2511-
signer_test.mine_nakamoto_block(Duration::from_secs(30));
2516+
signer_test.mine_nakamoto_block(Duration::from_secs(30), true);
25122517

25132518
wait_for(30, || {
25142519
let blocks_mined = signer_test
@@ -2609,7 +2614,7 @@ fn tenure_extend_after_idle() {
26092614
signer_test.boot_to_epoch_3();
26102615

26112616
info!("---- Nakamoto booted, starting test ----");
2612-
signer_test.mine_nakamoto_block(Duration::from_secs(30));
2617+
signer_test.mine_nakamoto_block(Duration::from_secs(30), true);
26132618

26142619
info!("---- Waiting for a tenure extend ----");
26152620

@@ -2671,7 +2676,7 @@ fn stx_transfers_dont_effect_idle_timeout() {
26712676
"info_height" => info_before.stacks_tip_height,
26722677
"blocks_before" => blocks_before,
26732678
);
2674-
signer_test.mine_nakamoto_block(Duration::from_secs(30));
2679+
signer_test.mine_nakamoto_block(Duration::from_secs(30), true);
26752680

26762681
info!("---- Getting current idle timeout ----");
26772682

@@ -2809,7 +2814,7 @@ fn idle_tenure_extend_active_mining() {
28092814
// Add a delay to the block validation process
28102815
TEST_VALIDATE_DELAY_DURATION_SECS.lock().unwrap().replace(3);
28112816

2812-
signer_test.mine_nakamoto_block(Duration::from_secs(30));
2817+
signer_test.mine_nakamoto_block(Duration::from_secs(30), true);
28132818

28142819
info!("---- Getting current idle timeout ----");
28152820

@@ -2877,7 +2882,7 @@ fn idle_tenure_extend_active_mining() {
28772882

28782883
info!("----- Submitted deploy txs, mining BTC block -----");
28792884

2880-
signer_test.mine_nakamoto_block(Duration::from_secs(30));
2885+
signer_test.mine_nakamoto_block(Duration::from_secs(30), true);
28812886
let mut last_response = signer_test.get_latest_block_response(slot_id);
28822887

28832888
// Make multiple tenures that get extended through idle timeouts
@@ -3990,7 +3995,7 @@ fn signer_set_rollover() {
39903995
send_amt,
39913996
);
39923997
submit_tx(&http_origin, &transfer_tx);
3993-
signer_test.mine_nakamoto_block(short_timeout);
3998+
signer_test.mine_nakamoto_block(short_timeout, true);
39943999
let mined_block = test_observer::get_mined_nakamoto_blocks().pop().unwrap();
39954000
let block_sighash = mined_block.signer_signature_hash;
39964001
let signer_signatures = mined_block.signer_signature;
@@ -4064,7 +4069,7 @@ fn signer_set_rollover() {
40644069
})
40654070
.expect("Timed out waiting for stacking txs to be mined");
40664071

4067-
signer_test.mine_nakamoto_block(short_timeout);
4072+
signer_test.mine_nakamoto_block(short_timeout, true);
40684073

40694074
let next_reward_cycle = reward_cycle.saturating_add(1);
40704075

@@ -4117,7 +4122,7 @@ fn signer_set_rollover() {
41174122
send_amt,
41184123
);
41194124
submit_tx(&http_origin, &transfer_tx);
4120-
signer_test.mine_nakamoto_block(short_timeout);
4125+
signer_test.mine_nakamoto_block(short_timeout, true);
41214126
let mined_block = test_observer::get_mined_nakamoto_blocks().pop().unwrap();
41224127

41234128
info!("---- Verifying that the new signers signed the block -----");
@@ -4304,7 +4309,7 @@ fn duplicate_signers() {
43044309

43054310
info!("------------------------- Try mining one block -------------------------");
43064311

4307-
signer_test.mine_and_verify_confirmed_naka_block(timeout, num_signers);
4312+
signer_test.mine_and_verify_confirmed_naka_block(timeout, num_signers, true);
43084313

43094314
info!("------------------------- Read all `BlockResponse::Accepted` messages -------------------------");
43104315

@@ -6816,7 +6821,7 @@ fn continue_after_tenure_extend() {
68166821
signer_test.boot_to_epoch_3();
68176822

68186823
info!("------------------------- Mine Normal Tenure -------------------------");
6819-
signer_test.mine_and_verify_confirmed_naka_block(timeout, num_signers);
6824+
signer_test.mine_and_verify_confirmed_naka_block(timeout, num_signers, true);
68206825

68216826
info!("------------------------- Extend Tenure -------------------------");
68226827
signer_test
@@ -7462,7 +7467,7 @@ fn block_validation_response_timeout() {
74627467
signer_test.boot_to_epoch_3();
74637468

74647469
info!("------------------------- Test Mine and Verify Confirmed Nakamoto Block -------------------------");
7465-
signer_test.mine_and_verify_confirmed_naka_block(timeout, num_signers);
7470+
signer_test.mine_and_verify_confirmed_naka_block(timeout, num_signers, true);
74667471
info!("------------------------- Test Block Validation Stalled -------------------------");
74677472
TEST_VALIDATE_STALL.lock().unwrap().replace(true);
74687473
let validation_stall_start = Instant::now();
@@ -7580,7 +7585,7 @@ fn block_validation_response_timeout() {
75807585
);
75817586
info!("------------------------- Test Mine and Verify Confirmed Nakamoto Block -------------------------");
75827587
let info_before = info_after;
7583-
signer_test.mine_and_verify_confirmed_naka_block(timeout, num_signers);
7588+
signer_test.mine_and_verify_confirmed_naka_block(timeout, num_signers, true);
75847589

75857590
wait_for(30, || {
75867591
let info = get_chain_info(&signer_test.running_nodes.conf);

0 commit comments

Comments
 (0)