@@ -3914,8 +3914,6 @@ fn forked_tenure_is_ignored() {
3914
3914
thread:: sleep ( Duration :: from_secs ( 1 ) ) ;
3915
3915
}
3916
3916
3917
- sleep_ms ( 1000 ) ;
3918
-
3919
3917
info ! ( "Tenure B broadcasted but did not process a block. Issue the next bitcon block and unstall block commits." ) ;
3920
3918
3921
3919
// the block will be stored, not processed, so load it out of staging
@@ -3947,18 +3945,25 @@ fn forked_tenure_is_ignored() {
3947
3945
// It should also build on block A, since the node has paused processing of block B.
3948
3946
let commits_before = commits_submitted. load ( Ordering :: SeqCst ) ;
3949
3947
let blocks_before = mined_blocks. load ( Ordering :: SeqCst ) ;
3948
+ let blocks_processed_before = coord_channel
3949
+ . lock ( )
3950
+ . expect ( "Mutex poisoned" )
3951
+ . get_stacks_blocks_processed ( ) ;
3950
3952
next_block_and ( & mut btc_regtest_controller, 60 , || {
3951
3953
test_skip_commit_op. 0 . lock ( ) . unwrap ( ) . replace ( false ) ;
3952
3954
TEST_BLOCK_ANNOUNCE_STALL . lock ( ) . unwrap ( ) . replace ( false ) ;
3953
3955
let commits_count = commits_submitted. load ( Ordering :: SeqCst ) ;
3954
3956
let blocks_count = mined_blocks. load ( Ordering :: SeqCst ) ;
3955
- Ok ( commits_count > commits_before && blocks_count > blocks_before)
3957
+ let blocks_processed = coord_channel
3958
+ . lock ( )
3959
+ . expect ( "Mutex poisoned" )
3960
+ . get_stacks_blocks_processed ( ) ;
3961
+ Ok ( commits_count > commits_before
3962
+ && blocks_count > blocks_before
3963
+ && blocks_processed > blocks_processed_before)
3956
3964
} )
3957
3965
. unwrap ( ) ;
3958
3966
3959
- // allow blocks B and C to be processed
3960
- sleep_ms ( 1000 ) ;
3961
-
3962
3967
info ! ( "Tenure C produced a block!" ) ;
3963
3968
let block_tenure_c = NakamotoChainState :: get_canonical_block_header ( chainstate. db ( ) , & sortdb)
3964
3969
. unwrap ( )
@@ -3976,6 +3981,10 @@ fn forked_tenure_is_ignored() {
3976
3981
3977
3982
// Now let's produce a second block for tenure C and ensure it builds off of block C.
3978
3983
let blocks_before = mined_blocks. load ( Ordering :: SeqCst ) ;
3984
+ let blocks_processed_before = coord_channel
3985
+ . lock ( )
3986
+ . expect ( "Mutex poisoned" )
3987
+ . get_stacks_blocks_processed ( ) ;
3979
3988
let start_time = Instant :: now ( ) ;
3980
3989
3981
3990
// submit a tx so that the miner will mine an extra block
@@ -3993,8 +4002,14 @@ fn forked_tenure_is_ignored() {
3993
4002
thread:: sleep ( Duration :: from_secs ( 1 ) ) ;
3994
4003
}
3995
4004
3996
- // give C's second block a moment to process
3997
- sleep_ms ( 1000 ) ;
4005
+ wait_for ( 10 , || {
4006
+ let blocks_processed = coord_channel
4007
+ . lock ( )
4008
+ . expect ( "Mutex poisoned" )
4009
+ . get_stacks_blocks_processed ( ) ;
4010
+ Ok ( blocks_processed > blocks_processed_before)
4011
+ } )
4012
+ . unwrap ( ) ;
3998
4013
3999
4014
info ! ( "Tenure C produced a second block!" ) ;
4000
4015
@@ -4014,16 +4029,23 @@ fn forked_tenure_is_ignored() {
4014
4029
// Submit a block commit op for tenure D and mine a stacks block
4015
4030
let commits_before = commits_submitted. load ( Ordering :: SeqCst ) ;
4016
4031
let blocks_before = mined_blocks. load ( Ordering :: SeqCst ) ;
4032
+ let blocks_processed_before = coord_channel
4033
+ . lock ( )
4034
+ . expect ( "Mutex poisoned" )
4035
+ . get_stacks_blocks_processed ( ) ;
4017
4036
next_block_and ( & mut btc_regtest_controller, 60 , || {
4018
4037
let commits_count = commits_submitted. load ( Ordering :: SeqCst ) ;
4019
4038
let blocks_count = mined_blocks. load ( Ordering :: SeqCst ) ;
4020
- Ok ( commits_count > commits_before && blocks_count > blocks_before)
4039
+ let blocks_processed = coord_channel
4040
+ . lock ( )
4041
+ . expect ( "Mutex poisoned" )
4042
+ . get_stacks_blocks_processed ( ) ;
4043
+ Ok ( commits_count > commits_before
4044
+ && blocks_count > blocks_before
4045
+ && blocks_processed > blocks_processed_before)
4021
4046
} )
4022
4047
. unwrap ( ) ;
4023
4048
4024
- // give tenure D's block a moment to process
4025
- sleep_ms ( 1000 ) ;
4026
-
4027
4049
let block_tenure_d = NakamotoChainState :: get_canonical_block_header ( chainstate. db ( ) , & sortdb)
4028
4050
. unwrap ( )
4029
4051
. unwrap ( ) ;
@@ -5703,6 +5725,11 @@ fn continue_tenure_extend() {
5703
5725
info ! ( "Nakamoto miner started..." ) ;
5704
5726
blind_signer ( & naka_conf, & signers, proposals_submitted) ;
5705
5727
5728
+ let blocks_processed_before = coord_channel
5729
+ . lock ( )
5730
+ . expect ( "Mutex poisoned" )
5731
+ . get_stacks_blocks_processed ( ) ;
5732
+
5706
5733
wait_for_first_naka_block_commit ( 60 , & commits_submitted) ;
5707
5734
5708
5735
// Mine a regular nakamoto tenure
@@ -5720,7 +5747,20 @@ fn continue_tenure_extend() {
5720
5747
& [ sender_signer_sk] ,
5721
5748
& signers,
5722
5749
) ;
5723
- sleep_ms ( 5_000 ) ;
5750
+
5751
+ wait_for ( 5 , || {
5752
+ let blocks_processed = coord_channel
5753
+ . lock ( )
5754
+ . expect ( "Mutex poisoned" )
5755
+ . get_stacks_blocks_processed ( ) ;
5756
+ Ok ( blocks_processed > blocks_processed_before)
5757
+ } )
5758
+ . unwrap ( ) ;
5759
+
5760
+ let blocks_processed_before = coord_channel
5761
+ . lock ( )
5762
+ . expect ( "Mutex poisoned" )
5763
+ . get_stacks_blocks_processed ( ) ;
5724
5764
5725
5765
info ! ( "Pausing commit ops to trigger a tenure extend." ) ;
5726
5766
test_skip_commit_op. 0 . lock ( ) . unwrap ( ) . replace ( true ) ;
@@ -5733,7 +5773,15 @@ fn continue_tenure_extend() {
5733
5773
& [ sender_signer_sk] ,
5734
5774
& signers,
5735
5775
) ;
5736
- sleep_ms ( 5_000 ) ;
5776
+
5777
+ wait_for ( 5 , || {
5778
+ let blocks_processed = coord_channel
5779
+ . lock ( )
5780
+ . expect ( "Mutex poisoned" )
5781
+ . get_stacks_blocks_processed ( ) ;
5782
+ Ok ( blocks_processed > blocks_processed_before)
5783
+ } )
5784
+ . unwrap ( ) ;
5737
5785
5738
5786
// Submit a TX
5739
5787
let transfer_tx = make_stacks_transfer ( & sender_sk, 0 , send_fee, & recipient, send_amt) ;
@@ -5759,6 +5807,11 @@ fn continue_tenure_extend() {
5759
5807
)
5760
5808
. unwrap ( ) ;
5761
5809
5810
+ let blocks_processed_before = coord_channel
5811
+ . lock ( )
5812
+ . expect ( "Mutex poisoned" )
5813
+ . get_stacks_blocks_processed ( ) ;
5814
+
5762
5815
next_block_and_process_new_stacks_block ( & mut btc_regtest_controller, 60 , & coord_channel)
5763
5816
. unwrap ( ) ;
5764
5817
@@ -5768,7 +5821,20 @@ fn continue_tenure_extend() {
5768
5821
& [ sender_signer_sk] ,
5769
5822
& signers,
5770
5823
) ;
5771
- sleep_ms ( 5_000 ) ;
5824
+
5825
+ wait_for ( 5 , || {
5826
+ let blocks_processed = coord_channel
5827
+ . lock ( )
5828
+ . expect ( "Mutex poisoned" )
5829
+ . get_stacks_blocks_processed ( ) ;
5830
+ Ok ( blocks_processed > blocks_processed_before)
5831
+ } )
5832
+ . unwrap ( ) ;
5833
+
5834
+ let blocks_processed_before = coord_channel
5835
+ . lock ( )
5836
+ . expect ( "Mutex poisoned" )
5837
+ . get_stacks_blocks_processed ( ) ;
5772
5838
5773
5839
next_block_and ( & mut btc_regtest_controller, 60 , || Ok ( true ) ) . unwrap ( ) ;
5774
5840
@@ -5778,7 +5844,15 @@ fn continue_tenure_extend() {
5778
5844
& [ sender_signer_sk] ,
5779
5845
& signers,
5780
5846
) ;
5781
- sleep_ms ( 5_000 ) ;
5847
+
5848
+ wait_for ( 5 , || {
5849
+ let blocks_processed = coord_channel
5850
+ . lock ( )
5851
+ . expect ( "Mutex poisoned" )
5852
+ . get_stacks_blocks_processed ( ) ;
5853
+ Ok ( blocks_processed > blocks_processed_before)
5854
+ } )
5855
+ . unwrap ( ) ;
5782
5856
5783
5857
info ! ( "Resuming commit ops to mine regular tenures." ) ;
5784
5858
test_skip_commit_op. 0 . lock ( ) . unwrap ( ) . replace ( false ) ;
@@ -5792,11 +5866,7 @@ fn continue_tenure_extend() {
5792
5866
. get_stacks_blocks_processed ( ) ;
5793
5867
next_block_and ( & mut btc_regtest_controller, 60 , || {
5794
5868
let commits_count = commits_submitted. load ( Ordering :: SeqCst ) ;
5795
- let blocks_processed = coord_channel
5796
- . lock ( )
5797
- . expect ( "Mutex poisoned" )
5798
- . get_stacks_blocks_processed ( ) ;
5799
- Ok ( commits_count > commits_before && blocks_processed > blocks_processed_before)
5869
+ Ok ( commits_count > commits_before)
5800
5870
} )
5801
5871
. unwrap ( ) ;
5802
5872
@@ -5807,6 +5877,15 @@ fn continue_tenure_extend() {
5807
5877
& signers,
5808
5878
) ;
5809
5879
5880
+ wait_for ( 5 , || {
5881
+ let blocks_processed = coord_channel
5882
+ . lock ( )
5883
+ . expect ( "Mutex poisoned" )
5884
+ . get_stacks_blocks_processed ( ) ;
5885
+ Ok ( blocks_processed > blocks_processed_before)
5886
+ } )
5887
+ . unwrap ( ) ;
5888
+
5810
5889
sleep_ms ( 5_000 ) ;
5811
5890
}
5812
5891
0 commit comments