Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Prev Previous commit
Next Next commit
Add the router.md itself
  • Loading branch information
montekki committed Jun 17, 2020
commit 46fa5d14c5f7d8c7ded9c58ad6c868110e312bbc
28 changes: 28 additions & 0 deletions roadmap/implementors-guide/src/runtime/router.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Router Module

The Router module is responsible for storing and dispatching Upwards and Downwards messages from and to parachains respectively. It is intended to later handle the XCMP logic as well.

## Storage

Storage layout:

```rust

/// Messages ready to be dispatched onto the relay chain.
/// This is subject to `max_upwards_queue_count` and
///`watermark_queue_size` from `HostConfiguration`.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
///`watermark_queue_size` from `HostConfiguration`.
/// `watermark_queue_size` from `HostConfiguration`.

RelayDispatchQueues: map ParaId => Vec<UpwardMessage>;
Copy link
Contributor

Choose a reason for hiding this comment

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

I wonder if we should give the definition for UpwardMessage somewhere?

/// 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.
RelayDispatchQueueSize: map ParaId => (u32, u32);
/// The ordered list of `ParaId`s that have a `RelayDispatchQueue` entry.
NeedsDispatch: Vec<ParaId>;
```

## Routines

* `queue_upward_messages(AttestedCandidate)`:
1. Updates `NeedsDispatch`, and enqueues upward messages into `RelayDispatchQueue` and modifies the respective entry in `RelayDispatchQueueSize`.
* `dispatch_upward_messages(ParaId)`:
Copy link
Contributor

Choose a reason for hiding this comment

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

cc @pepyakin (as we talked about this in DM)

Given that NeedsDispatch already contains all ParaIds, I'm not sure what the ParaId parameter here is for.

This seems like a function that should be called once per block - either in on_initialize, on_finalize, or at the end of InclusionInherent::inclusion. I'd favor the latter 2 as it can immediately dispatch calls by enacted candidate blocks in many cases, leading to lower minimum latency.

1. If `NeedsDispatch` contains an entry passed as an input parameter start dispatching messages from it's respective entry in `RelayDispatchQueues`. The dispatch is done in the FIFO order and it drains the queue and removes it from `RelayDispatchQueues`.