fix: move sync state check from server into test_miner (#2958)

* fix: move sync state check from server into test_miner

* fix: compile error from SyncState moving to grin_chain
This commit is contained in:
Joseph Goulden 2019-07-25 10:07:56 +01:00 committed by Antioch Peverell
parent 441e846af6
commit ecd16d114f
3 changed files with 14 additions and 13 deletions

View file

@ -388,19 +388,12 @@ impl Server {
self.tx_pool.clone(), self.tx_pool.clone(),
self.verifier_cache.clone(), self.verifier_cache.clone(),
stop_state, stop_state,
sync_state,
); );
miner.set_debug_output_id(format!("Port {}", self.config.p2p_config.port)); miner.set_debug_output_id(format!("Port {}", self.config.p2p_config.port));
let _ = thread::Builder::new() let _ = thread::Builder::new()
.name("test_miner".to_string()) .name("test_miner".to_string())
.spawn(move || { .spawn(move || miner.run_loop(wallet_listener_url));
// 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);
});
} }
/// The chain head /// The chain head
@ -421,8 +414,7 @@ impl Server {
/// Returns a set of stats about this server. This and the ServerStats /// Returns a set of stats about this server. This and the ServerStats
/// structure /// structure
/// can be updated over time to include any information needed by tests or /// can be updated over time to include any information needed by tests or
/// other /// other consumers
/// consumers
pub fn get_server_stats(&self) -> Result<ServerStats, Error> { pub fn get_server_stats(&self) -> Result<ServerStats, Error> {
let stratum_stats = self.state_info.stratum_stats.read().clone(); let stratum_stats = self.state_info.stratum_stats.read().clone();

View file

@ -30,6 +30,9 @@ use crate::core::global;
use crate::mining::mine_block; use crate::mining::mine_block;
use crate::pool; use crate::pool;
use crate::util::StopState; use crate::util::StopState;
use grin_chain::SyncState;
use std::thread;
use std::time::Duration;
pub struct Miner { pub struct Miner {
config: StratumServerConfig, config: StratumServerConfig,
@ -37,7 +40,7 @@ pub struct Miner {
tx_pool: Arc<RwLock<pool::TransactionPool>>, tx_pool: Arc<RwLock<pool::TransactionPool>>,
verifier_cache: Arc<RwLock<dyn VerifierCache>>, verifier_cache: Arc<RwLock<dyn VerifierCache>>,
stop_state: Arc<StopState>, stop_state: Arc<StopState>,
sync_state: Arc<SyncState>,
// Just to hold the port we're on, so this miner can be identified // Just to hold the port we're on, so this miner can be identified
// while watching debug output // while watching debug output
debug_output_id: String, debug_output_id: String,
@ -52,6 +55,7 @@ impl Miner {
tx_pool: Arc<RwLock<pool::TransactionPool>>, tx_pool: Arc<RwLock<pool::TransactionPool>>,
verifier_cache: Arc<RwLock<dyn VerifierCache>>, verifier_cache: Arc<RwLock<dyn VerifierCache>>,
stop_state: Arc<StopState>, stop_state: Arc<StopState>,
sync_state: Arc<SyncState>,
) -> Miner { ) -> Miner {
Miner { Miner {
config, config,
@ -60,6 +64,7 @@ impl Miner {
verifier_cache, verifier_cache,
debug_output_id: String::from("none"), debug_output_id: String::from("none"),
stop_state, stop_state,
sync_state,
} }
} }
@ -140,6 +145,10 @@ impl Miner {
break; break;
} }
while self.sync_state.is_syncing() {
thread::sleep(Duration::from_secs(5));
}
trace!("in miner loop. key_id: {:?}", key_id); trace!("in miner loop. key_id: {:?}", key_id);
// get the latest chain state and build a block on top of it // get the latest chain state and build a block on top of it

View file

@ -80,7 +80,7 @@ fn real_main() -> i32 {
match args.subcommand() { match args.subcommand() {
("wallet", _) => { ("wallet", _) => {
println!(); 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!( println!(
"Please visit https://github.com/mimblewimble/grin-wallet/releases to download" "Please visit https://github.com/mimblewimble/grin-wallet/releases to download"
); );