Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Closed
Changes from all 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
21 changes: 20 additions & 1 deletion roadmap/implementors-guide/src/runtime/paras.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ The Paras module is responsible for storing information on parachains and parath

It's also responsible for managing parachain validation code upgrades as well as maintaining availability of old parachain code and its pruning.

One other important thing happening in this module is dispatching of the `UpwardMessage`s.

## Storage

Utility structs:
Expand Down Expand Up @@ -89,6 +91,14 @@ UpcomingParas: Vec<ParaId>;
UpcomingParasGenesis: map ParaId => Option<ParaGenesisArgs>;
/// Paras that are to be cleaned up at the end of the session.
OutgoingParas: Vec<ParaId>;

/// Messages ready to be dispatched onto the relay chain.
RelayDispatchQueue: map ParaId => Vec<UpwardMessage>;
/// Cached sizes of the dispached queues. (msg_count, total_byte_size).
/// Exists for optimization purposes to avoid costly decoding.
RelayDispatchQueueSize: map ParaId => (u32, u32);
/// The ordered list of ParaIds that have a `RelayDispatchQueue` entry.
NeedsDispatch: Vec<ParaId>;
```

## Session Change
Expand All @@ -107,10 +117,19 @@ OutgoingParas: Vec<ParaId>;
* `schedule_para_initialize(ParaId, ParaGenesisArgs)`: schedule a para to be initialized at the next session.
* `schedule_para_cleanup(ParaId)`: schedule a para to be cleaned up at the next session.
* `schedule_code_upgrade(ParaId, ValidationCode, expected_at: BlockNumber)`: Schedule a future code upgrade of the given parachain, to be applied after inclusion of a block of the same parachain executed in the context of a relay-chain block with number >= `expected_at`.
* `note_new_head(ParaId, HeadData, BlockNumber)`: note that a para has progressed to a new head, where the new head was executed in the context of a relay-chain block with given number. This will apply pending code upgrades based on the block number provided.
* `note_new_head(ParaId, HeadData, BlockNumber)`: note that a para has progressed to a new head, where the new head was executed in the context of a relay-chain block with given number. This will apply pending code upgrades based on the block number provided. Also this will dispatch messages from `RelayDispatchQueue` accordingly to the limits.
* `validation_code_at(ParaId, at: BlockNumber, assume_intermediate: Option<BlockNumber>)`: Fetches the validation code to be used when validating a block in the context of the given relay-chain height. A second block number parameter may be used to tell the lookup to proceed as if an intermediate parablock has been included at the given relay-chain height. This may return past, current, or (with certain choices of `assume_intermediate`) future code. `assume_intermediate`, if provided, must be before `at`. If the validation code has been pruned, this will return `None`.
* `is_parathread(ParaId) -> bool`: Returns true if the para ID references any live parathread.

## New heads and Upward Message routing.

`note_new_head` contains logic that should happen when a para progresses to a new head. This includes the routing of `Upward` messages. The messages for each parachain that need routing reside in a `RelayDispatchQueue` storage field that acts as a simple FIFO dispatch. The dispatch process is a limited by two constants:

* `MAX_QUEUE_COUNT` - Total number of messages allowed in the parachain -> relay-chain message queue
* `WATERMARK_QUEUE_SIZE` - Total size of messages allowed in the parachain -> relay-chain message queue before which no further messages may be added to it.

In other words, if the queue contains more messages or the total message size in the queue is greater than these contants, `note_new_head` whill fail on the stage of checking the new head.
Copy link
Contributor

Choose a reason for hiding this comment

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

note_new_head happens after availability, whereas we need this check to happen before backing. It's not clear what should happen if note_new_head is fallible - so a candidate could be backed, become available, but then get dropped from the chain because of a queue size check that should have been done earlier?

So it's clear that this size check should be done as part of the process_candidates function of the Inclusion module.

But also, this logic doesn't belong in the paras module. What does it have to do with the head of the chain and validation code upgrades? This logic should go in a new Routing module which will handle upwards/downwards messages and later XCMP logic


## Finalization

No finalization routine runs for this module.