@@ -12355,13 +12355,10 @@ fn signer_can_accept_rejected_block() {
12355
12355
None ,
12356
12356
) ;
12357
12357
let http_origin = format ! ( "http://{}" , & signer_test. running_nodes. conf. node. rpc_bind) ;
12358
- signer_test. boot_to_epoch_3 ( ) ;
12358
+ let miner_sk = signer_test. running_nodes . conf . miner . mining_key . unwrap ( ) ;
12359
+ let miner_pk = StacksPublicKey :: from_private ( & miner_sk) ;
12359
12360
12360
- let proposed_blocks = signer_test
12361
- . running_nodes
12362
- . counters
12363
- . naka_proposed_blocks
12364
- . clone ( ) ;
12361
+ signer_test. boot_to_epoch_3 ( ) ;
12365
12362
12366
12363
signer_test. mine_nakamoto_block ( Duration :: from_secs ( 60 ) , true ) ;
12367
12364
@@ -12377,7 +12374,8 @@ fn signer_can_accept_rejected_block() {
12377
12374
let ignoring_signer = StacksPublicKey :: from_private ( & signer_test. signer_stacks_private_keys [ 1 ] ) ;
12378
12375
TEST_IGNORE_ALL_BLOCK_PROPOSALS . set ( vec ! [ ignoring_signer] ) ;
12379
12376
12380
- let proposals_before = proposed_blocks. load ( Ordering :: SeqCst ) ;
12377
+ // Stall block validation so we can ensure the timing we want to test
12378
+ TEST_VALIDATE_STALL . set ( true ) ;
12381
12379
12382
12380
// submit a tx so that the miner will mine a block
12383
12381
let transfer_tx = make_stacks_transfer (
@@ -12391,13 +12389,19 @@ fn signer_can_accept_rejected_block() {
12391
12389
submit_tx ( & http_origin, & transfer_tx) ;
12392
12390
12393
12391
info ! ( "Submitted transfer tx and waiting for block proposal" ) ;
12394
- wait_for ( 60 , || {
12395
- if proposed_blocks. load ( Ordering :: SeqCst ) > proposals_before {
12396
- return Ok ( true ) ;
12397
- }
12398
- Ok ( false )
12399
- } )
12400
- . expect ( "Timed out waiting for block proposal" ) ;
12392
+ let block = wait_for_block_proposal ( 30 , block_height_before + 1 , & miner_pk)
12393
+ . expect ( "Timed out waiting for block proposal" ) ;
12394
+
12395
+ // Wait for signer[0] to reject the block
12396
+ wait_for_block_rejections ( 30 , block. header . signer_signature_hash ( ) , 1 )
12397
+ . expect ( "Failed to get expected rejections for Miner 1's block" ) ;
12398
+
12399
+ info ! ( "Disable signer 0 from rejecting proposals" ) ;
12400
+ test_observer:: clear ( ) ;
12401
+ TEST_REJECT_ALL_BLOCK_PROPOSAL . set ( vec ! [ ] ) ;
12402
+
12403
+ // Unstall the other signers
12404
+ TEST_VALIDATE_STALL . set ( false ) ;
12401
12405
12402
12406
info ! (
12403
12407
"Block proposed, submitting another transaction that should not get included in the block"
@@ -12412,26 +12416,25 @@ fn signer_can_accept_rejected_block() {
12412
12416
) ;
12413
12417
submit_tx ( & http_origin, & transfer_tx) ;
12414
12418
12415
- info ! ( "Disable signer 0 from rejecting proposals" ) ;
12416
- test_observer:: clear ( ) ;
12417
- TEST_REJECT_ALL_BLOCK_PROPOSAL . set ( vec ! [ ] ) ;
12418
-
12419
12419
info ! ( "Waiting for the block to be approved" ) ;
12420
12420
wait_for ( 60 , || {
12421
12421
let blocks = test_observer:: get_blocks ( ) ;
12422
- let last_block = blocks. last ( ) . expect ( "No blocks found" ) ;
12423
- let height = last_block[ "block_height" ] . as_u64 ( ) . unwrap ( ) ;
12424
- if height > block_height_before {
12425
- return Ok ( true ) ;
12422
+
12423
+ // Look for a block with height `block_height_before + 1`
12424
+ if let Some ( block) = blocks
12425
+ . iter ( )
12426
+ . find ( |block| block[ "block_height" ] . as_u64 ( ) == Some ( block_height_before + 1 ) )
12427
+ {
12428
+ if transfers_in_block ( block) == 1 {
12429
+ Ok ( true ) // Success: found the block with exactly 1 transfer
12430
+ } else {
12431
+ Err ( "Transfer included in block" . into ( ) ) // Found the block, but it has the wrong number of transfers
12432
+ }
12433
+ } else {
12434
+ Ok ( false ) // Keep waiting if the block hasn't appeared yet
12426
12435
}
12427
- Ok ( false )
12428
12436
} )
12429
12437
. expect ( "Timed out waiting for block" ) ;
12430
12438
12431
- // Ensure that the block was the original block with just 1 transfer
12432
- let blocks = test_observer:: get_blocks ( ) ;
12433
- let block = blocks. last ( ) . expect ( "No blocks found" ) ;
12434
- assert_eq ! ( transfers_in_block( block) , 1 ) ;
12435
-
12436
12439
signer_test. shutdown ( ) ;
12437
12440
}
0 commit comments