Skip to content

Commit

Permalink
Fix custom on runtime upgrade not being called (paritytech#9399)
Browse files Browse the repository at this point in the history
When the `Executive` was used through the `ExecuteBlock` trait, the
custom on runtime upgrade wasn't called. This happened because we forgot
to forward the type and it instead used default type `()` that doesn't
do anything. This pr fixes it by forwarding the type and also adds a
regression test.
  • Loading branch information
bkchr authored Jul 20, 2021
1 parent 02d6644 commit dbd21b9
Showing 1 changed file with 55 additions and 1 deletion.
56 changes: 55 additions & 1 deletion frame/executive/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,14 @@ where
UnsignedValidator: ValidateUnsigned<Call=CallOf<Block::Extrinsic, Context>>,
{
fn execute_block(block: Block) {
Executive::<System, Block, Context, UnsignedValidator, AllPallets>::execute_block(block);
Executive::<
System,
Block,
Context,
UnsignedValidator,
AllPallets,
COnRuntimeUpgrade,
>::execute_block(block);
}
}

Expand Down Expand Up @@ -1193,6 +1200,53 @@ mod tests {
});
}

/// Regression test that ensures that the custom on runtime upgrade is called when executive is
/// used through the `ExecuteBlock` trait.
#[test]
fn custom_runtime_upgrade_is_called_when_using_execute_block_trait() {
let xt = TestXt::new(Call::Balances(BalancesCall::transfer(33, 0)), sign_extra(1, 0, 0));

let header = new_test_ext(1).execute_with(|| {
// Make sure `on_runtime_upgrade` is called.
RUNTIME_VERSION.with(|v| *v.borrow_mut() = sp_version::RuntimeVersion {
spec_version: 1,
..Default::default()
});

// Let's build some fake block.
Executive::initialize_block(&Header::new(
1,
H256::default(),
H256::default(),
[69u8; 32].into(),
Digest::default(),
));

Executive::apply_extrinsic(xt.clone()).unwrap().unwrap();

Executive::finalize_block()
});

// Reset to get the correct new genesis below.
RUNTIME_VERSION.with(|v| *v.borrow_mut() = sp_version::RuntimeVersion {
spec_version: 0,
..Default::default()
});

new_test_ext(1).execute_with(|| {
// Make sure `on_runtime_upgrade` is called.
RUNTIME_VERSION.with(|v| *v.borrow_mut() = sp_version::RuntimeVersion {
spec_version: 1,
..Default::default()
});

<Executive as ExecuteBlock<Block<TestXt>>>::execute_block(Block::new(header, vec![xt]));

assert_eq!(&sp_io::storage::get(TEST_KEY).unwrap()[..], *b"module");
assert_eq!(sp_io::storage::get(CUSTOM_ON_RUNTIME_KEY).unwrap(), true.encode());
});
}

#[test]
fn all_weights_are_recorded_correctly() {
new_test_ext(1).execute_with(|| {
Expand Down

0 comments on commit dbd21b9

Please sign in to comment.