Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Better Handling of Candidates Who Become Invulnerable #2801

Merged
merged 19 commits into from
Jul 7, 2023

Conversation

joepetrowski
Copy link
Contributor

@joepetrowski joepetrowski commented Jun 30, 2023

Closes #2782

Key points:

  • Changes the intent of MinCandidates and replaces it with MinEligibleCollators. Rather than enforcing a minimum number of Candidates (i.e. non-invulnerable collators), it treats all potential collators equally.
  • When calling add_invulnerable, it will remove an account from Candidates if it is there.
  • When calling set_invulnerables, it does not remove an account from Candidates. This is due to likely massive overestimates of weight, since it will be based on MaxCandidates, it loops through each account in new, and there's a good chance that many members are not candidates. Added docs that this call is a bit blunt and {add, remove}_invulnerable is the preferred method to manipulate the Invulnerable set. But just in case, ...
  • It removes any Invulnerable Candidates on session change.
  • Moved related runtime parameters from parameter_types! to ConstU32. Also adjusted values to more reasonable numbers.
  • Made set_invulnerables non-atomic. This call previously failed entirely if even one collator in new did not have session keys registered. This happened e.g. in Kusama referendum 224. The change here just removes a collator from new if they are not prepared to be a collator.
    • Up for discussion: This does change the semantics of the call. Rather than accepting a "set", the UpdateOrigin is accepting qualified collators as "individuals". On the other hand, it prevents one unprepared collator from ruining the whole batch. An alternative would be to revert this change (177b307) and just recommend always using a batch of {add, remove}_invulnerable to manage the invulnerable collators.

Question: I think there is probably a more graceful way to account for the weight of (maybe) removing accounts that are being set as invulnerable. <- Addressed

@joepetrowski joepetrowski added A0-please_review Pull request needs code review. B1-note_worthy Changes should be noted in the release notes C1-low PR touches the given topic and has a low impact on builders. D5-nicetohaveaudit ⚠️ PR contains trivial changes to logic that should be properly reviewed. T1-runtime This PR/Issue is related to the topic “runtime”. labels Jun 30, 2023
@paritytech-ci paritytech-ci requested a review from a team June 30, 2023 13:59
@kianenigma
Copy link
Contributor

@gpestana @Ank4n a bit of context here: The end goal of collator selection in asset hub (and possibly other parachains) is using approval stakes tracked in an instance of the bags-list as the election provider. This is being made for the relay chain as well, but in relay chain we use this merely as the pre-sorting step.

We might take over this task from SP in the future.

@liamaharon liamaharon self-requested a review July 2, 2023 20:44
@liamaharon liamaharon removed their request for review July 3, 2023 16:18
pallets/collator-selection/src/tests.rs Show resolved Hide resolved
origin: OriginFor<T>,
new: Vec<T::AccountId>,
) -> DispatchResultWithPostInfo {
pub fn set_invulnerables(origin: OriginFor<T>, new: Vec<T::AccountId>) -> DispatchResult {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From my PoV, I'd expect set_invulnerables to be atomic, so I lean towards removing the non-atomic group set dispatchable and expose an individual set_invulnerable that can be batched at the extrinsic level. Perhaps the non-atomic set is OK in this case, not sure what are the user's expectations when using this. However, perhaps it would be good to emit an event when at least one candidate was not set as invulnerable (or an event per candidate not set)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

an individual set_invulnerable that can be batched at the extrinsic level

This is pretty much add_invulnerable.

I waivered about the atomicity of this, but I think non-atomic is better (with the recommendation in the docs that add/remove invulnerable is better for many reasons). The reason is that you could set 20 Invulnerables, and one guy either decides not to set his keys or just forgets (probably makes him a bad choice for invulnerable...), but then this ruins the entire call.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

However, perhaps it would be good to emit an event when at least one candidate was not set as invulnerable (or an event per candidate not set)

Done

pallets/collator-selection/src/lib.rs Outdated Show resolved Hide resolved
@paritytech-ci paritytech-ci requested a review from a team July 7, 2023 07:47
@paritytech-ci paritytech-ci requested a review from a team July 7, 2023 07:48
}

// should never fail since `new_with_keys` must be equal to or shorter than `new`
let mut bounded_invulnerables =
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

slightly more performant to check the length of new as early as possible.

@@ -342,6 +396,8 @@ pub mod pallet {
}

/// Set the candidacy bond amount.
///
/// The origin for this call must be the `UpdateOrigin`.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@paritytech-ci paritytech-ci requested a review from a team July 7, 2023 07:49
@joepetrowski
Copy link
Contributor Author

bot merge

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
A0-please_review Pull request needs code review. B1-note_worthy Changes should be noted in the release notes C1-low PR touches the given topic and has a low impact on builders. D5-nicetohaveaudit ⚠️ PR contains trivial changes to logic that should be properly reviewed. T1-runtime This PR/Issue is related to the topic “runtime”.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Handle Collator Candidate to Invulnerable Path
3 participants