@@ -95,7 +95,6 @@ use wsts::net::Message;
95
95
use super :: bitcoin_regtest:: BitcoinCoreController ;
96
96
use crate :: config:: { EventKeyType , EventObserverConfig , InitialBalance } ;
97
97
use crate :: nakamoto_node:: miner:: TEST_BROADCAST_STALL ;
98
- use crate :: nakamoto_node:: relayer:: TEST_SKIP_COMMIT_OP ;
99
98
use crate :: neon:: { Counters , RunLoopCounter } ;
100
99
use crate :: operations:: BurnchainOpSigner ;
101
100
use crate :: run_loop:: boot_nakamoto;
@@ -626,6 +625,21 @@ where
626
625
Ok ( ( ) )
627
626
}
628
627
628
+ pub fn wait_for < F > ( timeout_secs : u64 , mut check : F ) -> Result < ( ) , String >
629
+ where
630
+ F : FnMut ( ) -> Result < bool , String > ,
631
+ {
632
+ let start = Instant :: now ( ) ;
633
+ while !check ( ) ? {
634
+ if start. elapsed ( ) > Duration :: from_secs ( timeout_secs) {
635
+ error ! ( "Timed out waiting for check to process" ) ;
636
+ return Err ( "Timed out" . into ( ) ) ;
637
+ }
638
+ thread:: sleep ( Duration :: from_millis ( 100 ) ) ;
639
+ }
640
+ Ok ( ( ) )
641
+ }
642
+
629
643
/// Mine a bitcoin block, and wait until:
630
644
/// (1) a new block has been processed by the coordinator
631
645
pub fn next_block_and_process_new_stacks_block (
@@ -1630,6 +1644,10 @@ fn multiple_miners() {
1630
1644
1631
1645
let ( mut naka_conf, _miner_account) = naka_neon_integration_conf ( None ) ;
1632
1646
naka_conf. node . local_peer_seed = vec ! [ 1 , 1 , 1 , 1 ] ;
1647
+ naka_conf. miner . mining_key = Some ( Secp256k1PrivateKey :: from_seed ( & [ 1 ] ) ) ;
1648
+
1649
+ let node_2_rpc = 51026 ;
1650
+ let node_2_p2p = 51025 ;
1633
1651
let http_origin = format ! ( "http://{}" , & naka_conf. node. rpc_bind) ;
1634
1652
naka_conf. miner . wait_on_interim_blocks = Duration :: from_secs ( 1 ) ;
1635
1653
let sender_sk = Secp256k1PrivateKey :: new ( ) ;
@@ -1654,7 +1672,11 @@ fn multiple_miners() {
1654
1672
let stacker_sk = setup_stacker ( & mut naka_conf) ;
1655
1673
1656
1674
let mut conf_node_2 = naka_conf. clone ( ) ;
1657
- set_random_binds ( & mut conf_node_2) ;
1675
+ let localhost = "127.0.0.1" ;
1676
+ conf_node_2. node . rpc_bind = format ! ( "{}:{}" , localhost, node_2_rpc) ;
1677
+ conf_node_2. node . p2p_bind = format ! ( "{}:{}" , localhost, node_2_p2p) ;
1678
+ conf_node_2. node . data_url = format ! ( "http://{}:{}" , localhost, node_2_rpc) ;
1679
+ conf_node_2. node . p2p_address = format ! ( "{}:{}" , localhost, node_2_p2p) ;
1658
1680
conf_node_2. node . seed = vec ! [ 2 , 2 , 2 , 2 ] ;
1659
1681
conf_node_2. burnchain . local_mining_public_key = Some (
1660
1682
Keychain :: default ( conf_node_2. node . seed . clone ( ) )
@@ -1663,6 +1685,8 @@ fn multiple_miners() {
1663
1685
) ;
1664
1686
conf_node_2. node . local_peer_seed = vec ! [ 2 , 2 , 2 , 2 ] ;
1665
1687
conf_node_2. node . miner = true ;
1688
+ conf_node_2. miner . mining_key = Some ( Secp256k1PrivateKey :: from_seed ( & [ 2 ] ) ) ;
1689
+ conf_node_2. events_observers . clear ( ) ;
1666
1690
1667
1691
let node_1_sk = Secp256k1PrivateKey :: from_seed ( & naka_conf. node . local_peer_seed ) ;
1668
1692
let node_1_pk = StacksPublicKey :: from_private ( & node_1_sk) ;
@@ -1802,16 +1826,14 @@ fn multiple_miners() {
1802
1826
make_stacks_transfer ( & sender_sk, sender_nonce, send_fee, & recipient, send_amt) ;
1803
1827
submit_tx ( & http_origin, & transfer_tx) ;
1804
1828
1805
- loop {
1829
+ wait_for ( 20 , || {
1806
1830
let blocks_processed = coord_channel
1807
1831
. lock ( )
1808
1832
. expect ( "Mutex poisoned" )
1809
1833
. get_stacks_blocks_processed ( ) ;
1810
- if blocks_processed > blocks_processed_before {
1811
- break ;
1812
- }
1813
- thread:: sleep ( Duration :: from_millis ( 100 ) ) ;
1814
- }
1834
+ Ok ( blocks_processed > blocks_processed_before)
1835
+ } )
1836
+ . unwrap ( ) ;
1815
1837
1816
1838
let info = get_chain_info_result ( & naka_conf) . unwrap ( ) ;
1817
1839
assert_ne ! ( info. stacks_tip, last_tip) ;
@@ -1821,13 +1843,10 @@ fn multiple_miners() {
1821
1843
last_tip_height = info. stacks_tip_height ;
1822
1844
}
1823
1845
1824
- let start_time = Instant :: now ( ) ;
1825
- while commits_submitted. load ( Ordering :: SeqCst ) <= commits_before {
1826
- if start_time. elapsed ( ) >= Duration :: from_secs ( 20 ) {
1827
- panic ! ( "Timed out waiting for block-commit" ) ;
1828
- }
1829
- thread:: sleep ( Duration :: from_millis ( 100 ) ) ;
1830
- }
1846
+ wait_for ( 20 , || {
1847
+ Ok ( commits_submitted. load ( Ordering :: SeqCst ) > commits_before)
1848
+ } )
1849
+ . unwrap ( ) ;
1831
1850
}
1832
1851
1833
1852
// load the chain tip, and assert that it is a nakamoto block and at least 30 blocks have advanced in epoch 3
@@ -3726,6 +3745,7 @@ fn forked_tenure_is_ignored() {
3726
3745
naka_submitted_commits : commits_submitted,
3727
3746
naka_proposed_blocks : proposals_submitted,
3728
3747
naka_mined_blocks : mined_blocks,
3748
+ naka_skip_commit_op : test_skip_commit_op,
3729
3749
..
3730
3750
} = run_loop. counters ( ) ;
3731
3751
@@ -3794,7 +3814,7 @@ fn forked_tenure_is_ignored() {
3794
3814
info ! ( "Commit op is submitted; unpause tenure B's block" ) ;
3795
3815
3796
3816
// Unpause the broadcast of Tenure B's block, do not submit commits.
3797
- TEST_SKIP_COMMIT_OP . lock ( ) . unwrap ( ) . replace ( true ) ;
3817
+ test_skip_commit_op . 0 . lock ( ) . unwrap ( ) . replace ( true ) ;
3798
3818
TEST_BROADCAST_STALL . lock ( ) . unwrap ( ) . replace ( false ) ;
3799
3819
3800
3820
// Wait for a stacks block to be broadcasted
@@ -3819,7 +3839,7 @@ fn forked_tenure_is_ignored() {
3819
3839
let commits_before = commits_submitted. load ( Ordering :: SeqCst ) ;
3820
3840
let blocks_before = mined_blocks. load ( Ordering :: SeqCst ) ;
3821
3841
next_block_and ( & mut btc_regtest_controller, 60 , || {
3822
- TEST_SKIP_COMMIT_OP . lock ( ) . unwrap ( ) . replace ( false ) ;
3842
+ test_skip_commit_op . 0 . lock ( ) . unwrap ( ) . replace ( false ) ;
3823
3843
let commits_count = commits_submitted. load ( Ordering :: SeqCst ) ;
3824
3844
let blocks_count = mined_blocks. load ( Ordering :: SeqCst ) ;
3825
3845
Ok ( commits_count > commits_before && blocks_count > blocks_before)
@@ -5493,6 +5513,7 @@ fn continue_tenure_extend() {
5493
5513
blocks_processed,
5494
5514
naka_submitted_commits : commits_submitted,
5495
5515
naka_proposed_blocks : proposals_submitted,
5516
+ naka_skip_commit_op : test_skip_commit_op,
5496
5517
..
5497
5518
} = run_loop. counters ( ) ;
5498
5519
@@ -5564,7 +5585,7 @@ fn continue_tenure_extend() {
5564
5585
) ;
5565
5586
5566
5587
info ! ( "Pausing commit ops to trigger a tenure extend." ) ;
5567
- TEST_SKIP_COMMIT_OP . lock ( ) . unwrap ( ) . replace ( true ) ;
5588
+ test_skip_commit_op . 0 . lock ( ) . unwrap ( ) . replace ( true ) ;
5568
5589
5569
5590
next_block_and ( & mut btc_regtest_controller, 60 , || Ok ( true ) ) . unwrap ( ) ;
5570
5591
@@ -5619,7 +5640,7 @@ fn continue_tenure_extend() {
5619
5640
) ;
5620
5641
5621
5642
info ! ( "Resuming commit ops to mine regular tenures." ) ;
5622
- TEST_SKIP_COMMIT_OP . lock ( ) . unwrap ( ) . replace ( false ) ;
5643
+ test_skip_commit_op . 0 . lock ( ) . unwrap ( ) . replace ( false ) ;
5623
5644
5624
5645
// Mine 15 more regular nakamoto tenures
5625
5646
for _i in 0 ..15 {
0 commit comments