-
Notifications
You must be signed in to change notification settings - Fork 732
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good!
bot bench polkadot-pallet --runtime=coretime-rococo-dev --pallet=pallet_broker |
bot help |
bot bench substrate-pallet --pallet=pallet_broker |
bot bench cumulus-coretime --pallet=pallet_broker |
…=dev --target_dir=substrate --pallet=pallet_broker
…=coretime-rococo --runtime_dir=coretime --target_dir=cumulus --pallet=pallet_broker
bot bench cumulus-coretime --runtime coretime-westend --pallet=pallet_broker |
…=coretime-westend --runtime_dir=coretime --target_dir=cumulus --pallet=pallet_broker
bot clean |
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. |
PR doc missing. Worth mentioning to users that this is taking care of their swaps. |
There was a problem hiding this 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; |
There was a problem hiding this comment.
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
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point though!
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
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); |
There was a problem hiding this comment.
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"
There was a problem hiding this comment.
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);
There was a problem hiding this comment.
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.
Co-authored-by: Bastian Köcher <[email protected]>
The CI pipeline was cancelled due to failure one of the required jobs. |
Tested locally with zombienet - no issues found. |
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]>
This PR notifies broker pallet for any parachain slot swaps performed on the relay chain. This is achieved by registering an
OnSwap
for the thecoretime
pallet. The hook sends XCM message to the broker chain and invokes a new extrinsicswap_leases
which updatesLeases
storage item (which keeps the legacy parachain leases).I made two assumptions in this PR:
Leases
inbroker
pallet andLeases
inslots
pallet are in sync.swap_leases
extrinsic frombroker
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 frombroker
pallet.Closes #3552
TODOs: