@@ -50,6 +50,8 @@ const STAKING_ID: LockIdentifier = *b"staking ";
5050
5151#[ frame_support:: pallet]
5252pub mod pallet {
53+ use std:: collections:: BTreeSet ;
54+
5355 use frame_election_provider_support:: ElectionDataProvider ;
5456
5557 use crate :: BenchmarkingConfig ;
@@ -516,6 +518,10 @@ pub mod pallet {
516518 #[ pallet:: storage]
517519 pub ( crate ) type ChillThreshold < T : Config > = StorageValue < _ , Percent , OptionQuery > ;
518520
521+ #[ pallet:: storage]
522+ #[ pallet:: getter( fn candidate_whitelist) ]
523+ pub type CandidateWhitelist < T : Config > = StorageValue < _ , BTreeSet < T :: AccountId > , ValueQuery > ;
524+
519525 #[ pallet:: genesis_config]
520526 pub struct GenesisConfig < T : Config > {
521527 pub history_depth : u32 ,
@@ -716,6 +722,8 @@ pub mod pallet {
716722 CommissionTooLow ,
717723 /// Can't kill the stash while it has some unclaimed era rewards. It will be possible after claiming.
718724 CantKillStashWithUnclaimedRewards ,
725+ /// Can only submit as candidates accounts that were whitelisted.
726+ NotInAWhitelist ,
719727 }
720728
721729 #[ pallet:: hooks]
@@ -1048,6 +1056,11 @@ pub mod pallet {
10481056 Error :: <T >:: CommissionTooLow
10491057 ) ;
10501058
1059+ ensure ! (
1060+ Self :: candidate_whitelist( ) . contains( & stash) ,
1061+ Error :: <T >:: NotInAWhitelist
1062+ ) ;
1063+
10511064 // Only check limits if they are not already a validator.
10521065 if !Validators :: < T > :: contains_key ( stash) {
10531066 // If this error is reached, we need to adjust the `MinValidatorBond` and start
@@ -1753,6 +1766,18 @@ pub mod pallet {
17531766 } ) ?;
17541767 Ok ( ( ) )
17551768 }
1769+
1770+ #[ pallet:: weight( T :: DbWeight :: get( ) . writes( 1 ) ) ]
1771+ pub fn set_whitelist (
1772+ origin : OriginFor < T > ,
1773+ whitelist : BTreeSet < T :: AccountId > ,
1774+ ) -> DispatchResult {
1775+ ensure_root ( origin) ?;
1776+
1777+ CandidateWhitelist :: < T > :: put ( whitelist) ;
1778+
1779+ Ok ( ( ) )
1780+ }
17561781 }
17571782}
17581783
0 commit comments