Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions prdoc/pr_8310.prdoc
Original file line number Diff line number Diff line change
@@ -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<T::AccountId> implementation
- In the historical::SessionManager<T::AccountId, sp_staking::Exposure<T::AccountId, BalanceOf<T>>>
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
23 changes: 20 additions & 3 deletions substrate/frame/staking-async/ah-client/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down Expand Up @@ -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(
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

[nitpick] we also need to cleanup comment at line 530 since we now implement new_session_genesis :)

new_index: SessionIndex,
) -> Option<Vec<(T::AccountId, sp_staking::Exposure<T::AccountId, BalanceOf<T>>)>> {
if Mode::<T>::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) {
<Self as pallet_session::SessionManager<_>>::start_session(start_index)
Expand All @@ -555,6 +564,14 @@ pub mod pallet {
}
}

fn new_session_genesis(new_index: SessionIndex) -> Option<Vec<T::AccountId>> {
if Mode::<T>::get() == OperatingMode::Passive {
T::Fallback::new_session_genesis(new_index)
} else {
None
}
}

fn end_session(session_index: u32) {
match Mode::<T>::get() {
OperatingMode::Passive => T::Fallback::end_session(session_index),
Expand Down
Loading