From 40b6cb71067e1765658e13e155706a0b2bafb6f5 Mon Sep 17 00:00:00 2001 From: Luke Parker Date: Wed, 2 Nov 2022 03:35:46 -0400 Subject: [PATCH] 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. --- substrate/tendermint/client/src/block_import.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/substrate/tendermint/client/src/block_import.rs b/substrate/tendermint/client/src/block_import.rs index b5ebb3a4..64c989c0 100644 --- a/substrate/tendermint/client/src/block_import.rs +++ b/substrate/tendermint/client/src/block_import.rs @@ -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, ) -> Result { + 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