Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
check if block is known before re-importing
  • Loading branch information
rphmeier committed May 14, 2018
commit 6ff00e5d95aba4639bf9976dc9bb5f3951c98edd
1 change: 0 additions & 1 deletion substrate/client/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,6 @@ impl<B, E> Client<B, E> where
body: Option<block::Body>,
) -> error::Result<ImportResult> {
// TODO: import lock
// TODO: validate block
// TODO: import justification.
let (header, justification) = header.into_inner();
match self.backend.blockchain().status(BlockId::Hash(header.parent_hash))? {
Expand Down
12 changes: 12 additions & 0 deletions substrate/network/src/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,18 @@ impl ChainSync {
let hash = header_hash(&header);
let parent = header.parent_hash;
let is_best = best_seen.as_ref().map_or(false, |n| number >= *n);

// check whether the block is known before importing.
match protocol.chain().block_status(&BlockId::Hash(hash)) {
Ok(BlockStatus::InChain) => continue,
Ok(_) => {},
Err(e) => {
debug!(target: "sync", "Error importing block {}: {:?}: {:?}", number, hash, e);
self.restart(io, protocol);
return;
}
}

let result = protocol.chain().import(
is_best,
header,
Expand Down