Paras Pallet
The Paras module is responsible for storing information on parachains. Registered parachains 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.
- vetting PVFs by means of the PVF pre-checking mechanism.
Storage
Utility Structs
Para Lifecycle
Because the state changes of parachains are delayed, we track the specific state of the para using the ParaLifecycle
enum.
None Parathread (on-demand parachain) Parachain
+ + +
| | |
| (≈2 Session Delay) | |
| | |
+----------------------->+ |
| Onboarding | |
| | |
+-------------------------------------------------->+
| Onboarding | |
| | |
| +------------------------->+
| | UpgradingParathread |
| | |
| +<-------------------------+
| | DowngradingParachain |
| | |
|<-----------------------+ |
| OutgoingParathread | |
| | |
+<--------------------------------------------------+
| | OutgoingParachain |
| | |
+ + +
Note that if PVF pre-checking is enabled, onboarding of a para may potentially be delayed. This can happen due to PVF pre-checking voting concluding late.
During the transition period, the para object is still considered in its existing state.
Storage Layout
Session Change
- Execute all queued actions for paralifecycle changes:
- Clean up outgoing paras.
- This means removing the entries under
Heads
,CurrentCode
,FutureCodeUpgrades
,FutureCode
andMostRecentContext
. An according entry should be added toPastCode
,PastCodeMeta
, andPastCodePruning
using the outgoingParaId
and removedCurrentCode
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.
- This means removing the entries under
- Apply all incoming paras by initializing the
Heads
andCurrentCode
using the genesis parameters as well asMostRecentContext
to0
. - Amend the
Parachains
list andParaLifecycle
to reflect changes in registered parachains. - Amend the
ParaLifecycle
set to reflect changes in registered on-demand parachains. - Upgrade all on-demand parachains that should become lease holding parachains, updating the
Parachains
list andParaLifecycle
. - Downgrade all lease holding parachains that should become on-demand parachains, updating the
Parachains
list andParaLifecycle
. - (Deferred) Return list of outgoing paras to the initializer for use by other modules.
- Go over all active PVF pre-checking votes:
- Increment
age
of the vote. - If
age
reachedcfg.pvf_voting_ttl
, then enact PVF rejection and remove the vote from the active list. - Otherwise, reinitialize the ballots. 1. Resize the
votes_accept
/votes_reject
to have the same length as the incoming validator set. 1. Zero all the votes.
Initialization
- Do pruning based on all entries in
PastCodePruning
withBlockNumber <= now
. Update the correspondingPastCodeMeta
andPastCode
accordingly. - Toggle the upgrade related signals
- Collect all
(para_id, expected_at)
fromUpcomingUpgrades
whereexpected_at <= now
and prune them. For each para pruned setUpgradeGoAheadSignal
toGoAhead
. Reserve weight for the state modification to upgrade each para pruned. - Collect all
(para_id, next_possible_upgrade_at)
fromUpgradeCooldowns
wherenext_possible_upgrade_at <= now
. For each para obtained this way reserve weight to remove itsUpgradeRestrictionSignal
on finalization.
Routines
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 someParaLifecycle
.schedule_para_cleanup(ParaId)
: Schedule a para to be cleaned up after the next full session.schedule_parathread_upgrade(ParaId)
: Schedule a parathread (on-demand parachain) to be upgraded to a parachain.schedule_parachain_downgrade(ParaId)
: Schedule a parachain to be downgraded from lease holding to on-demand.schedule_code_upgrade(ParaId, new_code, relay_parent: BlockNumber, HostConfiguration)
: Schedule a future code upgrade of the given parachain. In case the PVF pre-checking is disabled, or the new code is already present in the storage, the upgrade will be applied after inclusion of a block of the same parachain executed in the context of a relay-chain block with number >=relay_parent + config.validation_upgrade_delay
. If the upgrade is scheduledUpgradeRestrictionSignal
is set and it will remain set untilrelay_parent + config.validation_upgrade_cooldown
. In case the PVF pre-checking is enabled, or the new code is not already present in the storage, then the PVF pre-checking run will be scheduled for that validation code. If the pre-checking concludes with rejection, then the upgrade is canceled. Otherwise, after pre-checking is concluded the upgrade will be scheduled and be enacted as described above.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, the latter value is inserted into theMostRecentContext
mapping. This will apply pending code upgrades based on the block number provided. If an upgrade took place it will clear theUpgradeGoAheadSignal
.lifecycle(ParaId) -> Option<ParaLifecycle>
: Return theParaLifecycle
of a para.is_parachain(ParaId) -> bool
: Returns true if the para ID references any live lease holding parachain, including those which may be transitioning to an on-demand parachain in the future.is_parathread(ParaId) -> bool
: Returns true if the para ID references any live parathread (on-demand parachain), including those which may be transitioning to a lease holding parachain in the future.is_valid_para(ParaId) -> bool
: Returns true if the para ID references either a live on-demand parachain or live lease holding parachain.can_upgrade_validation_code(ParaId) -> bool
: Returns true if the given para can signal code upgrade right now.pvfs_require_prechecking() -> Vec<ValidationCodeHash>
: Returns the list of PVF validation code hashes that require PVF pre-checking votes.
Finalization
Collect all (para_id, next_possible_upgrade_at)
from UpgradeCooldowns
where next_possible_upgrade_at <= now
and
prune them. For each para pruned remove its UpgradeRestrictionSignal
.