Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 3 commits into from
Jul 25, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 3 additions & 11 deletions servers/src/grin/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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<ServerStats, Error> {
let stratum_stats = self.state_info.stratum_stats.read().clone();

Expand Down
12 changes: 10 additions & 2 deletions servers/src/mining/test_miner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,22 +22,24 @@ use chrono::prelude::Utc;
use std::sync::Arc;

use crate::chain;
use crate::common::types::StratumServerConfig;
use crate::common::types::{StratumServerConfig, SyncState};
use crate::core::core::hash::{Hash, Hashed};
use crate::core::core::verifier_cache::VerifierCache;
use crate::core::core::{Block, BlockHeader};
use crate::core::global;
use crate::mining::mine_block;
use crate::pool;
use crate::util::StopState;
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 +54,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 +63,7 @@ impl Miner {
verifier_cache,
debug_output_id: String::from("none"),
stop_state,
sync_state,
}
}

Expand Down Expand Up @@ -140,6 +144,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 @@ -77,7 +77,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