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

Coretime Lease Swap Instructions #6308

Merged
merged 8 commits into from
Oct 18, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
102 changes: 102 additions & 0 deletions docs/learn/learn-guides-coretime-swap.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
---
id: learn-guides-coretime-swap
title: Coretime Lease Swap
sidebar_label: Coretime Swap
description: A guide to leverage the swap lease functionality for different parachains
keywords: [coretime, blockspace, parachain, cores, lease]
slug: ../learn-guides-coretime-parachains
---

The following is a guide to leverage the swap functionality to change leases between different
paraIDs. This allows parachain teams to swap existing leases.

Coretime swapping requires two chains to send a `swap` instruction from an origin with Root
privileges. Depending on whether the parachain is locked or not, this can either be the manager
account of the parachain on the relay chain (if parachain is not locked), or the governance system
in place for the parachain (can be sudo) if the parachain is locked.

In order to check if a parachain is locked or not, teams need to query `registrar.paras` with the
corresponding paraID on the relay chain. It's important to note that since
[RFC #14](https://github.com/polkadot-fellows/RFCs/pull/14), if a parachain never produced a block
the it's by default unlocked.

## Initiate Swap from the Parachain

To swap from a parachain, an XCM message needs to be sent from the parachain to the relay chain.
This XCM message must be a send instruction that wraps the `registrar.swap` extrinsic that needs to
be executed on the relay chain.

Below, you can find an example hex encoded call for Composable Finance, assuming the team is still
operating under SUDO.

[0x0200290003010003140004000000000700e876481713000000000700e87648170006000700e40b540282380100284603e3070000320d0000140d01000001008d1f](https://polkadot.js.org/apps/?rpc=wss%3A%2F%2Fcomposable-rpc.dwellir.com#/extrinsics/decode/0x0200290003010003140004000000000700e876481713000000000700e87648170006000700e40b540282380100284603e3070000320d0000140d01000001008d1f)

As for weights (size and time), there's an overestimation from what can be queried from the polkadot
relay chain.
DrW3RK marked this conversation as resolved.
Show resolved Hide resolved

To check the exact weights, you can navigate to Polkadot JS UI > Developer > Runtime Calls and then
select `transactionPaymentCallInfo` and `queryCallInfo` and include the extrinsic being sent in the
`send` instruction of the XCM message:
[0x4603e3070000320d0000](https://polkadot.js.org/apps/?rpc=wss%3A%2F%2Frpc.ibp.network%2Fpolkadot#/extrinsics/decode/0x4603e3070000320d0000)

![TX-payment-API-Lease-Swap](../assets/coretime/tx-payment-api-weights-lease-swap.png)
Copy link
Contributor

Choose a reason for hiding this comment

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

Really its length should be provided since the screenshot also shows the partial fee, but here we're mostly interested in the weight so I get that it's not relevant.

Copy link
Member Author

Choose a reason for hiding this comment

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

Just curious. What value should be entered in len field? Like the pre-image length of this call which is 10?


## Perform Swap on the Relay chain for an unlocked Parachain

In the case a parachain is unlocked, then the manager of the parachain on the relaychain must send
the extrinsic directly on the relaychain.

In the case of paraID 3378 wanting to swap with Composable Finance, the extrinsic to send from its
manager account `13B8Tdhi4EuruwzVt3gdcTopXpqbUzmncutiQKKNbd8cpU91` is:

[0x4603320d0000e3070000](https://polkadot.js.org/apps/?rpc=wss%3A%2F%2Frpc.ibp.network%2Fpolkadot#/extrinsics/decode/0x4603320d0000e3070000)

## Coretime Swap Prerequisites

We need to ensure the parachains have a valid cores to execute the swap instruction. This can be
achieved either by getting a core in bulk from the coretime system chain, or by leveraging the
Copy link
Contributor

Choose a reason for hiding this comment

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

Also could be an ongoing lease (these are still respected by the coretime chain)

onDemand functionality on relay chain. Assuming that teams have a working parachain (with a valid
core) and a stalled parachain, the following instructions explain how to get a core `onDemand` for
the stalled parachain.

### Swap through an OnDemand Core

This functionality exists on the relay chain and allows users to request for 1 block of validation
of their parachain. In order to place an order for on demand, any account must call the
`onDemand.placeOrderAllowDeath` extrinsic.

![onDemand-block-production](../assets/coretime/onDemand-block-production.png)
Copy link
Contributor

Choose a reason for hiding this comment

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

It would be nice if the screenshot included the params mentioned in the doc

Copy link
Contributor

Choose a reason for hiding this comment

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

Only issue is what paraID to include, maybe we can add something like "your_para_id". And my OCD would also say with an updated metadata :)

Copy link
Contributor

Choose a reason for hiding this comment

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

I was thinking about the composable call included above, I think since that case is used up there we can use it throughout, or alternatively just have some fictitious swap between asset hub and bridge hub or something so people can see which numbers go where

Copy link
Member Author

Choose a reason for hiding this comment

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

Fair point. I'll go along with the composable example. This would be 2019 (the chain that is going to send the XCM call)


This extrinsic takes two parameters:

- Amount: This refers to the amount the user wants to pay for the parachain block to be validated by
a core. There's a minimum amount which depends on the queue, but the minimum amount the system
allows is 250,000,000 planckDOT (0.25 DOT)
DrW3RK marked this conversation as resolved.
Show resolved Hide resolved

- paraID: This refers to the `paraID` of the on-demand Parachain whose block must be
validated by a core.

### Core Swap Execution Steps

If you are a team with two parachains, one that has a lease with a fresh paraID, and an old one that
doesn't have a lease but contains the history of the chain then below is a list of steps to execute
to swap these leases.

Assumptions

- Your new paraID is unlocked and your old paraID is locked.
- You have access to the manager account on the relay chain for the new paraID
- You have your collators running on your old paraID and you can execute upward XCM messages from
that parachain.
- The sovereign account for both paraIDs on the relay chain has enough available funds to execute
DrW3RK marked this conversation as resolved.
Show resolved Hide resolved
transactions on the relay chain.

Steps

- Have the collator running for your original paraID.
- Send the [XCM instruction detailed before](#initiate-swap-from-the-parachain).
- Get a onDemandCore for your original paraID. Once this gets executed, your XCM message should be
dispatched to the relay chain and you should see a pending swap.
- Use the manager account on your new paraID to send the
[swap instruction](#perform-swap-on-the-relay-chain-for-an-unlocked-parachain) directly on the
relay chain.
3 changes: 2 additions & 1 deletion polkadot-wiki/sidebars.js
Original file line number Diff line number Diff line change
Expand Up @@ -568,7 +568,8 @@ module.exports = {
items: [
"build/build-guides-install-deps",
"build/build-guides-template-basic",
"build/build-guides-coretime-troubleshoot"
"build/build-guides-coretime-troubleshoot",
"learn/learn-guides-coretime-swap"
]
}
],
Expand Down
Loading