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: Expose on_genesis hook #7948

Draft
wants to merge 13 commits into
base: master
Choose a base branch
from
Draft

Conversation

skunert
Copy link
Contributor

@skunert skunert commented Mar 17, 2025

This PR enables parachain onboarding directly in the initial session. Previously, we had to wait one full session before a parachain could produce blocks, which created unnecessary delays in zombienet tests during local debugging and CI runs.

Enhanced on_genesis Hook

A trait for executing code after genesis storage initialization already existed in frame:

pub trait OnGenesis {
/// Something that should happen at genesis.
fn on_genesis() {}
}

However, this trait was not exposed to users through the Hooks trait and was only utilized internally by macros:

// Implement `OnGenesis` for `Pallet`
impl<#type_impl_gen> #frame_support::traits::OnGenesis
for #pallet_ident<#type_use_gen>
#config_where_clause
{
fn on_genesis() {
let storage_version: #frame_support::traits::StorageVersion = #storage_version;
storage_version.put::<Self>();
}
}

This PR adds an on_genesis method to the Hooks trait, allowing developers to define custom behavior that executes after each pallet has completed its genesis build process.

Session Handlers Now Called in on_genesis Hook

The previous inability to onboard parachains at genesis came from an initialization sequence issue. Parachain consensus-related pallets are initialized via the Initializer pallet here, which uses a SessionHandlers implementation. Previously, session handlers were called during the genesis build process, before parachain-related storage items were fully set up.

With this PR, session handlers are now called after the complete genesis state is established, enabling seamless parachain onboarding from the very first session.

@skunert skunert added the T1-FRAME This PR/Issue is related to core FRAME, the framework. label Mar 17, 2025
@skunert
Copy link
Contributor Author

skunert commented Mar 19, 2025

/cmd prdoc --audience runtime_dev --bump major

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
T1-FRAME This PR/Issue is related to core FRAME, the framework.
Projects
Status: backlog
Development

Successfully merging this pull request may close these issues.

2 participants