Skip to content
This repository has been archived by the owner on Oct 22, 2024. It is now read-only.

Commit

Permalink
Fixed local run for AssetHubKusama/AssetHubPolkadot asset transfer (K…
Browse files Browse the repository at this point in the history
…SMs/DOTs)
  • Loading branch information
bkontur committed Sep 11, 2023
1 parent 11e0931 commit a3d1264
Show file tree
Hide file tree
Showing 6 changed files with 129 additions and 75 deletions.
79 changes: 42 additions & 37 deletions cumulus/parachains/runtimes/bridge-hubs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 <somewhere-outside-polkadot-sdk-git-repo-dir>
# git clone https://github.com/paritytech/parachain-utils.git
# cd parachain-utils # -> this is <parachain-utils-git-repo-dir>
# cargo build --release --bin sudofi
#
# cd <polkadot-sdk-git-repo-dir>/pokladot
# <parachain-utils-git-repo-dir>/target/release/sudoif
cargo build --release --features fast-runtime
cd <polkadot-sdk-git-repo-dir>
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
Expand All @@ -74,7 +85,7 @@ cp target/release/substrate-relay ~/local_bridge_testing/bin/substrate-relay
---
# 4. Build cumulus polkadot-parachain binary
cd <cumulus-git-repo-dir>
cd <polkadot-sdk-git-repo-dir>
# checkout desired branch or use master:
# git checkout -b master --track origin/master
Expand All @@ -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
Expand Down Expand Up @@ -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 <polkadot-sdk-git-repo-dir>
# 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-sdk-git-repo-dir>
# 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 <cumulus-git-repo-dir>
./scripts/bridges_kusama_polkadot.sh run-relay
cd <polkadot-sdk-git-repo-dir>
./cumulus/scripts/bridges_kusama_polkadot.sh run-relay
```

### 3. Initialize transfer asset over bridge (DOTs/KSMs)
Expand All @@ -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 <polkadot-sdk-git-repo-dir>
./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 <polkadot-sdk-git-repo-dir>
# 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 <polkadot-sdk-git-repo-dir>
# 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)
Expand Down
43 changes: 32 additions & 11 deletions cumulus/scripts/bridges_kusama_polkadot.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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" \
Expand All @@ -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" \
Expand All @@ -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
Expand All @@ -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"
;;
Expand All @@ -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"
;;
Expand Down
36 changes: 32 additions & 4 deletions cumulus/scripts/bridges_rococo_wococo.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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}"
}
Expand Down Expand Up @@ -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
Expand Down
22 changes: 11 additions & 11 deletions cumulus/zombienet/bridge-hubs/bridge_hub_kusama_local_network.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[relaychain]
default_command = "../polkadot/target/release/polkadot"
default_command = "./target/release/polkadot"
default_args = [ "-lparachain=debug" ]
chain = "kusama-local"

Expand Down

0 comments on commit a3d1264

Please sign in to comment.