Files
pezkuwi-subxt/cumulus/parachains/runtimes/bridge-hubs
Adrian Catangiu 18257373b3 pallet-xcm: enhance reserve_transfer_assets to support remote reserves (#1672)
## Motivation

`pallet-xcm` is the main user-facing interface for XCM functionality,
including assets manipulation functions like `teleportAssets()` and
`reserve_transfer_assets()` calls.

While `teleportAsset()` works both ways, `reserve_transfer_assets()`
works only for sending reserve-based assets to a remote destination and
beneficiary when the reserve is the _local chain_.

## Solution

This PR enhances `pallet_xcm::(limited_)reserve_withdraw_assets` to
support transfers when reserves are other chains.
This will allow complete, **bi-directional** reserve-based asset
transfers user stories using `pallet-xcm`.

Enables following scenarios:
- transferring assets with local reserve (was previously supported iff
asset used as fee also had local reserve - now it works in all cases),
- transferring assets with reserve on destination,
- transferring assets with reserve on remote/third-party chain (iff
assets and fees have same remote reserve),
- transferring assets with reserve different than the reserve of the
asset to be used as fees - meaning can be used to transfer random asset
with local/dest reserve while using DOT for fees on all involved chains,
even if DOT local/dest reserve doesn't match asset reserve,
- transferring assets with any type of local/dest reserve while using
fees which can be teleported between involved chains.

All of the above is done by pallet inner logic without the user having
to specify which scenario/reserves/teleports/etc. The correct scenario
and corresponding XCM programs are identified, and respectively, built
automatically based on runtime configuration of trusted teleporters and
trusted reserves.

#### Current limitations:
- while `fees` and "non-fee" `assets` CAN have different reserves (or
fees CAN be teleported), the remaining "non-fee" `assets` CANNOT, among
themselves, have different reserve locations (this is also implicitly
enforced by `MAX_ASSETS_FOR_TRANSFER=2`, but this can be safely
increased in the future).
- `fees` and "non-fee" `assets` CANNOT have **different remote**
reserves (this could also be supported in the future, but adds even more
complexity while possibly not being worth it - we'll see what the future
holds).

Fixes https://github.com/paritytech/polkadot-sdk/issues/1584
Fixes https://github.com/paritytech/polkadot-sdk/issues/2055

---------

Co-authored-by: Francisco Aguirre <franciscoaguirreperez@gmail.com>
Co-authored-by: Branislav Kontur <bkontur@gmail.com>
2023-11-13 17:16:55 +02:00
..

Bridge-hub Parachains

BridgeHub(s) are system parachains that will house trustless bridges from the local ecosystem to others. The current trustless bridges planned for the BridgeHub(s) are:

  • BridgeHubPolkadot system parachain:
    1. Polkadot <-> Kusama bridge
    2. Polkadot <-> Ethereum bridge (Snowbridge)
  • BridgeHubKusama system parachain:
    1. Kusama <-> Polkadot bridge
    2. Kusama <-> Ethereum bridge The high-level responsibilities of each bridge living on BridgeHub:
  • sync finality proofs between relay chains (or equivalent)
  • sync finality proofs between BridgeHub parachains
  • pass (XCM) messages between different BridgeHub parachains

Requirements for local run/testing

# Prepare empty directory for testing
mkdir -p ~/local_bridge_testing/bin
mkdir -p ~/local_bridge_testing/logs

---
# 1. Install zombienet
Go to: https://github.com/paritytech/zombienet/releases
Copy the apropriate binary (zombienet-linux) from the latest release to ~/local_bridge_testing/bin


---
# 2. Build polkadot binary

# If you want to test Kusama/Polkadot bridge, we need "sudo pallet + fast-runtime",
# so we need to use sudofi in polkadot directory.
#
# Install sudofi: (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>/polkadot
# <parachain-utils-git-repo-dir>/target/release/sudofi

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
git clone https://github.com/paritytech/parity-bridges-common.git
cd parity-bridges-common

# checkout desired branch or use master:
# git checkout -b master --track origin/master
# `polkadot-staging` (recommended) is stabilized and compatible for Cumulus releases
# `master` is latest development
git checkout -b polkadot-staging --track origin/polkadot-staging

cargo build --release -p substrate-relay
cp target/release/substrate-relay ~/local_bridge_testing/bin/substrate-relay


---
# 4. Build cumulus polkadot-parachain binary
cd <polkadot-sdk-git-repo-dir>

cargo build --release -p polkadot-parachain-bin
cp target/release/polkadot-parachain ~/local_bridge_testing/bin/polkadot-parachain
cp target/release/polkadot-parachain ~/local_bridge_testing/bin/polkadot-parachain-asset-hub

How to test local Rococo <-> Wococo bridge

Run Rococo/Wococo chains with zombienet

cd <polkadot-sdk-git-repo-dir>

# Rococo + BridgeHubRococo + AssetHub for Rococo (mirroring Kusama)
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_ROCOCO=~/local_bridge_testing/bin/polkadot-parachain-asset-hub \
	~/local_bridge_testing/bin/zombienet-linux --provider native spawn ./cumulus/zombienet/bridge-hubs/bridge_hub_rococo_local_network.toml
cd <polkadot-sdk-git-repo-dir>

# Wococo + BridgeHubWococo + AssetHub for Wococo (mirroring Polkadot)
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_WOCOCO=~/local_bridge_testing/bin/polkadot-parachain-asset-hub \
	~/local_bridge_testing/bin/zombienet-linux --provider native spawn ./cumulus/zombienet/bridge-hubs/bridge_hub_wococo_local_network.toml

Init bridge and run relayer between BridgeHubRococo and BridgeHubWococo

Accounts of BridgeHub parachains:

  • Bob is pallet owner of all bridge pallets

Run with script

cd <polkadot-sdk-git-repo-dir>

./cumulus/scripts/bridges_rococo_wococo.sh run-relay

Check relay-chain headers relaying:

Check parachain headers relaying:

Initialize configuration for transfer asset over bridge (ROCs/WOCs)

This initialization does several things:

  • creates ForeignAssets for wrappedROCs/wrappedWOCs
  • drips SA for AssetHubRococo on AssetHubWococo (and vice versa) which holds reserved assets on source chains
cd <polkadot-sdk-git-repo-dir>

./cumulus/scripts/bridges_rococo_wococo.sh init-asset-hub-rococo-local
./cumulus/scripts/bridges_rococo_wococo.sh init-bridge-hub-rococo-local
./cumulus/scripts/bridges_rococo_wococo.sh init-asset-hub-wococo-local
./cumulus/scripts/bridges_rococo_wococo.sh init-bridge-hub-wococo-local

Send messages - transfer asset over bridge (ROCs/WOCs)

Do (asset) transfers:

cd <polkadot-sdk-git-repo-dir>

# ROCs from Rococo's Asset Hub to Wococo's.
./cumulus/scripts/bridges_rococo_wococo.sh reserve-transfer-assets-from-asset-hub-rococo-local
cd <polkadot-sdk-git-repo-dir>

# WOCs from Wococo's Asset Hub to Rococo's.
./cumulus/scripts/bridges_rococo_wococo.sh reserve-transfer-assets-from-asset-hub-wococo-local

Claim relayer's rewards on BridgeHubRococo and BridgeHubWococo

Accounts of BridgeHub parachains:

  • //Charlie is relayer account on BridgeHubRococo
  • //Charlie is relayer account on BridgeHubWococo
cd <polkadot-sdk-git-repo-dir>

# Claim rewards on BridgeHubWococo:
./cumulus/scripts/bridges_rococo_wococo.sh claim-rewards-bridge-hub-rococo-local

# Claim rewards on BridgeHubWococo:
./cumulus/scripts/bridges_rococo_wococo.sh claim-rewards-bridge-hub-wococo-local

How to test local Rococo <-> Westend bridge

Run Rococo/Westend chains with zombienet

cd <polkadot-sdk-git-repo-dir>

# Rococo + BridgeHubRococo + AssetHub for Rococo (mirroring Kusama)
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_ROCOCO=~/local_bridge_testing/bin/polkadot-parachain-asset-hub \
	~/local_bridge_testing/bin/zombienet-linux --provider native spawn ./cumulus/zombienet/bridge-hubs/bridge_hub_rococo_local_network.toml
cd <polkadot-sdk-git-repo-dir>

# Westend + BridgeHubWestend + AssetHub for Westend (mirroring Polkadot)
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_WESTEND=~/local_bridge_testing/bin/polkadot-parachain-asset-hub \
	~/local_bridge_testing/bin/zombienet-linux --provider native spawn ./cumulus/zombienet/bridge-hubs/bridge_hub_westend_local_network.toml

Init bridge and run relayer between BridgeHubRococo and BridgeHubWestend

Accounts of BridgeHub parachains:

  • Bob is pallet owner of all bridge pallets

Run with script

cd <polkadot-sdk-git-repo-dir>

./cumulus/scripts/bridges_rococo_westend.sh run-relay

Check relay-chain headers relaying:

Check parachain headers relaying:

Initialize configuration for transfer asset over bridge (ROCs/WNDs)

This initialization does several things:

  • creates ForeignAssets for wrappedROCs/wrappedWNDs
  • drips SA for AssetHubRococo on AssetHubWestend (and vice versa) which holds reserved assets on source chains
cd <polkadot-sdk-git-repo-dir>

./cumulus/scripts/bridges_rococo_westend.sh init-asset-hub-rococo-local
./cumulus/scripts/bridges_rococo_westend.sh init-bridge-hub-rococo-local
./cumulus/scripts/bridges_rococo_westend.sh init-asset-hub-westend-local
./cumulus/scripts/bridges_rococo_westend.sh init-bridge-hub-westend-local

Send messages - transfer asset over bridge (ROCs/WNDs)

Do reserve-backed transfers:

cd <polkadot-sdk-git-repo-dir>

# ROCs from Rococo's Asset Hub to Westend's.
./cumulus/scripts/bridges_rococo_westend.sh reserve-transfer-assets-from-asset-hub-rococo-local
cd <polkadot-sdk-git-repo-dir>

# WNDs from Westend's Asset Hub to Rococo's.
./cumulus/scripts/bridges_rococo_westend.sh reserve-transfer-assets-from-asset-hub-westend-local

Do reserve withdraw transfers: (when previous is finished)

cd <polkadot-sdk-git-repo-dir>

# wrappedWNDs from Rococo's Asset Hub to Westend's.
./cumulus/scripts/bridges_rococo_westend.sh withdraw-reserve-assets-from-asset-hub-rococo-local
cd <polkadot-sdk-git-repo-dir>

# wrappedROCs from Westend's Asset Hub to Rococo's.
./cumulus/scripts/bridges_rococo_westend.sh withdraw-reserve-assets-from-asset-hub-westend-local

Claim relayer's rewards on BridgeHubRococo and BridgeHubWestend

Accounts of BridgeHub parachains:

  • //Charlie is relayer account on BridgeHubRococo
  • //Charlie is relayer account on BridgeHubWestend
cd <polkadot-sdk-git-repo-dir>

# Claim rewards on BridgeHubWestend:
./cumulus/scripts/bridges_rococo_westend.sh claim-rewards-bridge-hub-rococo-local

# Claim rewards on BridgeHubWestend:
./cumulus/scripts/bridges_rococo_westend.sh claim-rewards-bridge-hub-westend-local

How to test local BridgeHubKusama/BridgeHubPolkadot

TODO: see # !!! READ HERE above