Skip to content

Commit 899ca58

Browse files
authored
Merge pull request #5009 from jbencin/test/eliminate-block-between-2.5-and-3.0
test: Eliminate block between 2.5 and 3.0
2 parents 56eec59 + b78afdc commit 899ca58

File tree

2 files changed

+67
-102
lines changed

2 files changed

+67
-102
lines changed

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

Lines changed: 33 additions & 102 deletions
Original file line numberDiff line numberDiff line change
@@ -1024,6 +1024,18 @@ pub fn boot_to_epoch_3_reward_set(
10241024
info!("Bootstrapped to Epoch 3.0 reward set calculation height: {epoch_3_reward_set_calculation}.");
10251025
}
10261026

1027+
/// Wait for a block commit, without producing a block
1028+
fn wait_for_first_naka_block_commit(timeout_secs: u64, naka_commits_submitted: &Arc<AtomicU64>) {
1029+
let start = Instant::now();
1030+
while naka_commits_submitted.load(Ordering::SeqCst) < 1 {
1031+
if start.elapsed() > Duration::from_secs(timeout_secs) {
1032+
error!("Timed out waiting for block commit");
1033+
panic!();
1034+
}
1035+
thread::sleep(Duration::from_millis(100));
1036+
}
1037+
}
1038+
10271039
#[test]
10281040
#[ignore]
10291041
/// This test spins up a nakamoto-neon node.
@@ -1134,12 +1146,7 @@ fn simple_neon_integration() {
11341146
info!("Nakamoto miner started...");
11351147
blind_signer(&naka_conf, &signers, proposals_submitted);
11361148

1137-
// Wait one block to confirm the VRF register, wait until a block commit is submitted
1138-
next_block_and(&mut btc_regtest_controller, 60, || {
1139-
let commits_count = commits_submitted.load(Ordering::SeqCst);
1140-
Ok(commits_count >= 1)
1141-
})
1142-
.unwrap();
1149+
wait_for_first_naka_block_commit(60, &commits_submitted);
11431150

11441151
// Mine 15 nakamoto tenures
11451152
for _i in 0..15 {
@@ -1232,6 +1239,10 @@ fn simple_neon_integration() {
12321239
assert!(tip.anchored_header.as_stacks_nakamoto().is_some());
12331240
assert!(tip.stacks_block_height >= block_height_pre_3_0 + 30);
12341241

1242+
// Check that we aren't missing burn blocks
1243+
let bhh = u64::from(tip.burn_header_height);
1244+
test_observer::contains_burn_block_range(220..=bhh).unwrap();
1245+
12351246
// make sure prometheus returns an updated height
12361247
#[cfg(feature = "monitoring_prom")]
12371248
{
@@ -1355,12 +1366,7 @@ fn mine_multiple_per_tenure_integration() {
13551366
info!("Nakamoto miner started...");
13561367
blind_signer(&naka_conf, &signers, proposals_submitted);
13571368

1358-
// Wait one block to confirm the VRF register, wait until a block commit is submitted
1359-
next_block_and(&mut btc_regtest_controller, 60, || {
1360-
let commits_count = commits_submitted.load(Ordering::SeqCst);
1361-
Ok(commits_count >= 1)
1362-
})
1363-
.unwrap();
1369+
wait_for_first_naka_block_commit(60, &commits_submitted);
13641370

13651371
// Mine `tenure_count` nakamoto tenures
13661372
for tenure_ix in 0..tenure_count {
@@ -1672,12 +1678,7 @@ fn correct_burn_outs() {
16721678
);
16731679
assert_eq!(stacker_response.stacker_set.rewarded_addresses.len(), 1);
16741680

1675-
// Wait one block to confirm the VRF register, wait until a block commit is submitted
1676-
next_block_and(&mut btc_regtest_controller, 60, || {
1677-
let commits_count = commits_submitted.load(Ordering::SeqCst);
1678-
Ok(commits_count >= 1)
1679-
})
1680-
.unwrap();
1681+
wait_for_first_naka_block_commit(60, &commits_submitted);
16811682

16821683
info!("Bootstrapped to Epoch-3.0 boundary, mining nakamoto blocks");
16831684

@@ -1874,12 +1875,7 @@ fn block_proposal_api_endpoint() {
18741875

18751876
info!("Nakamoto miner started...");
18761877

1877-
// Wait one block to confirm the VRF register, wait until a block commit is submitted
1878-
next_block_and(&mut btc_regtest_controller, 60, || {
1879-
let commits_count = commits_submitted.load(Ordering::SeqCst);
1880-
Ok(commits_count >= 1)
1881-
})
1882-
.unwrap();
1878+
wait_for_first_naka_block_commit(60, &commits_submitted);
18831879

18841880
// Mine 3 nakamoto tenures
18851881
for _ in 0..3 {
@@ -2218,12 +2214,7 @@ fn miner_writes_proposed_block_to_stackerdb() {
22182214
info!("Nakamoto miner started...");
22192215
blind_signer(&naka_conf, &signers, proposals_submitted);
22202216

2221-
// Wait one block to confirm the VRF register, wait until a block commit is submitted
2222-
next_block_and(&mut btc_regtest_controller, 60, || {
2223-
let commits_count = commits_submitted.load(Ordering::SeqCst);
2224-
Ok(commits_count >= 1)
2225-
})
2226-
.unwrap();
2217+
wait_for_first_naka_block_commit(60, &commits_submitted);
22272218

22282219
// Mine 1 nakamoto tenure
22292220
next_block_and_mine_commit(
@@ -2353,12 +2344,7 @@ fn vote_for_aggregate_key_burn_op() {
23532344
info!("Nakamoto miner started...");
23542345
blind_signer(&naka_conf, &signers, proposals_submitted);
23552346

2356-
// Wait one block to confirm the VRF register, wait until a block commit is submitted
2357-
next_block_and(&mut btc_regtest_controller, 60, || {
2358-
let commits_count = commits_submitted.load(Ordering::SeqCst);
2359-
Ok(commits_count >= 1)
2360-
})
2361-
.unwrap();
2347+
wait_for_first_naka_block_commit(60, &commits_submitted);
23622348

23632349
// submit a pre-stx op
23642350
let mut miner_signer = Keychain::default(naka_conf.node.seed.clone()).generate_op_signer();
@@ -2612,12 +2598,7 @@ fn follower_bootup() {
26122598
info!("Nakamoto miner started...");
26132599
blind_signer(&naka_conf, &signers, proposals_submitted);
26142600

2615-
// Wait one block to confirm the VRF register, wait until a block commit is submitted
2616-
next_block_and(&mut btc_regtest_controller, 60, || {
2617-
let commits_count = commits_submitted.load(Ordering::SeqCst);
2618-
Ok(commits_count >= 1)
2619-
})
2620-
.unwrap();
2601+
wait_for_first_naka_block_commit(60, &commits_submitted);
26212602

26222603
let mut follower_conf = naka_conf.clone();
26232604
follower_conf.events_observers.clear();
@@ -2916,12 +2897,7 @@ fn stack_stx_burn_op_integration_test() {
29162897
info!("Nakamoto miner started...");
29172898
blind_signer(&naka_conf, &signers, proposals_submitted);
29182899

2919-
// Wait one block to confirm the VRF register, wait until a block commit is submitted
2920-
next_block_and(&mut btc_regtest_controller, 60, || {
2921-
let commits_count = commits_submitted.load(Ordering::SeqCst);
2922-
Ok(commits_count >= 1)
2923-
})
2924-
.unwrap();
2900+
wait_for_first_naka_block_commit(60, &commits_submitted);
29252901

29262902
let block_height = btc_regtest_controller.get_headers_height();
29272903

@@ -3360,12 +3336,7 @@ fn forked_tenure_is_ignored() {
33603336
blind_signer(&naka_conf, &signers, proposals_submitted);
33613337

33623338
info!("Starting tenure A.");
3363-
// Wait one block to confirm the VRF register, wait until a block commit is submitted
3364-
next_block_and(&mut btc_regtest_controller, 60, || {
3365-
let commits_count = commits_submitted.load(Ordering::SeqCst);
3366-
Ok(commits_count >= 1)
3367-
})
3368-
.unwrap();
3339+
wait_for_first_naka_block_commit(60, &commits_submitted);
33693340

33703341
// In the next block, the miner should win the tenure and submit a stacks block
33713342
let commits_before = commits_submitted.load(Ordering::SeqCst);
@@ -3662,12 +3633,7 @@ fn check_block_heights() {
36623633
let preheights = heights0_value.expect_tuple().unwrap();
36633634
info!("Heights from pre-epoch 3.0: {}", preheights);
36643635

3665-
// Wait one block to confirm the VRF register, wait until a block commit is submitted
3666-
next_block_and(&mut btc_regtest_controller, 60, || {
3667-
let commits_count = commits_submitted.load(Ordering::SeqCst);
3668-
Ok(commits_count >= 1)
3669-
})
3670-
.unwrap();
3636+
wait_for_first_naka_block_commit(60, &commits_submitted);
36713637

36723638
let info = get_chain_info_result(&naka_conf).unwrap();
36733639
info!("Chain info: {:?}", info);
@@ -4051,12 +4017,7 @@ fn nakamoto_attempt_time() {
40514017

40524018
info!("Nakamoto miner started...");
40534019

4054-
// Wait one block to confirm the VRF register, wait until a block commit is submitted
4055-
next_block_and(&mut btc_regtest_controller, 60, || {
4056-
let commits_count = commits_submitted.load(Ordering::SeqCst);
4057-
Ok(commits_count >= 1)
4058-
})
4059-
.unwrap();
4020+
wait_for_first_naka_block_commit(60, &commits_submitted);
40604021

40614022
// Mine 3 nakamoto tenures
40624023
for _ in 0..3 {
@@ -4340,12 +4301,7 @@ fn clarity_burn_state() {
43404301
info!("Nakamoto miner started...");
43414302
blind_signer(&naka_conf, &signers, proposals_submitted);
43424303

4343-
// Wait one block to confirm the VRF register, wait until a block commit is submitted
4344-
next_block_and(&mut btc_regtest_controller, 60, || {
4345-
let commits_count = commits_submitted.load(Ordering::SeqCst);
4346-
Ok(commits_count >= 1)
4347-
})
4348-
.unwrap();
4304+
wait_for_first_naka_block_commit(60, &commits_submitted);
43494305

43504306
let mut sender_nonce = 0;
43514307

@@ -4624,12 +4580,7 @@ fn signer_chainstate() {
46244580
false,
46254581
);
46264582

4627-
// Wait one block to confirm the VRF register, wait until a block commit is submitted
4628-
next_block_and(&mut btc_regtest_controller, 60, || {
4629-
let commits_count = commits_submitted.load(Ordering::SeqCst);
4630-
Ok(commits_count >= 1)
4631-
})
4632-
.unwrap();
4583+
wait_for_first_naka_block_commit(60, &commits_submitted);
46334584

46344585
let mut signer_db =
46354586
SignerDb::new(format!("{}/signer_db_path", naka_conf.node.working_dir)).unwrap();
@@ -5155,12 +5106,7 @@ fn continue_tenure_extend() {
51555106
info!("Nakamoto miner started...");
51565107
blind_signer(&naka_conf, &signers, proposals_submitted);
51575108

5158-
// Wait one block to confirm the VRF register, wait until a block commit is submitted
5159-
next_block_and(&mut btc_regtest_controller, 60, || {
5160-
let commits_count = commits_submitted.load(Ordering::SeqCst);
5161-
Ok(commits_count >= 1)
5162-
})
5163-
.unwrap();
5109+
wait_for_first_naka_block_commit(60, &commits_submitted);
51645110

51655111
// Mine a regular nakamoto tenure
51665112
next_block_and_mine_commit(
@@ -5443,12 +5389,7 @@ fn check_block_times() {
54435389
.unwrap();
54445390
info!("Time from pre-epoch 3.0: {}", time0);
54455391

5446-
// Wait one block to confirm the VRF register, wait until a block commit is submitted
5447-
next_block_and(&mut btc_regtest_controller, 60, || {
5448-
let commits_count = commits_submitted.load(Ordering::SeqCst);
5449-
Ok(commits_count >= 1)
5450-
})
5451-
.unwrap();
5392+
wait_for_first_naka_block_commit(60, &commits_submitted);
54525393

54535394
// This version uses the Clarity 1 / 2 function
54545395
let contract1_name = "test-contract-1";
@@ -5928,12 +5869,7 @@ fn check_block_info() {
59285869
let tuple0 = result0.expect_tuple().unwrap().data_map;
59295870
info!("Info from pre-epoch 3.0: {:?}", tuple0);
59305871

5931-
// Wait one block to confirm the VRF register, wait until a block commit is submitted
5932-
next_block_and(&mut btc_regtest_controller, 60, || {
5933-
let commits_count = commits_submitted.load(Ordering::SeqCst);
5934-
Ok(commits_count >= 1)
5935-
})
5936-
.unwrap();
5872+
wait_for_first_naka_block_commit(60, &commits_submitted);
59375873

59385874
// This version uses the Clarity 1 / 2 function
59395875
let contract1_name = "test-contract-1";
@@ -6436,12 +6372,7 @@ fn check_block_info_rewards() {
64366372
let tuple0 = result0.expect_tuple().unwrap().data_map;
64376373
info!("Info from pre-epoch 3.0: {:?}", tuple0);
64386374

6439-
// Wait one block to confirm the VRF register, wait until a block commit is submitted
6440-
next_block_and(&mut btc_regtest_controller, 60, || {
6441-
let commits_count = commits_submitted.load(Ordering::SeqCst);
6442-
Ok(commits_count >= 1)
6443-
})
6444-
.unwrap();
6375+
wait_for_first_naka_block_commit(60, &commits_submitted);
64456376

64466377
// This version uses the Clarity 1 / 2 function
64476378
let contract1_name = "test-contract-1";

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

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,9 @@ pub fn neon_integration_test_conf_with_seed(seed: Vec<u8>) -> (Config, StacksAdd
186186
}
187187

188188
pub mod test_observer {
189+
use std::collections::HashSet;
189190
use std::convert::Infallible;
191+
use std::ops::{Bound, RangeBounds};
190192
use std::sync::Mutex;
191193
use std::thread;
192194

@@ -566,6 +568,38 @@ pub mod test_observer {
566568
ATTACHMENTS.lock().unwrap().clear();
567569
PROPOSAL_RESPONSES.lock().unwrap().clear();
568570
}
571+
572+
pub fn contains_burn_block_range(range: impl RangeBounds<u64>) -> Result<(), String> {
573+
// Get set of all burn block heights
574+
let burn_block_heights = get_blocks()
575+
.iter()
576+
.map(|x| x.get("burn_block_height").unwrap().as_u64().unwrap())
577+
.collect::<HashSet<_>>();
578+
579+
let start = match range.start_bound() {
580+
Bound::Unbounded => return Err("Unbounded ranges not supported".into()),
581+
Bound::Included(&x) => x,
582+
Bound::Excluded(&x) => x.saturating_add(1),
583+
};
584+
585+
let end = match range.end_bound() {
586+
Bound::Unbounded => return Err("Unbounded ranges not supported".into()),
587+
Bound::Included(&x) => x,
588+
Bound::Excluded(&x) => x.saturating_sub(1),
589+
};
590+
591+
// Find indexes in range for which we don't have burn block in set
592+
let missing = (start..=end)
593+
.into_iter()
594+
.filter(|i| !burn_block_heights.contains(&i))
595+
.collect::<Vec<_>>();
596+
597+
if missing.is_empty() {
598+
Ok(())
599+
} else {
600+
Err(format!("Missing the following burn blocks: {missing:?}"))
601+
}
602+
}
569603
}
570604

571605
const PANIC_TIMEOUT_SECS: u64 = 600;

0 commit comments

Comments
 (0)