@@ -4804,18 +4804,10 @@ fn miner_recovers_when_broadcast_block_delay_across_tenures_occurs() {
4804
4804
vec ! [ ( sender_addr. clone( ) , ( send_amt + send_fee) * nmb_txs) ] ,
4805
4805
) ;
4806
4806
let http_origin = format ! ( "http://{}" , & signer_test. running_nodes. conf. node. rpc_bind) ;
4807
- let short_timeout = Duration :: from_secs ( 30 ) ;
4808
4807
signer_test. boot_to_epoch_3 ( ) ;
4809
4808
4810
4809
info ! ( "------------------------- Starting Tenure A -------------------------" ) ;
4811
4810
info ! ( "------------------------- Test Mine Nakamoto Block N -------------------------" ) ;
4812
- let mined_blocks = signer_test. running_nodes . nakamoto_blocks_mined . clone ( ) ;
4813
- let blocks_before = mined_blocks. load ( Ordering :: SeqCst ) ;
4814
- let info_before = signer_test
4815
- . stacks_client
4816
- . get_peer_info ( )
4817
- . expect ( "Failed to get peer info" ) ;
4818
- let start_time = Instant :: now ( ) ;
4819
4811
4820
4812
// wait until we get a sortition.
4821
4813
// we might miss a block-commit at the start of epoch 3
@@ -4828,6 +4820,12 @@ fn miner_recovers_when_broadcast_block_delay_across_tenures_occurs() {
4828
4820
} )
4829
4821
. expect ( "Timed out waiting for sortition" ) ;
4830
4822
4823
+ let mined_blocks = signer_test. running_nodes . nakamoto_blocks_mined . clone ( ) ;
4824
+ let blocks_before = mined_blocks. load ( Ordering :: SeqCst ) ;
4825
+ let info_before = signer_test
4826
+ . stacks_client
4827
+ . get_peer_info ( )
4828
+ . expect ( "Failed to get peer info" ) ;
4831
4829
// submit a tx so that the miner will mine a stacks block
4832
4830
let mut sender_nonce = 0 ;
4833
4831
let transfer_tx = make_stacks_transfer (
@@ -4842,13 +4840,10 @@ fn miner_recovers_when_broadcast_block_delay_across_tenures_occurs() {
4842
4840
info ! ( "Submitted tx {tx} in to mine block N" ) ;
4843
4841
4844
4842
// a tenure has begun, so wait until we mine a block
4845
- while mined_blocks. load ( Ordering :: SeqCst ) <= blocks_before {
4846
- assert ! (
4847
- start_time. elapsed( ) < short_timeout,
4848
- "FAIL: Test timed out while waiting for block production" ,
4849
- ) ;
4850
- thread:: sleep ( Duration :: from_secs ( 1 ) ) ;
4851
- }
4843
+ wait_for ( 30 , || {
4844
+ Ok ( mined_blocks. load ( Ordering :: SeqCst ) > blocks_before)
4845
+ } )
4846
+ . expect ( "Timed out waiting for block to be mined and processed" ) ;
4852
4847
4853
4848
sender_nonce += 1 ;
4854
4849
let info_after = signer_test
@@ -4892,61 +4887,51 @@ fn miner_recovers_when_broadcast_block_delay_across_tenures_occurs() {
4892
4887
let tx = submit_tx ( & http_origin, & transfer_tx) ;
4893
4888
4894
4889
info ! ( "Submitted tx {tx} in to attempt to mine block N+1" ) ;
4895
- let start_time = Instant :: now ( ) ;
4896
4890
let mut block = None ;
4897
- loop {
4898
- if block. is_none ( ) {
4899
- block = test_observer:: get_stackerdb_chunks ( )
4900
- . into_iter ( )
4901
- . flat_map ( |chunk| chunk. modified_slots )
4902
- . find_map ( |chunk| {
4903
- let message = SignerMessage :: consensus_deserialize ( & mut chunk. data . as_slice ( ) )
4904
- . expect ( "Failed to deserialize SignerMessage" ) ;
4905
- match message {
4906
- SignerMessage :: BlockProposal ( proposal) => {
4907
- if proposal. block . header . consensus_hash
4908
- == info_before. stacks_tip_consensus_hash
4909
- {
4910
- Some ( proposal. block )
4911
- } else {
4912
- None
4913
- }
4891
+ wait_for ( 30 , || {
4892
+ block = test_observer:: get_stackerdb_chunks ( )
4893
+ . into_iter ( )
4894
+ . flat_map ( |chunk| chunk. modified_slots )
4895
+ . find_map ( |chunk| {
4896
+ let message = SignerMessage :: consensus_deserialize ( & mut chunk. data . as_slice ( ) )
4897
+ . expect ( "Failed to deserialize SignerMessage" ) ;
4898
+ match message {
4899
+ SignerMessage :: BlockProposal ( proposal) => {
4900
+ if proposal. block . header . consensus_hash
4901
+ == info_before. stacks_tip_consensus_hash
4902
+ {
4903
+ Some ( proposal. block )
4904
+ } else {
4905
+ None
4914
4906
}
4915
- _ => None ,
4916
4907
}
4917
- } ) ;
4918
- }
4919
- if let Some ( block ) = & block {
4920
- let signatures = test_observer :: get_stackerdb_chunks ( )
4921
- . into_iter ( )
4922
- . flat_map ( |chunk| chunk . modified_slots )
4923
- . filter_map ( |chunk| {
4924
- let message = SignerMessage :: consensus_deserialize ( & mut chunk . data . as_slice ( ) )
4925
- . expect ( "Failed to deserialize SignerMessage" ) ;
4926
- match message {
4927
- SignerMessage :: BlockResponse ( BlockResponse :: Accepted ( accepted ) ) => {
4928
- if block . header . signer_signature_hash ( )
4929
- == accepted . signer_signature_hash
4930
- {
4931
- Some ( accepted. signature )
4932
- } else {
4933
- None
4934
- }
4908
+ _ => None ,
4909
+ }
4910
+ } ) ;
4911
+ let Some ( block ) = & block else {
4912
+ return Ok ( false ) ;
4913
+ } ;
4914
+ let signatures = test_observer :: get_stackerdb_chunks ( )
4915
+ . into_iter ( )
4916
+ . flat_map ( |chunk| chunk . modified_slots )
4917
+ . filter_map ( |chunk| {
4918
+ let message = SignerMessage :: consensus_deserialize ( & mut chunk . data . as_slice ( ) )
4919
+ . expect ( "Failed to deserialize SignerMessage" ) ;
4920
+ match message {
4921
+ SignerMessage :: BlockResponse ( BlockResponse :: Accepted ( accepted ) ) => {
4922
+ if block . header . signer_signature_hash ( ) == accepted. signer_signature_hash {
4923
+ Some ( accepted . signature )
4924
+ } else {
4925
+ None
4935
4926
}
4936
- _ => None ,
4937
4927
}
4938
- } )
4939
- . collect :: < Vec < _ > > ( ) ;
4940
- if signatures. len ( ) == num_signers {
4941
- break ;
4942
- }
4943
- }
4944
- assert ! (
4945
- start_time. elapsed( ) < short_timeout,
4946
- "FAIL: Test timed out while waiting for signers signatures for first block proposal" ,
4947
- ) ;
4948
- sleep_ms ( 1000 ) ;
4949
- }
4928
+ _ => None ,
4929
+ }
4930
+ } )
4931
+ . collect :: < Vec < _ > > ( ) ;
4932
+ Ok ( signatures. len ( ) == num_signers)
4933
+ } )
4934
+ . expect ( "Test timed out while waiting for signers signatures for first block proposal" ) ;
4950
4935
let block = block. unwrap ( ) ;
4951
4936
4952
4937
let blocks_after = mined_blocks. load ( Ordering :: SeqCst ) ;
@@ -4979,9 +4964,8 @@ fn miner_recovers_when_broadcast_block_delay_across_tenures_occurs() {
4979
4964
"------------------------- Attempt to Mine Nakamoto Block N+1' -------------------------"
4980
4965
) ;
4981
4966
// Wait for the miner to propose a new invalid block N+1'
4982
- let start_time = Instant :: now ( ) ;
4983
4967
let mut rejected_block = None ;
4984
- while rejected_block . is_none ( ) {
4968
+ wait_for ( 30 , || {
4985
4969
rejected_block = test_observer:: get_stackerdb_chunks ( )
4986
4970
. into_iter ( )
4987
4971
. flat_map ( |chunk| chunk. modified_slots )
@@ -5002,11 +4986,9 @@ fn miner_recovers_when_broadcast_block_delay_across_tenures_occurs() {
5002
4986
_ => None ,
5003
4987
}
5004
4988
} ) ;
5005
- assert ! (
5006
- start_time. elapsed( ) < short_timeout,
5007
- "FAIL: Test timed out while waiting for N+1' block proposal" ,
5008
- ) ;
5009
- }
4989
+ Ok ( rejected_block. is_some ( ) )
4990
+ } )
4991
+ . expect ( "Timed out waiting for block proposal of N+1' block proposal" ) ;
5010
4992
5011
4993
info ! ( "Allowing miner to accept block responses again. " ) ;
5012
4994
TEST_IGNORE_SIGNERS . lock ( ) . unwrap ( ) . replace ( false ) ;
@@ -5015,7 +4997,7 @@ fn miner_recovers_when_broadcast_block_delay_across_tenures_occurs() {
5015
4997
5016
4998
// Assert the N+1' block was rejected
5017
4999
let rejected_block = rejected_block. unwrap ( ) ;
5018
- loop {
5000
+ wait_for ( 30 , || {
5019
5001
let stackerdb_events = test_observer:: get_stackerdb_chunks ( ) ;
5020
5002
let block_rejections = stackerdb_events
5021
5003
. into_iter ( )
@@ -5037,14 +5019,9 @@ fn miner_recovers_when_broadcast_block_delay_across_tenures_occurs() {
5037
5019
}
5038
5020
} )
5039
5021
. collect :: < Vec < _ > > ( ) ;
5040
- if block_rejections. len ( ) == num_signers {
5041
- break ;
5042
- }
5043
- assert ! (
5044
- start_time. elapsed( ) < short_timeout,
5045
- "FAIL: Test timed out while waiting for block proposal rejections" ,
5046
- ) ;
5047
- }
5022
+ Ok ( block_rejections. len ( ) == num_signers)
5023
+ } )
5024
+ . expect ( "FAIL: Timed out waiting for block proposal rejections" ) ;
5048
5025
5049
5026
// Induce block N+2 to get mined
5050
5027
let transfer_tx = make_stacks_transfer (
@@ -5060,24 +5037,17 @@ fn miner_recovers_when_broadcast_block_delay_across_tenures_occurs() {
5060
5037
info ! ( "Submitted tx {tx} in to attempt to mine block N+2" ) ;
5061
5038
5062
5039
info ! ( "------------------------- Asserting a both N+1 and N+2 are accepted -------------------------" ) ;
5063
- loop {
5040
+ wait_for ( 30 , || {
5064
5041
// N.B. have to use /v2/info because mined_blocks only increments if the miner's signing
5065
5042
// coordinator returns successfully (meaning, mined_blocks won't increment for block N+1)
5066
5043
let info = signer_test
5067
5044
. stacks_client
5068
5045
. get_peer_info ( )
5069
5046
. expect ( "Failed to get peer info" ) ;
5070
5047
5071
- if info_before. stacks_tip_height + 2 <= info. stacks_tip_height {
5072
- break ;
5073
- }
5074
-
5075
- assert ! (
5076
- start_time. elapsed( ) < short_timeout,
5077
- "FAIL: Test timed out while waiting for block production" ,
5078
- ) ;
5079
- thread:: sleep ( Duration :: from_secs ( 1 ) ) ;
5080
- }
5048
+ Ok ( info_before. stacks_tip_height + 2 <= info. stacks_tip_height )
5049
+ } )
5050
+ . expect ( "Timed out waiting for blocks to be mined" ) ;
5081
5051
5082
5052
let info_after = signer_test
5083
5053
. stacks_client
@@ -5096,7 +5066,7 @@ fn miner_recovers_when_broadcast_block_delay_across_tenures_occurs() {
5096
5066
. expect ( "Not a Nakamoto block" )
5097
5067
. signer_signature
5098
5068
. len ( ) ;
5099
- assert_eq ! ( nmb_signatures, num_signers) ;
5069
+ assert ! ( nmb_signatures >= num_signers * 7 / 10 ) ;
5100
5070
5101
5071
// Ensure that the block was accepted globally so the stacks tip has advanced to N+2
5102
5072
let nakamoto_blocks = test_observer:: get_mined_nakamoto_blocks ( ) ;
0 commit comments