From 3fa1776ecf43cb639c5ce688e85a5de1dc17c0f1 Mon Sep 17 00:00:00 2001 From: arkpar Date: Fri, 4 Mar 2016 19:11:44 +0100 Subject: [PATCH] Fixed sync stalling on a new block arriving while body request is pending --- sync/src/chain.rs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/sync/src/chain.rs b/sync/src/chain.rs index fd690e790..0b985f217 100644 --- a/sync/src/chain.rs +++ b/sync/src/chain.rs @@ -475,7 +475,7 @@ impl ChainSync { peer.latest_number = Some(header.number()); } // TODO: Decompose block and add to self.headers and self.bodies instead - if header.number == From::from(self.current_base_block() + 1) { + if header.number <= From::from(self.current_base_block() + 1) { match io.chain().import_block(block_rlp.as_raw().to_vec()) { Err(Error::Import(ImportError::AlreadyInChain)) => { trace!(target: "sync", "New block already in chain {:?}", h); @@ -484,7 +484,10 @@ impl ChainSync { trace!(target: "sync", "New block already queued {:?}", h); }, Ok(_) => { - self.last_imported_block = Some(header.number); + if self.current_base_block() < header.number { + self.last_imported_block = Some(header.number); + self.remove_downloaded_blocks(header.number); + } trace!(target: "sync", "New block queued {:?}", h); }, Err(Error::Block(BlockError::UnknownParent(p))) => {