Skip to content
This repository was archived by the owner on Nov 6, 2020. It is now read-only.

Commit 0eb8655

Browse files
committed
Reject headers with no gaps when ChainHead
1 parent 56747ef commit 0eb8655

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

ethcore/sync/src/block_sync.rs

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -282,11 +282,21 @@ impl BlockDownloader {
282282
match self.state {
283283
State::ChainHead => {
284284
if !headers.is_empty() {
285-
// TODO: validate heads better. E.g. check that there is enough distance between blocks.
286-
trace!(target: "sync", "Received {} subchain heads, proceeding to download", headers.len());
287-
self.blocks.reset_to(hashes);
288-
self.state = State::Blocks;
289-
return Ok(DownloadAction::Reset);
285+
let mut is_subchain_heads = headers.len() == 1;
286+
if headers.len() > 1 {
287+
let n0 = BlockNumber::from(headers[0].header.number());
288+
let n1 = BlockNumber::from(headers[1].header.number());
289+
is_subchain_heads = n1 - n0 > 1
290+
}
291+
292+
if is_subchain_heads {
293+
trace!(target: "sync", "Received {} subchain heads, proceeding to download", headers.len());
294+
self.blocks.reset_to(hashes);
295+
self.state = State::Blocks;
296+
return Ok(DownloadAction::Reset);
297+
} else {
298+
debug!(target: "sync", "Ignoring consecutive headers. Expected subchains with gap.");
299+
}
290300
} else {
291301
let best = io.chain().chain_info().best_block_number;
292302
let oldest_reorg = io.chain().pruning_info().earliest_state;

0 commit comments

Comments
 (0)