Polkadot XCMP Explained — How Parachains Talk to Each Other

PolkaWorld
6 min readJan 7, 2022

--

Polkadot’s first batch of 5 parachains was successfully launched on December 18th, marking Polkadot’s entry into the “parachain era”. What everyone is looking forward to seeing is what kind of innovation and network effects the cross-chain interaction between parachains will bring.

In this article, we will take a look at the XCMP protocol — the foundation of cross-chain interoperability between Polkadot parachains.

What is XCMP?

The full name of XCMP is “Cross-Chain Message Passing”. It is one of Polkadot’s cross-chain message transmission protocols, which specifies the way of cross-chain message transmission between parachains of the same relay chain.

The XCMP protocol uses a simple queuing mechanism based on Merkle trees to ensure the accuracy of cross-chain information. The relay chain validator needs to move the transaction on the output queue of a parachain to the input queue of the destination parachain.

Why XCMP

Why is there a need for cross-chain messaging between parachains?

Traditional blockchains are highly isolated. Although smart contracts within one blockchain can call each other mutually, the cross-chain between blockchains is difficult, just like a closed country.

Polkadot’s vision is to build a multi-chain ecosystem. Each parachain connected to the Polkadot relay chain does not need to be omnipotent. Instead, it can focus on doing what it is good at, optimize itself towards a specific direction, and then interact with other chains to learn from each other through cross-chain interoperability.

For example, a game developer wants to develop a game in Polkadot’s multi-chain ecosystem. He/She can run the game on a high-performance game parachain, use the game characters provided by the NFT parachain, and use stablecoins provided by the DeFi parachain to exchange game props.

In this way, each parachain can play its own comparative advantage just like a free-trade country. As there are more and more parachains, there are more and more “components” that can be used by other parachains, thus forming a network effect.

The prerequisite for all of this is that there must be a set of cross-chain protocols between parachains to specify the entire message transmission process, just as there are general trade rules in international trades. And this protocol is XCMP.

One thing that needs to be explained is that the cross-chain that XCMP can do includes not only the cross-chain of assets. XCMP can not only be used to send tokens between parachains, but also any type of data and messages. For example, smart contracts can be called across chains between parachains. This allows Polkadot ecosystem developers to take advantage of the traits of multiple parachains instead of being limited to the traits of one chain, thereby opening up more new use cases. Parachains can have interoperability, that is, cross-chain composability.

How Does XCMP Work?

There are two important roles in the Polkadot network-validator nodes and collator nodes.

The validator nodes are on the relay chain and are responsible for producing blocks in the relay chain and receiving the state transition proof from the collator.

The collator nodes are on the parachains, and the collators are full nodes of both their parachain and relay chain. They will collect the transactions of the parachain and provide state transition proofs for the validators. In addition, the collators will also send and receive messages from other parachains through XCMP.

Let’s take an example to understand how XCMP works.

Suppose a smart contract on parachain A wants to send a message to parachain B, thereby calling another smart contract on parachain B to transfer some assets in the parachain B.

The collator of parachain A will put this message in the output queue of parachain A together with its destination and timestamp.

The collator of parachain B found this message when requesting a new message from the network, and then put it in his input queue.

The validators of parachain A and parachain B will also read the output and input queues respectively, so they can verify that this message passing happened.

When the collator of the parachain B producing the next block on parachain B, the new message will be processed from the input queue, and this message will be executed on the parachain B to complete the asset transfer as expected.

Then this collator submits the block to the validator, the validator will verify that the message has been processed and other aspects look fine, so the validator will include the block on the relay chain. The entire process of cross-chain messaging is done.

XCMP Design

XCMP is currently under development, and the details may change. However, the overall architecture and design decisions are as follows:

  • Cross-chain messages will not be delivered to the Relay Chain.
  • Cross-chain messages will be constrained to a maximum size in bytes.
  • Parachains are allowed to block messages from other parachains, in which case the dispatching parachain would be aware of this block.
  • Collator nodes are responsible for routing messages between chains.
  • Collators produce a list of egress messages and will receive the ingress messages from other parachains.
  • On each block, parachains are expected to route messages from some subset of all other parachains.
  • When a collator produces a new block to hand off to a validator, it will collect the latest ingress queue information and process it.
  • Validators will check the proof that the new candidate for the next parachain block includes the processing of the expected ingress messages to that parachain.

XCMP queues must be initiated by first opening a channel between two parachains. The channel is identified by both the sender and recipient parachains, meaning that it’s a one-way channel. A pair of parachains can have at most two channels between them, one for sending messages to the other chain and another for receiving messages. The channel will require a deposit in DOT to be opened, which will get returned when the channel is closed.

XCMP vs XCM

The abbreviations of XCMP and XCM are similar, in order to avoid potential confusion, we make a distinction here.

XCM is the abbreviation of Cross-Consensus Message Format in Polkadot. It is a message format, not a cross-chain protocol. It specifies how the message transmission should be understood but cannot transmit the message itself.

Messages in XCM format can be used not only for cross-chain protocols such as XCMP, but also for transferring messages between different consensus systems.

XCMP Updates

XCMP is currently under development and has not yet been launched, so some details have yet to be determined.

At present, the cross-chain communication between parachains uses HRMP (Horizontal Rela-routed Message Passing) as a stop-gap protocol. For example, the cross-chain between Karura and Bifrost uses HRMP. This scheme has the same function as XCMP. The difference is that it consumes much more resources, because it stores all messages in the relay chain storage, while in XCMP only the associated metadata is stored as a hash in the Relay Chain storage. After XCMP goes online, HRMP will retire.

About PolkaWorld

PolkaWorld is a Polkadot global community founded in 2019. We have gathered more than 40,000 Polkadot enthusiasts, and have always been committed to spreading Polkadot knowledge, training Substrate developers, and supporting Polkadot/Kusama ecosystem.

Twitter: @polkaworld_org.

Youtube: https://www.youtube.com/c/PolkaWorld

Telegram: https://t.me/polkaworld

--

--

PolkaWorld
PolkaWorld

Written by PolkaWorld

A global Polkadot/Kusama community

No responses yet