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

Migrate parachain swaps to Coretime #3714

Merged
merged 24 commits into from
Mar 26, 2024
Merged

Migrate parachain swaps to Coretime #3714

merged 24 commits into from
Mar 26, 2024

Conversation

tdimitrov
Copy link
Contributor

@tdimitrov tdimitrov commented Mar 15, 2024

This PR notifies broker pallet for any parachain slot swaps performed on the relay chain. This is achieved by registering an OnSwap for the the coretime pallet. The hook sends XCM message to the broker chain and invokes a new extrinsic swap_leases which updates Leases storage item (which keeps the legacy parachain leases).

I made two assumptions in this PR:

  1. Leases in broker pallet and Leases in slots pallet are in sync.
  2. swap_leases extrinsic from broker pallet can be triggered only by root or by the XCM message from the relay chain. If not - the extrinsic will generate an error and do nothing.

As a side effect from the changes OnSwap trait is moved from runtime/common/traits.rs to runtime/parachains. Otherwise it is not accessible from broker pallet.

Closes #3552

TODOs:

  • Weights
  • Tests

Copy link
Member

@eskimor eskimor left a comment

Choose a reason for hiding this comment

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

Looks good!

polkadot/runtime/common/src/traits.rs Outdated Show resolved Hide resolved
@tdimitrov tdimitrov added the T8-polkadot This PR/Issue is related to/affects the Polkadot network. label Mar 18, 2024
@tdimitrov
Copy link
Contributor Author

bot bench polkadot-pallet --runtime=coretime-rococo-dev --pallet=pallet_broker
bot bench polkadot-pallet --runtime=dev --pallet=pallet_broker

@tdimitrov
Copy link
Contributor Author

bot help

@tdimitrov
Copy link
Contributor Author

bot bench substrate-pallet --pallet=pallet_broker

@tdimitrov
Copy link
Contributor Author

bot bench cumulus-coretime --pallet=pallet_broker

command-bot added 3 commits March 20, 2024 07:55
…=dev --target_dir=substrate --pallet=pallet_broker
…=coretime-rococo --runtime_dir=coretime --target_dir=cumulus --pallet=pallet_broker
@tdimitrov
Copy link
Contributor Author

bot bench cumulus-coretime --runtime coretime-westend --pallet=pallet_broker

…=coretime-westend --runtime_dir=coretime --target_dir=cumulus --pallet=pallet_broker
@tdimitrov
Copy link
Contributor Author

bot clean

@tdimitrov tdimitrov marked this pull request as ready for review March 21, 2024 09:27
@tdimitrov tdimitrov requested a review from a team as a code owner March 21, 2024 09:27
@tdimitrov
Copy link
Contributor Author

To get this tested we need to ensure that the interaction between the relay and broker chain works correctly. So unit test or integration test (as in runtime integration tests) is not enough.

We can test this with zombienet but this will mean to port this test to zombienet which won't be trivial.

For these reasons the plan is to test this PR directly on Rococo.

@tdimitrov tdimitrov requested a review from antonva March 21, 2024 09:30
@eskimor
Copy link
Member

eskimor commented Mar 21, 2024

PR doc missing. Worth mentioning to users that this is taking care of their swaps.

polkadot/runtime/rococo/src/lib.rs Outdated Show resolved Hide resolved
Copy link
Contributor

@antonva antonva left a comment

Choose a reason for hiding this comment

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

Looks good to me so far.

.into_iter()
.map(|mut lease| {
if lease.task == id {
lease.task = other;
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: I don't think TaskId uniqueness is enforced anywhere in Leases, so this effectively swaps all leases sharing a TaskId. This shouldn't really matter as there should only be one task for both id and other.

Copy link
Member

Choose a reason for hiding this comment

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

Good point though!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I thought there could be multiple leases and we do want to swap all of them.

If this is the case, we'd better add another ensure! for it?

Copy link
Contributor Author

@tdimitrov tdimitrov Mar 21, 2024

Choose a reason for hiding this comment

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

Like this -> f5f6dce

The error code I use is not entirely correct but I don't see a point adding a new one just for a temp call.

Copy link
Member

Choose a reason for hiding this comment

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

No Basti has a point. The "correctness" of the swap has already been verified on the relay chain, we should be very lenient on the Coretime chain. In particular, there could be a race and the lease of one para expired by the time the message arrives at the coretime chain (admittedly super unlikely edge case, but still), we should still do the swap, although one of the leases does not exist.

I mean that race in particular is really super niche, if a user updates that close he could miss the deadline himself already.

Nevertheless, I would err on as little ensures as possible: The swap is confirmed, it actually has to be good.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, I came to the same conclusion and removed everything. Even if someone decides to use the extrinsic directly it can be called again and 'undo' the result.

Comment on lines 461 to 463
ensure!(id_leases_count > 0 && other_leases_count > 0, Error::<T>::UnknownReservation);
// And ensure there are just to leases to be swapped
ensure!(id_leases_count == 1 && other_leases_count == 1, Error::<T>::TooManyLeases);
Copy link
Member

Choose a reason for hiding this comment

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

This is wrong. When one of the leases for example already ended, you should still be able to swap it with a "working one"

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I can imagine the source lease (id in this case) might not exist and is not correct to enforce its existence because of what you wrote.

But why would one want to swap something with a non-existent lease? The way I understand it we should have:

ensure!(other_leases_count > 0, Error::<T>::UnknownXXX);

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Never mind, it's unnecessary complication. Even if someone does it - he/she can revert it back anytime.

substrate/frame/broker/src/dispatchable_impls.rs Outdated Show resolved Hide resolved
substrate/frame/broker/src/dispatchable_impls.rs Outdated Show resolved Hide resolved
@paritytech-review-bot paritytech-review-bot bot requested a review from a team March 22, 2024 08:48
@paritytech-cicd-pr
Copy link

The CI pipeline was cancelled due to failure one of the required jobs.
Job name: test-linux-stable 2/3
Logs: https://gitlab.parity.io/parity/mirrors/polkadot-sdk/-/jobs/5613814

@tdimitrov
Copy link
Contributor Author

Tested locally with zombienet - no issues found.

@tdimitrov tdimitrov added this pull request to the merge queue Mar 26, 2024
Merged via the queue into master with commit 9023454 Mar 26, 2024
125 of 132 checks passed
@tdimitrov tdimitrov deleted the tsv-ct-parachain-swaps branch March 26, 2024 17:00
dharjeezy pushed a commit to dharjeezy/polkadot-sdk that referenced this pull request Apr 9, 2024
This PR notifies broker pallet for any parachain slot swaps performed on
the relay chain. This is achieved by registering an `OnSwap` for the the
`coretime` pallet. The hook sends XCM message to the broker chain and
invokes a new extrinsic `swap_leases` which updates `Leases` storage
item (which keeps the legacy parachain leases).

I made two assumptions in this PR:
1.
[`Leases`](https://github.com/paritytech/polkadot-sdk/blob/4987d7982461e2e5ffe219cdf71ec697284cea7c/substrate/frame/broker/src/lib.rs#L120)
in `broker` pallet and
[`Leases`](https://github.com/paritytech/polkadot-sdk/blob/4987d7982461e2e5ffe219cdf71ec697284cea7c/polkadot/runtime/common/src/slots/mod.rs#L118)
in `slots` pallet are in sync.
2. `swap_leases` extrinsic from `broker` pallet can be triggered only by
root or by the XCM message from the relay chain. If not - the extrinsic
will generate an error and do nothing.

As a side effect from the changes `OnSwap` trait is moved from
runtime/common/traits.rs to runtime/parachains. Otherwise it is not
accessible from `broker` pallet.

Closes paritytech#3552

TODOs:

- [x] Weights
- [x] Tests

---------

Co-authored-by: command-bot <>
Co-authored-by: eskimor <[email protected]>
Co-authored-by: Bastian Köcher <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
T8-polkadot This PR/Issue is related to/affects the Polkadot network.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Migrate parachain swaps to Coretime + cancel auctions
6 participants