@@ -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 (
@@ -1627,6 +1641,10 @@ fn multiple_miners() {
1627
1641
1628
1642
let ( mut naka_conf, _miner_account) = naka_neon_integration_conf ( None ) ;
1629
1643
naka_conf. node . local_peer_seed = vec ! [ 1 , 1 , 1 , 1 ] ;
1644
+ naka_conf. miner . mining_key = Some ( Secp256k1PrivateKey :: from_seed ( & [ 1 ] ) ) ;
1645
+
1646
+ let node_2_rpc = 51026 ;
1647
+ let node_2_p2p = 51025 ;
1630
1648
let http_origin = format ! ( "http://{}" , & naka_conf. node. rpc_bind) ;
1631
1649
naka_conf. miner . wait_on_interim_blocks = Duration :: from_secs ( 1 ) ;
1632
1650
let sender_sk = Secp256k1PrivateKey :: new ( ) ;
@@ -1651,7 +1669,11 @@ fn multiple_miners() {
1651
1669
let stacker_sk = setup_stacker ( & mut naka_conf) ;
1652
1670
1653
1671
let mut conf_node_2 = naka_conf. clone ( ) ;
1654
- set_random_binds ( & mut conf_node_2) ;
1672
+ let localhost = "127.0.0.1" ;
1673
+ conf_node_2. node . rpc_bind = format ! ( "{}:{}" , localhost, node_2_rpc) ;
1674
+ conf_node_2. node . p2p_bind = format ! ( "{}:{}" , localhost, node_2_p2p) ;
1675
+ conf_node_2. node . data_url = format ! ( "http://{}:{}" , localhost, node_2_rpc) ;
1676
+ conf_node_2. node . p2p_address = format ! ( "{}:{}" , localhost, node_2_p2p) ;
1655
1677
conf_node_2. node . seed = vec ! [ 2 , 2 , 2 , 2 ] ;
1656
1678
conf_node_2. burnchain . local_mining_public_key = Some (
1657
1679
Keychain :: default ( conf_node_2. node . seed . clone ( ) )
@@ -1660,6 +1682,8 @@ fn multiple_miners() {
1660
1682
) ;
1661
1683
conf_node_2. node . local_peer_seed = vec ! [ 2 , 2 , 2 , 2 ] ;
1662
1684
conf_node_2. node . miner = true ;
1685
+ conf_node_2. miner . mining_key = Some ( Secp256k1PrivateKey :: from_seed ( & [ 2 ] ) ) ;
1686
+ conf_node_2. events_observers . clear ( ) ;
1663
1687
1664
1688
let node_1_sk = Secp256k1PrivateKey :: from_seed ( & naka_conf. node . local_peer_seed ) ;
1665
1689
let node_1_pk = StacksPublicKey :: from_private ( & node_1_sk) ;
@@ -1799,16 +1823,14 @@ fn multiple_miners() {
1799
1823
make_stacks_transfer ( & sender_sk, sender_nonce, send_fee, & recipient, send_amt) ;
1800
1824
submit_tx ( & http_origin, & transfer_tx) ;
1801
1825
1802
- loop {
1826
+ wait_for ( 20 , || {
1803
1827
let blocks_processed = coord_channel
1804
1828
. lock ( )
1805
1829
. expect ( "Mutex poisoned" )
1806
1830
. get_stacks_blocks_processed ( ) ;
1807
- if blocks_processed > blocks_processed_before {
1808
- break ;
1809
- }
1810
- thread:: sleep ( Duration :: from_millis ( 100 ) ) ;
1811
- }
1831
+ Ok ( blocks_processed > blocks_processed_before)
1832
+ } )
1833
+ . unwrap ( ) ;
1812
1834
1813
1835
let info = get_chain_info_result ( & naka_conf) . unwrap ( ) ;
1814
1836
assert_ne ! ( info. stacks_tip, last_tip) ;
@@ -1818,13 +1840,10 @@ fn multiple_miners() {
1818
1840
last_tip_height = info. stacks_tip_height ;
1819
1841
}
1820
1842
1821
- let start_time = Instant :: now ( ) ;
1822
- while commits_submitted. load ( Ordering :: SeqCst ) <= commits_before {
1823
- if start_time. elapsed ( ) >= Duration :: from_secs ( 20 ) {
1824
- panic ! ( "Timed out waiting for block-commit" ) ;
1825
- }
1826
- thread:: sleep ( Duration :: from_millis ( 100 ) ) ;
1827
- }
1843
+ wait_for ( 20 , || {
1844
+ Ok ( commits_submitted. load ( Ordering :: SeqCst ) > commits_before)
1845
+ } )
1846
+ . unwrap ( ) ;
1828
1847
}
1829
1848
1830
1849
// load the chain tip, and assert that it is a nakamoto block and at least 30 blocks have advanced in epoch 3
@@ -3723,6 +3742,7 @@ fn forked_tenure_is_ignored() {
3723
3742
naka_submitted_commits : commits_submitted,
3724
3743
naka_proposed_blocks : proposals_submitted,
3725
3744
naka_mined_blocks : mined_blocks,
3745
+ naka_skip_commit_op : test_skip_commit_op,
3726
3746
..
3727
3747
} = run_loop. counters ( ) ;
3728
3748
@@ -3791,7 +3811,7 @@ fn forked_tenure_is_ignored() {
3791
3811
info ! ( "Commit op is submitted; unpause tenure B's block" ) ;
3792
3812
3793
3813
// Unpause the broadcast of Tenure B's block, do not submit commits.
3794
- TEST_SKIP_COMMIT_OP . lock ( ) . unwrap ( ) . replace ( true ) ;
3814
+ test_skip_commit_op . 0 . lock ( ) . unwrap ( ) . replace ( true ) ;
3795
3815
TEST_BROADCAST_STALL . lock ( ) . unwrap ( ) . replace ( false ) ;
3796
3816
3797
3817
// Wait for a stacks block to be broadcasted
@@ -3816,7 +3836,7 @@ fn forked_tenure_is_ignored() {
3816
3836
let commits_before = commits_submitted. load ( Ordering :: SeqCst ) ;
3817
3837
let blocks_before = mined_blocks. load ( Ordering :: SeqCst ) ;
3818
3838
next_block_and ( & mut btc_regtest_controller, 60 , || {
3819
- TEST_SKIP_COMMIT_OP . lock ( ) . unwrap ( ) . replace ( false ) ;
3839
+ test_skip_commit_op . 0 . lock ( ) . unwrap ( ) . replace ( false ) ;
3820
3840
let commits_count = commits_submitted. load ( Ordering :: SeqCst ) ;
3821
3841
let blocks_count = mined_blocks. load ( Ordering :: SeqCst ) ;
3822
3842
Ok ( commits_count > commits_before && blocks_count > blocks_before)
@@ -5478,6 +5498,7 @@ fn continue_tenure_extend() {
5478
5498
blocks_processed,
5479
5499
naka_submitted_commits : commits_submitted,
5480
5500
naka_proposed_blocks : proposals_submitted,
5501
+ naka_skip_commit_op : test_skip_commit_op,
5481
5502
..
5482
5503
} = run_loop. counters ( ) ;
5483
5504
@@ -5549,7 +5570,7 @@ fn continue_tenure_extend() {
5549
5570
) ;
5550
5571
5551
5572
info ! ( "Pausing commit ops to trigger a tenure extend." ) ;
5552
- TEST_SKIP_COMMIT_OP . lock ( ) . unwrap ( ) . replace ( true ) ;
5573
+ test_skip_commit_op . 0 . lock ( ) . unwrap ( ) . replace ( true ) ;
5553
5574
5554
5575
next_block_and ( & mut btc_regtest_controller, 60 , || Ok ( true ) ) . unwrap ( ) ;
5555
5576
@@ -5604,7 +5625,7 @@ fn continue_tenure_extend() {
5604
5625
) ;
5605
5626
5606
5627
info ! ( "Resuming commit ops to mine regular tenures." ) ;
5607
- TEST_SKIP_COMMIT_OP . lock ( ) . unwrap ( ) . replace ( false ) ;
5628
+ test_skip_commit_op . 0 . lock ( ) . unwrap ( ) . replace ( false ) ;
5608
5629
5609
5630
// Mine 15 more regular nakamoto tenures
5610
5631
for _i in 0 ..15 {
0 commit comments