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

Session Delayed Para Changes / Actions Queue #2406

Merged
merged 48 commits into from
Feb 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
ceb0bee
initial implementation of lifecycles and upgrades
shawntabrizi Jan 30, 2021
ca2e930
clean up a bit
shawntabrizi Jan 30, 2021
f03cf68
fix doc comment
shawntabrizi Jan 31, 2021
8ab27f0
more rigid lifecycle checks
shawntabrizi Jan 31, 2021
af59148
include paras which are transitioning, and lifecycle query
shawntabrizi Jan 31, 2021
a154cf8
format guide
shawntabrizi Jan 31, 2021
bfc96a1
update api
shawntabrizi Jan 31, 2021
fdde35f
update guide
shawntabrizi Jan 31, 2021
623746c
explicit outgoing state, fix genesis
shawntabrizi Jan 31, 2021
2eb5e19
handle outgoing with transitioning paras
shawntabrizi Feb 1, 2021
80c7b64
do not include transitioning paras in identifier
shawntabrizi Feb 1, 2021
ee07f80
Update roadmap/implementers-guide/src/runtime/paras.md
gavofyork Feb 2, 2021
ea62e00
Update roadmap/implementers-guide/src/runtime/paras.md
gavofyork Feb 2, 2021
1289e39
Update roadmap/implementers-guide/src/runtime/paras.md
gavofyork Feb 2, 2021
c26b42e
Apply suggestions from code review
gavofyork Feb 2, 2021
26d6c99
Use matches macro
gavofyork Feb 2, 2021
4f26659
Correct terms
gavofyork Feb 2, 2021
a785985
Apply suggestions from code review
gavofyork Feb 2, 2021
b2e9011
actions queue
shawntabrizi Feb 3, 2021
f56777c
Revert "actions queue"
shawntabrizi Feb 3, 2021
7455165
collapse onboarding state
shawntabrizi Feb 4, 2021
f63b087
starting actions queue
shawntabrizi Feb 4, 2021
45cc0c6
consolidate actions queue
shawntabrizi Feb 8, 2021
e1df6f7
schedule para initialize result
shawntabrizi Feb 8, 2021
7ebfa65
more actions queue for upgrade/downgrade
shawntabrizi Feb 8, 2021
077a550
clean up with fully implemented actions queue
shawntabrizi Feb 8, 2021
516d182
fix tests
shawntabrizi Feb 8, 2021
bf74d5f
fix scheduler tests
shawntabrizi Feb 8, 2021
53a42fa
fix hrmp tests
shawntabrizi Feb 9, 2021
b0a1444
Merge branch 'master' into shawntabrizi-para-session-delay
shawntabrizi Feb 9, 2021
c14b17e
fix test
shawntabrizi Feb 9, 2021
17b6128
doc fixes
shawntabrizi Feb 9, 2021
c3aa6ea
fix hrmp test w/ valid para
shawntabrizi Feb 9, 2021
3df71fe
Update paras.md
shawntabrizi Feb 9, 2021
27cb18e
fix paras registrar
shawntabrizi Feb 9, 2021
92d456f
Merge branch 'master' into shawntabrizi-para-session-delay
shawntabrizi Feb 9, 2021
8b724e5
Update propose_parachain.rs
shawntabrizi Feb 9, 2021
fd4bb23
Merge branch 'master' into shawntabrizi-para-session-delay
shawntabrizi Feb 15, 2021
9342f21
fix merge
shawntabrizi Feb 15, 2021
3fbaa20
Introduce "shared" module
shawntabrizi Feb 16, 2021
fd959ab
fix rococo build
shawntabrizi Feb 16, 2021
b340613
fix up and use shared
shawntabrizi Feb 16, 2021
e6b79e7
guide updates
shawntabrizi Feb 16, 2021
40b05a4
add shared config to common tests
shawntabrizi Feb 16, 2021
44fb36e
add shared to test-runtime
shawntabrizi Feb 16, 2021
9da4b9e
Merge branch 'master' into shawntabrizi-para-session-delay
shawntabrizi Feb 16, 2021
62cead5
remove println
shawntabrizi Feb 18, 2021
442f0fb
fix note
shawntabrizi Feb 18, 2021
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
4 changes: 4 additions & 0 deletions roadmap/implementers-guide/src/runtime/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,15 @@ There is some functionality of the relay chain relating to parachains that we al
We will split the logic of the runtime up into these modules:

* Initializer: manage initialization order of the other modules.
* Shared: manages shared storage and configurations for other modules.
* Configuration: manage configuration and configuration updates in a non-racy manner.
* Paras: manage chain-head and validation code for parachains and parathreads.
* Scheduler: manages parachain and parathread scheduling as well as validator assignments.
* Inclusion: handles the inclusion and availability of scheduled parachains and parathreads.
* Validity: handles secondary checks and dispute resolution for included, available parablocks.
* Hrmp: handles horizontal messages between paras.
* Ump: Handles upward messages from a para to the relay chain.
* Dmp: Handles downward messages from the relay chain to the para.

The [Initializer module](initializer.md) is special - it's responsible for handling the initialization logic of the other modules to ensure that the correct initialization order and related invariants are maintained. The other modules won't specify a on-initialize logic, but will instead expose a special semi-private routine that the initialization module will call. The other modules are relatively straightforward and perform the roles described above.

Expand Down
4 changes: 0 additions & 4 deletions roadmap/implementers-guide/src/runtime/inclusion.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,13 @@ PendingAvailabilityCommitments: map ParaId => CandidateCommitments;

/// The current validators, by their parachain session keys.
Validators: Vec<ValidatorId>;

/// The current session index.
CurrentSessionIndex: SessionIndex;
```

## Session Change

1. Clear out all candidates pending availability.
1. Clear out all validator bitfields.
1. Update `Validators` with the validators from the session change notification.
1. Update `CurrentSessionIndex` with the session index from the session change notification.

## Routines

Expand Down
71 changes: 31 additions & 40 deletions roadmap/implementers-guide/src/runtime/paras.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# Paras Module

The Paras module is responsible for storing information on parachains and parathreads. Registered
parachains and parathreads cannot change except at session boundaries. This is primarily to ensure
that the number and meaning of bits required for the availability bitfields does not change except at session
boundaries.
parachains and parathreads cannot change except at session boundaries and after at least a full
session has passed. This is primarily to ensure that the number and meaning of bits required for the
availability bitfields does not change except at session boundaries.

It's also responsible for managing parachain validation code upgrades as well as maintaining
availability of old parachain code and its pruning.
Expand Down Expand Up @@ -63,9 +63,9 @@ pub enum ParaLifecycle {
/// Para is a Parachain.
Parachain,
/// Para is a Parathread which is upgrading to a Parachain.
UpgradingToParachain,
UpgradingParathread,
/// Para is a Parachain which is downgrading to a Parathread.
DowngradingToParathread,
DowngradingParachain,
/// Parathread is being offboarded.
OutgoingParathread,
/// Parachain is being offboarded.
Expand All @@ -82,7 +82,7 @@ state of the para using the `ParaLifecycle` enum.
None Parathread Parachain
+ + +
| | |
| (Session Delay) | |
| (2 Session Delay) | |
| | |
+----------------------->+ |
| Onboarding | |
Expand All @@ -91,10 +91,10 @@ None Parathread Parachain
| Onboarding | |
| | |
| +------------------------->+
| | UpgradingToParachain |
| | UpgradingParathread |
| | |
| +<-------------------------+
| | DowngradingToParathread |
| | DowngradingParachain |
| | |
|<-----------------------+ |
| OutgoingParathread | |
Expand Down Expand Up @@ -137,38 +137,31 @@ PastCodePruning: Vec<(ParaId, BlockNumber)>;
FutureCodeUpgrades: map ParaId => Option<BlockNumber>;
/// The actual future code of a para.
FutureCode: map ParaId => Option<ValidationCode>;

/// Upcoming paras (chains and threads). These are only updated on session change. Corresponds to an
/// entry in the upcoming-genesis map. Ordered ascending by ParaId.
UpcomingParas: Vec<ParaId>;
/// The actions to perform during the start of a specific session index.
ActionsQueue: map SessionIndex => Vec<ParaId>;
/// Upcoming paras instantiation arguments.
UpcomingParasGenesis: map ParaId => Option<ParaGenesisArgs>;
/// Paras that are to be cleaned up at the end of the session. Ordered ascending by ParaId.
OutgoingParas: Vec<ParaId>;
/// Existing Parathreads that should upgrade to be a Parachain. Ordered ascending by ParaId.
UpcomingUpgrades: Vec<ParaId>;
/// Existing Parachains that should downgrade to be a Parathread. Ordered ascending by ParaId.
UpcomingDowngrades: Vec<ParaId>;
```

## Session Change

1. Clean up outgoing paras.
1. This means removing the entries under `Heads`, `ValidationCode`, `FutureCodeUpgrades`, and
`FutureCode`. An according entry should be added to `PastCode`, `PastCodeMeta`, and
`PastCodePruning` using the outgoing `ParaId` and removed `ValidationCode` value. This is
because any outdated validation code must remain available on-chain for a determined amount of
blocks, and validation code outdated by de-registering the para is still subject to that
invariant.
1. Apply all incoming paras by initializing the `Heads` and `ValidationCode` using the genesis
parameters.
1. Amend the `Parachains` list and `ParaLifecycle` to reflect changes in registered parachains.
1. Amend the `ParaLifecycle` set to reflect changes in registered parathreads.
1. Upgrade all parathreads that should become parachains, updating the `Parachains` list and
`ParaLifecycle`.
1. Downgrade all parachains that should become parathreads, updating the `Parachains` list and
`ParaLifecycle`.
1. Return list of outgoing paras to the initializer for use by other modules.
1. Execute all queued actions for paralifecycle changes:
1. Clean up outgoing paras.
1. This means removing the entries under `Heads`, `ValidationCode`, `FutureCodeUpgrades`, and
`FutureCode`. An according entry should be added to `PastCode`, `PastCodeMeta`, and
`PastCodePruning` using the outgoing `ParaId` and removed `ValidationCode` value. This is
because any outdated validation code must remain available on-chain for a determined amount
of blocks, and validation code outdated by de-registering the para is still subject to that
invariant.
1. Apply all incoming paras by initializing the `Heads` and `ValidationCode` using the genesis
parameters.
1. Amend the `Parachains` list and `ParaLifecycle` to reflect changes in registered parachains.
1. Amend the `ParaLifecycle` set to reflect changes in registered parathreads.
1. Upgrade all parathreads that should become parachains, updating the `Parachains` list and
`ParaLifecycle`.
1. Downgrade all parachains that should become parathreads, updating the `Parachains` list and
`ParaLifecycle`.
1. Return list of outgoing paras to the initializer for use by other modules.

## Initialization

Expand All @@ -179,11 +172,9 @@ UpcomingDowngrades: Vec<ParaId>;

* `schedule_para_initialize(ParaId, ParaGenesisArgs)`: Schedule a para to be initialized at the next
session. Noop if para is already registered in the system with some `ParaLifecycle`.
* `schedule_para_cleanup(ParaId)`: Schedule a para to be cleaned up at the next session.
* `schedule_parathread_upgrade(ParaId)`: Schedule a parathread to be upgraded to a parachain. Noop
if `ParaLifecycle` is not `Parathread`.
* `schedule_para_cleanup(ParaId)`: Schedule a para to be cleaned up after the next full session.
* `schedule_parathread_upgrade(ParaId)`: Schedule a parathread to be upgraded to a parachain.
* `schedule_parachain_downgrade(ParaId)`: Schedule a parachain to be downgraded to a parathread.
Noop if `ParaLifecycle` is not `Parachain`.
* `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`.
Expand All @@ -197,8 +188,8 @@ UpcomingDowngrades: Vec<ParaId>;
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`.
* `lifecycle(ParaId) -> Option<ParaLifecycle>`: Return the `ParaLifecycle` of a para.
* `is_parachain(ParaId) -> bool`: Returns true if the para ID references any live parachain, including
those which may be transitioning to a parathread in the future.
* `is_parachain(ParaId) -> bool`: Returns true if the para ID references any live parachain,
including those which may be transitioning to a parathread in the future.
* `is_parathread(ParaId) -> bool`: Returns true if the para ID references any live parathread,
including those which may be transitioning to a parachain in the future.
* `is_valid_para(ParaId) -> bool`: Returns true if the para ID references either a live parathread
Expand Down
55 changes: 55 additions & 0 deletions roadmap/implementers-guide/src/runtime/shared.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# Shared Module

This module is responsible for managing shared storage and configuration for other modules.

It is important that other pallets are able to use the Shared Module, so it should not have a
dependency on any other modules in the Parachains Runtime.

For the moment, it is used exclusively to track the current session index across the Parachains
Runtime system, and when it should be allowed to schedule future changes to Paras or Configurations.

## Constants

```rust
// `SESSION_DELAY` is used to delay any changes to Paras registration or configurations.
// Wait until the session index is 2 larger then the current index to apply any changes,
// which guarantees that at least one full session has passed before any changes are applied.
pub(crate) const SESSION_DELAY: SessionIndex = 2;
```

## Storage

```rust
// The current session index within the Parachains Runtime system.
CurrentSessionIndex: SessionIndex;
```

## Initialization

The Shared Module currently has no initialization routines.

The Shared Module is initialized directly after the Configuration module, but before all other
modules. It is important to update the Shared Module before any other module since its state may be
used within the logic of other modules, and it is important that the state is consistent across
them.

## Session Change

During a session change, the Shared Module receives and stores the current Session Index for that
block through the Session Change Notification.

This information is used in the:

* Configuration Module: For delaying updates to configurations until at lease one full session has
passed.
* Paras Module: For delaying updates to paras until at least one full session has passed.

## Finalization

The Shared Module currently has no finalization routines.

## Functions

* `scheduled_sessions() -> SessionIndex`: Return the next session index where updates to the
Parachains Runtime system would be safe to apply.
* `set_session_index(SessionIndex)`: For tests. Set the current session index in the Shared Module.
Loading