Add an already in chain check to block import

While the inner should do this for us, we call verify_order on our end 
*before* inner to ensure sequential import. Accordingly, we need to 
provide our own check.

Removes errors of "non-sequential import" when trying to re-import an 
existing block.
This commit is contained in:
Luke Parker 2022-11-02 03:35:46 -04:00
parent 16065ccd4e
commit 40b6cb7106
No known key found for this signature in database
GPG key ID: F9F1386DB1E119B6

View file

@ -4,7 +4,7 @@ use async_trait::async_trait;
use sp_api::BlockId;
use sp_runtime::traits::Block;
use sp_blockchain::{HeaderBackend, Backend as BlockchainBackend};
use sp_blockchain::{BlockStatus, HeaderBackend, Backend as BlockchainBackend};
use sp_consensus::{Error, CacheKeyId, SelectChain};
use sc_consensus::{BlockCheckParams, BlockImportParams, ImportResult, BlockImport, Verifier};
@ -28,6 +28,9 @@ where
&mut self,
mut block: BlockCheckParams<T::Block>,
) -> Result<ImportResult, Self::Error> {
if self.client.status(BlockId::Hash(block.hash)).unwrap() == BlockStatus::InChain {
return Ok(ImportResult::AlreadyInChain);
}
self.verify_order(block.parent_hash, block.number)?;
// Does not verify origin here as origin only applies to unfinalized blocks