@@ -89,7 +89,7 @@ use crate::neon_node::RelayerThread;
89
89
use crate :: operations:: BurnchainOpSigner ;
90
90
use crate :: stacks_common:: types:: PrivateKey ;
91
91
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 } ;
93
93
use crate :: util:: hash:: { MerkleTree , Sha512Trunc256Sum } ;
94
94
use crate :: util:: secp256k1:: MessageSignature ;
95
95
use crate :: { neon, BitcoinRegtestController , BurnchainController , Config , ConfigFile , Keychain } ;
@@ -9909,15 +9909,15 @@ fn test_problematic_blocks_are_not_mined() {
9909
9909
cur_files = cur_files_new;
9910
9910
}
9911
9911
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" ) ;
9913
9918
9914
- // blocks were all processed
9915
- assert_eq ! (
9916
- tip_info. stacks_tip_height,
9917
- old_tip_info. stacks_tip_height + 5
9918
- ) ;
9919
9919
// no blocks considered problematic
9920
- assert_eq ! ( all_new_files. len ( ) , 0 ) ;
9920
+ assert ! ( all_new_files. is_empty ( ) ) ;
9921
9921
9922
9922
// one block contained tx_exceeds
9923
9923
let blocks = test_observer:: get_blocks ( ) ;
@@ -9968,14 +9968,12 @@ fn test_problematic_blocks_are_not_mined() {
9968
9968
btc_regtest_controller. build_next_block ( 1 ) ;
9969
9969
9970
9970
// wait for runloop to advance
9971
- loop {
9972
- sleep_ms ( 1_000 ) ;
9971
+ wait_for ( 30 , || {
9973
9972
let sortdb = btc_regtest_controller. sortdb_mut ( ) ;
9974
9973
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" ) ;
9979
9977
9980
9978
let cur_ast_rules = {
9981
9979
let sortdb = btc_regtest_controller. sortdb_mut ( ) ;
@@ -10003,12 +10001,15 @@ fn test_problematic_blocks_are_not_mined() {
10003
10001
cur_files = cur_files_new;
10004
10002
}
10005
10003
10006
- let tip_info = get_chain_info ( & conf) ;
10007
-
10008
10004
// 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
+
10010
10011
// none were problematic
10011
- assert_eq ! ( all_new_files. len ( ) , 0 ) ;
10012
+ assert ! ( all_new_files. is_empty ( ) ) ;
10012
10013
10013
10014
// recently-submitted problematic transactions are not in the mempool
10014
10015
// (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() {
10047
10048
follower_conf. node. p2p_bind, follower_conf. node. rpc_bind
10048
10049
) ;
10049
10050
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 , || {
10052
10053
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
- }
10056
10054
eprintln ! (
10057
10055
"\n Follower 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
10059
10057
) ;
10060
- sleep_ms ( 1000 ) ;
10061
- }
10058
+ Ok ( follower_tip_info . stacks_tip_height == new_tip_info . stacks_tip_height )
10059
+ } ) ;
10062
10060
10063
10061
// make sure we aren't just slow -- wait for the follower to do a few download passes
10064
10062
let num_download_passes = pox_sync_comms. get_download_passes ( ) ;
@@ -10068,14 +10066,15 @@ fn test_problematic_blocks_are_not_mined() {
10068
10066
num_download_passes + 5
10069
10067
) ;
10070
10068
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 ( ) ;
10073
10071
eprintln ! (
10074
- "\n Follower has performed {} download passes; wait for {}\n " ,
10075
- pox_sync_comms. get_download_passes( ) ,
10072
+ "\n Follower has performed {download_passes} download passes; wait for {}\n " ,
10076
10073
num_download_passes + 5
10077
10074
) ;
10078
- }
10075
+ Ok ( download_passes >= num_download_passes + 5 )
10076
+ } )
10077
+ . expect ( "Failed waiting for follower to perform enough download passes" ) ;
10079
10078
10080
10079
eprintln ! (
10081
10080
"\n Follower has performed {} download passes\n " ,
@@ -10674,15 +10673,15 @@ fn test_problematic_microblocks_are_not_mined() {
10674
10673
sleep_ms ( 5_000 ) ;
10675
10674
}
10676
10675
10677
- let tip_info = get_chain_info ( & conf) ;
10678
-
10679
10676
// 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
+
10684
10683
// no microblocks considered problematic
10685
- assert_eq ! ( all_new_files. len ( ) , 0 ) ;
10684
+ assert ! ( all_new_files. is_empty ( ) ) ;
10686
10685
10687
10686
// one microblock contained tx_exceeds
10688
10687
let microblocks = test_observer:: get_microblocks ( ) ;
@@ -10741,14 +10740,13 @@ fn test_problematic_microblocks_are_not_mined() {
10741
10740
) ;
10742
10741
10743
10742
// wait for runloop to advance
10744
- loop {
10745
- sleep_ms ( 1_000 ) ;
10743
+ wait_for ( 30 , || {
10746
10744
let sortdb = btc_regtest_controller. sortdb_mut ( ) ;
10747
10745
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
+
10752
10750
let cur_ast_rules = {
10753
10751
let sortdb = btc_regtest_controller. sortdb_mut ( ) ;
10754
10752
let tip = SortitionDB :: get_canonical_burn_chain_tip ( & sortdb. conn ( ) ) . unwrap ( ) ;
@@ -10779,13 +10777,14 @@ fn test_problematic_microblocks_are_not_mined() {
10779
10777
}
10780
10778
10781
10779
// 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" ) ;
10784
10785
10785
- // all microblocks were processed
10786
- assert ! ( tip_info. stacks_tip_height >= old_tip_info. stacks_tip_height + 5 ) ;
10787
10786
// none were problematic
10788
- assert_eq ! ( all_new_files. len ( ) , 0 ) ;
10787
+ assert ! ( all_new_files. is_empty ( ) ) ;
10789
10788
10790
10789
// recently-submitted problematic transactions are not in the mempool
10791
10790
// (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() {
10824
10823
follower_conf. node. p2p_bind, follower_conf. node. rpc_bind
10825
10824
) ;
10826
10825
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 , || {
10829
10828
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
- }
10833
10829
eprintln ! (
10834
10830
"\n Follower is at burn block {} stacks block {}\n " ,
10835
10831
follower_tip_info. burn_block_height, follower_tip_info. stacks_tip_height,
10836
10832
) ;
10837
- sleep_ms ( 1000 ) ;
10838
- }
10833
+ Ok ( follower_tip_info . stacks_tip_height == new_tip_info . stacks_tip_height )
10834
+ } ) ;
10839
10835
10840
10836
// make sure we aren't just slow -- wait for the follower to do a few download passes
10841
10837
let num_download_passes = pox_sync_comms. get_download_passes ( ) ;
@@ -10845,14 +10841,15 @@ fn test_problematic_microblocks_are_not_mined() {
10845
10841
num_download_passes + 5
10846
10842
) ;
10847
10843
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 ( ) ;
10850
10846
eprintln ! (
10851
- "\n Follower has performed {} download passes; wait for {}\n " ,
10852
- pox_sync_comms. get_download_passes( ) ,
10847
+ "\n Follower has performed {download_passes} download passes; wait for {}\n " ,
10853
10848
num_download_passes + 5
10854
10849
) ;
10855
- }
10850
+ Ok ( download_passes >= num_download_passes + 5 )
10851
+ } )
10852
+ . expect ( "Failed waiting for follower to perform enough download passes" ) ;
10856
10853
10857
10854
eprintln ! (
10858
10855
"\n Follower has performed {} download passes\n " ,
@@ -11056,15 +11053,15 @@ fn test_problematic_microblocks_are_not_relayed_or_stored() {
11056
11053
sleep_ms ( 5_000 ) ;
11057
11054
}
11058
11055
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" ) ;
11060
11062
11061
- // microblocks were all processed
11062
- assert_eq ! (
11063
- tip_info. stacks_tip_height,
11064
- old_tip_info. stacks_tip_height + 5
11065
- ) ;
11066
11063
// no microblocks considered problematic
11067
- assert_eq ! ( all_new_files. len ( ) , 0 ) ;
11064
+ assert ! ( all_new_files. is_empty ( ) ) ;
11068
11065
11069
11066
// one microblock contained tx_exceeds
11070
11067
let microblocks = test_observer:: get_microblocks ( ) ;
@@ -11102,14 +11099,13 @@ fn test_problematic_microblocks_are_not_relayed_or_stored() {
11102
11099
btc_regtest_controller. build_next_block ( 1 ) ;
11103
11100
11104
11101
// wait for runloop to advance
11105
- loop {
11106
- sleep_ms ( 1_000 ) ;
11102
+ wait_for ( 30 , || {
11107
11103
let sortdb = btc_regtest_controller. sortdb_mut ( ) ;
11108
11104
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
+
11113
11109
let cur_ast_rules = {
11114
11110
let sortdb = btc_regtest_controller. sortdb_mut ( ) ;
11115
11111
let tip = SortitionDB :: get_canonical_burn_chain_tip ( & sortdb. conn ( ) ) . unwrap ( ) ;
@@ -11185,11 +11181,12 @@ fn test_problematic_microblocks_are_not_relayed_or_stored() {
11185
11181
}
11186
11182
11187
11183
// 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" ) ;
11190
11189
11191
- // all microblocks were processed
11192
- assert ! ( tip_info. stacks_tip_height >= old_tip_info. stacks_tip_height + 5 ) ;
11193
11190
// at least one was problematic.
11194
11191
// the miner might make multiple microblocks (only some of which are confirmed), so also check
11195
11192
// 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() {
11244
11241
follower_conf. node. p2p_bind, follower_conf. node. rpc_bind
11245
11242
) ;
11246
11243
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 , || {
11249
11246
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
- }
11255
11247
eprintln ! (
11256
- "\n Follower 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
+ "\n Follower is at burn block {} stacks block {}\n " ,
11249
+ follower_tip_info. burn_block_height, follower_tip_info. stacks_tip_height,
11260
11250
) ;
11261
- sleep_ms ( 1000 ) ;
11262
- }
11251
+ Ok ( follower_tip_info . stacks_tip_height == new_tip_info . stacks_tip_height )
11252
+ } ) ;
11263
11253
11264
11254
// make sure we aren't just slow -- wait for the follower to do a few download passes
11265
11255
let num_download_passes = pox_sync_comms. get_download_passes ( ) ;
@@ -11269,15 +11259,15 @@ fn test_problematic_microblocks_are_not_relayed_or_stored() {
11269
11259
num_download_passes + 5
11270
11260
) ;
11271
11261
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 ( ) ;
11274
11264
eprintln ! (
11275
- "\n Follower has performed {} download passes; wait for {}\n " ,
11276
- pox_sync_comms. get_download_passes( ) ,
11265
+ "\n Follower has performed {download_passes} download passes; wait for {}\n " ,
11277
11266
num_download_passes + 5
11278
11267
) ;
11279
- }
11280
-
11268
+ Ok ( download_passes >= num_download_passes + 5 )
11269
+ } )
11270
+ . expect ( "Failed waiting for follower to perform enough download passes" ) ;
11281
11271
eprintln ! (
11282
11272
"\n Follower has performed {} download passes\n " ,
11283
11273
pox_sync_comms. get_download_passes( )
0 commit comments