-
Notifications
You must be signed in to change notification settings - Fork 47
feat: Permissioned collators #882
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
Changes from all commits
9b7f8f0
28d427b
514a30e
bb746e2
811d495
cdcb73c
f09ee62
8aa19c6
c5f7d05
8a71d6e
6407d31
5e68c6a
cc706fa
12a5b7f
2dcd021
7239539
f4baa2c
88beae9
9da1f23
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,81 @@ | ||
| // KILT Blockchain – <https://kilt.io> | ||
| // Copyright (C) 2025, KILT Foundation | ||
|
|
||
| // The KILT Blockchain is free software: you can redistribute it and/or modify | ||
| // it under the terms of the GNU General Public License as published by | ||
| // the Free Software Foundation, either version 3 of the License, or | ||
| // (at your option) any later version. | ||
|
|
||
| // The KILT Blockchain is distributed in the hope that it will be useful, | ||
| // but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| // GNU General Public License for more details. | ||
|
|
||
| // You should have received a copy of the GNU General Public License | ||
| // along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
|
|
||
| // If you feel like getting in touch with us, you can do so at <hello@kilt.io> | ||
|
|
||
| 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_session::SessionManager as SessionManagerTrait; | ||
| pub use sp_consensus_aura::sr25519::AuthorityId; | ||
| use sp_core::Get; | ||
| use sp_runtime::SaturatedConversion; | ||
| use sp_staking::SessionIndex; | ||
| use sp_std::{marker::PhantomData, vec::Vec}; | ||
|
|
||
| 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>); | ||
|
|
||
| impl<Runtime> SessionManagerTrait<AccountIdOf<Runtime>> for SessionManager<Runtime> | ||
| where | ||
| Runtime: MembershipConfig<Instance3> + pallet_session::Config, | ||
ntn-x2 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| <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(); | ||
|
|
||
| log::debug!( | ||
| "assembling new collators for new session {} at #{:?} with {:?}", | ||
| new_index, | ||
| SystemPallet::<Runtime>::block_number(), | ||
| collators | ||
| ); | ||
|
|
||
| let has_collator_keys = collators.iter().any(|collator| { | ||
| pallet_session::NextKeys::<Runtime>::contains_key(<Runtime as pallet_session::Config>::ValidatorId::from( | ||
| collator.clone(), | ||
| )) | ||
| }); | ||
|
|
||
| SystemPallet::<Runtime>::register_extra_weight_unchecked( | ||
| <Runtime as frame_system::Config>::DbWeight::get() | ||
| .reads(2u64.saturating_add(collators.len().saturated_into::<u64>())), | ||
ntn-x2 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| frame_support::pallet_prelude::DispatchClass::Mandatory, | ||
| ); | ||
|
|
||
| if collators.is_empty() || !has_collator_keys { | ||
| // 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!"); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think a different error message depending on which condition is
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fair point. I created a new PR: #887 |
||
| return None; | ||
| } | ||
|
|
||
| Some(collators) | ||
| } | ||
|
|
||
| fn start_session(_start_index: SessionIndex) { | ||
| // We don't care | ||
| } | ||
|
|
||
| fn end_session(_end_index: SessionIndex) { | ||
| // We don't care | ||
| } | ||
| } | ||
|
|
||
| pub type FixedLengthSession = pallet_session::PeriodicSessions<DefaultBlocksPerRound, DefaultBlocksPerRound>; | ||
Uh oh!
There was an error while loading. Please reload this page.