Fix returning non-canonical headers

This commit is contained in:
arkpar 2016-06-10 17:12:51 +02:00
parent bee3669e9b
commit 925869d462

View File

@ -927,7 +927,16 @@ impl ChainSync {
let hash: H256 = try!(r.val_at(0)); let hash: H256 = try!(r.val_at(0));
trace!(target: "sync", "-> GetBlockHeaders (hash: {}, max: {}, skip: {}, reverse:{})", hash, max_headers, skip, reverse); trace!(target: "sync", "-> GetBlockHeaders (hash: {}, max: {}, skip: {}, reverse:{})", hash, max_headers, skip, reverse);
match io.chain().block_header(BlockID::Hash(hash)) { 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 None => return Ok(Some((BLOCK_HEADERS_PACKET, RlpStream::new_list(0)))) //no such header, return nothing
} }
} else { } else {