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

Commit

Permalink
Reject headers with no gaps when ChainHead
Browse files Browse the repository at this point in the history
  • Loading branch information
ascjones committed Sep 11, 2018
1 parent 56747ef commit 0eb8655
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions ethcore/sync/src/block_sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -282,11 +282,21 @@ impl BlockDownloader {
match self.state {
State::ChainHead => {
if !headers.is_empty() {
// TODO: validate heads better. E.g. check that there is enough distance between blocks.
trace!(target: "sync", "Received {} subchain heads, proceeding to download", headers.len());
self.blocks.reset_to(hashes);
self.state = State::Blocks;
return Ok(DownloadAction::Reset);
let mut is_subchain_heads = headers.len() == 1;
if headers.len() > 1 {
let n0 = BlockNumber::from(headers[0].header.number());
let n1 = BlockNumber::from(headers[1].header.number());
is_subchain_heads = n1 - n0 > 1
}

if is_subchain_heads {
trace!(target: "sync", "Received {} subchain heads, proceeding to download", headers.len());
self.blocks.reset_to(hashes);
self.state = State::Blocks;
return Ok(DownloadAction::Reset);
} else {
debug!(target: "sync", "Ignoring consecutive headers. Expected subchains with gap.");
}
} else {
let best = io.chain().chain_info().best_block_number;
let oldest_reorg = io.chain().pruning_info().earliest_state;
Expand Down

0 comments on commit 0eb8655

Please sign in to comment.