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

impl guide: Update Collator Generation #7250

Merged
merged 5 commits into from
May 24, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions node/collation-generation/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,17 @@
// along with Polkadot. If not, see <http://www.gnu.org/licenses/>.

//! The collation generation subsystem is the interface between polkadot and the collators.
//!
//! # Protocol
//!
//! On every `ActiveLeavesUpdate`:
//!
//! * If there is no collation generation config, ignore.
//! * Otherwise, for each `activated` head in the update:
//! * Determine if the para is scheduled on any core by fetching the `availability_cores` Runtime API.
//! * Use the Runtime API subsystem to fetch the full validation data.
//! * Invoke the `collator`, and use its outputs to produce a [`CandidateReceipt`], signed with the configuration's `key`.
//! * Dispatch a [`CollatorProtocolMessage::DistributeCollation`](receipt, pov)`.
#![deny(missing_docs)]

Expand Down
3 changes: 3 additions & 0 deletions roadmap/implementers-guide/src/node/collators/README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# Collators

Collators are special nodes which bridge a parachain to the relay chain. They are simultaneously full nodes of the parachain, and at least light clients of the relay chain. Their overall contribution to the system is the generation of Proofs of Validity for parachain candidates.

The **Collation Generation** subsystem triggers collators to produce collations
and then forwards them to **Collator Protocol** to circulate to validators.
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,32 @@ The collation generation subsystem is executed on collator nodes and produces ca

## Protocol

Input: `CollationGenerationMessage`
Collation generation for Parachains currently works in the following way:

```rust
enum CollationGenerationMessage {
Initialize(CollationGenerationConfig),
}
```
1. A new relay chain block is imported.
2. The collation generation subsystem checks if the core associated to
the parachain is free and if yes, continues.
3. Collation generation calls our collator callback to generate a PoV.
4. Authoring logic determines if the current node should build a PoV.
5. Build new PoV and give it back to collation generation.

## Messages

### Incoming

No more than one initialization message should ever be sent to the collation generation subsystem.
- `ActiveLeaves`
- Notification of a change in the set of active leaves.
- Triggers collation generation procedure outlined in "Protocol" section.
- `CollationGenerationMessage::Initialize`
- Initializes the subsystem. Carries a config.
- No more than one initialization message should ever be sent to the collation
generation subsystem.
- Sent by a collator to initialize this subsystem.

Output: `CollationDistributionMessage`
### Outgoing

- `CollatorProtocolMessage::DistributeCollation`
- Provides a generated collation to distribute to validators.

## Functionality

Expand Down Expand Up @@ -94,15 +109,42 @@ pub struct CollationGenerationConfig {

The configuration should be optional, to allow for the case where the node is not run with the capability to collate.

On `ActiveLeavesUpdate`:
### Summary in plain English

- **Collation (output of a collator)**

- Contains the PoV (proof to verify the state transition of the
parachain) and other data.

- **Collation result**

- Contains the collation, and an optional result sender for a
collation-seconded signal.

- **Collation seconded signal**

- The signal that is returned when a collation was seconded by a
validator.

- **Collation function**

- Called with the relay chain block the parablock will be built on top
of.
- Called with the validation data.
- Provides information about the state of the parachain on the relay
chain.

- **Collation generation config**

- Contains collator's authentication key, collator function, and
parachain ID.

## Glossary

- *Slot:* Time is divided into discrete slots. Each validator in the validator
set produces a verifiable random value, using a VRF, per slot. If below a
threshold, this allows the validator to author a new block for that slot.
Copy link
Contributor

Choose a reason for hiding this comment

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

leftover


* If there is no collation generation config, ignore.
* Otherwise, for each `activated` head in the update:
* Determine if the para is scheduled on any core by fetching the `availability_cores` Runtime API.
* Determine an occupied core assumption to make about the para. Scheduled cores can make `OccupiedCoreAssumption::Free`.
* Use the Runtime API subsystem to fetch the full validation data.
* Invoke the `collator`, and use its outputs to produce a `CandidateReceipt`, signed with the configuration's `key`.
* Dispatch a [`CollatorProtocolMessage`][CPM]`::DistributeCollation(receipt, pov)`.
- *VRF:* Verifiable random function.

[CP]: collator-protocol.md
[CPM]: ../../types/overseer-protocol.md#collatorprotocolmessage