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

min collator check #498

Merged
merged 9 commits into from
Jun 22, 2021
Merged

min collator check #498

merged 9 commits into from
Jun 22, 2021

Conversation

JesseAbram
Copy link
Contributor

This PR checks to make sure that there is a min amount of collators before a collator gets kicked, or tries to leave. This is a defence mechanism for better disaster recovery of a chain

Copy link
Member

@bkchr bkchr left a comment

Choose a reason for hiding this comment

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

Looks good, beside the minimum number of collators

polkadot-parachains/statemine-runtime/src/lib.rs Outdated Show resolved Hide resolved
@@ -365,7 +375,7 @@ pub mod pallet {
let new_candidates = candidates.into_iter().filter_map(|c| {
let last_block = <LastAuthoredBlock<T>>::get(c.who.clone());
let since_last = now.saturating_sub(last_block);
if since_last < kick_threshold {
if since_last < kick_threshold || Self::candidates().len() <= T::MinCandidates::get() {
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
if since_last < kick_threshold || Self::candidates().len() <= T::MinCandidates::get() {
if since_last < kick_threshold || Self::candidates().len() <= T::MinCandidates::get() {

Why are you reading candidates here but also getting candidates from the input params of this function?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

so the candidates input does not get changed, it gets at the end collected into new_candidates, so if 5 people get removed, it does not know that, however the global candidates is tracking this, so it would for each candidate have the current knowledge of how many are left after the previous have been kicked

JesseAbram and others added 2 commits June 17, 2021 12:29
Co-authored-by: Shawn Tabrizi <shawntabrizi@gmail.com>
Co-authored-by: Shawn Tabrizi <shawntabrizi@gmail.com>
@@ -127,6 +130,12 @@ pub mod pallet {
/// This does not take into account the invulnerables.
type MaxCandidates: Get<u32>;

/// Minimum number of candidates that we should have. This is used for disaster recovery.
///
/// This does not take into account the invulnerables.
Copy link
Member

@shawntabrizi shawntabrizi Jun 17, 2021

Choose a reason for hiding this comment

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

You are saying this count is the number of people required not including any existing invulnerables?

I think that is over doing it. Invulnerables existing should satisfy the requirement for a minimum number of collators.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I agree in theory but invulnerables can be removed all at once (through a permissioned call) I was thinking this would be more of a assume invulnerables would be removed soon thing would be an easier transition, but open to changing

Copy link
Contributor

Choose a reason for hiding this comment

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

Invulnerables should eventually be removed and by then minimum number of collators will be super useful

@@ -323,7 +333,7 @@ pub mod pallet {
#[pallet::weight(T::WeightInfo::leave_intent(T::MaxCandidates::get()))]
pub fn leave_intent(origin: OriginFor<T>) -> DispatchResultWithPostInfo {
let who = ensure_signed(origin)?;

ensure!(Self::candidates().len() as u32 > T::MinCandidates::get(), Error::<T>::TooFewCandidates);
Copy link
Member

Choose a reason for hiding this comment

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

shouldn't this logic be in try_remove_candidate?

Else it may not be checked everywhere that this is happening correctly.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I had originally looked at that, but try_remove_candidates is used in kick_candidates and that would track two items, the candidates array and the current candidates to be accumulated as collators. So if one failed while the other passed they would not track each other correctly. So it was either rewrite the function, or add this here, this was less code and I don't see how this would not cause it to track properly.

@JesseAbram JesseAbram merged commit 6c688ce into master Jun 22, 2021
@JesseAbram JesseAbram deleted the jesse-collator-kick-check branch June 22, 2021 16:59
chevdor pushed a commit to chevdor/cumulus that referenced this pull request Jun 24, 2021
* min collator check

* change statemint/mine min candidates

* Ci pass

* Update pallets/collator-selection/src/lib.rs

Co-authored-by: Shawn Tabrizi <shawntabrizi@gmail.com>

* Update pallets/collator-selection/src/lib.rs

Co-authored-by: Shawn Tabrizi <shawntabrizi@gmail.com>

* Apply suggestions from code review

* build fixes

* add error messages to errors

* added validator register check

Co-authored-by: Shawn Tabrizi <shawntabrizi@gmail.com>
slumber pushed a commit that referenced this pull request Sep 1, 2021
* min collator check

* change statemint/mine min candidates

* Ci pass

* Update pallets/collator-selection/src/lib.rs

Co-authored-by: Shawn Tabrizi <shawntabrizi@gmail.com>

* Update pallets/collator-selection/src/lib.rs

Co-authored-by: Shawn Tabrizi <shawntabrizi@gmail.com>

* Apply suggestions from code review

* build fixes

* add error messages to errors

* added validator register check

Co-authored-by: Shawn Tabrizi <shawntabrizi@gmail.com>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants