diff --git a/Cargo.toml b/Cargo.toml
index ff551e69c..5804771f3 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -20,6 +20,7 @@ time = "0.1"
evmjit = { path = "rust-evmjit", optional = true }
ethash = { path = "ethash" }
num_cpus = "0.2"
+ctrlc = "1.0"
clippy = "*" # Always newest, since we use nightly
[features]
diff --git a/ethash/src/lib.rs b/ethash/src/lib.rs
index f7b6d2308..e87ee1a03 100644
--- a/ethash/src/lib.rs
+++ b/ethash/src/lib.rs
@@ -30,11 +30,13 @@ impl EthashManager {
/// `nonce` - The nonce to pack into the mix
pub fn compute_light(&self, block_number: u64, header_hash: &H256, nonce: u64) -> ProofOfWork {
let epoch = block_number / ETHASH_EPOCH_LENGTH;
- if !self.lights.read().unwrap().contains_key(&epoch) {
- let mut lights = self.lights.write().unwrap(); // obtain write lock
- if !lights.contains_key(&epoch) {
- let light = Light::new(block_number);
- lights.insert(epoch, light);
+ while !self.lights.read().unwrap().contains_key(&epoch) {
+ if let Ok(mut lights) = self.lights.try_write()
+ {
+ if !lights.contains_key(&epoch) {
+ let light = Light::new(block_number);
+ lights.insert(epoch, light);
+ }
}
}
self.lights.read().unwrap().get(&epoch).unwrap().compute(header_hash, nonce)
diff --git a/src/bin/client/main.rs b/src/bin/client/main.rs
index 3335d8a72..638ac8216 100644
--- a/src/bin/client/main.rs
+++ b/src/bin/client/main.rs
@@ -3,17 +3,18 @@ extern crate ethcore;
extern crate rustc_serialize;
extern crate log;
extern crate env_logger;
+extern crate ctrlc;
-use std::io::stdin;
use std::env;
use log::{LogLevelFilter};
use env_logger::LogBuilder;
+use ctrlc::CtrlC;
use util::*;
use ethcore::client::*;
-use ethcore::service::ClientService;
+use ethcore::service::{ClientService, NetSyncMessage};
use ethcore::ethereum;
use ethcore::blockchain::CacheSize;
-use ethcore::sync::*;
+use ethcore::sync::EthSync;
fn setup_log() {
let mut builder = LogBuilder::new();
@@ -30,41 +31,56 @@ fn main() {
setup_log();
let spec = ethereum::new_frontier();
let mut service = ClientService::start(spec).unwrap();
- let io_handler = Box::new(ClientIoHandler { client: service.client(), timer: 0, info: Default::default() });
+ let io_handler = Arc::new(ClientIoHandler { client: service.client(), info: Default::default(), sync: service.sync() });
service.io().register_handler(io_handler).expect("Error registering IO handler");
- loop {
- let mut cmd = String::new();
- stdin().read_line(&mut cmd).unwrap();
- if cmd == "quit\n" || cmd == "exit\n" || cmd == "q\n" {
- break;
+
+ let exit = Arc::new(Condvar::new());
+ let e = exit.clone();
+ CtrlC::set_handler(move || { e.notify_all(); });
+ let mutex = Mutex::new(());
+ let _ = exit.wait(mutex.lock().unwrap()).unwrap();
+}
+
+struct Informant {
+ chain_info: RwLock