Skip to content

Commit a823146

Browse files
committed
Cleanup tests that should be using mine_nakamoto_block or mine_bitcoin block
Signed-off-by: Jacinta Ferrant <[email protected]>
1 parent 77cc93e commit a823146

File tree

1 file changed

+22
-126
lines changed
  • stacks-node/src/tests/signer

1 file changed

+22
-126
lines changed

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

Lines changed: 22 additions & 126 deletions
Original file line numberDiff line numberDiff line change
@@ -785,8 +785,11 @@ impl MultipleMinerTest {
785785
.unwrap()
786786
.block_height;
787787

788+
debug!("HERE Building {nmb_blocks} BTC blocks.");
788789
self.btc_regtest_controller_mut()
789790
.build_next_block(nmb_blocks);
791+
792+
debug!("HERE Waiting to for burn chain tip to advance {nmb_blocks} blocks.");
790793
wait_for(timeout_secs, || {
791794
let burn_block = SortitionDB::get_canonical_burn_chain_tip(sortdb.conn())
792795
.unwrap()
@@ -795,6 +798,10 @@ impl MultipleMinerTest {
795798
&& self.get_peer_info().burn_block_height >= burn_block_before + nmb_blocks)
796799
})?;
797800
let peer_after = self.get_peer_info();
801+
debug!(
802+
"HERE Waiting for updates for burn block {} with block height {}.",
803+
peer_after.pox_consensus, peer_after.burn_block_height
804+
);
798805
wait_for_state_machine_update(
799806
timeout_secs,
800807
&peer_after.pox_consensus,
@@ -1841,33 +1848,12 @@ fn miner_gather_signatures() {
18411848
info!("------------------------- Test Setup -------------------------");
18421849
let num_signers = 5;
18431850
let signer_test: SignerTest<SpawnedSigner> = SignerTest::new(num_signers, vec![]);
1844-
let miner_sk = signer_test.running_nodes.conf.miner.mining_key.unwrap();
1845-
let miner_pk = StacksPublicKey::from_private(&miner_sk);
1846-
let miner_pkh = Hash160::from_node_public_key(&miner_pk);
18471851

18481852
signer_test.boot_to_epoch_3();
18491853

18501854
info!("------------------------- Test Mine and Verify Confirmed Nakamoto Block -------------------------");
18511855
TEST_MINE_SKIP.set(true);
1852-
let info_before = get_chain_info(&signer_test.running_nodes.conf);
1853-
next_block_and(
1854-
&signer_test.running_nodes.btc_regtest_controller,
1855-
30,
1856-
|| {
1857-
let info = get_chain_info(&signer_test.running_nodes.conf);
1858-
Ok(info.burn_block_height > info_before.burn_block_height)
1859-
},
1860-
)
1861-
.expect("Failed to process bitcoin block");
1862-
let info_after = get_chain_info(&signer_test.running_nodes.conf);
1863-
wait_for_state_machine_update(
1864-
30,
1865-
&info_after.pox_consensus,
1866-
info_after.burn_block_height,
1867-
Some((miner_pkh, info_before.stacks_tip_height)),
1868-
&signer_test.signer_addresses_versions(),
1869-
)
1870-
.expect("Failed to update state machine");
1856+
signer_test.mine_bitcoin_block();
18711857
TEST_MINE_SKIP.set(false);
18721858
signer_test.check_signer_states_normal();
18731859

@@ -7079,17 +7065,7 @@ fn empty_tenure_delayed() {
70797065
} = signer_test.running_nodes.counters.clone();
70807066

70817067
info!("------------------------- Test Mine Regular Tenure A -------------------------");
7082-
let info_before = signer_test.get_peer_info();
7083-
// Mine a regular tenure, but wait for commits to be submitted
7084-
next_block_and(
7085-
&signer_test.running_nodes.btc_regtest_controller,
7086-
60,
7087-
|| {
7088-
let info = signer_test.get_peer_info();
7089-
Ok(info.stacks_tip_height > info_before.stacks_tip_height)
7090-
},
7091-
)
7092-
.unwrap();
7068+
signer_test.mine_nakamoto_block(Duration::from_secs(30), true);
70937069
signer_test.check_signer_states_normal();
70947070

70957071
info!("------------------------- Test Mine Empty Tenure B -------------------------");
@@ -7251,7 +7227,6 @@ fn empty_sortition_before_approval() {
72517227
.expect("Timed out waiting for commit to be submitted for Tenure A");
72527228

72537229
let info = get_chain_info(&signer_test.running_nodes.conf);
7254-
let burn_height_before = info.burn_block_height;
72557230
let stacks_height_before = info.stacks_tip_height;
72567231

72577232
info!("Forcing miner to ignore signatures for next block");
@@ -7274,15 +7249,7 @@ fn empty_sortition_before_approval() {
72747249
info!("------------------------- Test Mine Empty Tenure B -------------------------");
72757250

72767251
// Trigger an empty tenure
7277-
next_block_and(
7278-
&signer_test.running_nodes.btc_regtest_controller,
7279-
60,
7280-
|| {
7281-
let burn_height = get_chain_info(&signer_test.running_nodes.conf).burn_block_height;
7282-
Ok(burn_height == burn_height_before + 2)
7283-
},
7284-
)
7285-
.expect("Failed to mine empty tenure");
7252+
signer_test.mine_bitcoin_block();
72867253
signer_test.check_signer_states_normal_missed_sortition();
72877254

72887255
info!("Unpause block commits");
@@ -10530,19 +10497,10 @@ fn block_commit_delay() {
1053010497
TEST_REJECT_ALL_BLOCK_PROPOSAL.set(all_signers);
1053110498

1053210499
info!("------------------------- Test Mine Burn Block -------------------------");
10533-
let burn_height_before = get_chain_info(&signer_test.running_nodes.conf).burn_block_height;
1053410500
let commits_before = commits_submitted.load(Ordering::SeqCst);
1053510501

1053610502
// Mine a burn block and wait for it to be processed.
10537-
next_block_and(
10538-
&signer_test.running_nodes.btc_regtest_controller,
10539-
60,
10540-
|| {
10541-
let burn_height = get_chain_info(&signer_test.running_nodes.conf).burn_block_height;
10542-
Ok(burn_height > burn_height_before)
10543-
},
10544-
)
10545-
.unwrap();
10503+
signer_test.mine_bitcoin_block();
1054610504

1054710505
// Sleep an extra minute to ensure no block commits are sent
1054810506
sleep_ms(60_000);
@@ -11105,17 +11063,7 @@ fn new_tenure_while_validating_previous_scenario() {
1110511063

1110611064
info!("----- Mining a new BTC block -----");
1110711065
TEST_MINE_SKIP.set(true);
11108-
next_block_and(
11109-
&signer_test.running_nodes.btc_regtest_controller,
11110-
30,
11111-
|| {
11112-
Ok(
11113-
get_chain_info(&signer_test.running_nodes.conf).burn_block_height
11114-
> info_before.burn_block_height,
11115-
)
11116-
},
11117-
)
11118-
.unwrap();
11066+
signer_test.mine_bitcoin_block();
1111911067

1112011068
let info = signer_test.get_peer_info();
1112111069
wait_for_state_machine_update_by_miner_tenure_id(
@@ -11853,17 +11801,7 @@ fn global_acceptance_depends_on_block_announcement() {
1185311801
TEST_REJECT_ALL_BLOCK_PROPOSAL.set(Vec::new());
1185411802
TEST_IGNORE_SIGNERS.set(false);
1185511803
test_observer::clear();
11856-
next_block_and(
11857-
&signer_test.running_nodes.btc_regtest_controller,
11858-
60,
11859-
|| {
11860-
Ok(
11861-
get_chain_info(&signer_test.running_nodes.conf).burn_block_height
11862-
> info_before.burn_block_height,
11863-
)
11864-
},
11865-
)
11866-
.unwrap();
11804+
signer_test.mine_bitcoin_block();
1186711805

1186811806
let info = get_chain_info(&signer_test.running_nodes.conf);
1186911807
info!(
@@ -13167,16 +13105,8 @@ fn reorg_attempts_activity_timeout_exceeded() {
1316713105

1316813106
info!("------------------------- Start Tenure B -------------------------");
1316913107
test_observer::clear();
13170-
let chain_before = get_chain_info(&signer_test.running_nodes.conf);
13171-
next_block_and(
13172-
&signer_test.running_nodes.btc_regtest_controller,
13173-
60,
13174-
|| {
13175-
let chain_info = get_chain_info(&signer_test.running_nodes.conf);
13176-
Ok(chain_info.burn_block_height > chain_before.burn_block_height)
13177-
},
13178-
)
13179-
.unwrap();
13108+
let chain_before = chain_after;
13109+
signer_test.mine_bitcoin_block();
1318013110
let chain_after = get_chain_info(&signer_test.running_nodes.conf);
1318113111
wait_for_state_machine_update_by_miner_tenure_id(
1318213112
30,
@@ -13977,14 +13907,8 @@ fn disallow_reorg_within_first_proposal_burn_block_timing_secs_but_more_than_one
1397713907
get_chain_info(&conf_1).stacks_tip_height,
1397813908
block_n_height + 3
1397913909
);
13980-
let burn_height_before = get_chain_info(&conf_1).burn_block_height;
1398113910
info!("------------------------- Miner 1 Wins the Next Tenure, Mines N+1', got rejected -------------------------");
13982-
next_block_and(miners.btc_regtest_controller_mut(), 30, || {
13983-
let info = get_chain_info(&conf_1);
13984-
Ok(info.burn_block_height == burn_height_before + 1)
13985-
})
13986-
.expect("Failed to advance chain tip");
13987-
13911+
miners.signer_test.mine_bitcoin_block();
1398813912
// assure we have a successful sortition that miner 1 won
1398913913
verify_sortition_winner(&sortdb, &miner_pkh_1);
1399013914
// wait for a block N+1' proposal from miner1
@@ -15503,6 +15427,7 @@ fn mark_miner_as_invalid_if_reorg_is_rejected_v1() {
1550315427

1550415428
info!("------------------------- Miner 1 Mines a Nakamoto Block N -------------------------");
1550515429
let info_before = get_chain_info(&conf_1);
15430+
// Because rl1 is not submitting commits, we cannot use mine_nakamoto_block (commit will never advance)
1550615431
next_block_and(&miners.btc_regtest_controller_mut(), 30, || {
1550715432
let chain_info = get_chain_info(&conf_1);
1550815433
Ok(chain_info.stacks_tip_height > info_before.stacks_tip_height)
@@ -15532,12 +15457,7 @@ fn mark_miner_as_invalid_if_reorg_is_rejected_v1() {
1553215457
fault_injection_stall_miner();
1553315458

1553415459
info!("------------------------- Mine 2 wins the Next Tenure -------------------------");
15535-
let info_before = info_after;
15536-
next_block_and(&miners.btc_regtest_controller_mut(), 30, || {
15537-
let chain_info = get_chain_info(&conf_1);
15538-
Ok(chain_info.burn_block_height > info_before.burn_block_height)
15539-
})
15540-
.expect("Failed to build BTC block");
15460+
miners.signer_test.mine_bitcoin_block();
1554115461
verify_sortition_winner(&sortdb, &miner_pkh_2);
1554215462
miners.signer_test.check_signer_states_normal();
1554315463

@@ -15559,12 +15479,7 @@ fn mark_miner_as_invalid_if_reorg_is_rejected_v1() {
1555915479

1556015480
info!("------------------------- Miner 1 Wins the Next Tenure, Mines N+1' -------------------------");
1556115481
test_observer::clear();
15562-
let info_before = info_after;
15563-
next_block_and(&miners.btc_regtest_controller_mut(), 30, || {
15564-
let chain_info = get_chain_info(&conf_1);
15565-
Ok(chain_info.burn_block_height > info_before.burn_block_height)
15566-
})
15567-
.expect("Failed to build BTC block");
15482+
miners.signer_test.mine_bitcoin_block();
1556815483

1556915484
let block_n_1_prime = wait_for_block_proposal(30, block_n_height + 1, &miner_pk_1)
1557015485
.expect("Failed to get block proposal N+1'");
@@ -17174,16 +17089,7 @@ fn burn_block_height_behavior() {
1717417089
skip_commit_op.set(true);
1717517090

1717617091
// Mine a regular tenure
17177-
let info_before = signer_test.get_peer_info();
17178-
next_block_and(
17179-
&signer_test.running_nodes.btc_regtest_controller,
17180-
60,
17181-
|| {
17182-
let chain_info = get_chain_info(&signer_test.running_nodes.conf);
17183-
Ok(chain_info.stacks_tip_height > info_before.stacks_tip_height)
17184-
},
17185-
)
17186-
.expect("Timed out waiting for block");
17092+
signer_test.mine_nakamoto_block(Duration::from_secs(30), true);
1718717093

1718817094
let info = get_chain_info(&signer_test.running_nodes.conf);
1718917095
let stacks_height_before = info.stacks_tip_height;
@@ -18302,14 +18208,9 @@ fn signer_loads_stackerdb_updates_on_startup() {
1830218208
skip_commit_op_rl1.set(true);
1830318209

1830418210
info!("------------------------- Miner A Wins Tenure A -------------------------");
18305-
let info_before = get_chain_info(&conf_1);
1830618211
// Let's not mine anything until we see consensus on new tenure start.
1830718212
TEST_MINE_SKIP.set(true);
18308-
next_block_and(&miners.btc_regtest_controller_mut(), 60, || {
18309-
let info = get_chain_info(&conf_1);
18310-
Ok(info.burn_block_height > info_before.burn_block_height)
18311-
})
18312-
.unwrap();
18213+
miners.signer_test.mine_bitcoin_block();
1831318214
let chain_after = get_chain_info(&conf_1);
1831418215
wait_for_state_machine_update_by_miner_tenure_id(
1831518216
30,
@@ -18335,14 +18236,9 @@ fn signer_loads_stackerdb_updates_on_startup() {
1833518236

1833618237
info!("------------------------- Miner B Wins Tenure B -------------------------");
1833718238
miners.submit_commit_miner_2(&sortdb);
18338-
let chain_before = get_chain_info(&conf_1);
1833918239
// Let's not mine anything until we see consensus on new tenure start.
1834018240
TEST_MINE_SKIP.set(true);
18341-
next_block_and(&miners.btc_regtest_controller_mut(), 60, || {
18342-
let info = get_chain_info(&conf_1);
18343-
Ok(info.burn_block_height > chain_before.burn_block_height)
18344-
})
18345-
.unwrap();
18241+
miners.signer_test.mine_bitcoin_block();
1834618242
let chain_after = get_chain_info(&conf_1);
1834718243
wait_for_state_machine_update_by_miner_tenure_id(
1834818244
30,

0 commit comments

Comments
 (0)