From fd4361e284caa1ea846d4a29de1d575d7fca3d5a Mon Sep 17 00:00:00 2001 From: Robert Habermeier Date: Sun, 11 Sep 2016 14:04:56 +0200 Subject: [PATCH] import: keep informant going until finished (#2065) --- parity/blockchain.rs | 10 +++++++--- parity/io_handler.rs | 16 ++++++++++++++++ 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/parity/blockchain.rs b/parity/blockchain.rs index ccdf61130..1c22a9844 100644 --- a/parity/blockchain.rs +++ b/parity/blockchain.rs @@ -31,6 +31,7 @@ use ethcore::error::ImportError; use ethcore::miner::Miner; use cache::CacheConfig; use informant::Informant; +use io_handler::ImportIoHandler; use params::{SpecType, Pruning}; use helpers::{to_client_config, execute_upgrades}; use dir::Directories; @@ -170,6 +171,10 @@ fn execute_import(cmd: ImportBlockchain) -> Result { let informant = Informant::new(client.clone(), None, None, cmd.logger_config.color); + try!(service.register_io_handler(Arc::new(ImportIoHandler { + info: Arc::new(informant), + })).map_err(|_| "Unable to register informant handler".to_owned())); + let do_import = |bytes| { while client.queue_info().is_full() { sleep(Duration::from_secs(1)); } match client.import_block(bytes) { @@ -181,7 +186,6 @@ fn execute_import(cmd: ImportBlockchain) -> Result { }, Ok(_) => {}, } - informant.tick(); Ok(()) }; @@ -266,10 +270,10 @@ fn execute_export(cmd: ExportBlockchain) -> Result { }; let from = try!(client.block_number(cmd.from_block).ok_or("From block could not be found")); - let to = try!(client.block_number(cmd.to_block).ok_or("From block could not be found")); + let to = try!(client.block_number(cmd.to_block).ok_or("To block could not be found")); for i in from..(to + 1) { - let b = client.block(BlockID::Number(i)).unwrap(); + let b = try!(client.block(BlockID::Number(i)).ok_or("Error exporting incomplete chain")); match format { DataFormat::Binary => { out.write(&b).expect("Couldn't write to stream."); } DataFormat::Hex => { out.write_fmt(format_args!("{}", b.pretty())).expect("Couldn't write to stream."); } diff --git a/parity/io_handler.rs b/parity/io_handler.rs index 8386c2d1b..bf73f55bb 100644 --- a/parity/io_handler.rs +++ b/parity/io_handler.rs @@ -46,3 +46,19 @@ impl IoHandler for ClientIoHandler { } } } + +pub struct ImportIoHandler { + pub info: Arc, +} + +impl IoHandler for ImportIoHandler { + fn initialize(&self, io: &IoContext) { + io.register_timer(INFO_TIMER, 5000).expect("Error registering timer"); + } + + fn timeout(&self, _io: &IoContext, timer: TimerToken) { + if let INFO_TIMER = timer { + self.info.tick() + } + } +} \ No newline at end of file