Merge pull request #338 from ethcore/sync-fix-temp

sync queue limit hotfix
This commit is contained in:
Arkadiy Paronyan 2016-02-04 02:30:27 +01:00
commit f904dc109a
3 changed files with 10 additions and 3 deletions

View File

@ -79,6 +79,8 @@ struct Verification {
bad: HashSet<H256>,
}
const MAX_UNVERIFIED_QUEUE_SIZE: usize = 50000;
impl BlockQueue {
/// Creates a new queue instance.
pub fn new(engine: Arc<Box<Engine>>, message_channel: IoChannel<NetSyncMessage>) -> 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(),

View File

@ -376,7 +376,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(());
}
@ -995,7 +995,11 @@ impl ChainSync {
}
/// Maintain other peers. Send out any new blocks and transactions
pub fn _maintain_sync(&mut self, _io: &mut SyncIo) {
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);
}
}
}

View File

@ -107,6 +107,7 @@ impl NetworkProtocolHandler<SyncMessage> for EthSync {
fn timeout(&self, io: &NetworkContext<SyncMessage>, _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()));
}
}