From 925869d46251fe1ffeb8028282e67a2b44a8525a Mon Sep 17 00:00:00 2001 From: arkpar Date: Fri, 10 Jun 2016 17:12:51 +0200 Subject: [PATCH] Fix returning non-canonical headers --- sync/src/chain.rs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/sync/src/chain.rs b/sync/src/chain.rs index 569b6402d..cd8f43aee 100644 --- a/sync/src/chain.rs +++ b/sync/src/chain.rs @@ -927,7 +927,16 @@ impl ChainSync { let hash: H256 = try!(r.val_at(0)); trace!(target: "sync", "-> GetBlockHeaders (hash: {}, max: {}, skip: {}, reverse:{})", hash, max_headers, skip, reverse); match io.chain().block_header(BlockID::Hash(hash)) { - Some(hdr) => From::from(HeaderView::new(&hdr).number()), + Some(hdr) => { + let number = From::from(HeaderView::new(&hdr).number()); + if io.chain().block_hash(BlockID::Number(number)) != Some(hash) { + // Non canonical header requested, return just a single header + let mut rlp = RlpStream::new_list(1); + rlp.append_raw(&hdr, 1); + return Ok(Some((BLOCK_HEADERS_PACKET, rlp))); + } + number + } None => return Ok(Some((BLOCK_HEADERS_PACKET, RlpStream::new_list(0)))) //no such header, return nothing } } else {