From 3dd220b62fe1b43614de0e9c6820d53ed4ee6a4b Mon Sep 17 00:00:00 2001 From: Nikolay Volf Date: Mon, 8 Feb 2016 03:14:48 -0800 Subject: [PATCH] refactoring of report functions, some comments --- ethcore/src/block_queue.rs | 16 ++++++++++------ ethcore/src/client.rs | 2 +- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/ethcore/src/block_queue.rs b/ethcore/src/block_queue.rs index e4569a21b..ed3201ee2 100644 --- a/ethcore/src/block_queue.rs +++ b/ethcore/src/block_queue.rs @@ -30,16 +30,12 @@ use client::BlockStatus; /// Block queue status #[derive(Debug)] pub struct BlockQueueInfo { - /// Indicates that queue is full - pub full: bool, /// Number of queued blocks pending verification pub unverified_queue_size: usize, /// Number of verified queued blocks pending import pub verified_queue_size: usize, /// Number of blocks being verified pub verifying_queue_size: usize, - /// Indicates queue is empty - pub empty: bool } impl BlockQueueInfo { @@ -48,6 +44,16 @@ impl BlockQueueInfo { /// The size of the unverified and verifying queues. pub fn incomplete_queue_size(&self) -> usize { self.unverified_queue_size + self.verifying_queue_size } + + /// Indicates that queue is full + pub fn is_full(&self) -> bool { + self.unverified_queue_size + self.verified_queue_size + self.verifying_queue_size > MAX_UNVERIFIED_QUEUE_SIZE + } + + /// Indicates that queue is empty + pub fn is_empty(&self) -> bool { + self.unverified_queue_size + self.verified_queue_size + self.verifying_queue_size == 0 + } } /// A queue of blocks. Sits between network or other I/O and the BlockChain. @@ -311,11 +317,9 @@ impl BlockQueue { pub fn queue_info(&self) -> BlockQueueInfo { let verification = self.verification.lock().unwrap(); BlockQueueInfo { - full: verification.unverified.len() + verification.verifying.len() + verification.verified.len() >= MAX_UNVERIFIED_QUEUE_SIZE, verified_queue_size: verification.verified.len(), unverified_queue_size: verification.unverified.len(), verifying_queue_size: verification.verifying.len(), - empty: verification.verified.is_empty() && verification.unverified.is_empty() && verification.verifying.is_empty(), } } } diff --git a/ethcore/src/client.rs b/ethcore/src/client.rs index 3b5627504..cf43395e7 100644 --- a/ethcore/src/client.rs +++ b/ethcore/src/client.rs @@ -296,7 +296,7 @@ impl Client { trace!(target: "client", "Imported #{} ({})", header.number(), header.hash()); ret += 1; - if self.block_queue.read().unwrap().queue_info().empty { + if self.block_queue.read().unwrap().queue_info().is_empty() { io.send(NetworkIoMessage::User(SyncMessage::BlockVerified)).unwrap(); } }