@@ -50,6 +50,8 @@ const STAKING_ID: LockIdentifier = *b"staking ";
5050
5151#[ frame_support:: pallet]
5252pub mod pallet {
53+ use alloc:: collections:: BTreeSet ;
54+
5355 use frame_election_provider_support:: ElectionDataProvider ;
5456
5557 use crate :: BenchmarkingConfig ;
@@ -516,6 +518,11 @@ 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 > =
524+ StorageValue < _ , Option < BTreeSet < T :: AccountId > > , ValueQuery > ;
525+
519526 #[ pallet:: genesis_config]
520527 pub struct GenesisConfig < T : Config > {
521528 pub history_depth : u32 ,
@@ -716,6 +723,8 @@ pub mod pallet {
716723 CommissionTooLow ,
717724 /// Can't kill the stash while it has some unclaimed era rewards. It will be possible after claiming.
718725 CantKillStashWithUnclaimedRewards ,
726+ /// Can only submit as candidates accounts that were whitelisted.
727+ NotInAWhitelist ,
719728 }
720729
721730 #[ pallet:: hooks]
@@ -1048,6 +1057,11 @@ pub mod pallet {
10481057 Error :: <T >:: CommissionTooLow
10491058 ) ;
10501059
1060+ ensure ! (
1061+ Self :: candidate_whitelist( ) . map_or( true , |set| set. contains( & stash) ) ,
1062+ Error :: <T >:: NotInAWhitelist
1063+ ) ;
1064+
10511065 // Only check limits if they are not already a validator.
10521066 if !Validators :: < T > :: contains_key ( stash) {
10531067 // If this error is reached, we need to adjust the `MinValidatorBond` and start
@@ -1753,6 +1767,18 @@ pub mod pallet {
17531767 } ) ?;
17541768 Ok ( ( ) )
17551769 }
1770+
1771+ #[ pallet:: weight( T :: DbWeight :: get( ) . writes( 1 ) ) ]
1772+ pub fn set_whitelist (
1773+ origin : OriginFor < T > ,
1774+ whitelist : Option < BTreeSet < T :: AccountId > > ,
1775+ ) -> DispatchResult {
1776+ ensure_root ( origin) ?;
1777+
1778+ CandidateWhitelist :: < T > :: put ( whitelist) ;
1779+
1780+ Ok ( ( ) )
1781+ }
17561782 }
17571783}
17581784
0 commit comments