diff --git a/cumulus/pallets/collator-selection/src/lib.rs b/cumulus/pallets/collator-selection/src/lib.rs index 90435ca352..f4eade0593 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::::NoAssociatedValidatorId)?; + ensure!( + T::ValidatorRegistration::is_registered(&validator_key), + Error::::ValidatorNotRegistered + ); + } + >::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 d8cba9f227..730bfd489c 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::::ValidatorNotRegistered + ); }); }