@@ -4128,25 +4128,24 @@ fn locally_rejected_blocks_overriden_by_global_acceptance() {
4128
4128
signer_test. boot_to_epoch_3 ( ) ;
4129
4129
info ! ( "------------------------- Test Mine Nakamoto Block N -------------------------" ) ;
4130
4130
let mined_blocks = signer_test. running_nodes . nakamoto_blocks_mined . clone ( ) ;
4131
- let blocks_before = mined_blocks. load ( Ordering :: SeqCst ) ;
4132
4131
let info_before = signer_test
4133
4132
. stacks_client
4134
4133
. get_peer_info ( )
4135
4134
. expect ( "Failed to get peer info" ) ;
4136
- let start_time = Instant :: now ( ) ;
4137
4135
// submit a tx so that the miner will mine a stacks block
4138
4136
let mut sender_nonce = 0 ;
4139
4137
let transfer_tx =
4140
4138
make_stacks_transfer ( & sender_sk, sender_nonce, send_fee, & recipient, send_amt) ;
4141
4139
let tx = submit_tx ( & http_origin, & transfer_tx) ;
4142
4140
info ! ( "Submitted tx {tx} in to mine block N" ) ;
4143
- while mined_blocks. load ( Ordering :: SeqCst ) <= blocks_before {
4144
- assert ! (
4145
- start_time. elapsed( ) < short_timeout,
4146
- "FAIL: Test timed out while waiting for block production" ,
4147
- ) ;
4148
- thread:: sleep ( Duration :: from_secs ( 1 ) ) ;
4149
- }
4141
+ wait_for ( short_timeout. as_secs ( ) , || {
4142
+ let info_after = signer_test
4143
+ . stacks_client
4144
+ . get_peer_info ( )
4145
+ . expect ( "Failed to get peer info" ) ;
4146
+ Ok ( info_after. stacks_tip_height > info_before. stacks_tip_height )
4147
+ } )
4148
+ . expect ( "Timed out waiting for block to be mined and processed" ) ;
4150
4149
4151
4150
sender_nonce += 1 ;
4152
4151
let info_after = signer_test
@@ -4196,13 +4195,14 @@ fn locally_rejected_blocks_overriden_by_global_acceptance() {
4196
4195
. stacks_client
4197
4196
. get_peer_info ( )
4198
4197
. expect ( "Failed to get peer info" ) ;
4199
- while mined_blocks. load ( Ordering :: SeqCst ) <= blocks_before {
4200
- assert ! (
4201
- start_time. elapsed( ) < short_timeout,
4202
- "FAIL: Test timed out while waiting for block production" ,
4203
- ) ;
4204
- thread:: sleep ( Duration :: from_secs ( 1 ) ) ;
4205
- }
4198
+ wait_for ( short_timeout. as_secs ( ) , || {
4199
+ let info_after = signer_test
4200
+ . stacks_client
4201
+ . get_peer_info ( )
4202
+ . expect ( "Failed to get peer info" ) ;
4203
+ Ok ( info_after. stacks_tip_height > info_before. stacks_tip_height )
4204
+ } )
4205
+ . expect ( "Timed out waiting for block to be mined and processed" ) ;
4206
4206
loop {
4207
4207
let stackerdb_events = test_observer:: get_stackerdb_chunks ( ) ;
4208
4208
let block_rejections = stackerdb_events
@@ -4274,13 +4274,14 @@ fn locally_rejected_blocks_overriden_by_global_acceptance() {
4274
4274
make_stacks_transfer ( & sender_sk, sender_nonce, send_fee, & recipient, send_amt) ;
4275
4275
let tx = submit_tx ( & http_origin, & transfer_tx) ;
4276
4276
info ! ( "Submitted tx {tx} in to mine block N+2" ) ;
4277
- while mined_blocks. load ( Ordering :: SeqCst ) <= blocks_before {
4278
- assert ! (
4279
- start_time. elapsed( ) < short_timeout,
4280
- "FAIL: Test timed out while waiting for block production" ,
4281
- ) ;
4282
- thread:: sleep ( Duration :: from_secs ( 1 ) ) ;
4283
- }
4277
+ wait_for ( short_timeout. as_secs ( ) , || {
4278
+ let info_after = signer_test
4279
+ . stacks_client
4280
+ . get_peer_info ( )
4281
+ . expect ( "Failed to get peer info" ) ;
4282
+ Ok ( info_after. stacks_tip_height > info_before. stacks_tip_height )
4283
+ } )
4284
+ . expect ( "Timed out waiting for block to be mined and processed" ) ;
4284
4285
let blocks_after = mined_blocks. load ( Ordering :: SeqCst ) ;
4285
4286
assert_eq ! ( blocks_after, blocks_before + 1 ) ;
4286
4287
@@ -4348,31 +4349,31 @@ fn reorg_locally_accepted_blocks_across_tenures_succeeds() {
4348
4349
info ! ( "------------------------- Starting Tenure A -------------------------" ) ;
4349
4350
info ! ( "------------------------- Test Mine Nakamoto Block N -------------------------" ) ;
4350
4351
let mined_blocks = signer_test. running_nodes . nakamoto_blocks_mined . clone ( ) ;
4351
- let blocks_before = mined_blocks. load ( Ordering :: SeqCst ) ;
4352
4352
let info_before = signer_test
4353
4353
. stacks_client
4354
4354
. get_peer_info ( )
4355
4355
. expect ( "Failed to get peer info" ) ;
4356
- let start_time = Instant :: now ( ) ;
4357
4356
// submit a tx so that the miner will mine a stacks block
4358
4357
let mut sender_nonce = 0 ;
4359
4358
let transfer_tx =
4360
4359
make_stacks_transfer ( & sender_sk, sender_nonce, send_fee, & recipient, send_amt) ;
4361
4360
let tx = submit_tx ( & http_origin, & transfer_tx) ;
4362
4361
info ! ( "Submitted tx {tx} in to mine block N" ) ;
4363
- while mined_blocks. load ( Ordering :: SeqCst ) <= blocks_before {
4364
- assert ! (
4365
- start_time. elapsed( ) < short_timeout,
4366
- "FAIL: Test timed out while waiting for block production" ,
4367
- ) ;
4368
- thread:: sleep ( Duration :: from_secs ( 1 ) ) ;
4369
- }
4362
+ wait_for ( short_timeout. as_secs ( ) , || {
4363
+ let info_after = signer_test
4364
+ . stacks_client
4365
+ . get_peer_info ( )
4366
+ . expect ( "Failed to get peer info" ) ;
4367
+ Ok ( info_after. stacks_tip_height > info_before. stacks_tip_height )
4368
+ } )
4369
+ . expect ( "Timed out waiting for block to be mined and processed" ) ;
4370
4370
4371
4371
sender_nonce += 1 ;
4372
4372
let info_after = signer_test
4373
4373
. stacks_client
4374
4374
. get_peer_info ( )
4375
4375
. expect ( "Failed to get peer info" ) ;
4376
+
4376
4377
assert_eq ! (
4377
4378
info_before. stacks_tip_height + 1 ,
4378
4379
info_after. stacks_tip_height
@@ -4400,13 +4401,12 @@ fn reorg_locally_accepted_blocks_across_tenures_succeeds() {
4400
4401
make_stacks_transfer ( & sender_sk, sender_nonce, send_fee, & recipient, send_amt) ;
4401
4402
let tx = submit_tx ( & http_origin, & transfer_tx) ;
4402
4403
info ! ( "Submitted tx {tx} in to attempt to mine block N+1" ) ;
4403
- let start_time = Instant :: now ( ) ;
4404
4404
let blocks_before = mined_blocks. load ( Ordering :: SeqCst ) ;
4405
4405
let info_before = signer_test
4406
4406
. stacks_client
4407
4407
. get_peer_info ( )
4408
4408
. expect ( "Failed to get peer info" ) ;
4409
- loop {
4409
+ wait_for ( short_timeout . as_secs ( ) , || {
4410
4410
let ignored_signers = test_observer:: get_stackerdb_chunks ( )
4411
4411
. into_iter ( )
4412
4412
. flat_map ( |chunk| chunk. modified_slots )
@@ -4423,15 +4423,9 @@ fn reorg_locally_accepted_blocks_across_tenures_succeeds() {
4423
4423
}
4424
4424
} )
4425
4425
. collect :: < Vec < _ > > ( ) ;
4426
- if ignored_signers. len ( ) + ignoring_signers. len ( ) == num_signers {
4427
- break ;
4428
- }
4429
- assert ! (
4430
- start_time. elapsed( ) < short_timeout,
4431
- "FAIL: Test timed out while waiting for block proposal acceptance" ,
4432
- ) ;
4433
- sleep_ms ( 1000 ) ;
4434
- }
4426
+ Ok ( ignored_signers. len ( ) + ignoring_signers. len ( ) == num_signers)
4427
+ } )
4428
+ . expect ( "FAIL: Timed out waiting for block proposal acceptance" ) ;
4435
4429
let blocks_after = mined_blocks. load ( Ordering :: SeqCst ) ;
4436
4430
let info_after = signer_test
4437
4431
. stacks_client
@@ -4464,25 +4458,23 @@ fn reorg_locally_accepted_blocks_across_tenures_succeeds() {
4464
4458
. lock ( )
4465
4459
. unwrap ( )
4466
4460
. replace ( Vec :: new ( ) ) ;
4467
- let mined_blocks = signer_test. running_nodes . nakamoto_blocks_mined . clone ( ) ;
4468
- let blocks_before = mined_blocks. load ( Ordering :: SeqCst ) ;
4469
4461
let info_before = signer_test
4470
4462
. stacks_client
4471
4463
. get_peer_info ( )
4472
4464
. expect ( "Failed to get peer info" ) ;
4473
- let start_time = Instant :: now ( ) ;
4474
4465
// submit a tx so that the miner will mine a stacks block
4475
4466
let transfer_tx =
4476
4467
make_stacks_transfer ( & sender_sk, sender_nonce, send_fee, & recipient, send_amt) ;
4477
4468
let tx = submit_tx ( & http_origin, & transfer_tx) ;
4478
4469
info ! ( "Submitted tx {tx} in to mine block N" ) ;
4479
- while mined_blocks. load ( Ordering :: SeqCst ) <= blocks_before {
4480
- assert ! (
4481
- start_time. elapsed( ) < short_timeout,
4482
- "FAIL: Test timed out while waiting for block production" ,
4483
- ) ;
4484
- thread:: sleep ( Duration :: from_secs ( 1 ) ) ;
4485
- }
4470
+ wait_for ( short_timeout. as_secs ( ) , || {
4471
+ let info_after = signer_test
4472
+ . stacks_client
4473
+ . get_peer_info ( )
4474
+ . expect ( "Failed to get peer info" ) ;
4475
+ Ok ( info_after. stacks_tip_height > info_before. stacks_tip_height )
4476
+ } )
4477
+ . expect ( "Timed out waiting for block to be mined and processed" ) ;
4486
4478
4487
4479
let info_after = signer_test
4488
4480
. stacks_client
0 commit comments