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: 12 additions & 7 deletions runtimes/common/src/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

pub use frame_support::weights::constants::{BlockExecutionWeight, ExtrinsicBaseWeight, RocksDbWeight};
use frame_system::Pallet as SystemPallet;
use pallet_membership::{Config as MembershipConfig, Instance3, Pallet as MembershipPallet};
use pallet_membership::{Config as MembershipConfig, Pallet as MembershipPallet};
use pallet_session::SessionManager as SessionManagerTrait;
pub use sp_consensus_aura::sr25519::AuthorityId;
use sp_core::Get;
Expand All @@ -31,15 +31,15 @@ use crate::constants::staking::DefaultBlocksPerRound;
type AccountIdOf<Runtime> = <Runtime as frame_system::Config>::AccountId;

/// The session manager for the collator set.
pub struct SessionManager<Runtime>(PhantomData<Runtime>);
pub struct SessionManager<Runtime, Instance>(PhantomData<Runtime>, PhantomData<Instance>);

impl<Runtime> SessionManagerTrait<AccountIdOf<Runtime>> for SessionManager<Runtime>
impl<Runtime, Instance: 'static> SessionManagerTrait<AccountIdOf<Runtime>> for SessionManager<Runtime, Instance>
where
Runtime: MembershipConfig<Instance3> + pallet_session::Config,
Runtime: MembershipConfig<Instance> + pallet_session::Config,
<Runtime as pallet_session::Config>::ValidatorId: From<AccountIdOf<Runtime>>,
{
fn new_session(new_index: SessionIndex) -> Option<Vec<AccountIdOf<Runtime>>> {
let collators = MembershipPallet::<Runtime, Instance3>::members().to_vec();
let collators = MembershipPallet::<Runtime, Instance>::members().to_vec();

log::debug!(
"assembling new collators for new session {} at #{:?} with {:?}",
Expand All @@ -56,11 +56,16 @@ where

SystemPallet::<Runtime>::register_extra_weight_unchecked(
<Runtime as frame_system::Config>::DbWeight::get()
.reads(2u64.saturating_add(collators.len().saturated_into::<u64>())),
.reads(1u64.saturating_add(collators.len().saturated_into::<u64>())),
frame_support::pallet_prelude::DispatchClass::Mandatory,
);

if collators.is_empty() || !has_collator_keys {
if !has_collator_keys {
log::error!("💥 keeping old session because of missing collator keys!");
return None;
}

if collators.is_empty() {
// we never want to pass an empty set of collators. This would brick the chain.
log::error!("💥 keeping old session because of empty collator set!");
return None;
Expand Down
2 changes: 1 addition & 1 deletion runtimes/peregrine/src/system/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ impl pallet_session::Config for Runtime {
type ValidatorIdOf = ConvertInto;
type ShouldEndSession = FixedLengthSession;
type NextSessionRotation = FixedLengthSession;
type SessionManager = SessionManager<Runtime>;
type SessionManager = SessionManager<Runtime, CollatorMembershipProvider>;
type SessionHandler = <SessionKeys as OpaqueKeys>::KeyTypeIdProviders;
type Keys = SessionKeys;
type WeightInfo = weights::pallet_session::WeightInfo<Runtime>;
Expand Down
2 changes: 1 addition & 1 deletion runtimes/spiritnet/src/system/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ impl pallet_session::Config for Runtime {
type ValidatorIdOf = ConvertInto;
type ShouldEndSession = FixedLengthSession;
type NextSessionRotation = FixedLengthSession;
type SessionManager = SessionManager<Runtime>;
type SessionManager = SessionManager<Runtime, CollatorMembershipProvider>;
type SessionHandler = <SessionKeys as OpaqueKeys>::KeyTypeIdProviders;
type Keys = SessionKeys;
type WeightInfo = weights::pallet_session::WeightInfo<Runtime>;
Expand Down
Loading