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

check if block is known before importing #161

Merged
merged 1 commit into from
May 15, 2018
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
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