From de8462ec2b08434ea226ff394294edd44e4671ca Mon Sep 17 00:00:00 2001 From: omadoyeabraham Date: Mon, 7 Feb 2022 17:42:37 +0100 Subject: [PATCH] Ensure invulnerables have associated validator keys before they are set (#812) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 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 * Added test for associated validators when setting invulnerables * FMT Co-authored-by: Omadoye Abraham Co-authored-by: Ricardo Rius <9488369+riusricardo@users.noreply.github.com> Co-authored-by: Keith Yeung Co-authored-by: Bastian Köcher --- cumulus/pallets/collator-selection/src/lib.rs | 11 +++++++++++ cumulus/pallets/collator-selection/src/tests.rs | 10 ++++++++++ 2 files changed, 21 insertions(+) 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 + ); }); }