From b5f0a412657276b2dba90fa17c5a436925772f5f Mon Sep 17 00:00:00 2001 From: arkpar Date: Fri, 22 Jan 2016 15:58:52 +0100 Subject: [PATCH] Fixed tests and tweaked sync progress report --- src/bin/client/main.rs | 5 +++-- src/block_queue.rs | 10 +++++++--- src/sync/mod.rs | 2 +- src/sync/tests.rs | 6 ++++-- 4 files changed, 15 insertions(+), 8 deletions(-) diff --git a/src/bin/client/main.rs b/src/bin/client/main.rs index 638ac8216..5c79b7755 100644 --- a/src/bin/client/main.rs +++ b/src/bin/client/main.rs @@ -69,7 +69,7 @@ impl Informant { let sync_info = sync.status(); if let (_, &Some(ref last_cache_info), &Some(ref last_report)) = (self.chain_info.read().unwrap().deref(), self.cache_info.read().unwrap().deref(), self.report.read().unwrap().deref()) { - println!("[ {} {} ]---[ {} blk/s | {} tx/s | {} gas/s //··· {}/{} peers, {} downloaded, {} queued ···// {} ({}) bl {} ({}) ex ]", + println!("[ {} {} ]---[ {} blk/s | {} tx/s | {} gas/s //··· {}/{} peers, {} downloaded, {}+{} queued ···// {} ({}) bl {} ({}) ex ]", chain_info.best_block_number, chain_info.best_block_hash, (report.blocks_imported - last_report.blocks_imported) / dur, @@ -79,7 +79,8 @@ impl Informant { sync_info.num_active_peers, sync_info.num_peers, sync_info.blocks_received, - queue_info.queue_size, + queue_info.unverified_queue_size, + queue_info.verified_queue_size, cache_info.blocks, cache_info.blocks as isize - last_cache_info.blocks as isize, diff --git a/src/block_queue.rs b/src/block_queue.rs index c2cbb35b6..239c559c5 100644 --- a/src/block_queue.rs +++ b/src/block_queue.rs @@ -15,8 +15,10 @@ use service::*; pub struct BlockQueueInfo { /// Indicates that queue is full pub full: bool, - /// Number of queued blocks - pub queue_size: usize, + /// Number of queued blocks pending verification + pub unverified_queue_size: usize, + /// Number of verified queued blocks pending import + pub verified_queue_size: usize, } /// A queue of blocks. Sits between network or other I/O and the BlockChain. @@ -235,9 +237,11 @@ impl BlockQueue { /// Get queue status. pub fn queue_info(&self) -> BlockQueueInfo { + let verification = self.verification.lock().unwrap(); BlockQueueInfo { full: false, - queue_size: self.verification.lock().unwrap().unverified.len(), + verified_queue_size: verification.verified.len(), + unverified_queue_size: verification.unverified.len(), } } } diff --git a/src/sync/mod.rs b/src/sync/mod.rs index 078100084..78a5d7613 100644 --- a/src/sync/mod.rs +++ b/src/sync/mod.rs @@ -17,7 +17,7 @@ /// fn main() { /// let mut service = NetworkService::start().unwrap(); /// let dir = env::temp_dir(); -/// let client = Arc::new(Client::new(ethereum::new_frontier(), &dir).unwrap()); +/// let client = Client::new(ethereum::new_frontier(), &dir, service.io().channel()).unwrap(); /// EthSync::register(&mut service, client); /// } /// ``` diff --git a/src/sync/tests.rs b/src/sync/tests.rs index 24b012b5b..7f8a1748b 100644 --- a/src/sync/tests.rs +++ b/src/sync/tests.rs @@ -131,7 +131,8 @@ impl BlockChainClient for TestBlockChainClient { } } } - if number == self.numbers.read().unwrap().len() { + let len = self.numbers.read().unwrap().len(); + if number == len { *self.difficulty.write().unwrap().deref_mut() += header.difficulty; mem::replace(self.last_hash.write().unwrap().deref_mut(), header.hash()); self.blocks.write().unwrap().insert(header.hash(), b); @@ -155,7 +156,8 @@ impl BlockChainClient for TestBlockChainClient { fn queue_info(&self) -> BlockQueueInfo { BlockQueueInfo { full: false, - queue_size: 0, + verified_queue_size: 0, + unverified_queue_size: 0, } }