Merge branch 'master' into remerge-264

Conflicts:
	sync/src/chain.rs
This commit is contained in:
Nikolay Volf 2016-02-04 04:35:38 +03:00
commit d7aa315309
3 changed files with 12 additions and 2 deletions

View File

@ -79,6 +79,8 @@ struct Verification {
bad: HashSet<H256>, bad: HashSet<H256>,
} }
const MAX_UNVERIFIED_QUEUE_SIZE: usize = 50000;
impl BlockQueue { impl BlockQueue {
/// Creates a new queue instance. /// Creates a new queue instance.
pub fn new(engine: Arc<Box<Engine>>, message_channel: IoChannel<NetSyncMessage>) -> BlockQueue { pub fn new(engine: Arc<Box<Engine>>, message_channel: IoChannel<NetSyncMessage>) -> BlockQueue {
@ -290,7 +292,7 @@ impl BlockQueue {
pub fn queue_info(&self) -> BlockQueueInfo { pub fn queue_info(&self) -> BlockQueueInfo {
let verification = self.verification.lock().unwrap(); let verification = self.verification.lock().unwrap();
BlockQueueInfo { BlockQueueInfo {
full: false, full: verification.unverified.len() + verification.verifying.len() + verification.verified.len() >= MAX_UNVERIFIED_QUEUE_SIZE,
verified_queue_size: verification.verified.len(), verified_queue_size: verification.verified.len(),
unverified_queue_size: verification.unverified.len(), unverified_queue_size: verification.unverified.len(),
verifying_queue_size: verification.verifying.len(), verifying_queue_size: verification.verifying.len(),

View File

@ -379,7 +379,7 @@ impl ChainSync {
trace!(target: "sync", "Ignored unexpected block bodies"); trace!(target: "sync", "Ignored unexpected block bodies");
return Ok(()); return Ok(());
} }
if self.state == SyncState::Waiting { if self.state == SyncState::Waiting {
trace!(target: "sync", "Ignored block bodies while waiting"); trace!(target: "sync", "Ignored block bodies while waiting");
return Ok(()); 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);
}
}
} }

View File

@ -107,6 +107,7 @@ impl NetworkProtocolHandler<SyncMessage> for EthSync {
fn timeout(&self, io: &NetworkContext<SyncMessage>, _timer: TimerToken) { 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_peers(&mut NetSyncIo::new(io, self.chain.deref()));
self.sync.write().unwrap().maintain_sync(&mut NetSyncIo::new(io, self.chain.deref()));
} }
} }