@@ -12398,6 +12398,10 @@ fn bitcoin_reorg_flap() {
12398
12398
channel. stop_chains_coordinator ( ) ;
12399
12399
}
12400
12400
12401
+ /// Advance the bitcoin chain and wait for the miner and any followers to
12402
+ /// process the next block.
12403
+ /// NOTE: This only works if the followers are mock-mining, or else the counter
12404
+ /// will not be updated.
12401
12405
fn next_block_and_wait_all (
12402
12406
btc_controller : & mut BitcoinRegtestController ,
12403
12407
miner_blocks_processed : & Arc < AtomicU64 > ,
@@ -12447,7 +12451,7 @@ fn bitcoin_reorg_flap_with_follower() {
12447
12451
}
12448
12452
12449
12453
let ( conf, _miner_account) = neon_integration_test_conf ( ) ;
12450
- let timeout = None ;
12454
+ let timeout = Some ( Duration :: from_secs ( 60 ) ) ;
12451
12455
12452
12456
let mut btcd_controller = BitcoinCoreController :: new ( conf. clone ( ) ) ;
12453
12457
btcd_controller
@@ -12461,10 +12465,12 @@ fn bitcoin_reorg_flap_with_follower() {
12461
12465
eprintln ! ( "Chain bootstrapped..." ) ;
12462
12466
12463
12467
let mut miner_run_loop = neon:: RunLoop :: new ( conf. clone ( ) ) ;
12468
+ let run_loop_stopper = miner_run_loop. get_termination_switch ( ) ;
12464
12469
let miner_blocks_processed = miner_run_loop. get_blocks_processed_arc ( ) ;
12465
12470
let miner_channel = miner_run_loop. get_coordinator_channel ( ) . unwrap ( ) ;
12466
12471
12467
12472
let mut follower_conf = conf. clone ( ) ;
12473
+ follower_conf. node . mock_mining = true ;
12468
12474
follower_conf. events_observers . clear ( ) ;
12469
12475
follower_conf. node . working_dir = format ! ( "{}-follower" , & conf. node. working_dir) ;
12470
12476
follower_conf. node . seed = vec ! [ 0x01 ; 32 ] ;
@@ -12483,7 +12489,7 @@ fn bitcoin_reorg_flap_with_follower() {
12483
12489
follower_conf. node . data_url = format ! ( "http://{}:{}" , & localhost, rpc_port) ;
12484
12490
follower_conf. node . p2p_address = format ! ( "{}:{}" , & localhost, p2p_port) ;
12485
12491
12486
- thread:: spawn ( move || miner_run_loop. start ( None , 0 ) ) ;
12492
+ let run_loop_thread = thread:: spawn ( move || miner_run_loop. start ( None , 0 ) ) ;
12487
12493
wait_for_runloop ( & miner_blocks_processed) ;
12488
12494
12489
12495
// figure out the started node's port
@@ -12499,23 +12505,20 @@ fn bitcoin_reorg_flap_with_follower() {
12499
12505
) ;
12500
12506
12501
12507
let mut follower_run_loop = neon:: RunLoop :: new ( follower_conf. clone ( ) ) ;
12508
+ let follower_run_loop_stopper = follower_run_loop. get_termination_switch ( ) ;
12502
12509
let follower_blocks_processed = follower_run_loop. get_blocks_processed_arc ( ) ;
12503
12510
let follower_channel = follower_run_loop. get_coordinator_channel ( ) . unwrap ( ) ;
12504
12511
12505
- thread:: spawn ( move || follower_run_loop. start ( None , 0 ) ) ;
12512
+ let follower_thread = thread:: spawn ( move || follower_run_loop. start ( None , 0 ) ) ;
12506
12513
wait_for_runloop ( & follower_blocks_processed) ;
12507
12514
12508
12515
eprintln ! ( "Follower bootup complete!" ) ;
12509
12516
12510
12517
// first block wakes up the run loop
12511
- next_block_and_wait_all (
12512
- & mut btc_regtest_controller,
12513
- & miner_blocks_processed,
12514
- & [ ] ,
12515
- timeout,
12516
- ) ;
12518
+ next_block_and_wait_with_timeout ( & mut btc_regtest_controller, & miner_blocks_processed, 60 ) ;
12517
12519
12518
- // first block will hold our VRF registration
12520
+ // next block will hold our VRF registration
12521
+ // Note that the follower will not see its block processed counter bumped here
12519
12522
next_block_and_wait_all (
12520
12523
& mut btc_regtest_controller,
12521
12524
& miner_blocks_processed,
@@ -12609,9 +12612,11 @@ fn bitcoin_reorg_flap_with_follower() {
12609
12612
assert_eq ! ( miner_channel. get_sortitions_processed( ) , 225 ) ;
12610
12613
assert_eq ! ( follower_channel. get_sortitions_processed( ) , 225 ) ;
12611
12614
12612
- btcd_controller. stop_bitcoind ( ) . unwrap ( ) ;
12613
- miner_channel. stop_chains_coordinator ( ) ;
12614
- follower_channel. stop_chains_coordinator ( ) ;
12615
+ run_loop_stopper. store ( false , Ordering :: SeqCst ) ;
12616
+ follower_run_loop_stopper. store ( false , Ordering :: SeqCst ) ;
12617
+
12618
+ run_loop_thread. join ( ) . unwrap ( ) ;
12619
+ follower_thread. join ( ) . unwrap ( ) ;
12615
12620
}
12616
12621
12617
12622
/// Tests the following:
@@ -12841,3 +12846,44 @@ fn listunspent_max_utxos() {
12841
12846
let utxos = res. expect ( "Failed to get utxos" ) ;
12842
12847
assert_eq ! ( utxos. num_utxos( ) , 10 ) ;
12843
12848
}
12849
+
12850
+ #[ test]
12851
+ #[ ignore]
12852
+ /// Test out stopping bitcoind and restarting it
12853
+ fn start_stop_bitcoind ( ) {
12854
+ if env:: var ( "BITCOIND_TEST" ) != Ok ( "1" . into ( ) ) {
12855
+ return ;
12856
+ }
12857
+
12858
+ let ( mut conf, _miner_account) = neon_integration_test_conf ( ) ;
12859
+ let prom_bind = format ! ( "{}:{}" , "127.0.0.1" , 6000 ) ;
12860
+ conf. node . prometheus_bind = Some ( prom_bind. clone ( ) ) ;
12861
+
12862
+ conf. burnchain . max_rbf = 1000000 ;
12863
+
12864
+ let mut btcd_controller = BitcoinCoreController :: new ( conf. clone ( ) ) ;
12865
+ btcd_controller
12866
+ . start_bitcoind ( )
12867
+ . map_err ( |_e| ( ) )
12868
+ . expect ( "Failed starting bitcoind" ) ;
12869
+
12870
+ let mut btc_regtest_controller = BitcoinRegtestController :: new ( conf. clone ( ) , None ) ;
12871
+
12872
+ btc_regtest_controller. bootstrap_chain ( 201 ) ;
12873
+
12874
+ eprintln ! ( "Chain bootstrapped..." ) ;
12875
+
12876
+ btcd_controller
12877
+ . stop_bitcoind ( )
12878
+ . expect ( "Failed to stop bitcoind" ) ;
12879
+
12880
+ thread:: sleep ( Duration :: from_secs ( 5 ) ) ;
12881
+
12882
+ btcd_controller
12883
+ . start_bitcoind ( )
12884
+ . expect ( "Failed to start bitcoind" ) ;
12885
+
12886
+ btcd_controller
12887
+ . stop_bitcoind ( )
12888
+ . expect ( "Failed to stop bitcoind" ) ;
12889
+ }
0 commit comments