diff --git a/prdoc/pr_8310.prdoc b/prdoc/pr_8310.prdoc new file mode 100644 index 0000000000000..3f51b7a298246 --- /dev/null +++ b/prdoc/pr_8310.prdoc @@ -0,0 +1,19 @@ +title: 'staking-async: add missing new_session_genesis' +doc: + - audience: Runtime Dev + description: |- + Fix issue #8302 as introduced by #8127 where the staking-async module could fail during genesis. + The issue was related to the staking-async module in the Polkadot SDK, specifically with the implementation of the `historical::SessionManager` + trait in the `ah-client` pallet with missing implementations of the new_session_genesis method in two different places: + - In the pallet_session::SessionManager implementation + - In the historical::SessionManager>> + implementation + + Note: the SessionManager trait requires the implementation of new_session_genesis for proper functioning, especially during chain initialization. + The pallet-staking-async/ah-client has different operating modes: + - Passive: Delegates operations to a fallback implementation + - Buffered: Buffers operations for later processing + - Active: Performs operations directly +crates: +- name: pallet-staking-async-ah-client + bump: patch diff --git a/substrate/frame/staking-async/ah-client/src/lib.rs b/substrate/frame/staking-async/ah-client/src/lib.rs index 416d1d12dec57..910f0c7cb90a2 100644 --- a/substrate/frame/staking-async/ah-client/src/lib.rs +++ b/substrate/frame/staking-async/ah-client/src/lib.rs @@ -226,7 +226,7 @@ pub mod pallet { use alloc::vec; use frame_support::traits::UnixTime; use frame_system::pallet_prelude::*; - use pallet_session::historical; + use pallet_session::{historical, SessionManager}; use sp_runtime::{Perbill, Saturating}; use sp_staking::{ offence::{OffenceSeverity, OnOffenceHandler}, @@ -527,8 +527,17 @@ pub mod pallet { .map(|v| v.into_iter().map(|v| (v, sp_staking::Exposure::default())).collect()) } - // We don't implement `new_session_genesis` because we rely on the default implementation - // which calls `new_session` + fn new_session_genesis( + new_index: SessionIndex, + ) -> Option>)>> { + if Mode::::get() == OperatingMode::Passive { + T::Fallback::new_session_genesis(new_index).map(|validators| { + validators.into_iter().map(|v| (v, sp_staking::Exposure::default())).collect() + }) + } else { + None + } + } fn start_session(start_index: SessionIndex) { >::start_session(start_index) @@ -555,6 +564,14 @@ pub mod pallet { } } + fn new_session_genesis(new_index: SessionIndex) -> Option> { + if Mode::::get() == OperatingMode::Passive { + T::Fallback::new_session_genesis(new_index) + } else { + None + } + } + fn end_session(session_index: u32) { match Mode::::get() { OperatingMode::Passive => T::Fallback::end_session(session_index),