mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-09 08:18:04 +00:00
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:
@@ -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
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user