diff --git a/ethcore/src/block_queue.rs b/ethcore/src/block_queue.rs index 1fe31ba19..e14f2a06a 100644 --- a/ethcore/src/block_queue.rs +++ b/ethcore/src/block_queue.rs @@ -79,6 +79,8 @@ struct Verification { bad: HashSet, } +const MAX_UNVERIFIED_QUEUE_SIZE: usize = 50000; + impl BlockQueue { /// Creates a new queue instance. pub fn new(engine: Arc>, message_channel: IoChannel) -> BlockQueue { @@ -290,7 +292,7 @@ impl BlockQueue { pub fn queue_info(&self) -> BlockQueueInfo { let verification = self.verification.lock().unwrap(); BlockQueueInfo { - full: false, + 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(), diff --git a/sync/src/chain.rs b/sync/src/chain.rs index e351ad837..301bf80a8 100644 --- a/sync/src/chain.rs +++ b/sync/src/chain.rs @@ -379,7 +379,7 @@ impl ChainSync { trace!(target: "sync", "Ignored unexpected block bodies"); return Ok(()); } - if self.state == SyncState::Waiting { + if self.state == SyncState::Waiting { trace!(target: "sync", "Ignored block bodies while waiting"); return Ok(()); } @@ -1005,4 +1005,11 @@ impl ChainSync { } } } + /// Maintain other peers. Send out any new blocks and transactions + pub fn maintain_sync(&mut self, io: &mut SyncIo) { + if !io.chain().queue_info().full && self.state == SyncState::Waiting { + self.state = SyncState::Idle; + self.continue_sync(io); + } + } } diff --git a/sync/src/lib.rs b/sync/src/lib.rs index 40b67dc5b..f3b43396c 100644 --- a/sync/src/lib.rs +++ b/sync/src/lib.rs @@ -107,6 +107,7 @@ impl NetworkProtocolHandler for EthSync { fn timeout(&self, io: &NetworkContext, _timer: TimerToken) { self.sync.write().unwrap().maintain_peers(&mut NetSyncIo::new(io, self.chain.deref())); + self.sync.write().unwrap().maintain_sync(&mut NetSyncIo::new(io, self.chain.deref())); } }