Check for block parent before verification. (#1714)

* Treat verification errors more seriously

* Track obsolete requests

* Check block parent before verification

* Style
This commit is contained in:
Arkadiy Paronyan
2019-02-07 11:58:27 +01:00
committed by GitHub
parent fb0f4dfb03
commit 1dc15be5bd
8 changed files with 117 additions and 135 deletions
+21
View File
@@ -1302,6 +1302,27 @@ impl<B, E, Block, RA> consensus::BlockImport<Block> for Client<B, E, Block, RA>
self.apply_block(operation, import_block, new_authorities)
}).map_err(|e| ConsensusErrorKind::ClientImport(e.to_string()).into())
}
/// Check block preconditions.
fn check_block(
&self,
hash: Block::Hash,
parent_hash: Block::Hash,
) -> Result<ImportResult, Self::Error> {
match self.backend.blockchain().status(BlockId::Hash(parent_hash))
.map_err(|e| ConsensusError::from(ConsensusErrorKind::ClientImport(e.to_string())))?
{
blockchain::BlockStatus::InChain => {},
blockchain::BlockStatus::Unknown => return Ok(ImportResult::UnknownParent),
}
match self.backend.blockchain().status(BlockId::Hash(hash))
.map_err(|e| ConsensusError::from(ConsensusErrorKind::ClientImport(e.to_string())))?
{
blockchain::BlockStatus::InChain => return Ok(ImportResult::AlreadyInChain),
blockchain::BlockStatus::Unknown => {},
}
Ok(ImportResult::Queued)
}
}
impl<B, E, Block, RA> consensus::Authorities<Block> for Client<B, E, Block, RA> where