Skip to content

Commit

Permalink
fix: move sync state check from server into test_miner (#2958)
Browse files Browse the repository at this point in the history
* fix: move sync state check from server into test_miner

* fix: compile error from SyncState moving to grin_chain
  • Loading branch information
Joseph Goulden authored and antiochp committed Jul 25, 2019
1 parent 441e846 commit ecd16d1
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 13 deletions.
14 changes: 3 additions & 11 deletions servers/src/grin/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -388,19 +388,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
Expand All @@ -421,8 +414,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<ServerStats, Error> {
let stratum_stats = self.state_info.stratum_stats.read().clone();

Expand Down
11 changes: 10 additions & 1 deletion servers/src/mining/test_miner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,17 @@ 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,
chain: Arc<chain::Chain>,
tx_pool: Arc<RwLock<pool::TransactionPool>>,
verifier_cache: Arc<RwLock<dyn VerifierCache>>,
stop_state: Arc<StopState>,

sync_state: Arc<SyncState>,
// Just to hold the port we're on, so this miner can be identified
// while watching debug output
debug_output_id: String,
Expand All @@ -52,6 +55,7 @@ impl Miner {
tx_pool: Arc<RwLock<pool::TransactionPool>>,
verifier_cache: Arc<RwLock<dyn VerifierCache>>,
stop_state: Arc<StopState>,
sync_state: Arc<SyncState>,
) -> Miner {
Miner {
config,
Expand All @@ -60,6 +64,7 @@ impl Miner {
verifier_cache,
debug_output_id: String::from("none"),
stop_state,
sync_state,
}
}

Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/bin/grin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,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"
);
Expand Down

0 comments on commit ecd16d1

Please sign in to comment.