Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Configure XCM messaging between Relay Chain and Parachain #31

Merged
merged 11 commits into from
May 27, 2024

Conversation

th7nder
Copy link
Contributor

@th7nder th7nder commented May 21, 2024

Related to #16.

It's a part of an end-user scenario, when someone wants to use our system chain, first needs to have an account and funds to seal some kind of storage deal.
This PR answers the question: how do we transfer Native DOTs to the parachain and how to implement it?

Transfering native assets between chains happens via XCM messages which are executed by a XCM virtual machine on nodes.
Here is a great description how does it work under the hood.

Bottom line is, there are 2 kinds of asset transfer. One is Teleport, the other one is Reserve. Our chain is a system parachain, so we are using Teleportation, because it's designed for a trusted chains.
Under the hood it burns the tokens on one chain and mints them on the other one, that's why they need to be trusted.
In this regard, our chain works similarly to the Asset Hub(which also uses native tokens).

The configuration I did is based off two main configurations:

Basically, we needed to setup trust:

  • by using TrustedTeleporters in the xcm_config, so we don't Mint assets from god knows who,
  • allow HRMP communication, so the chains can talk with each other (XCM messages are just messages, they need a communication protocol)
  • configuring some fees, so the parachain/system chain don't pay any additional fees for transfers.

And a whole lot of testing...

The tests were performed using https://polkadot.js.org/apps/, Developer -> Extrinsics tab, and the website was connected to our local testnet.
Basically, you dispatch an extrinsic: xcmPallet.teleportAssets with a proper configuration (it took some time to figure this one out). Proper configuration in the end, could be based off the implementation of teleport functionality in the polkadot.js.org/apps. This teleport functionality for Polkadot<->AssetHub, Kusama<->AssetHub is there, but for some reason it doesn't show for our chain, didn't debug why though.

image

In the end, the proper XCM messages are:

  1. Relay Chain -> Parachain:
{
    dest: {
        interior: {
            X1: {
                ParaChain: 1000,
            }
        },
        parents: 0
    },
    beneficiary: {
        interior: {
            X1: {
                AccountId32: {
                    id: '0x1cbd2d43530a44705ad088af313e18f80b53ef16b36177cd4b77b846f2a5f07c',
                    network: null
                }
            }
        },
        parents: 0
    },
    assets: [{
        fun: {
            Fungible: 69100200300400,
        },
        id: {
            Concrete: {
                interior: 'Here',
                parents: 0
            }
        }
    }]
}
  1. Parachain <-> Relay:
{
    dest: {
        interior: 'Here',
        parents: 1
    },
    beneficiary: {
        interior: {
            X1: {
                AccountId32: {
                    id: '0x1cbd2d43530a44705ad088af313e18f80b53ef16b36177cd4b77b846f2a5f07c',
                    network: null
                }
            }
        },
        parents: 0
    },
    assets: [{
        fun: {
            Fungible: 69100200300400,
        },
        id: {
            Concrete: {
                interior: 'Here',
                parents: 1
            }
        }
    }]
};

Where accounts ID where converted using the subkey command, by just copying AccountIDs there:

➜  polkadot-sdk git:(polkadot-v1.11.0) ✗ ./target/release/subkey inspect 5CiPPseXPECbkjWCa6MnjNokrgYjMqmKndv2rSnekmSK2DjL
Public Key URI `5CiPPseXPECbkjWCa6MnjNokrgYjMqmKndv2rSnekmSK2DjL` is account:
  Network ID/Version: substrate
  Public key (hex):   0x1cbd2d43530a44705ad088af313e18f80b53ef16b36177cd4b77b846f2a5f07c
  Account ID:         0x1cbd2d43530a44705ad088af313e18f80b53ef16b36177cd4b77b846f2a5f07c
  Public key (SS58):  5CiPPseXPECbkjWCa6MnjNokrgYjMqmKndv2rSnekmSK2DjL
  SS58 Address:       5CiPPseXPECbkjWCa6MnjNokrgYjMqmKndv2rSnekmSK2DjL

Note that the accounts on the relay chain and parachain have the same account id, as they use the same SS58 prefix.

Tested the scenario, screenshots, i.e. Eve received funds when it was teleported from the relay chain.
image
image
image

@th7nder th7nder self-assigned this May 21, 2024
@th7nder th7nder linked an issue May 21, 2024 that may be closed by this pull request
@th7nder
Copy link
Contributor Author

th7nder commented May 21, 2024

note to self: make a test to teleport from the parachain to the relay chain

@th7nder
Copy link
Contributor Author

th7nder commented May 22, 2024

So...
In the end, I managed to transfer the balances out (Burn them in our parachain), but failed to receive them in the relay chain, because:

2024-05-22 16:32:24.009 TRACE tokio-runtime-worker xcm::fungible_adapter: can_check_in origin: Location { parents: 0, interior: X1([Parachain(1000)]) }, what: Asset { id: AssetId(Location { parents: 0, interior: Here }), fun: Fungible(69100) }
2024-05-22 16:32:24.009 TRACE tokio-runtime-worker xcm::execute: !!! ERROR: NotWithdrawable
2024-05-22 16:32:24.009 TRACE tokio-runtime-worker xcm::execute: result: Err(ExecutorError { index: 0, xcm_error: NotWithdrawable, weight: Weight { ref_time: 157409000, proof_size: 3593 } })

However, I'd say that's acceptable as I was able to replicate the same thing with launching local rococo asset hub and local rococo relay chain. For some reason, teleporting it back to the relay chain doesn't work (locally).

It took me a while to figure out correct parameters for the transaction back and I was going around in circles.
Here is the correct XCM message for Parachain -> Relay Chain teleport, based on polkadot.js.org UI. - which for some reason doesn't show on our local set-up, haven't digged out why.

image

Most important thing about those parameters is that you need to set Parents = 1 in the assets.

@th7nder th7nder marked this pull request as ready for review May 22, 2024 16:05
@th7nder th7nder requested review from aidan46 and serg-temchenko May 22, 2024 16:05
@th7nder th7nder added the ready for review Review is needed label May 22, 2024
@serg-temchenko
Copy link
Contributor

This PR is also related to Issue #14 and highlights an overlooked aspect related to transferring assets from other parachains. To avoid confusion and clarify the concepts, we need to distinguish between two types of asset transfers in our system: one involves teleporting assets using XCM, and the other involves transferring assets internally within our parachain between different accounts using the balances pallet.

Also, I've created a separate issue #36 for this PR.

Copy link
Contributor

@serg-temchenko serg-temchenko left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please point to some docs or describe what has been changed and why in this PR so we could easily understand what is happening here?

runtime/src/configs/xcm_config.rs Show resolved Hide resolved
runtime/src/configs/xcm_config.rs Outdated Show resolved Hide resolved
@th7nder th7nder linked an issue May 23, 2024 that may be closed by this pull request
Copy link
Contributor

@jmg-duarte jmg-duarte left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nothing particularly sticks out to me, but I do have some questions.

Basically, you dispatch an extrinsic: xcmPallet.teleportAssets with a proper configuration (it took some time to figure this one out). Proper configuration in the end, could be based off the implementation of teleport functionality in the polkadot.js.org/apps.

  • Should we open a new issue for further investigation?
  • Is there any way of automating these tests?
  • Shouldn't we document the procedure somewhere?

This teleport functionality for Polkadot<->AssetHub, Kusama<->AssetHub is there, but for some reason it doesn't show for our chain, didn't debug why though.

Could this be related to the IDs?

runtime/src/configs/xcm_config.rs Outdated Show resolved Hide resolved
runtime/src/configs/xcm_config.rs Show resolved Hide resolved
runtime/src/configs/xcm_config.rs Outdated Show resolved Hide resolved
@th7nder
Copy link
Contributor Author

th7nder commented May 23, 2024

Nothing particularly sticks out to me, but I do have some questions.

Basically, you dispatch an extrinsic: xcmPallet.teleportAssets with a proper configuration (it took some time to figure this one out). Proper configuration in the end, could be based off the implementation of teleport functionality in the polkadot.js.org/apps.

* Should we open a new issue for further investigation?

Created one: #39.

* Is there any way of automating these tests?

Probably there is, but it needs to be designed and consider. It boils down to e2e testing on local testnet.
When was scouring through the network, found something like this. Added an issue #38 .

* Shouldn't we document the procedure somewhere?

It's kinda documented here, in the PR description, but I'll add it to the parachain-implementation in the scope of #16 , and documenting the actor functionality.

This teleport functionality for Polkadot<->AssetHub, Kusama<->AssetHub is there, but for some reason it doesn't show for our chain, didn't debug why though.

Could this be related to the IDs?

Got no idea, #39.

@th7nder th7nder removed the ready for review Review is needed label May 24, 2024
@th7nder th7nder added the ready for review Review is needed label May 24, 2024
@th7nder
Copy link
Contributor Author

th7nder commented May 24, 2024

It should be merged after #37 is merged, for the build to succeed.

@th7nder th7nder requested a review from jmg-duarte May 27, 2024 12:13
@th7nder th7nder added ready for review Review is needed and removed ready for review Review is needed labels May 27, 2024
@th7nder th7nder enabled auto-merge May 27, 2024 14:21
@th7nder th7nder added ready for review Review is needed and removed ready for review Review is needed labels May 27, 2024
@th7nder th7nder merged commit f09016e into develop May 27, 2024
3 checks passed
@th7nder th7nder deleted the feat/16/accounts branch May 27, 2024 18:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ready for review Review is needed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Assets transfer between our parachain and other parachains
3 participants