Simulate Parachains
Explains how you can set up a local test network to simulate a relay chain with validators and parachain collator nodes.
You can use the zombienet
command-line tool to set up a local test network to simulate a relay chain with validators and parachain collator nodes. You can configure the test network to include multiple validators and parachains with multiple collators.
This tutorial illustrates how to set up a basic test network with the following configuration:
Four validators
Two parachains
One collator per parachain
One message passing channel that enables the parachains to exchange messages
Prepare a working folder with the binaries
The zombienet
command-line interface relies on a configuration file to specify the characteristics of the test network, including the name and location of the binaries, Docker image, or Kubernetes deployment to use.
This tutorial illustrates how to configure a test network that uses the native relay chain and collator binaries, so the first step in setting up your test network is to prepare a working folder with the binaries you'll need.
To prepare a working folder with the binaries for the test network:
Open a new terminal shell on your computer, if needed.
Change to your home directory and create a new folder to hold the binaries required to generate a test network.
For example:
Clone the InfraBlockSpace repository by running a command similar to the following:
Change to the root of the
infrablockchain-substrate
directory by running the following command:Checkout the latest release of infrablockchain-substrate.
Release branches use the naming convention
release-v<n.n.n>
. For example, the release branch used in this tutorial isrelease-v1.0.0
. You can check out a more recent release branch instead of usingrelease-v1.0.0
. You can find information about recent releases and what's included in each release on the Releases tab.For example:
Compile the relay chain node by running the following command:
Copy the InfraBlockSpace binary into your working
binaries
folder by running a command similar to the following:As this example illustrates, it's generally a good practice to append the version of
infrablockspace
to the binary name to keep the files in thebinaries
folder organized.Change to your home directory.
Add the Parachain binary
Your working folder now has the binary for the relay chain, but you also need the binary for the parachain collator nodes. You can add the parachain collator binary to your working folder by cloning the substrate-parachain-template
repository. By default, compiling the substrate-parachain-template
creates a parachain collator binary that is configured with the paraId
1000. You can use this paraId
for the first parachain in the test network.
To add the parachain collator binary to the working folder:
Navigate to the root directory of
infrablockchain-substrate
and enter the following command:You now have a parachain collator binary for paraId 1000.
Copy the parachain binary into your working
bin
folder by running a command similar to the following:In this example, it's generally a good practice to append the version and
paraId
to the binary name to keep the files in thebin
folder organized.
Configure the test network settings
Now that you have the binaries you need in a working folder, you are ready to configure the settings for the test network that Zombienet will use.
To download and configure Zombienet:
Download the appropriate Zombienet executable for the Linux or macOS operating system.
Depending on your security settings, you might need to explicitly allow access to the executable.
If you want the executable to be available system-wide, run commands similar to the following after downloading the executable:
Verify that Zombienet is installed correctly by running the following command:
If command-line help is displayed, the Zombienet is ready to configure.
Create a configuration file for Zombienet by running the following command:
You are going to use the configuration file to specify the following information:
Location of the binaries for the test network.
The relay chain specification—
infra-relay-local
—to use.Information about the four relay chain validators.
Identifiers for parachains included in the test network.
Information about the collators for each parachains.
WebSocket endpoint ports to use to connect to each node.
For example:
Save your changes and close the file.
Start the test network using this configuration file by running a command similar to the following:
The command displays information about the test network nodes being started.
Take note of the relay chain and parachain node endpoints. For example, the direct link to the relay chain endpoints should look similar to the following:
alice: https://portal.infrablockspace.net/?rpc=ws://127.0.0.1:7101#/explorer
bob: https://portal.infrablockspace.net/?rpc=ws://127.0.0.1:7201#/explorer
charlie: https://portal.infrablockspace.net/?rpc=ws://127.0.0.1:7301#/explorer
dave: https://portal.infrablockspace.net/?rpc=ws://127.0.0.1:7401#/explorer
The direct link to the parachain collator endpoints should look similar to the following:
parachain-1000-collator: https://portal.infrablockspace.net/?rpc=ws://127.0.0.1:9901#/explorer
parachain-1001-collator: https://portal.infrablockspace.net/?rpc=ws://127.0.0.1:10001#/explorer
After all of the nodes are running, you can interact with your nodes by opening the InfraBlockchain Explorerand connecting to any of the node endpoints.
Open a message passing channel
Now that you have your test network up, you can open horizontal relay message passing channels to enable communication between parachain A (1000) and parachain B (1001). Because channels are unidirectional, you need to
Send a request to open channel from parachain A (1000) to parachain B (1001).
Accept the request on parachain B (1001).
Send a request to open channel from parachain B (1001) to parachain A (1000).
Accept the request on parachain A (1000).
Zombienet simplifies opening these channels by enabling you to include basic channel settings in the configuration file for testing purposes.
To set up communication between the parachains in the test network:
Open the
config.toml
file in a text editor.Add channel information similar to the following to the configuration file:
Note that the values you set for max_capacity and max_message_size shouldn't exceed the values defined for the
hrmpChannelMaxCapacity
andhrmpChannelMaxMessageSize
parameters for the relay chain.To check the configuration settings for the current relay chain using the InfraBlockchain Explorer:
Click Developer and select Chain State.
Select configuration, then select activeConfig().
Check the following parameter values:
Save your changes and close the file.
Restart Zombienet by running the following command:
You now have a test network with a bidirectional HRMP channel open between the parachains A (1000) and parachain B (1001).
You can use the InfraBlockchain Explorer to connect to the parachains and send messages.
Click Developer and select Extrinsics.
Select ibsXcm or xcmPallet, then select sent(dest, message) to craft the XCM messages you want to send.
You should note that XCM messages are like other transactions and require the sender to pay for the execution of the operation. All of the information required must be included in the message itself. For information about how to craft messages using XCM after you've opened HRMP channels, see Cross-consensus communication and Transfer assets with XCM.
Where to go next
For a more complex preconfigured environment that uses Zombienet, download and explore the Trappist playground. For more information about the properties you can set in the configuration file, see the Network definition specification.
Last updated