Previous Versionsv2.0.2Pallets
parachain_system
Outdated Version
You're viewing an older version (v2.0.2) The latest documentation is available for the current version. Click here to visit latest version.
Branch/Release: release-polkadot-v1.10.0
Source Code link:https://github.com/paritytech/polkadot-sdk/blob/release-polkadot-v1.10.0/cumulus/pallets/parachain-system/src/lib.rs[pass:[],role=heading-link]
Purpose
This pallet is a core element of each parachain. It will:
- Aggregate information about built blocks
- Process binary code upgrades
- Process incoming messages from both relay chain and other parachains (if a channel is established between them)
- Send outgoing messages to relay chain and other parachains
- Build collation info when requested by collator
Config
- Pallet-specific configs:
OnSystemEvent— a handler that will be called when new validation data will be set (once each block). New validation data will also be passed to it. Look totrait OnSystemEventfor more details.SelfParaId— getter for a parachain id of this chainOutboundXcmpMessageSource— source of outgoing XCMP messages. It is queried infinalize_blockand later included into collation informationDmpQueue— a handler for the incoming downward messages from relay chainReservedDmpWeight— weight reserved for DMP message processing. This config seems to be is not used as the function that processes these messages (enqueue_inbound_downward_messages) returns used weight.XcmpMessageHandler— a handler for the incoming horizontal messages from other parachainsReservedXcmpWeight— default weight limit for the for the XCMP message processing. May be overriden by storageReservedXcmpWeightOverride. If incoming messages in block will exceed the weight limit, they won’t be processed.CheckAssociatedRelayNumber— type that implementstrait CheckAssociatedRelayNumber. Currently there are three implementations: no check (AnyRelayNumber), strict increase (RelayNumberStrictlyIncreases), monotonic increase (RelayNumberMonotonicallyIncreases). It is needed to maintain some order between blocks in relay chain and parachain.ConsensusHook— this is a feature-enabled config ( for the management of the unincluded segment. Requires the implementation oftrait ConsensusHook. There are several implementations of it, inparachain-systemcrate (FixedCapacityUnincludedSegment) and inaura-extcrate (FixedVelocityConsensusHook). It is needed to maintain the logic of segment length handling.
- Common parameters for all pallets:
RuntimeEventWeightInfo
Dispatchables
[.contract-item-name]#set_validation_data#
pub fn set_validation_data(
data: ParachainInherentData,
)This call is an inherent, you can’t call this from another dispatchable or from client side. This call sets up validation data for collation, processes code upgrades and updates unincluded segments.
[.contract-item-name]#sudo_send_upward_message#
pub fn sudo_send_upward_message(
message: UpwardMessage,
)Send a message to relay as a sudo.
Params:
message— a vec of bytes that represents a message that you send to the relay
Errors:
BadOrigin— call was made not from a sudo
[.contract-item-name]#authorize_upgrade#
pub fn authorize_upgrade(
code_hash: T::Hash,
check_version: bool,
)Authorize the upgrade. This call will put the hash and flag to the storage AuthorizedUpgrade. This call must be made as a sudo.
Params:
code_hash— hash of the authorized runtime binarycheck_version— flag that indicates that the code should be checked for the possibility to upgrade. It will happen during the upgrade process itself.
Errors:
BadOrigin— call was made not from a sudo
Events:
UpgradeAuthorized(code_hash)
[.contract-item-name]#enact_authorized_upgrade#
pub fn enact_authorized_upgrade(
code: Vec<u8>,
)Validate and perform the authorized upgrade.
Params:
code— runtime binary for the upgrade
Errors:
NothingAuthorized— there is no authorized upgrade, callauthorize_upgradein advanceUnauthorized— there is another upgrade authorized
Important Mentions and FAQ's
Pallet's workflow
- Block Initialization
- Remove already processed validation code
- Update
UnincludedSegmentwith latest parent hash - Cleans up
ValidationDataand other functions. - Calculate weights for everything that was done in
on_finalizehook
- Inherents —
set_validation_datacall- Clean the included segments from
UnincludedSegmentand update theAggregatedUnincludedSegment - Update
ValidationData,RelayStateProofand other configs from relay. - Process the
ValidationCodeupgrade
- Clean the included segments from
- Block Finalization
- Enqueue all received messages from relay chain and other parachains
- Update
UnincludedSegmentandAggregatedUnincludedSegmentwith the latest block data