diff --git a/cumulus/pallets/collator-selection/src/lib.rs b/cumulus/pallets/collator-selection/src/lib.rs index 90435ca3522d404a5cc8f7707846e3c3cec91f40..f4eade05937e5c81cdb70df76034294b88d60940 100644 --- a/cumulus/pallets/collator-selection/src/lib.rs +++ b/cumulus/pallets/collator-selection/src/lib.rs @@ -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()) diff --git a/cumulus/pallets/collator-selection/src/tests.rs b/cumulus/pallets/collator-selection/src/tests.rs index d8cba9f227ce044a3c984c97e8e82c4cad2adcba..730bfd489c6b179610e8195751e7c1138e13dd98 100644 --- a/cumulus/pallets/collator-selection/src/tests.rs +++ b/cumulus/pallets/collator-selection/src/tests.rs @@ -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 + ); }); }