mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-12 14:41:11 +00:00
check if block is known before re-importing (#161)
This commit is contained in:
committed by
Gav Wood
parent
8bfded8d72
commit
413ebf3f19
@@ -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))? {
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user