From a3d1264b86368788bdf4ffc1217fc4b3787dac99 Mon Sep 17 00:00:00 2001 From: Branislav Kontur Date: Mon, 11 Sep 2023 11:02:20 +0200 Subject: [PATCH] Fixed local run for AssetHubKusama/AssetHubPolkadot asset transfer (KSMs/DOTs) --- .../parachains/runtimes/bridge-hubs/README.md | 79 ++++++++++--------- cumulus/scripts/bridges_kusama_polkadot.sh | 43 +++++++--- cumulus/scripts/bridges_rococo_wococo.sh | 36 ++++++++- .../bridge_hub_kusama_local_network.toml | 22 +++--- .../bridge_hub_polkadot_local_network.toml | 22 +++--- .../statemine_kusama_local_network.toml | 2 +- 6 files changed, 129 insertions(+), 75 deletions(-) diff --git a/cumulus/parachains/runtimes/bridge-hubs/README.md b/cumulus/parachains/runtimes/bridge-hubs/README.md index 7600c52d3530..ac9b9122942d 100644 --- a/cumulus/parachains/runtimes/bridge-hubs/README.md +++ b/cumulus/parachains/runtimes/bridge-hubs/README.md @@ -45,17 +45,28 @@ Copy the apropriate binary (zombienet-linux) from the latest release to ~/local_ --- # 2. Build polkadot binary -git clone https://github.com/paritytech/polkadot.git -cd polkadot -# if you want to test Kusama/Polkadot bridge, we need "sudo pallet + fast-runtime", -# so please, find the latest polkadot's repository branch `it/release-vX.Y.Z-fast-sudo` -# e.g: -# git checkout -b it/release-v0.9.43-fast-sudo --track origin/it/release-v0.9.43-fast-sudo +# If you want to test Kusama/Polkadot bridge, we need "sudo pallet + fast-runtime", +# so we need to use sudoif in polkadot directory. +# +# Install sudoif: (skip if already installed) +# cd +# git clone https://github.com/paritytech/parachain-utils.git +# cd parachain-utils # -> this is +# cargo build --release --bin sudofi +# +# cd /pokladot +# /target/release/sudoif -cargo build --release --features fast-runtime +cd +cargo build --release --features fast-runtime --bin polkadot cp target/release/polkadot ~/local_bridge_testing/bin/polkadot +cargo build --release --features fast-runtime --bin polkadot-prepare-worker +cp target/release/polkadot-prepare-worker ~/local_bridge_testing/bin/polkadot-prepare-worker + +cargo build --release --features fast-runtime --bin polkadot-execute-worker +cp target/release/polkadot-execute-worker ~/local_bridge_testing/bin/polkadot-execute-worker --- # 3. Build substrate-relay binary @@ -74,7 +85,7 @@ cp target/release/substrate-relay ~/local_bridge_testing/bin/substrate-relay --- # 4. Build cumulus polkadot-parachain binary -cd +cd # checkout desired branch or use master: # git checkout -b master --track origin/master @@ -83,25 +94,7 @@ cargo build --release --locked --bin polkadot-parachain cp target/release/polkadot-parachain ~/local_bridge_testing/bin/polkadot-parachain cp target/release/polkadot-parachain ~/local_bridge_testing/bin/polkadot-parachain-asset-hub - - -# !!! READ HERE (TODO remove once all mentioned branches bellow are merged) -# The use case "moving assets over bridge" is not merged yet and is implemented in separate branches. -# So, if you want to try it, you need to checkout different branch and continue with these instructions there. - -# For Kusama/Polkadot local bridge testing: -# -# build BridgeHubs (polkadot-parachain) from branch: -# git checkout -b bridge-hub-kusama-polkadot --track origin/bridge-hub-kusama-polkadot -# cargo build --release --locked --bin polkadot-parachain -# cp target/release/polkadot-parachain ~/local_bridge_testing/bin/polkadot-parachain -# -# build AssetHubs (polkadot-parachain-asset-hub) from branch: -# git checkout -b bko-transfer-asset-via-bridge-pallet-xcm --track origin/bko-transfer-asset-via-bridge-pallet-xcm -# cargo build --release --locked --bin polkadot-parachain -# cp target/release/polkadot-parachain ~/local_bridge_testing/bin/polkadot-parachain-asset-hub - -# For Rococo/Wococo local bridge testing: +# For Rococo/Wococo local bridge testing: (obsolete) # # build AssetHubs (polkadot-parachain-asset-hub) from branch: # git checkout -b bko-transfer-asset-via-bridge-pallet-xcm-ro-wo --track origin/bko-transfer-asset-via-bridge-pallet-xcm-ro-wo @@ -236,27 +229,33 @@ Check [requirements](#requirements-for-local-runtesting) for "sudo pallet + fast ### 1. Run chains (Kusama + BridgeHub + AssetHub, Polkadot + BridgeHub + AssetHub) with zombienet + ``` +cd + # Kusama + BridgeHubKusama + AssetHubKusama POLKADOT_BINARY_PATH=~/local_bridge_testing/bin/polkadot \ POLKADOT_PARACHAIN_BINARY_PATH=~/local_bridge_testing/bin/polkadot-parachain \ POLKADOT_PARACHAIN_BINARY_PATH_FOR_ASSET_HUB_KUSAMA=~/local_bridge_testing/bin/polkadot-parachain-asset-hub \ - ~/local_bridge_testing/bin/zombienet-linux --provider native spawn ./zombienet/bridge-hubs/bridge_hub_kusama_local_network.toml + ~/local_bridge_testing/bin/zombienet-linux --provider native spawn ./cumulus/zombienet/bridge-hubs/bridge_hub_kusama_local_network.toml ``` ``` +cd + # Polkadot + BridgeHubPolkadot + AssetHubPolkadot POLKADOT_BINARY_PATH=~/local_bridge_testing/bin/polkadot \ POLKADOT_PARACHAIN_BINARY_PATH=~/local_bridge_testing/bin/polkadot-parachain \ POLKADOT_PARACHAIN_BINARY_PATH_FOR_ASSET_HUB_POLKADOT=~/local_bridge_testing/bin/polkadot-parachain-asset-hub \ - ~/local_bridge_testing/bin/zombienet-linux --provider native spawn ./zombienet/bridge-hubs/bridge_hub_polkadot_local_network.toml + ~/local_bridge_testing/bin/zombienet-linux --provider native spawn ./cumulus/zombienet/bridge-hubs/bridge_hub_polkadot_local_network.toml ``` ### 2. Init bridge and run relayer (BridgeHubKusama, BridgeHubPolkadot) ``` -cd -./scripts/bridges_kusama_polkadot.sh run-relay +cd + +./cumulus/scripts/bridges_kusama_polkadot.sh run-relay ``` ### 3. Initialize transfer asset over bridge (DOTs/KSMs) @@ -265,22 +264,28 @@ This initialization does several things: - creates `ForeignAssets` for wrappedDOTs/wrappedKSMs - drips SA for AssetHubKusama on AssetHubPolkadot (and vice versa) which holds reserved assets on source chains ``` -./scripts/bridges_kusama_polkadot.sh init-asset-hub-kusama-local -./scripts/bridges_kusama_polkadot.sh init-bridge-hub-kusama-local -./scripts/bridges_kusama_polkadot.sh init-asset-hub-polkadot-local -./scripts/bridges_kusama_polkadot.sh init-bridge-hub-polkadot-local +cd + +./cumulus/scripts/bridges_kusama_polkadot.sh init-asset-hub-kusama-local +./cumulus/scripts/bridges_kusama_polkadot.sh init-bridge-hub-kusama-local +./cumulus/scripts/bridges_kusama_polkadot.sh init-asset-hub-polkadot-local +./cumulus/scripts/bridges_kusama_polkadot.sh init-bridge-hub-polkadot-local ``` ### 4. Send messages - transfer asset over bridge (DOTs/KSMs) Do (asset) transfers: ``` +cd + # KSMs from Kusama's Asset Hub to Polkadot's. -./scripts/bridges_kusama_polkadot.sh reserve-transfer-assets-from-asset-hub-kusama-local +./cumulus/scripts/bridges_kusama_polkadot.sh reserve-transfer-assets-from-asset-hub-kusama-local ``` ``` +cd + # DOTs from Polkadot's Asset Hub to Kusama's. -./scripts/bridges_kusama_polkadot.sh reserve-transfer-assets-from-asset-hub-polkadot-local +./cumulus/scripts/bridges_kusama_polkadot.sh reserve-transfer-assets-from-asset-hub-polkadot-local ``` - open explorers: (see zombienets) diff --git a/cumulus/scripts/bridges_kusama_polkadot.sh b/cumulus/scripts/bridges_kusama_polkadot.sh index a417ef49a9ca..4aa2f010bf4c 100755 --- a/cumulus/scripts/bridges_kusama_polkadot.sh +++ b/cumulus/scripts/bridges_kusama_polkadot.sh @@ -133,6 +133,7 @@ case "$1" in run_relay ;; init-asset-hub-kusama-local) + ensure_polkadot_js_api # create foreign assets for native Polkadot token (governance call on Kusama) force_create_foreign_asset \ "ws://127.0.0.1:9942" \ @@ -149,8 +150,18 @@ case "$1" in "//Alice" \ "$GLOBAL_CONSENSUS_POLKADOT_ASSET_HUB_POLKADOT_1000_SOVEREIGN_ACCOUNT" \ $((1000000000 + 50000000000 * 20)) + # HRMP + open_hrmp_channels \ + "ws://127.0.0.1:9942" \ + "//Alice" \ + 1000 1002 4 524288 + open_hrmp_channels \ + "ws://127.0.0.1:9942" \ + "//Alice" \ + 1002 1000 4 524288 ;; init-bridge-hub-kusama-local) + ensure_polkadot_js_api # SA of sibling asset hub pays for the execution transfer_balance \ "ws://127.0.0.1:8943" \ @@ -159,22 +170,32 @@ case "$1" in $((1000000000 + 50000000000 * 20)) ;; init-asset-hub-polkadot-local) + ensure_polkadot_js_api # create foreign assets for native Polkadot token (governance call on Kusama) - force_create_foreign_asset \ - "ws://127.0.0.1:9945" \ - "//Alice" \ - 1000 \ - "ws://127.0.0.1:9010" \ - "$(jq --null-input '{ "parents": 2, "interior": { "X1": { "GlobalConsensus": "Kusama" } } }')" \ - "$GLOBAL_CONSENSUS_KUSAMA_SOVEREIGN_ACCOUNT" \ - 1000000000 \ - true + force_create_foreign_asset \ + "ws://127.0.0.1:9945" \ + "//Alice" \ + 1000 \ + "ws://127.0.0.1:9010" \ + "$(jq --null-input '{ "parents": 2, "interior": { "X1": { "GlobalConsensus": "Kusama" } } }')" \ + "$GLOBAL_CONSENSUS_KUSAMA_SOVEREIGN_ACCOUNT" \ + 10000000000 \ + true # drip SA which holds reserves transfer_balance \ "ws://127.0.0.1:9010" \ "//Alice" \ "$GLOBAL_CONSENSUS_KUSAMA_ASSET_HUB_KUSAMA_1000_SOVEREIGN_ACCOUNT" \ $((1000000000 + 50000000000 * 20)) + # HRMP + open_hrmp_channels \ + "ws://127.0.0.1:9945" \ + "//Alice" \ + 1000 1002 4 524288 + open_hrmp_channels \ + "ws://127.0.0.1:9945" \ + "//Alice" \ + 1002 1000 4 524288 ;; init-bridge-hub-polkadot-local) # SA of sibling asset hub pays for the execution @@ -192,7 +213,7 @@ case "$1" in "//Alice" \ "$(jq --null-input '{ "V3": { "parents": 2, "interior": { "X2": [ { "GlobalConsensus": "Polkadot" }, { "Parachain": 1000 } ] } } }')" \ "$(jq --null-input '{ "V3": { "parents": 0, "interior": { "X1": { "AccountId32": { "id": [212, 53, 147, 199, 21, 253, 211, 28, 97, 20, 26, 189, 4, 169, 159, 214, 130, 44, 133, 88, 133, 76, 205, 227, 154, 86, 132, 231, 165, 109, 162, 125] } } } } }')" \ - "$(jq --null-input '{ "V3": [ { "id": { "Concrete": { "parents": 1, "interior": "Here" } }, "fun": { "Fungible": 1000000000000 } } ] }')" \ + "$(jq --null-input '{ "V3": [ { "id": { "Concrete": { "parents": 1, "interior": "Here" } }, "fun": { "Fungible": 200000000000 } } ] }')" \ 0 \ "Unlimited" ;; @@ -204,7 +225,7 @@ case "$1" in "//Alice" \ "$(jq --null-input '{ "V3": { "parents": 2, "interior": { "X2": [ { "GlobalConsensus": "Kusama" }, { "Parachain": 1000 } ] } } }')" \ "$(jq --null-input '{ "V3": { "parents": 0, "interior": { "X1": { "AccountId32": { "id": [212, 53, 147, 199, 21, 253, 211, 28, 97, 20, 26, 189, 4, 169, 159, 214, 130, 44, 133, 88, 133, 76, 205, 227, 154, 86, 132, 231, 165, 109, 162, 125] } } } } }')" \ - "$(jq --null-input '{ "V3": [ { "id": { "Concrete": { "parents": 1, "interior": "Here" } }, "fun": { "Fungible": 2000000000000 } } ] }')" \ + "$(jq --null-input '{ "V3": [ { "id": { "Concrete": { "parents": 1, "interior": "Here" } }, "fun": { "Fungible": 3000000000 } } ] }')" \ 0 \ "Unlimited" ;; diff --git a/cumulus/scripts/bridges_rococo_wococo.sh b/cumulus/scripts/bridges_rococo_wococo.sh index 2ed43a4be64e..f0e54be1591b 100755 --- a/cumulus/scripts/bridges_rococo_wococo.sh +++ b/cumulus/scripts/bridges_rococo_wococo.sh @@ -87,8 +87,8 @@ function ensure_polkadot_js_api() { echo "" echo "" echo "-------------------" - echo "Installing (nodejs) sub module: ./scripts/generate_hex_encoded_call" - pushd ./scripts/generate_hex_encoded_call + echo "Installing (nodejs) sub module: $(dirname "$0")/generate_hex_encoded_call" + pushd $(dirname "$0")/generate_hex_encoded_call npm install popd fi @@ -103,7 +103,7 @@ function generate_hex_encoded_call_data() { shift echo "Input params: $@" - node ./scripts/generate_hex_encoded_call "$type" "$endpoint" "$output" "$@" + node $(dirname "$0")/generate_hex_encoded_call "$type" "$endpoint" "$output" "$@" local retVal=$? if [ $type != "check" ]; then @@ -129,7 +129,7 @@ function transfer_balance() { polkadot-js-api \ --ws "${runtime_para_endpoint}" \ --seed "${seed?}" \ - tx.balances.transfer \ + tx.balances.transferAllowDeath \ "${target_account}" \ "${amount}" } @@ -200,6 +200,34 @@ function send_governance_transact() { "${message}" } +function open_hrmp_channels() { + local relay_url=$1 + local relay_chain_seed=$2 + local sender_para_id=$3 + local recipient_para_id=$4 + local max_capacity=$5 + local max_message_size=$6 + echo " calling open_hrmp_channels:" + echo " relay_url: ${relay_url}" + echo " relay_chain_seed: ${relay_chain_seed}" + echo " sender_para_id: ${sender_para_id}" + echo " recipient_para_id: ${recipient_para_id}" + echo " max_capacity: ${max_capacity}" + echo " max_message_size: ${max_message_size}" + echo " params:" + echo "--------------------------------------------------" + + polkadot-js-api \ + --ws "${relay_url?}" \ + --seed "${relay_chain_seed?}" \ + --sudo \ + tx.hrmp.forceOpenHrmpChannel \ + ${sender_para_id} \ + ${recipient_para_id} \ + ${max_capacity} \ + ${max_message_size} +} + function allow_assets_transfer_send() { local relay_url=$1 local relay_chain_seed=$2 diff --git a/cumulus/zombienet/bridge-hubs/bridge_hub_kusama_local_network.toml b/cumulus/zombienet/bridge-hubs/bridge_hub_kusama_local_network.toml index 7f753d6dd504..d4b264c89911 100644 --- a/cumulus/zombienet/bridge-hubs/bridge_hub_kusama_local_network.toml +++ b/cumulus/zombienet/bridge-hubs/bridge_hub_kusama_local_network.toml @@ -94,14 +94,14 @@ cumulus_based = true "-- --port 51433 --rpc-port 58833 --ws-port 58843 --no-mdns", "--bootnodes {{'alice-validator'|zombie('multiAddress')}}" ] -[[hrmp_channels]] -sender = 1000 -recipient = 1002 -max_capacity = 4 -max_message_size = 524288 - -[[hrmp_channels]] -sender = 1002 -recipient = 1000 -max_capacity = 4 -max_message_size = 524288 +#[[hrmp_channels]] +#sender = 1000 +#recipient = 1002 +#max_capacity = 4 +#max_message_size = 524288 +# +#[[hrmp_channels]] +#sender = 1002 +#recipient = 1000 +#max_capacity = 4 +#max_message_size = 524288 diff --git a/cumulus/zombienet/bridge-hubs/bridge_hub_polkadot_local_network.toml b/cumulus/zombienet/bridge-hubs/bridge_hub_polkadot_local_network.toml index 320456a25652..800b9c41c70d 100644 --- a/cumulus/zombienet/bridge-hubs/bridge_hub_polkadot_local_network.toml +++ b/cumulus/zombienet/bridge-hubs/bridge_hub_polkadot_local_network.toml @@ -94,14 +94,14 @@ cumulus_based = true "-- --port 31433 --rpc-port 38833 --ws-port 38843 --no-mdns", "--bootnodes {{'alice-validator-dot'|zombie('multiAddress')}}" ] -[[hrmp_channels]] -sender = 1000 -recipient = 1002 -max_capacity = 4 -max_message_size = 524288 - -[[hrmp_channels]] -sender = 1002 -recipient = 1000 -max_capacity = 4 -max_message_size = 524288 +#[[hrmp_channels]] +#sender = 1000 +#recipient = 1002 +#max_capacity = 4 +#max_message_size = 524288 +# +#[[hrmp_channels]] +#sender = 1002 +#recipient = 1000 +#max_capacity = 4 +#max_message_size = 524288 diff --git a/cumulus/zombienet/examples/statemine_kusama_local_network.toml b/cumulus/zombienet/examples/statemine_kusama_local_network.toml index 1f3debfb9d29..f7de44a1fb63 100644 --- a/cumulus/zombienet/examples/statemine_kusama_local_network.toml +++ b/cumulus/zombienet/examples/statemine_kusama_local_network.toml @@ -1,5 +1,5 @@ [relaychain] -default_command = "../polkadot/target/release/polkadot" +default_command = "./target/release/polkadot" default_args = [ "-lparachain=debug" ] chain = "kusama-local"