Properly use check_block

This commit is contained in:
Luke Parker 2022-10-20 04:27:53 -04:00
parent eb59dd5a55
commit 49a26e5841
No known key found for this signature in database
GPG key ID: F9F1386DB1E119B6

View file

@ -76,7 +76,18 @@ where
type Error = Error;
type Transaction = TransactionFor<C, B>;
async fn check_block(&mut self, block: BlockCheckParams<B>) -> Result<ImportResult, Self::Error> {
async fn check_block(
&mut self,
mut block: BlockCheckParams<B>,
) -> Result<ImportResult, Self::Error> {
let info = self.client.info();
if (info.best_hash != block.parent_hash) || ((info.best_number + 1u16.into()) != block.number) {
Err(Error::Other("non-sequential import".into()))?;
}
block.allow_missing_state = false;
block.allow_missing_parent = false;
self.inner.check_block(block).await.map_err(Into::into)
}
@ -85,11 +96,6 @@ where
mut block: BlockImportParams<B, Self::Transaction>,
new_cache: HashMap<CacheKeyId, Vec<u8>>,
) -> Result<ImportResult, Self::Error> {
let parent_hash = *block.header.parent_hash();
if self.client.info().best_hash != parent_hash {
Err(Error::Other("non-sequential import".into()))?;
}
if let Some(body) = block.body.clone() {
if let Some(justifications) = block.justifications {
let mut iter = justifications.iter();
@ -111,7 +117,7 @@ where
self
.check_inherents(
B::new(block.header.clone(), body),
self.providers.create_inherent_data_providers(parent_hash, ()).await?,
self.providers.create_inherent_data_providers(*block.header.parent_hash(), ()).await?,
)
.await?;
}