Make on_slot return the block with the post header (#8188)

* Make `on_slot` return the block with the post header

Before this pr `on_slot` returned the pre block. However this is wrong,
because adding some post digest changes the hash of the header. Thus,
we need to make sure to return the correct block that uses the post
header.

* Update primitives/consensus/common/src/block_import.rs

Co-authored-by: André Silva <123550+andresilva@users.noreply.github.com>

Co-authored-by: André Silva <123550+andresilva@users.noreply.github.com>
This commit is contained in:
Bastian KöcherandAndré Silva authored and GitHub committed 2021-02-24 08:03:05 +01:00
1 parent 3e3b5f9cba
commit 76d3814e90
3 files changed
+67 -14

No files matched your search

@@ -193,16 +193,21 @@ impl<Block: BlockT, Transaction> BlockImportParams<Block, Transaction> {
if let Some(hash) = self.post_hash {
hash
} else {
if self.post_digests.is_empty() {
self.header.hash()
} else {
let mut hdr = self.header.clone();
for digest_item in &self.post_digests {
hdr.digest_mut().push(digest_item.clone());
}
self.post_header().hash()
}
}
hdr.hash()
/// Get the post header.
pub fn post_header(&self) -> Block::Header {
if self.post_digests.is_empty() {
self.header.clone()
} else {
let mut hdr = self.header.clone();
for digest_item in &self.post_digests {
hdr.digest_mut().push(digest_item.clone());
}
hdr
}
}