From f0ef5e6943f90765a07a810263d79f37ebe3946a Mon Sep 17 00:00:00 2001 From: Robert Habermeier Date: Mon, 5 Sep 2016 14:25:56 +0200 Subject: [PATCH] keep snapshot watcher alive --- ethcore/src/snapshot/service.rs | 7 +++++++ ethcore/src/snapshot/watcher.rs | 4 ++++ parity/run.rs | 16 ++++++++++++++++ 3 files changed, 27 insertions(+) diff --git a/ethcore/src/snapshot/service.rs b/ethcore/src/snapshot/service.rs index 449ced23f..ea5ec1a0a 100644 --- a/ethcore/src/snapshot/service.rs +++ b/ethcore/src/snapshot/service.rs @@ -275,6 +275,13 @@ impl Service { } } + // delete the temporary snapshot dir if it does exist. + if let Err(e) = fs::remove_dir_all(service.temp_snapshot_dir()) { + if e.kind() != ErrorKind { + return Err(e.into()) + } + } + Ok(service) } diff --git a/ethcore/src/snapshot/watcher.rs b/ethcore/src/snapshot/watcher.rs index 5bf157312..5a0c3eafc 100644 --- a/ethcore/src/snapshot/watcher.rs +++ b/ethcore/src/snapshot/watcher.rs @@ -49,6 +49,8 @@ impl Broadcast for IoChannel { None => return, }; + trace!(target: "snapshot_watcher", "broadcast: {}", num); + if let Err(e) = self.send(ClientIoMessage::TakeSnapshot(num)) { warn!("Snapshot watcher disconnected from IoService: {}", e); } @@ -88,6 +90,8 @@ impl ChainNotify for Watcher { _: Vec, _duration: u64) { + trace!(target: "snapshot_watcher", "{} imported", imported.len()); + let highest = imported.into_iter() .filter_map(|h| self.oracle.to_number(h)) .filter(|&num| num >= self.period + self.history) diff --git a/parity/run.rs b/parity/run.rs index d384a3a7c..618a9f0db 100644 --- a/parity/run.rs +++ b/parity/run.rs @@ -257,6 +257,22 @@ pub fn execute(cmd: RunCmd) -> Result<(), String> { }); service.register_io_handler(io_handler).expect("Error registering IO handler"); + // the watcher must be kept alive. + let _watcher = match cmd.no_periodic_snapshot { + true => None, + false => { + let watcher = Arc::new(snapshot::Watcher::new( + service.client(), + service.io().channel(), + SNAPSHOT_PERIOD, + SNAPSHOT_HISTORY, + )); + + service.add_notify(watcher.clone()); + Some(watcher) + }, + }; + if !cmd.no_periodic_snapshot { let watcher = snapshot::Watcher::new( service.client(),