diff --git a/Cargo.lock b/Cargo.lock index f86b37a14..8000617df 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1393,6 +1393,7 @@ dependencies = [ "ethcore-ipc 1.5.0", "ethcore-ipc-codegen 1.5.0", "ethcore-util 1.5.0", + "ethsync 1.5.0", "ipc-common-types 1.5.0", "log 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", "parity-hash-fetch 1.5.0", diff --git a/updater/Cargo.toml b/updater/Cargo.toml index b97e057d7..e166b4c65 100644 --- a/updater/Cargo.toml +++ b/updater/Cargo.toml @@ -13,6 +13,7 @@ ethcore-ipc-codegen = { path = "../ipc/codegen" } log = "0.3" ethabi = "0.2.2" ethcore = { path = "../ethcore" } +ethsync = { path = "../sync" } ethcore-util = { path = "../util" } parity-hash-fetch = { path = "../hash-fetch" } ipc-common-types = { path = "../ipc-common-types" } diff --git a/updater/src/lib.rs b/updater/src/lib.rs index 1567a88a0..92992deb2 100644 --- a/updater/src/lib.rs +++ b/updater/src/lib.rs @@ -22,6 +22,7 @@ extern crate ipc_common_types; extern crate parity_hash_fetch as hash_fetch; extern crate ethcore; extern crate ethabi; +extern crate ethsync; extern crate ethcore_ipc as ipc; mod updater; diff --git a/updater/src/updater.rs b/updater/src/updater.rs index c5697c623..a82748c84 100644 --- a/updater/src/updater.rs +++ b/updater/src/updater.rs @@ -21,11 +21,13 @@ use std::path::{PathBuf}; use util::misc::platform; use ipc_common_types::{VersionInfo, ReleaseTrack}; use util::{Address, H160, H256, FixedHash, Mutex, Bytes}; +use ethsync::{SyncProvider}; use ethcore::client::{BlockId, BlockChainClient, ChainNotify}; use hash_fetch::{self as fetch, HashFetch}; use operations::Operations; use service::{Service}; use types::all::{ReleaseInfo, OperationsInfo, CapState}; +use ethcore_rpc::is_major_importing; /// Filter for releases. #[derive(Debug, Eq, PartialEq, Clone)] @@ -82,6 +84,7 @@ pub struct Updater { update_policy: UpdatePolicy, weak_self: Mutex>, client: Weak, + sync: Weak, fetcher: Mutex>, operations: Mutex>, exit_handler: Mutex>>, @@ -96,11 +99,12 @@ pub struct Updater { const CLIENT_ID: &'static str = "parity"; impl Updater { - pub fn new(client: Weak, update_policy: UpdatePolicy) -> Arc { + pub fn new(client: Weak, sync: Arc, update_policy: UpdatePolicy) -> Arc { let r = Arc::new(Updater { update_policy: update_policy, weak_self: Mutex::new(Default::default()), client: client.clone(), + sync: sync.clone(), fetcher: Mutex::new(None), operations: Mutex::new(None), exit_handler: Mutex::new(None), @@ -290,10 +294,10 @@ impl Updater { impl ChainNotify for Updater { fn new_blocks(&self, _imported: Vec, _invalid: Vec, _enacted: Vec, _retracted: Vec, _sealed: Vec, _proposed: Vec, _duration: u64) { - // TODO: something like this -// if !self.client.upgrade().map_or(true, |c| c.is_major_syncing()) { - self.poll(); -// } + match (self.client.upgrade(), self.sync.upgrade()) { + (Some(c), Some(s)) if is_major_importing(s.status().state, c.queue_info()) => self.poll(), + _ => {}, + } } }