Skip to content

Commit 2d8ab37

Browse files
committed
Tweaks
1 parent 6d2b2fb commit 2d8ab37

File tree

4 files changed

+9
-11
lines changed

4 files changed

+9
-11
lines changed

substrate/frame/staking/src/mock.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -422,10 +422,6 @@ impl ExtBuilder {
422422
.build_storage::<Test>()
423423
.unwrap();
424424

425-
sp_state_machine::BasicExternalities::execute_with_storage(&mut storage, || {
426-
Staking::set_whitelist(Origin::root(), (0..100).collect()).unwrap();
427-
});
428-
429425
let _ = pallet_balances::GenesisConfig::<Test> {
430426
balances: vec![
431427
(1, 10 * self.balance_factor),

substrate/frame/staking/src/pallet/impls.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -444,7 +444,11 @@ impl<T: Config> Pallet<T> {
444444

445445
let whitelist = Self::candidate_whitelist();
446446
let to_remove: Vec<_> = Validators::<T>::iter_keys()
447-
.filter(|validator| !whitelist.contains(&validator))
447+
.filter(|validator| {
448+
whitelist
449+
.as_ref()
450+
.map_or(false, |set| !set.contains(&validator))
451+
})
448452
.collect();
449453
for validator in to_remove {
450454
Self::do_remove_validator(&validator);

substrate/frame/staking/src/pallet/mod.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -520,7 +520,8 @@ pub mod pallet {
520520

521521
#[pallet::storage]
522522
#[pallet::getter(fn candidate_whitelist)]
523-
pub type CandidateWhitelist<T: Config> = StorageValue<_, BTreeSet<T::AccountId>, ValueQuery>;
523+
pub type CandidateWhitelist<T: Config> =
524+
StorageValue<_, Option<BTreeSet<T::AccountId>>, ValueQuery>;
524525

525526
#[pallet::genesis_config]
526527
pub struct GenesisConfig<T: Config> {
@@ -1057,7 +1058,7 @@ pub mod pallet {
10571058
);
10581059

10591060
ensure!(
1060-
Self::candidate_whitelist().contains(&stash),
1061+
Self::candidate_whitelist().map_or(true, |set| set.contains(&stash)),
10611062
Error::<T>::NotInAWhitelist
10621063
);
10631064

@@ -1770,7 +1771,7 @@ pub mod pallet {
17701771
#[pallet::weight(T::DbWeight::get().writes(1))]
17711772
pub fn set_whitelist(
17721773
origin: OriginFor<T>,
1773-
whitelist: BTreeSet<T::AccountId>,
1774+
whitelist: Option<BTreeSet<T::AccountId>>,
17741775
) -> DispatchResult {
17751776
ensure_root(origin)?;
17761777

substrate/frame/staking/src/testing_utils.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,6 @@ pub fn create_stash_controller<T: Config>(
8888
amount,
8989
destination,
9090
)?;
91-
let mut whitelist = Staking::<T>::candidate_whitelist();
92-
whitelist.insert(stash.clone());
93-
Staking::<T>::set_whitelist(RawOrigin::Root.into(), whitelist).unwrap();
9491

9592
Ok((stash, controller))
9693
}

0 commit comments

Comments
 (0)