This repository has been archived by the owner on Nov 15, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
guide: collator networking & subsystems (#1452)
* Do a small write-up on collation-generation * preamble to collator protocol * notes on protocol * collation-generation: point to collator protocol * fix missing bracket * expand on collator protocol wire protocol * add a couple more sentences * expand on requests some more * go higher level * network bridge: note peerset * note peer-set = validation for protocols * add `ConnectToValidators` message * use ConnectToValidators in collator protocol * typo * remove references to sentry nodes
- Loading branch information
Showing
11 changed files
with
228 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 0 additions & 9 deletions
9
roadmap/implementers-guide/src/node/collators/collation-distribution.md
This file was deleted.
Oops, something went wrong.
31 changes: 29 additions & 2 deletions
31
roadmap/implementers-guide/src/node/collators/collation-generation.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,36 @@ | ||
# Collation Generation | ||
|
||
> TODO | ||
The collation generation subsystem is executed on collator nodes and produces candidates to be distributed to validators. If configured to produce collations for a para, it produces collations and then feeds them to the [Collator Protocol][CP] subsystem, which handles the networking. | ||
|
||
## Protocol | ||
|
||
Input: None | ||
|
||
Output: CollationDistributionMessage | ||
|
||
## Functionality | ||
|
||
## Jobs, if any | ||
The process of generating a collation for a parachain is very parachain-specific. As such, the details of how to do so are left beyond the scope of this description. The subsystem should be implemented as an abstract wrapper, which is aware of this configuration: | ||
|
||
```rust | ||
struct CollationGenerationConfig { | ||
key: CollatorPair, | ||
collation_producer: Fn(params) -> async (HeadData, Vec<UpwardMessage>, PoV), | ||
} | ||
``` | ||
|
||
The configuration should be optional, to allow for the case where the node is not run with the capability to collate. | ||
|
||
On `ActiveLeavesUpdate`: | ||
* If there is no collation generation config, ignore. | ||
* Otherwise, for each `activated` head in the update: | ||
* Determine if the para is scheduled or is next up on any occupied core by fetching the `availability_cores` Runtime API. | ||
* Determine an occupied core assumption to make about the para. The simplest thing to do is to always assume that if the para occupies a core, that the candidate will become available. Further on, this might be determined based on bitfields seen or validator requests. | ||
* Use the Runtime API subsystem to fetch the global validation data and local validation data. | ||
* Construct validation function params based on validation data. | ||
* Invoke the `collation_producer`. | ||
* Construct a `CommittedCandidateReceipt` using the outputs of the `collation_producer` and signing with the `key`. | ||
* Dispatch a [`CollatorProtocolMessage`][CPM]`::DistributeCollation(receipt, pov)`. | ||
|
||
[CP]: collator-protocol.md | ||
[CPM]: ../../types/overseer-protocol.md#collatorprotocolmessage |
133 changes: 133 additions & 0 deletions
133
roadmap/implementers-guide/src/node/collators/collator-protocol.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,133 @@ | ||
# Collator Protocol | ||
|
||
The Collator Protocol implements the network protocol by which collators and validators communicate. It is used by collators to distribute collations to validators and used by validators to accept collations by collators. | ||
|
||
Collator-to-Validator networking is more difficult than Validator-to-Validator networking because the set of possible collators for any given para is unbounded, unlike the validator set. Validator-to-Validator networking protocols can easily be implemented as gossip because the data can be bounded, and validators can authenticate each other by their `PeerId`s for the purposes of instantiating and accepting connections. | ||
|
||
Since, at least at the level of the para abstraction, the collator-set for any given para is unbounded, validators need to make sure that they are receiving connections from capable and honest collators and that their bandwidth and time are not being wasted by attackers. Communicating across this trust-boundary is the most difficult part of this subsystem. | ||
|
||
Validation of candidates is a heavy task, and furthermore, the [`PoV`][PoV] itself is a large piece of data. Empirically, `PoV`s are on the order of 10MB. | ||
|
||
> TODO: note the incremental validation function Ximin proposes at https://github.com/paritytech/polkadot/issues/1348 | ||
As this network protocol serves as a bridge between collators and validators, it communicates primarily with one subsystem on behalf of each. As a collator, this will receive messages from the [`CollationGeneration`][CG] subsystem. As a validator, this will communicate with the [`CandidateBacking`][CB] subsystem. | ||
|
||
## Protocol | ||
|
||
Input: [`CollatorProtocolMessage`][CPM] | ||
|
||
Output: | ||
- [`RuntimeApiMessage`][RAM] | ||
- [`NetworkBridgeMessage`][NBM] | ||
|
||
## Functionality | ||
|
||
This network protocol uses the `Collation` peer-set of the [`NetworkBridge`][NB]. | ||
|
||
```rust | ||
type RequestId = u64; | ||
|
||
enum WireMessage { | ||
/// Declare the intent to advertise collations under a collator ID. | ||
Declare(CollatorId), | ||
/// Advertise a collation to a validator. Can only be sent once the peer has declared | ||
/// that they are a collator with given ID. | ||
AdvertiseCollation(Hash, ParaId), | ||
/// Request the advertised collation at that relay-parent. | ||
RequestCollation(RequestId, Hash, ParaId), | ||
/// A requested collation. | ||
Collation(RequestId, CandidateReceipt, PoV), | ||
} | ||
``` | ||
|
||
Since this protocol functions both for validators and collators, it is easiest to go through the protocol actions for each of them separately. | ||
|
||
Validators and collators. | ||
```dot process | ||
digraph { | ||
c1 [shape=MSquare, label="Collator 1"]; | ||
c2 [shape=MSquare, label="Collator 2"]; | ||
v1 [shape=MSquare, label="Validator 1"]; | ||
v2 [shape=MSquare, label="Validator 2"]; | ||
c1 -> v1; | ||
c1 -> v2; | ||
c2 -> v2; | ||
} | ||
``` | ||
|
||
### Collators | ||
|
||
It is assumed that collators are only collating on a single parachain. Collations are generated by the [Collation Generation][CG] subsystem. We will keep up to one local collation per relay-parent, based on `DistributeCollation` messages. If the para is not scheduled or next up on any core, at the relay-parent, or the relay-parent isn't in the active-leaves set, we ignore the message as it must be invalid in that case - although this indicates a logic error elsewhere in the node. | ||
|
||
We keep track of the Para ID we are collating on as a collator. This starts as `None`, and is updated with each `CollateOn` message received. If the `ParaId` of a collation requested to be distributed does not match the one we expect, we ignore the message. | ||
|
||
As with most other subsystems, we track the active leaves set by following `ActiveLeavesUpdate` signals. | ||
|
||
For the purposes of actually distributing a collation, we need to be connected to the validators who are interested in collations on that `ParaId` at this point in time. We assume that there is a discovery API for connecting to a set of validators. | ||
|
||
> TODO: design & expose the discovery API not just for connecting to such peers but also to determine which of our current peers are validators. | ||
As seen in the [Scheduler Module][SCH] of the runtime, validator groups are fixed for an entire session and their rotations across cores are predictable. Collators will want to do these things when attempting to distribute collations at a given relay-parent: | ||
* Determine which core the para collated-on is assigned to. | ||
* Determine the group on that core and the next group on that core. | ||
* Issue a discovery request for the validators of the current group and the next group with[`NetworkBridgeMessage`][NBM]`::ConnectToValidators`. | ||
|
||
Once connected to the relevant peers for the current group assigned to the core (transitively, the para), advertise the collation to any of them which advertise the relay-parent in their view (as provided by the [Network Bridge][NB]). If any respond with a request for the full collation, provide it. Upon receiving a view update from any of these peers which includes a relay-parent for which we have a collation that they will find relevant, advertise the collation to them if we haven't already. | ||
|
||
### Validators | ||
|
||
On the validator side of the protocol, validators need to accept incoming connections from collators. They should keep some peer slots open for accepting new speculative connections from collators and should disconnect from collators who are not relevant. | ||
|
||
```dot process | ||
digraph G { | ||
label = "Declaring, advertising, and providing collations"; | ||
labelloc = "t"; | ||
rankdir = LR; | ||
subgraph cluster_collator { | ||
rank = min; | ||
label = "Collator"; | ||
graph[style = border, rank = min]; | ||
c1, c2 [label = ""]; | ||
} | ||
subgraph cluster_validator { | ||
rank = same; | ||
label = "Validator"; | ||
graph[style = border]; | ||
v1, v2 [label = ""]; | ||
} | ||
c1 -> v1 [label = "Declare and advertise"]; | ||
v1 -> c2 [label = "Request"]; | ||
c2 -> v2 [label = "Provide"]; | ||
v2 -> v2 [label = "Note Good/Bad"]; | ||
} | ||
``` | ||
|
||
When peers connect to us, they can `Declare` that they represent a collator with given public key. Once they've declared that, they can begin to send advertisements of collations. The peers should not send us any advertisements for collations that are on a relay-parent outside of our view. | ||
|
||
The protocol tracks advertisements received and the source of the advertisement. The advertisement source is the `PeerId` of the peer who sent the message. We accept one advertisement per collator per source per relay-parent. | ||
|
||
As a validator, we will handle requests from other subsystems to fetch a collation on a specific `ParaId` and relay-parent. These requests are made with the [`CollatorProtocolMessage`][CPM]`::FetchCollation`. To do so, we need to first check if we have already gathered a collation on that `ParaId` and relay-parent. If not, we need to select one of the advertisements and issue a request for it. If we've already issued a request, we shouldn't issue another one until the first has returned. | ||
|
||
When acting on an advertisement, we issue a `WireMessage::RequestCollation`. If the request times out, we need to note the collator as being unreliable and reduce its priority relative to other collators. And then make another request - repeat until we get a response or the chain has moved on. | ||
|
||
As a validator, once the collation has been fetched some other subsystem will inspect and do deeper validation of the collation. The subsystem will report to this subsystem with a [`CollatorProtocolMessage`][CPM]`::ReportCollator` or `NoteGoodCollation` message. In that case, if we are connected directly to the collator, we apply a cost to the `PeerId` associated with the collator and potentially disconnect or blacklist it. | ||
|
||
[PoV]: ../../types/availability.md#proofofvalidity | ||
[CPM]: ../../types/overseer-protocol.md#collatorprotocolmessage | ||
[CG]: collation-generation.md | ||
[CB]: ../backing/candidate-backing.md | ||
[NB]: ../utility/network-bridge.md | ||
[CBM]: ../../types/overseer-protocol.md#candidatebackingmesage | ||
[RAM]: ../../types/overseer-protocol.md#runtimeapimessage | ||
[NBM]: ../../types/overseer-protocol.md#networkbridgemessage | ||
[SCH]: ../../runtime/scheduler.md |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters