Skip to content

Commit 9b2f515

Browse files
committed
Fix flakiness in problematic microblocks tests
Signed-off-by: Jacinta Ferrant <[email protected]>
1 parent a4597f5 commit 9b2f515

File tree

1 file changed

+87
-97
lines changed

1 file changed

+87
-97
lines changed

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

Lines changed: 87 additions & 97 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ use crate::neon_node::RelayerThread;
8989
use crate::operations::BurnchainOpSigner;
9090
use crate::stacks_common::types::PrivateKey;
9191
use crate::syncctl::PoxSyncWatchdogComms;
92-
use crate::tests::nakamoto_integrations::get_key_for_cycle;
92+
use crate::tests::nakamoto_integrations::{get_key_for_cycle, wait_for};
9393
use crate::util::hash::{MerkleTree, Sha512Trunc256Sum};
9494
use crate::util::secp256k1::MessageSignature;
9595
use crate::{neon, BitcoinRegtestController, BurnchainController, Config, ConfigFile, Keychain};
@@ -9909,15 +9909,15 @@ fn test_problematic_blocks_are_not_mined() {
99099909
cur_files = cur_files_new;
99109910
}
99119911

9912-
let tip_info = get_chain_info(&conf);
9912+
// all blocks were processed
9913+
wait_for(30, || {
9914+
let tip_info = get_chain_info(&conf);
9915+
Ok(tip_info.stacks_tip_height == old_tip_info.stacks_tip_height + 5)
9916+
})
9917+
.expect("Failed waiting for blocks to be processed");
99139918

9914-
// blocks were all processed
9915-
assert_eq!(
9916-
tip_info.stacks_tip_height,
9917-
old_tip_info.stacks_tip_height + 5
9918-
);
99199919
// no blocks considered problematic
9920-
assert_eq!(all_new_files.len(), 0);
9920+
assert!(all_new_files.is_empty());
99219921

99229922
// one block contained tx_exceeds
99239923
let blocks = test_observer::get_blocks();
@@ -9968,14 +9968,12 @@ fn test_problematic_blocks_are_not_mined() {
99689968
btc_regtest_controller.build_next_block(1);
99699969

99709970
// wait for runloop to advance
9971-
loop {
9972-
sleep_ms(1_000);
9971+
wait_for(30, || {
99739972
let sortdb = btc_regtest_controller.sortdb_mut();
99749973
let new_tip = SortitionDB::get_canonical_burn_chain_tip(&sortdb.conn()).unwrap();
9975-
if new_tip.block_height > tip.block_height {
9976-
break;
9977-
}
9978-
}
9974+
Ok(new_tip.block_height > tip.block_height)
9975+
})
9976+
.expect("Failed waiting for blocks to be processed");
99799977

99809978
let cur_ast_rules = {
99819979
let sortdb = btc_regtest_controller.sortdb_mut();
@@ -10003,12 +10001,15 @@ fn test_problematic_blocks_are_not_mined() {
1000310001
cur_files = cur_files_new;
1000410002
}
1000510003

10006-
let tip_info = get_chain_info(&conf);
10007-
1000810004
// all blocks were processed
10009-
assert!(tip_info.stacks_tip_height >= old_tip_info.stacks_tip_height + 5);
10005+
wait_for(30, || {
10006+
let tip_info = get_chain_info(&conf);
10007+
Ok(tip_info.stacks_tip_height >= old_tip_info.stacks_tip_height + 5)
10008+
})
10009+
.expect("Failed waiting for blocks to be processed");
10010+
1001010011
// none were problematic
10011-
assert_eq!(all_new_files.len(), 0);
10012+
assert!(all_new_files.is_empty());
1001210013

1001310014
// recently-submitted problematic transactions are not in the mempool
1001410015
// (but old ones that were already mined, and thus never considered, could still be present)
@@ -10047,18 +10048,15 @@ fn test_problematic_blocks_are_not_mined() {
1004710048
follower_conf.node.p2p_bind, follower_conf.node.rpc_bind
1004810049
);
1004910050

10050-
let deadline = get_epoch_time_secs() + 300;
10051-
while get_epoch_time_secs() < deadline {
10051+
// Do not unwrap in case we were just slow
10052+
let _ = wait_for(300, || {
1005210053
let follower_tip_info = get_chain_info(&follower_conf);
10053-
if follower_tip_info.stacks_tip_height == new_tip_info.stacks_tip_height {
10054-
break;
10055-
}
1005610054
eprintln!(
1005710055
"\nFollower is at burn block {} stacks block {}\n",
10058-
follower_tip_info.burn_block_height, follower_tip_info.stacks_tip_height,
10056+
follower_tip_info.burn_block_height, follower_tip_info.stacks_tip_height
1005910057
);
10060-
sleep_ms(1000);
10061-
}
10058+
Ok(follower_tip_info.stacks_tip_height == new_tip_info.stacks_tip_height)
10059+
});
1006210060

1006310061
// make sure we aren't just slow -- wait for the follower to do a few download passes
1006410062
let num_download_passes = pox_sync_comms.get_download_passes();
@@ -10068,14 +10066,15 @@ fn test_problematic_blocks_are_not_mined() {
1006810066
num_download_passes + 5
1006910067
);
1007010068

10071-
while num_download_passes + 5 > pox_sync_comms.get_download_passes() {
10072-
sleep_ms(1000);
10069+
wait_for(30, || {
10070+
let download_passes = pox_sync_comms.get_download_passes();
1007310071
eprintln!(
10074-
"\nFollower has performed {} download passes; wait for {}\n",
10075-
pox_sync_comms.get_download_passes(),
10072+
"\nFollower has performed {download_passes} download passes; wait for {}\n",
1007610073
num_download_passes + 5
1007710074
);
10078-
}
10075+
Ok(download_passes >= num_download_passes + 5)
10076+
})
10077+
.expect("Failed waiting for follower to perform enough download passes");
1007910078

1008010079
eprintln!(
1008110080
"\nFollower has performed {} download passes\n",
@@ -10674,15 +10673,15 @@ fn test_problematic_microblocks_are_not_mined() {
1067410673
sleep_ms(5_000);
1067510674
}
1067610675

10677-
let tip_info = get_chain_info(&conf);
10678-
1067910676
// microblocks and blocks were all processed
10680-
assert_eq!(
10681-
tip_info.stacks_tip_height,
10682-
old_tip_info.stacks_tip_height + 5
10683-
);
10677+
wait_for(30, || {
10678+
let tip_info = get_chain_info(&conf);
10679+
Ok(tip_info.stacks_tip_height == old_tip_info.stacks_tip_height + 5)
10680+
})
10681+
.expect("Failed waiting for microblocks to be processed");
10682+
1068410683
// no microblocks considered problematic
10685-
assert_eq!(all_new_files.len(), 0);
10684+
assert!(all_new_files.is_empty());
1068610685

1068710686
// one microblock contained tx_exceeds
1068810687
let microblocks = test_observer::get_microblocks();
@@ -10741,14 +10740,13 @@ fn test_problematic_microblocks_are_not_mined() {
1074110740
);
1074210741

1074310742
// wait for runloop to advance
10744-
loop {
10745-
sleep_ms(1_000);
10743+
wait_for(30, || {
1074610744
let sortdb = btc_regtest_controller.sortdb_mut();
1074710745
let new_tip = SortitionDB::get_canonical_burn_chain_tip(&sortdb.conn()).unwrap();
10748-
if new_tip.block_height > tip.block_height {
10749-
break;
10750-
}
10751-
}
10746+
Ok(new_tip.block_height > tip.block_height)
10747+
})
10748+
.expect("Failed waiting for runloop to advance");
10749+
1075210750
let cur_ast_rules = {
1075310751
let sortdb = btc_regtest_controller.sortdb_mut();
1075410752
let tip = SortitionDB::get_canonical_burn_chain_tip(&sortdb.conn()).unwrap();
@@ -10779,13 +10777,14 @@ fn test_problematic_microblocks_are_not_mined() {
1077910777
}
1078010778

1078110779
// sleep a little longer before checking tip info; this should help with test flakiness
10782-
sleep_ms(10_000);
10783-
let tip_info = get_chain_info(&conf);
10780+
wait_for(30, || {
10781+
let tip_info = get_chain_info(&conf);
10782+
Ok(tip_info.stacks_tip_height >= old_tip_info.stacks_tip_height + 5)
10783+
})
10784+
.expect("Failed waiting for microblocks to be processed");
1078410785

10785-
// all microblocks were processed
10786-
assert!(tip_info.stacks_tip_height >= old_tip_info.stacks_tip_height + 5);
1078710786
// none were problematic
10788-
assert_eq!(all_new_files.len(), 0);
10787+
assert!(all_new_files.is_empty());
1078910788

1079010789
// recently-submitted problematic transactions are not in the mempool
1079110790
// (but old ones that were already mined, and thus never considered, could still be present)
@@ -10824,18 +10823,15 @@ fn test_problematic_microblocks_are_not_mined() {
1082410823
follower_conf.node.p2p_bind, follower_conf.node.rpc_bind
1082510824
);
1082610825

10827-
let deadline = get_epoch_time_secs() + 300;
10828-
while get_epoch_time_secs() < deadline {
10826+
// Do not unwrap as we may just be slow
10827+
let _ = wait_for(300, || {
1082910828
let follower_tip_info = get_chain_info(&follower_conf);
10830-
if follower_tip_info.stacks_tip_height == new_tip_info.stacks_tip_height {
10831-
break;
10832-
}
1083310829
eprintln!(
1083410830
"\nFollower is at burn block {} stacks block {}\n",
1083510831
follower_tip_info.burn_block_height, follower_tip_info.stacks_tip_height,
1083610832
);
10837-
sleep_ms(1000);
10838-
}
10833+
Ok(follower_tip_info.stacks_tip_height == new_tip_info.stacks_tip_height)
10834+
});
1083910835

1084010836
// make sure we aren't just slow -- wait for the follower to do a few download passes
1084110837
let num_download_passes = pox_sync_comms.get_download_passes();
@@ -10845,14 +10841,15 @@ fn test_problematic_microblocks_are_not_mined() {
1084510841
num_download_passes + 5
1084610842
);
1084710843

10848-
while num_download_passes + 5 > pox_sync_comms.get_download_passes() {
10849-
sleep_ms(1000);
10844+
wait_for(30, || {
10845+
let download_passes = pox_sync_comms.get_download_passes();
1085010846
eprintln!(
10851-
"\nFollower has performed {} download passes; wait for {}\n",
10852-
pox_sync_comms.get_download_passes(),
10847+
"\nFollower has performed {download_passes} download passes; wait for {}\n",
1085310848
num_download_passes + 5
1085410849
);
10855-
}
10850+
Ok(download_passes >= num_download_passes + 5)
10851+
})
10852+
.expect("Failed waiting for follower to perform enough download passes");
1085610853

1085710854
eprintln!(
1085810855
"\nFollower has performed {} download passes\n",
@@ -11056,15 +11053,15 @@ fn test_problematic_microblocks_are_not_relayed_or_stored() {
1105611053
sleep_ms(5_000);
1105711054
}
1105811055

11059-
let tip_info = get_chain_info(&conf);
11056+
// microblocks and blocks were all processed
11057+
wait_for(30, || {
11058+
let tip_info = get_chain_info(&conf);
11059+
Ok(tip_info.stacks_tip_height == old_tip_info.stacks_tip_height + 5)
11060+
})
11061+
.expect("Failed waiting for microblocks to be processed");
1106011062

11061-
// microblocks were all processed
11062-
assert_eq!(
11063-
tip_info.stacks_tip_height,
11064-
old_tip_info.stacks_tip_height + 5
11065-
);
1106611063
// no microblocks considered problematic
11067-
assert_eq!(all_new_files.len(), 0);
11064+
assert!(all_new_files.is_empty());
1106811065

1106911066
// one microblock contained tx_exceeds
1107011067
let microblocks = test_observer::get_microblocks();
@@ -11102,14 +11099,13 @@ fn test_problematic_microblocks_are_not_relayed_or_stored() {
1110211099
btc_regtest_controller.build_next_block(1);
1110311100

1110411101
// wait for runloop to advance
11105-
loop {
11106-
sleep_ms(1_000);
11102+
wait_for(30, || {
1110711103
let sortdb = btc_regtest_controller.sortdb_mut();
1110811104
let new_tip = SortitionDB::get_canonical_burn_chain_tip(&sortdb.conn()).unwrap();
11109-
if new_tip.block_height > tip.block_height {
11110-
break;
11111-
}
11112-
}
11105+
Ok(new_tip.block_height > tip.block_height)
11106+
})
11107+
.expect("Failed waiting for runloop to advance");
11108+
1111311109
let cur_ast_rules = {
1111411110
let sortdb = btc_regtest_controller.sortdb_mut();
1111511111
let tip = SortitionDB::get_canonical_burn_chain_tip(&sortdb.conn()).unwrap();
@@ -11185,11 +11181,12 @@ fn test_problematic_microblocks_are_not_relayed_or_stored() {
1118511181
}
1118611182

1118711183
// sleep a little longer before checking tip info; this should help with test flakiness
11188-
sleep_ms(10_000);
11189-
let tip_info = get_chain_info(&conf);
11184+
wait_for(30, || {
11185+
let tip_info = get_chain_info(&conf);
11186+
Ok(tip_info.stacks_tip_height >= old_tip_info.stacks_tip_height + 5)
11187+
})
11188+
.expect("Failed waiting for microblocks to be processed");
1119011189

11191-
// all microblocks were processed
11192-
assert!(tip_info.stacks_tip_height >= old_tip_info.stacks_tip_height + 5);
1119311190
// at least one was problematic.
1119411191
// the miner might make multiple microblocks (only some of which are confirmed), so also check
1119511192
// the event observer to see that we actually picked up tx_high
@@ -11244,22 +11241,15 @@ fn test_problematic_microblocks_are_not_relayed_or_stored() {
1124411241
follower_conf.node.p2p_bind, follower_conf.node.rpc_bind
1124511242
);
1124611243

11247-
let deadline = get_epoch_time_secs() + 300;
11248-
while get_epoch_time_secs() < deadline {
11244+
// Do not unwrap as we may just be slow
11245+
let _ = wait_for(300, || {
1124911246
let follower_tip_info = get_chain_info(&follower_conf);
11250-
if follower_tip_info.stacks_tip_height == new_tip_info.stacks_tip_height
11251-
|| follower_tip_info.stacks_tip_height == bad_block_height
11252-
{
11253-
break;
11254-
}
1125511247
eprintln!(
11256-
"\nFollower is at burn block {} stacks block {} (bad_block is {})\n",
11257-
follower_tip_info.burn_block_height,
11258-
follower_tip_info.stacks_tip_height,
11259-
bad_block_height
11248+
"\nFollower is at burn block {} stacks block {}\n",
11249+
follower_tip_info.burn_block_height, follower_tip_info.stacks_tip_height,
1126011250
);
11261-
sleep_ms(1000);
11262-
}
11251+
Ok(follower_tip_info.stacks_tip_height == new_tip_info.stacks_tip_height)
11252+
});
1126311253

1126411254
// make sure we aren't just slow -- wait for the follower to do a few download passes
1126511255
let num_download_passes = pox_sync_comms.get_download_passes();
@@ -11269,15 +11259,15 @@ fn test_problematic_microblocks_are_not_relayed_or_stored() {
1126911259
num_download_passes + 5
1127011260
);
1127111261

11272-
while num_download_passes + 5 > pox_sync_comms.get_download_passes() {
11273-
sleep_ms(1000);
11262+
wait_for(30, || {
11263+
let download_passes = pox_sync_comms.get_download_passes();
1127411264
eprintln!(
11275-
"\nFollower has performed {} download passes; wait for {}\n",
11276-
pox_sync_comms.get_download_passes(),
11265+
"\nFollower has performed {download_passes} download passes; wait for {}\n",
1127711266
num_download_passes + 5
1127811267
);
11279-
}
11280-
11268+
Ok(download_passes >= num_download_passes + 5)
11269+
})
11270+
.expect("Failed waiting for follower to perform enough download passes");
1128111271
eprintln!(
1128211272
"\nFollower has performed {} download passes\n",
1128311273
pox_sync_comms.get_download_passes()

0 commit comments

Comments
 (0)