From 85833d228a4843438b23d332c1fba2b2558669bd Mon Sep 17 00:00:00 2001 From: arkpar Date: Tue, 15 Mar 2016 01:22:58 +0100 Subject: [PATCH 1/2] Ignore new blocks while seeking --- sync/src/chain.rs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/sync/src/chain.rs b/sync/src/chain.rs index 57f53f459..363597d40 100644 --- a/sync/src/chain.rs +++ b/sync/src/chain.rs @@ -479,6 +479,9 @@ impl ChainSync { let header_rlp = try!(block_rlp.at(0)); let h = header_rlp.as_raw().sha3(); trace!(target: "sync", "{} -> NewBlock ({})", peer_id, h); + if !self.have_common_block { + trace!(target: "sync", "NewBlock ignored while seeking"); + } let header: BlockHeader = try!(header_rlp.as_val()); let mut unknown = false; { @@ -498,9 +501,10 @@ impl ChainSync { Ok(_) => { if self.current_base_block() < header.number { self.last_imported_block = Some(header.number); + self.last_imported_hash = Some(header.hash()); self.remove_downloaded_blocks(header.number); } - trace!(target: "sync", "New block queued {:?}", h); + trace!(target: "sync", "New block queued {:?} ({})", h, header.number); }, Err(Error::Block(BlockError::UnknownParent(p))) => { unknown = true; @@ -779,7 +783,7 @@ impl ChainSync { { let headers = self.headers.range_iter().next().unwrap(); let bodies = self.bodies.range_iter().next().unwrap(); - if headers.0 != bodies.0 || headers.0 != self.current_base_block() + 1 { + if headers.0 != bodies.0 || headers.0 > self.current_base_block() + 1 { return; } From b9b0444662e651df8f30416d0f27eed5fd166fe7 Mon Sep 17 00:00:00 2001 From: arkpar Date: Tue, 15 Mar 2016 11:20:19 +0100 Subject: [PATCH 2/2] Trace sending to unconfirmed session --- util/src/network/session.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/util/src/network/session.rs b/util/src/network/session.rs index 84c063c92..2f30d7376 100644 --- a/util/src/network/session.rs +++ b/util/src/network/session.rs @@ -213,6 +213,10 @@ impl Session { /// Send a protocol packet to peer. pub fn send_packet(&mut self, protocol: &str, packet_id: u8, data: &[u8]) -> Result<(), UtilError> { + if self.info.capabilities.is_empty() || !self.had_hello { + debug!(target: "network", "Sending to unconfirmed session {}, protocol: {}, packet: {}", self.token(), protocol, packet_id); + return Err(From::from(NetworkError::BadProtocol)); + } if self.expired() { return Err(From::from(NetworkError::Expired)); }