diff --git a/servers/src/grin/server.rs b/servers/src/grin/server.rs index ee8cbc54e8..fa0fbea336 100644 --- a/servers/src/grin/server.rs +++ b/servers/src/grin/server.rs @@ -390,19 +390,12 @@ impl Server { self.tx_pool.clone(), self.verifier_cache.clone(), stop_state, + sync_state, ); miner.set_debug_output_id(format!("Port {}", self.config.p2p_config.port)); let _ = thread::Builder::new() .name("test_miner".to_string()) - .spawn(move || { - // TODO push this down in the run loop so miner gets paused anytime we - // decide to sync again - let secs_5 = time::Duration::from_secs(5); - while sync_state.is_syncing() { - thread::sleep(secs_5); - } - miner.run_loop(wallet_listener_url); - }); + .spawn(move || miner.run_loop(wallet_listener_url)); } /// The chain head @@ -423,8 +416,7 @@ impl Server { /// Returns a set of stats about this server. This and the ServerStats /// structure /// can be updated over time to include any information needed by tests or - /// other - /// consumers + /// other consumers pub fn get_server_stats(&self) -> Result { let stratum_stats = self.state_info.stratum_stats.read().clone(); diff --git a/servers/src/mining/test_miner.rs b/servers/src/mining/test_miner.rs index 832fc32446..8eebfd401e 100644 --- a/servers/src/mining/test_miner.rs +++ b/servers/src/mining/test_miner.rs @@ -30,6 +30,9 @@ use crate::core::global; use crate::mining::mine_block; use crate::pool; use crate::util::StopState; +use grin_chain::SyncState; +use std::thread; +use std::time::Duration; pub struct Miner { config: StratumServerConfig, @@ -37,7 +40,7 @@ pub struct Miner { tx_pool: Arc>, verifier_cache: Arc>, stop_state: Arc, - + sync_state: Arc, // Just to hold the port we're on, so this miner can be identified // while watching debug output debug_output_id: String, @@ -52,6 +55,7 @@ impl Miner { tx_pool: Arc>, verifier_cache: Arc>, stop_state: Arc, + sync_state: Arc, ) -> Miner { Miner { config, @@ -60,6 +64,7 @@ impl Miner { verifier_cache, debug_output_id: String::from("none"), stop_state, + sync_state, } } @@ -140,6 +145,10 @@ impl Miner { break; } + while self.sync_state.is_syncing() { + thread::sleep(Duration::from_secs(5)); + } + trace!("in miner loop. key_id: {:?}", key_id); // get the latest chain state and build a block on top of it diff --git a/src/bin/grin.rs b/src/bin/grin.rs index 94e4fe8bc8..7f5989350a 100644 --- a/src/bin/grin.rs +++ b/src/bin/grin.rs @@ -78,7 +78,7 @@ fn real_main() -> i32 { match args.subcommand() { ("wallet", _) => { println!(); - println!("As of v1.1.0, the wallet has been split into a seperate executable."); + println!("As of v1.1.0, the wallet has been split into a separate executable."); println!( "Please visit https://github.com/mimblewimble/grin-wallet/releases to download" );