Expand sanity checks

Substrate doesn't expect nor officially support children with less work 
than their parents. It's a trick used here. Accordingly, ensure the 
trick's validity.
This commit is contained in:
Luke Parker
2022-10-24 04:43:59 -04:00
parent b6dddc469f
commit 78fa292230

View File

@@ -348,6 +348,7 @@ where
let hash = block.hash(); let hash = block.hash();
let (header, body) = block.clone().deconstruct(); let (header, body) = block.clone().deconstruct();
let parent = *header.parent_hash(); let parent = *header.parent_hash();
let number = *header.number();
*self.importing_block.write().unwrap() = Some(hash); *self.importing_block.write().unwrap() = Some(hash);
self.queue.write().await.as_mut().unwrap().import_blocks( self.queue.write().await.as_mut().unwrap().import_blocks(
// We do not want this block, which hasn't been confirmed, to be broadcast over the net // We do not want this block, which hasn't been confirmed, to be broadcast over the net
@@ -372,7 +373,15 @@ where
if !ImportFuture::new(hash, self.queue.write().await.as_mut().unwrap()).await { if !ImportFuture::new(hash, self.queue.write().await.as_mut().unwrap()).await {
todo!() todo!()
} }
assert_eq!(self.client.info().best_hash, parent);
// Sanity checks that a child block can have less work than its parent
{
let info = self.client.info();
assert_eq!(info.best_hash, parent);
assert_eq!(info.finalized_hash, parent);
assert_eq!(info.best_number, number - 1);
assert_eq!(info.finalized_number, number - 1);
}
Ok(()) Ok(())
} }