-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Breakdown the Router module on Dmp, Ump, Hrmp modules #1939
Changes from 1 commit
2915d79
5195118
08fc261
6bdf541
a97fc34
c88bdc9
a870f71
8e37d00
536a914
eb43e4c
3800729
2069f6e
64aa82c
d205269
02f65ac
da1e56e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| # DMP Module | ||
|
|
||
| ## Storage | ||
|
|
||
| General storage entries | ||
|
|
||
| ```rust | ||
| /// Paras that are to be cleaned up at the end of the session. | ||
| /// The entries are sorted ascending by the para id. | ||
| OutgoingParas: Vec<ParaId>; | ||
| ``` | ||
|
|
||
| Storage layout required for implementation of DMP. | ||
|
|
||
| ```rust | ||
| /// The downward messages addressed for a certain para. | ||
| DownwardMessageQueues: map ParaId => Vec<InboundDownwardMessage>; | ||
| /// A mapping that stores the downward message queue MQC head for each para. | ||
| /// | ||
| /// Each link in this chain has a form: | ||
| /// `(prev_head, B, H(M))`, where | ||
| /// - `prev_head`: is the previous head hash or zero if none. | ||
| /// - `B`: is the relay-chain block number in which a message was appended. | ||
| /// - `H(M)`: is the hash of the message being appended. | ||
| DownwardMessageQueueHeads: map ParaId => Hash; | ||
| ``` | ||
|
|
||
| ## Initialization | ||
|
|
||
| No initialization routine runs for this module. | ||
|
|
||
| ## Routines | ||
|
|
||
| Candidate Acceptance Function: | ||
|
|
||
| * `check_processed_downward_messages(P: ParaId, processed_downward_messages)`: | ||
pepyakin marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| 1. Checks that `DownwardMessageQueues` for `P` is at least `processed_downward_messages` long. | ||
| 1. Checks that `processed_downward_messages` is at least 1 if `DownwardMessageQueues` for `P` is not empty. | ||
|
|
||
| Candidate Enactment: | ||
|
|
||
| * `prune_dmq(P: ParaId, processed_downward_messages)`: | ||
| 1. Remove the first `processed_downward_messages` from the `DownwardMessageQueues` of `P`. | ||
|
|
||
| Utility routines. | ||
|
|
||
| `queue_downward_message(P: ParaId, M: DownwardMessage)`: | ||
| 1. Check if the size of `M` exceeds the `config.max_downward_message_size`. If so, return an error. | ||
| 1. Wrap `M` into `InboundDownwardMessage` using the current block number for `sent_at`. | ||
| 1. Obtain a new MQC link for the resulting `InboundDownwardMessage` and replace `DownwardMessageQueueHeads` for `P` with the resulting hash. | ||
| 1. Add the resulting `InboundDownwardMessage` into `DownwardMessageQueues` for `P`. | ||
|
|
||
| ## Session Change | ||
|
|
||
| 1. Drain `OutgoingParas`. For each `P` happened to be in the list: | ||
| 1. Remove all `DownwardMessageQueues` of `P`. | ||
| 1. Remove `DownwardMessageQueueHeads` for `P`. | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,98 @@ | ||
| # UMP Module | ||
pepyakin marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| ## Storage | ||
|
|
||
| General storage entries | ||
|
|
||
| ```rust | ||
| /// Paras that are to be cleaned up at the end of the session. | ||
| /// The entries are sorted ascending by the para id. | ||
| OutgoingParas: Vec<ParaId>; | ||
| ``` | ||
|
|
||
| Storage related to UMP | ||
|
|
||
| ```rust | ||
| /// The messages waiting to be handled by the relay-chain originating from a certain parachain. | ||
| /// | ||
| /// Note that some upward messages might have been already processed by the inclusion logic. E.g. | ||
| /// channel management messages. | ||
| /// | ||
| /// The messages are processed in FIFO order. | ||
| RelayDispatchQueues: map ParaId => Vec<UpwardMessage>; | ||
| /// Size of the dispatch queues. Caches sizes of the queues in `RelayDispatchQueue`. | ||
| /// | ||
| /// First item in the tuple is the count of messages and second | ||
| /// is the total length (in bytes) of the message payloads. | ||
| /// | ||
| /// Note that this is an auxilary mapping: it's possible to tell the byte size and the number of | ||
| /// messages only looking at `RelayDispatchQueues`. This mapping is separate to avoid the cost of | ||
| /// loading the whole message queue if only the total size and count are required. | ||
| /// | ||
| /// Invariant: | ||
| /// - The set of keys should exactly match the set of keys of `RelayDispatchQueues`. | ||
| RelayDispatchQueueSize: map ParaId => (u32, u32); // (num_messages, total_bytes) | ||
| /// The ordered list of `ParaId`s that have a `RelayDispatchQueue` entry. | ||
| /// | ||
| /// Invariant: | ||
| /// - The set of items from this vector should be exactly the set of the keys in | ||
| /// `RelayDispatchQueues` and `RelayDispatchQueueSize`. | ||
| NeedsDispatch: Vec<ParaId>; | ||
| /// This is the para that gets dispatched first during the next upward dispatchable queue | ||
| /// execution round. | ||
| /// | ||
| /// Invariant: | ||
| /// - If `Some(para)`, then `para` must be present in `NeedsDispatch`. | ||
| NextDispatchRoundStartWith: Option<ParaId>; | ||
| ``` | ||
|
|
||
|
|
||
| ## Initialization | ||
|
|
||
| No initialization routine runs for this module. | ||
|
|
||
| ## Routines | ||
|
|
||
| Candidate Acceptance Function: | ||
|
|
||
| * `check_upward_messages(P: ParaId, Vec<UpwardMessage>`): | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should it though? Isn't it already clear that when we say "the messages" it refers to those? I am not entirely against that, but in that case we should probably address it throughout the whole doc |
||
| 1. Checks that there are at most `config.max_upward_message_num_per_candidate` messages. | ||
| 1. Checks that no message exceeds `config.max_upward_message_size`. | ||
| 1. Verify that `RelayDispatchQueueSize` for `P` has enough capacity for the messages | ||
|
|
||
| Candidate Enactment: | ||
|
|
||
| * `enact_upward_messages(P: ParaId, Vec<UpwardMessage>)`: | ||
| 1. Process each upward message `M` in order: | ||
| 1. Append the message to `RelayDispatchQueues` for `P` | ||
| 1. Increment the size and the count in `RelayDispatchQueueSize` for `P`. | ||
| 1. Ensure that `P` is present in `NeedsDispatch`. | ||
|
|
||
| The following routine is intended to be called in the same time when `Paras::schedule_para_cleanup` is called. | ||
|
|
||
| `schedule_para_cleanup(ParaId)`: | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. again, the same logic as here |
||
| 1. Add the para into the `OutgoingParas` vector maintaining the sorted order. | ||
|
|
||
| The following routine is meant to execute pending entries in upward message queues. This function doesn't fail, even if | ||
| dispatcing any of individual upward messages returns an error. | ||
|
|
||
| `process_pending_upward_messages()`: | ||
| 1. Initialize a cumulative weight counter `T` to 0 | ||
| 1. Iterate over items in `NeedsDispatch` cyclically, starting with `NextDispatchRoundStartWith`. If the item specified is `None` start from the beginning. For each `P` encountered: | ||
| 1. Dequeue the first upward message `D` from `RelayDispatchQueues` for `P` | ||
| 1. Decrement the size of the message from `RelayDispatchQueueSize` for `P` | ||
| 1. Delegate processing of the message to the runtime. The weight consumed is added to `T`. | ||
| 1. If `T >= config.preferred_dispatchable_upward_messages_step_weight`, set `NextDispatchRoundStartWith` to `P` and finish processing. | ||
| 1. If `RelayDispatchQueues` for `P` became empty, remove `P` from `NeedsDispatch`. | ||
| 1. If `NeedsDispatch` became empty then finish processing and set `NextDispatchRoundStartWith` to `None`. | ||
| > NOTE that in practice we would need to approach the weight calculation more thoroughly, i.e. incorporate all operations | ||
| > that could take place on the course of handling these upward messages. | ||
|
|
||
| ## Session Change | ||
|
|
||
| 1. Drain `OutgoingParas`. For each `P` happened to be in the list:. | ||
| 1. Remove `RelayDispatchQueueSize` of `P`. | ||
| 1. Remove `RelayDispatchQueues` of `P`. | ||
| 1. Remove `P` if it exists in `NeedsDispatch`. | ||
| 1. If `P` is in `NextDispatchRoundStartWith`, then reset it to `None` | ||
| - Note that if we don't remove the open/close requests since they are going to die out naturally at the end of the session. | ||
Uh oh!
There was an error while loading. Please reload this page.