Manual Seal: Calculate the block's post hash (#10498)

* calculate the post hash

* Add test

Co-authored-by: tgmichel <telmo@purestake.com>
This commit is contained in:
Joshy Orndorff
2022-01-10 06:55:05 -05:00
committed by GitHub
parent 3093bed933
commit 2178cb1939
2 changed files with 86 additions and 2 deletions
@@ -153,9 +153,14 @@ pub async fn seal_block<B, BI, SC, C, E, TP, CIDP>(
digest_provider.append_block_import(&parent, &mut params, &inherent_data)?;
}
// Make sure we return the same post-hash that will be calculated when importing the block
// This is important in case the digest_provider added any signature, seal, ect.
let mut post_header = header.clone();
post_header.digest_mut().logs.extend(params.post_digests.iter().cloned());
match block_import.import_block(params, HashMap::new()).await? {
ImportResult::Imported(aux) =>
Ok(CreatedBlock { hash: <B as BlockT>::Header::hash(&header), aux }),
Ok(CreatedBlock { hash: <B as BlockT>::Header::hash(&post_header), aux }),
other => Err(other.into()),
}
};