From 4e93537e45110ea76f244cfed09f0bcd82404502 Mon Sep 17 00:00:00 2001 From: arkpar Date: Tue, 10 Oct 2017 20:30:11 +0200 Subject: [PATCH] Prevent going offline when restoring or taking snapshot --- ethcore/src/client/client.rs | 14 ++++++++------ ethcore/src/service.rs | 8 ++++++-- ethcore/src/tests/client.rs | 2 +- 3 files changed, 15 insertions(+), 9 deletions(-) diff --git a/ethcore/src/client/client.rs b/ethcore/src/client/client.rs index 06d034897..9d359aef6 100644 --- a/ethcore/src/client/client.rs +++ b/ethcore/src/client/client.rs @@ -970,9 +970,11 @@ impl Client { /// Tick the client. // TODO: manage by real events. - pub fn tick(&self) { + pub fn tick(&self, prevent_sleep: bool) { self.check_garbage(); - self.check_snooze(); + if !prevent_sleep { + self.check_snooze(); + } } fn check_garbage(&self) { @@ -1079,7 +1081,7 @@ impl Client { if !self.liveness.load(AtomicOrdering::Relaxed) { self.liveness.store(true, AtomicOrdering::Relaxed); self.notify(|n| n.start()); - trace!(target: "mode", "wake_up: Waking."); + info!(target: "mode", "wake_up: Waking."); } } @@ -1089,11 +1091,11 @@ impl Client { if self.queue_info().total_queue_size() <= MAX_QUEUE_SIZE_TO_SLEEP_ON { self.liveness.store(false, AtomicOrdering::Relaxed); self.notify(|n| n.stop()); - trace!(target: "mode", "sleep: Sleeping."); + info!(target: "mode", "sleep: Sleeping."); } else { - trace!(target: "mode", "sleep: Cannot sleep - syncing ongoing."); + info!(target: "mode", "sleep: Cannot sleep - syncing ongoing."); // TODO: Consider uncommenting. - //*self.last_activity.lock() = Some(Instant::now()); + //(*self.sleep_state.lock()).last_activity = Some(Instant::now()); } } } diff --git a/ethcore/src/service.rs b/ethcore/src/service.rs index e4c3d7519..f004d4680 100644 --- a/ethcore/src/service.rs +++ b/ethcore/src/service.rs @@ -23,7 +23,7 @@ use error::*; use client::{Client, ClientConfig, ChainNotify}; use miner::Miner; -use snapshot::ManifestData; +use snapshot::{ManifestData, RestorationStatus}; use snapshot::service::{Service as SnapshotService, ServiceParams as SnapServiceParams}; use std::sync::atomic::AtomicBool; @@ -175,7 +175,11 @@ impl IoHandler for ClientIoHandler { fn timeout(&self, _io: &IoContext, timer: TimerToken) { match timer { - CLIENT_TICK_TIMER => self.client.tick(), + CLIENT_TICK_TIMER => { + use snapshot::SnapshotService; + let snapshot_restoration = if let RestorationStatus::Ongoing{..} = self.snapshot.status() { true } else { false }; + self.client.tick(snapshot_restoration) + }, SNAPSHOT_TICK_TIMER => self.snapshot.tick(), _ => warn!("IO service triggered unregistered timer '{}'", timer), } diff --git a/ethcore/src/tests/client.rs b/ethcore/src/tests/client.rs index b94ae1fe3..2bcb0b867 100644 --- a/ethcore/src/tests/client.rs +++ b/ethcore/src/tests/client.rs @@ -190,7 +190,7 @@ fn imports_block_sequence() { #[test] fn can_collect_garbage() { let client = generate_dummy_client(100); - client.tick(); + client.tick(true); assert!(client.blockchain_cache_info().blocks < 100 * 1024); }