Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FRAME] Execution phases ApplyInherent and AfterInherent #3666

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
12 changes: 12 additions & 0 deletions prdoc/pr_3666.prdoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
title: "[FRAME] Execution phases ApplyInherent and AfterInherent"

doc:
- audience: Runtime User
description: |
FRAME runtimes now have two additional execution phases; `ApplyInherent(u32)` and `AfterInherent`. These are used to distinct in what phase of a block some logic runs. Formerly, inherents would also use the `ApplyExtrinsic(u32)` phase and all logic that runs in hooks between inherent and extrinsic application did not have a dedicated phase.

crates:
- name: frame-system
bump: major
- name: frame-executive
bump: major
4 changes: 2 additions & 2 deletions substrate/bin/node/cli/tests/basic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ fn full_native_block_import_works() {
alice_last_known_balance = Balances::total_balance(&alice());
let events = vec![
EventRecord {
phase: Phase::ApplyExtrinsic(0),
phase: Phase::ApplyInherent(0), // Timestamp::set
event: RuntimeEvent::System(frame_system::Event::ExtrinsicSuccess {
dispatch_info: DispatchInfo {
weight: timestamp_weight,
Expand Down Expand Up @@ -422,7 +422,7 @@ fn full_native_block_import_works() {
topics: vec![],
},
EventRecord {
phase: Phase::ApplyExtrinsic(0),
phase: Phase::ApplyInherent(0), // Timestamp::set
event: RuntimeEvent::System(frame_system::Event::ExtrinsicSuccess {
dispatch_info: DispatchInfo {
weight: timestamp_weight,
Expand Down
10 changes: 6 additions & 4 deletions substrate/frame/executive/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ where
return Err(InvalidTransaction::BadMandatory.into())
}

<frame_system::Pallet<System>>::note_applied_extrinsic(&r, dispatch_info);
<frame_system::Pallet<System>>::note_applied_extrinsic(&r, dispatch_info, is_inherent);

Ok(r.map(|_| ()).map_err(|e| e.error))
};
Expand Down Expand Up @@ -601,8 +601,8 @@ where
DispatchClass::Mandatory,
);

frame_system::Pallet::<System>::note_finished_initialize();
<System as frame_system::Config>::PreInherents::pre_inherents();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

here you wanna have it within Initialization phase?

frame_system::Pallet::<System>::note_finished_initialize();
}

/// Returns if the runtime has been upgraded, based on [`frame_system::LastRuntimeUpgrade`].
Expand Down Expand Up @@ -683,6 +683,9 @@ where
let block_number = <frame_system::Pallet<System>>::block_number();
Self::on_poll_hook(block_number);
}

// MBMs and poll should run in phase `AfterInherent`, hence this goes here.
<frame_system::Pallet<System>>::note_after_inherents_done();
}

/// Execute given extrinsics.
Expand Down Expand Up @@ -747,7 +750,6 @@ where
let weight = <frame_system::Pallet<System>>::block_weight();
let max_weight = <System::BlockWeights as frame_support::traits::Get<_>>::get().max_block;
let remaining = max_weight.saturating_sub(weight.total());

if remaining.all_gt(Weight::zero()) {
let mut meter = WeightMeter::with_limit(remaining);
<AllPalletsWithSystem as OnPoll<BlockNumberFor<System>>>::on_poll(
Expand Down Expand Up @@ -806,7 +808,7 @@ where
return Err(InvalidTransaction::BadMandatory.into())
}

<frame_system::Pallet<System>>::note_applied_extrinsic(&r, dispatch_info);
<frame_system::Pallet<System>>::note_applied_extrinsic(&r, dispatch_info, is_inherent);

Ok(r.map(|_| ()).map_err(|e| e.error))
}
Expand Down
Loading
Loading