Make ExecuteBlock::execute_block return the final block header (#8244)

This pr changes the `ExecuteBlock` trait to return the final header that
results from executing the given block.
This commit is contained in:
Bastian Köcher
2021-03-03 09:44:34 +01:00
committed by GitHub
parent dc190a69f2
commit 4de4662480
9 changed files with 48 additions and 37 deletions
+10 -8
View File
@@ -107,11 +107,11 @@ pub fn polish_block(block: &mut Block) {
execute_block_with_state_root_handler(block, Mode::Overwrite);
}
pub fn execute_block(mut block: Block) {
execute_block_with_state_root_handler(&mut block, Mode::Verify);
pub fn execute_block(mut block: Block) -> Header {
execute_block_with_state_root_handler(&mut block, Mode::Verify)
}
fn execute_block_with_state_root_handler(block: &mut Block, mode: Mode) {
fn execute_block_with_state_root_handler(block: &mut Block, mode: Mode) -> Header {
let header = &mut block.header;
initialize_block(header);
@@ -142,14 +142,16 @@ fn execute_block_with_state_root_handler(block: &mut Block, mode: Mode) {
"Transaction trie root must be valid.",
);
}
new_header
}
/// The block executor.
pub struct BlockExecutor;
impl frame_executive::ExecuteBlock<Block> for BlockExecutor {
fn execute_block(block: Block) {
execute_block(block);
impl frame_support::traits::ExecuteBlock<Block> for BlockExecutor {
fn execute_block(block: Block) -> Header {
execute_block(block)
}
}
@@ -407,7 +409,7 @@ mod tests {
#[test]
fn block_import_works_native() {
block_import_works(|b, ext| ext.execute_with(|| execute_block(b)));
block_import_works(|b, ext| ext.execute_with(|| { execute_block(b); }));
}
#[test]
@@ -507,7 +509,7 @@ mod tests {
#[test]
fn block_import_with_transaction_works_native() {
block_import_with_transaction_works(|b, ext| ext.execute_with(|| execute_block(b)));
block_import_with_transaction_works(|b, ext| ext.execute_with(|| { execute_block(b); }));
}
#[test]