Zum Hauptinhalt springen

Setup Rococo Parachain Testnet parachain testnet for Datahighway on 'rococo-local' using Polkadot-Launch

How do you setup a DataHighway Parachain testnet on 'rococo-local' using Polkadot-Launch?#

The following is based on using an Apple macOS 11.2.2 with M1 processor. It generally follows the steps here https://docs.substrate.io/tutorials/v3/cumulus/start-relay/. The versions used are specified here https://docs.substrate.io/tutorials/v3/cumulus/start-relay/#software-versioning, including:

create the following shell scripts and chmod 777 <FILENAME> each of them, and then run ./run_polkadot_launch.sh

Install Substrate#

setup_substrate.sh

#!/bin/bash
curl https://getsubstrate.io -sSf | bash -s -- --fast

Install Rust#

setup_rust.sh

#!/bin/bash
wget -O - https://sh.rustup.rs | sh -s -- -yPATH=$PATH:/root/.cargo/binrustup update stablerustup update nightly

Clone Polkadot-Launch. Note that this forked repository already includes a config.json file that has been preconfigured.#

setup_datahighway_polkadot_launch.sh

#!/bin/bash
mkdir -p ~/parachainscd ~/parachainsgit clone https://github.com/DataHighway-DHX/polkadot-launchcd ~/parachains/polkadot-launchmkdir -p ~/parachains/polkadot-launch/bin

Build the Polkadot repository using v0.9.17#

This is for the the relay chain node on the Rococo network, generated the relay chain specification, and convert it to a SCALE encoded raw chain spec for use when starting nodes. Then copy across the Polkadot binary and the chain specifications to the Polkadot-Launch folder.

Note that stable-aarch64-apple-darwin is required for an Apple M1 processor (otherwise you get illegal hardware instruction error) https://github.com/paritytech/subport/issues/242#issuecomment-923678332

setup_polkadot_relaychain.sh

#!/bin/bash
cd ~/parachainsgit clone https://github.com/paritytech/polkadotcd polkadotgit checkout v0.9.17. ~/.cargo/envPATH=$PATH:/root/.cargo/binrustup update stablerustup toolchain install nightlyrustup target add wasm32-unknown-unknown --toolchain nightlyrustup install stable-aarch64-apple-darwinrustup default stable-aarch64-apple-darwinrustup override set stable-aarch64-apple-darwincargo build --releasecp ./target/release/polkadot ~/parachains/polkadot-launch/bin./target/release/polkadot build-spec --chain=rococo-local --disable-default-bootnode > rococo-local.json./target/release/polkadot build-spec --chain rococo-local.json --raw --disable-default-bootnode > rococo-local-raw.jsoncp ./rococo-local.json ~/parachains/polkadot-launchcp ./rococo-local-raw.json ~/parachains/polkadot-launch

[OPTION 1] Build the DataHighway-Parachain codebase#

setup_datahighway_parachain.sh

#!/bin/bash
cd ~/parachainsgit clone https://github.com/DataHighway-DHX/DataHighway-Parachaincd DataHighway-Parachaingit checkout main./scripts/init.shcargo build --releasecp ./target/release/datahighway-collator ~/parachains/polkadot-launch/bin

[OPTION 2] Build the Substrate-Parachain-Template#

Instead of building the DataHighway-Parachain codebase, you can alternatively build a fork of Substrate-Parachain-Template instead using v0.9.16 for the Cumulus-based parachain collators on the Rococo network. Change the parachain id values in the chain_spec.rs file from 1000 to 2000 (i.e. find/replace "1000.into()," with "2000.into(),", and find/replace "para_id: 1000," with "para_id: 2000,"). Also change "" | "local" to "" | "local" | "rococo-local" in command.rs, so it would run in Polkadot-Launch. After building it then copy across the Substrate-Parachain-Template binary to the Polkadot-Launch folder.

git clone https://github.com/ltfschoen/substrate-parachain-templatecd substrate-parachain-templategit remote add upstream https://github.com/substrate-developer-hub/substrate-parachain-templategit fetch upstream polkadot-v0.9.17:polkadot-v0.9.17git checkout polkadot-v0.9.17. ~/.cargo/envPATH=$PATH:/root/.cargo/binrustup update stablerustup toolchain install nightly-2021-12-15-x86_64-apple-darwinrustup target add wasm32-unknown-unknown --toolchain nightly-2021-12-15-x86_64-apple-darwinrustup default nightly-2021-12-15-x86_64-apple-darwinrustup override set nightly-2021-12-15-x86_64-apple-darwincargo build --releasecp ./target/release/parachain-collator ~/parachains/polkadot-launch/bin

Then install dependencies including Node.js. Modify the Polkadot-Launch config.json file by changing ./bin/datahighway-collator to ./bin/parachain-collator in both places in the config.json file.

Note that the example config.json file that is included in https://github.com/ltfschoen/substrate-parachain-template is likely the same as the config.json file in https://github.com/DataHighway-DHX/polkadot-launch/blob/master/config.json

Note that any pallets that you incorporate from the Substrate repository should be also from its similar branch 'polkadot_v0.9.17'

[SKIP] Build Cumulus codebase#

setup_cumulus_parachain.sh

#!/bin/bash
cd ~/parachainsgit clone https://github.com/paritytech/cumuluscd cumulusgit checkout polkadot-v0.9.17cargo build --release -p polkadot-collatorcp ./target/release/polkadot-collator ~/parachains/polkadot-launch/bin
  • Change the "bin": location of the binary executables to point to the files in the polkadot-launch/bin/ subfolder (i.e. "bin": "./datahighway-collator", rather than ./target/release/datahighway-collator)

Run Polkadot-Launch#

Run Polkadot-Launch and the other scripts

run_polkadot_launch.sh

#!/bin/bash
./setup_substrate.sh./setup_rust.sh./change_rustup_toolchain.sh./setup_datahighway_polkadot_launch.sh./setup_datahighway_parachain.sh# ./setup_cumulus_parachain.sh./setup_polkadot_relaychain.sh
cd ~/parachains/polkadot-launchcurl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bashexport NVM_DIR="$([ -z "${XDG_CONFIG_HOME-}" ] && printf %s "${HOME}/.nvm" || printf %s "${XDG_CONFIG_HOME}/nvm")"[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"nvm install v16.3.0nvm use v16.3.0npm install -g yarnyarnyarn start config.json

Manually add further DataHighway collator nodes#

See https://docs.substrate.io/tutorials/v3/cumulus/connect-parachain/#connecting-additional-parachain-nodes

Note: If you used [OPTION 2] instead of [OPTION 1] then the below commands should start with ./target/release/parachain-collator instead of ./target/release/datahighway-collator and you will be making the commands from the substrate-parachain-template folder instead of the DataHighway-Parachain folder.

Build the raw chain specification for the "rococo-local" chain from the DataHighway-Parachain chain_spec.rs file. Note that we need to generate it from the binary that we copied across into Polkadot-Launch since that is the binary that we are using to run the other collator nodes. The files we need will be added into the DataHighway-Parachain folder. Then we use that raw chain specification to export the genesis state and genesis WASM file for use in running further DataHighway collator nodes. See https://docs.substrate.io/tutorials/v3/cumulus/connect-parachain/

cd DataHighway-Parachain~/parachains/polkadot-launch/bin/datahighway-collator build-spec --chain "rococo-local" --disable-default-bootnode > rococo-local-parachain-2000-plain.json~/parachains/polkadot-launch/bin/datahighway-collator build-spec --chain rococo-local-parachain-2000-plain.json --raw --disable-default-bootnode > rococo-local-parachain-2000-raw.json~/parachains/polkadot-launch/bin/datahighway-collator export-genesis-wasm --chain rococo-local-parachain-2000-raw.json > para-2000-wasm~/parachains/polkadot-launch/bin/datahighway-collator export-genesis-state --chain rococo-local-parachain-2000-raw.json > para-2000-genesis

Copy the "rococo" original generated chain specification, "raw" chain specification, exported state and wasm file from server to local machine that is used to run the collator so it may be stored in the ./res folder

scp -J luke@<IP_ADDR_1> luke@<IP_ADDR_2>:/home/luke/DataHighway-DHX/DataHighway-Parachain/target/release/wbuild/datahighway-parachain-runtime/datahighway_runtime.compact.wasm .

Copy the files into the ./res folder

cd DataHighway-Parachaincp ./res/rococo.json .

Obtain Alice's secret Seed

subkey inspect //Alice--> outputs: 0xe5be9a5092b81bca64be81d212e7f2f9eba183bb7a90954f7b76361f6edb5c0a

If you are using a chain specification with custom keys rather than defaults like Alice, and running the node without the flag --alice then it is necessary to add the keys to the keystore.

~/parachains/polkadot-launch/bin/datahighway-collator key insert \--base-path /tmp/parachain/alice \--chain rococo-local-parachain-2000-raw.json \--scheme Sr25519 \--suri 0xe5be9a5092b81bca64be81d212e7f2f9eba183bb7a90954f7b76361f6edb5c0a \--key-type aura

Try to run another DataHighway collator node manually on your local machine with the following: Important note: Remove --alice if you are using custom session keys that have been added to the keystore.

The same binary file datahighway-collator that started the first collator must be used.

rm -rf /tmp/parachain/alice
./target/release/datahighway-collator \    --collator \    --alice \    --chain rococo-local-parachain-2000-raw.json \    --base-path /tmp/parachain/alice \    --bootnodes <INSERT_EXISTING_COLLATOR_BOOTNODE_FROM_POLKADOT_LAUNCH_LOGS> \    --name "DataHighway-Collator-Alice" \    --force-authoring \    --port 31400 \    --rpc-port 9933 \    --ws-port 9977 \    --unsafe-ws-external \    --unsafe-rpc-external \    --rpc-cors=all \    --rpc-max-payload 1000 \    --rpc-cors=all \    --rpc-methods=Unsafe \    -- \    --execution wasm \    --chain rococo-local-raw.json \    --port 30342 \    --rpc-port 9942 \    --ws-port 9953

Note: The following was added to support Try-Runtime. See https://docs.substrate.io/v3/tools/try-runtime/#usage

    --rpc-max-payload 1000 \    --rpc-cors=all \

Note: Obtain <INSERT_EXISTING_COLLATOR_BOOTNODE_FROM_POLKADOT_LAUNCH_LOGS> from the Polkadot-Launch logs. An example of what it outputs is the following, but the Local Node Identities may be different:

Added Boot Nodes: /ip4/127.0.0.1/tcp/30336/p2p/12D3KooWRxTiM5vAPZ9RNSgd7Uqwfa8bpx4MoNo2M1m4f34nrCot,/ip4/127.0.0.1/tcp/30337/p2p/12D3KooWAWqYpvBZvvmPJ8wQ5PeiCcv8XuFzjVQrT6JGyXyU72Fu

Wait for about 15 blocks until the logs say Starting collation., which is when the parachain will start collating and finalizing blocks

Check it works in the UI

git clone https://github.com/polkadot-js/appsgit checkout 129508461b062907c85bfa32ade096296cd3fe76nvm use v16.3.0yarnyarn start

Go to http://localhost:3000/?rpc=ws://127.0.0.1:9988#/accounts and verify that the parachain is generating and finalizing blocks, that you can transfer 1 UNIT from Alice to Bob

Benchmarking#

Run the following:

./scripts/benchmark_all_pallets.sh

Try-Runtime#

  • Build whilst specifying the try-runtime feature
./scripts/init.sh
cargo build --release --features=try-runtime
  • Run Try-Runtime so on-runtime-upgrade will invoke all OnRuntimeUpgrade hooks in pallets and the runtime
RUST_LOG=runtime=trace,try-runtime::cli=trace,executor=trace \RUST_BACKTRACE=1 \./target/release/datahighway-collator \try-runtime \--chain rococo-local-parachain-2000-raw.json \--url <ws/s port>--block-at <block-hash> \on-runtime-upgrade \live

See ./scripts/try-runtime.sh

Additional Notes:#

  • Previously DataHighway standalone chain required these dependencies:
rustup toolchain install nightly-2020-10-06rustup target add wasm32-unknown-unknown --toolchain nightly-2020-10-06rustup default nightly-2020-10-06rustup override set nightly-2020-10-06
  • On macOS the version required for Rustup is for example stable-x86_64-apple-darwin, whereas on Linux it is stable-aarch64-unknown-linux-gnu