Ensure invulnerables have associated validator keys before they are set (#812)

* Added check to ensure invulnerables have associated validator keys before they are set

* Added check to ensure invulnerables have associated validator keys before they are set

* Update pallets/collator-selection/src/lib.rs

Co-authored-by: Keith Yeung <kungfukeith11@gmail.com>

* Added test for associated validators when setting invulnerables

* FMT

Co-authored-by: Omadoye Abraham <abraham.o@turing.com>
Co-authored-by: Ricardo Rius <9488369+riusricardo@users.noreply.github.com>
Co-authored-by: Keith Yeung <kungfukeith11@gmail.com>
Co-authored-by: Bastian Köcher <info@kchr.de>
This commit is contained in:
omadoyeabraham
2022-02-07 17:42:37 +01:00
committed by GitHub
parent b5a268e69b
commit de8462ec2b
2 changed files with 21 additions and 0 deletions
@@ -296,6 +296,17 @@ pub mod pallet {
"invulnerables > T::MaxInvulnerables; you might need to run benchmarks again"
);
}
// check if the invulnerables have associated validator keys before they are set
for account_id in &new {
let validator_key = T::ValidatorIdOf::convert(account_id.clone())
.ok_or(Error::<T>::NoAssociatedValidatorId)?;
ensure!(
T::ValidatorRegistration::is_registered(&validator_key),
Error::<T>::ValidatorNotRegistered
);
}
<Invulnerables<T>>::put(&new);
Self::deposit_event(Event::NewInvulnerables(new));
Ok(().into())
@@ -48,6 +48,16 @@ fn it_should_set_invulnerables() {
CollatorSelection::set_invulnerables(Origin::signed(1), new_set.clone()),
BadOrigin
);
// cannot set invulnerables without associated validator keys
let invulnerables = vec![7];
assert_noop!(
CollatorSelection::set_invulnerables(
Origin::signed(RootAccount::get()),
invulnerables.clone()
),
Error::<Test>::ValidatorNotRegistered
);
});
}