14 releases (major breaking)

new 13.0.0 Apr 9, 2024
12.0.0 Mar 18, 2024
11.0.0 Feb 26, 2024
10.0.0 Feb 13, 2024
0.0.0 Nov 21, 2022

#743 in Magic Beans

Download history 86/week @ 2023-12-21 271/week @ 2023-12-28 1032/week @ 2024-01-04 549/week @ 2024-01-11 349/week @ 2024-01-18 488/week @ 2024-01-25 234/week @ 2024-02-01 535/week @ 2024-02-08 1104/week @ 2024-02-15 1719/week @ 2024-02-22 874/week @ 2024-02-29 424/week @ 2024-03-07 821/week @ 2024-03-14 920/week @ 2024-03-21 727/week @ 2024-03-28 458/week @ 2024-04-04

2,993 downloads per month
Used in 34 crates (22 directly)

Apache-2.0

2MB
40K SLoC

License: Apache-2.0


lib.rs:

Collator Selection pallet.

A pallet to manage collators in a parachain.

Overview

The Collator Selection pallet manages the collators of a parachain. Collation is not a secure activity and this pallet does not implement any game-theoretic mechanisms to meet BFT safety assumptions of the chosen set.

Terminology

  • Collator: A parachain block producer.
  • Bond: An amount of Balance reserved for candidate registration.
  • Invulnerable: An account guaranteed to be in the collator set.

Implementation

The final Collators are aggregated from two individual lists:

  1. Invulnerables: a set of collators appointed by governance. These accounts will always be collators.
  2. CandidateList: these are candidates to the collation task and may or may not be elected as a final collator.

The current implementation resolves congestion of CandidateList through a simple auction mechanism. Candidates bid for the collator slots and at the end of the session, the auction ends and the top candidates are selected to become collators. The number of selected candidates is determined by the value of DesiredCandidates.

Before the list reaches full capacity, candidates can register by placing the minimum bond through register_as_candidate. Then, if an account wants to participate in the collator slot auction, they have to replace an existing candidate by placing a greater deposit through take_candidate_slot. Existing candidates can increase their bids through update_bond.

At any point, an account can take the place of another account in the candidate list if they put up a greater deposit than the target. While new joiners would like to deposit as little as possible to participate in the auction, the replacement threat incentivizes candidates to bid as close to their budget as possible in order to avoid being replaced.

Candidates which are not on "winning" slots in the list can also decrease their deposits through update_bond, but candidates who are on top slots and try to decrease their deposits will fail in order to enforce auction mechanics and have meaningful bids.

Candidates will not be allowed to get kicked or leave_intent if the total number of collators would fall below MinEligibleCollators. This is to ensure that some collators will always exist, i.e. someone is eligible to produce a block.

When a new session starts, candidates with the highest deposits will be selected in order until the desired number of collators is reached. Candidates can increase or decrease their deposits between sessions in order to ensure they receive a slot in the collator list.

Rewards

The Collator Selection pallet maintains an on-chain account (the "Pot"). In each block, the collator who authored it receives:

  • Half the value of the Pot.
  • Half the value of the transaction fees within the block. The other half of the transaction fees are deposited into the Pot.

To initiate rewards, an ED needs to be transferred to the pot address.

Note: Eventually the Pot distribution may be modified as discussed in this issue.

Dependencies

~19–33MB
~543K SLoC