Migrate parachain swaps to Coretime (#3714)

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 https://github.com/paritytech/polkadot-sdk/issues/3552

TODOs:

- [x] Weights
- [x] Tests

---------

Co-authored-by: command-bot <>
Co-authored-by: eskimor <eskimor@users.noreply.github.com>
Co-authored-by: Bastian Köcher <git@kchr.de>
This commit is contained in:
Tsvetomir Dimitrov
2024-03-26 17:54:24 +02:00
committed by GitHub
parent fd79b3b08a
commit 90234543f3
10 changed files with 461 additions and 322 deletions
@@ -16,26 +16,24 @@
//! Autogenerated weights for `pallet_broker`
//!
//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev
//! DATE: 2024-01-12, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]`
//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 32.0.0
//! DATE: 2024-03-20, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]`
//! WORST CASE MAP SIZE: `1000000`
//! HOSTNAME: `runner-j8vvqcjr-project-674-concurrent-0`, CPU: `Intel(R) Xeon(R) CPU @ 2.60GHz`
//! HOSTNAME: `runner-h2rr8wx7-project-674-concurrent-0`, CPU: `Intel(R) Xeon(R) CPU @ 2.60GHz`
//! WASM-EXECUTION: `Compiled`, CHAIN: `Some("coretime-rococo-dev")`, DB CACHE: 1024
// Executed Command:
// ./target/production/polkadot-parachain
// target/production/polkadot-parachain
// benchmark
// pallet
// --chain=coretime-rococo-dev
// --wasm-execution=compiled
// --pallet=pallet_broker
// --no-storage-info
// --no-median-slopes
// --no-min-squares
// --extrinsic=*
// --steps=50
// --repeat=20
// --json
// --extrinsic=*
// --wasm-execution=compiled
// --heap-pages=4096
// --json-file=/builds/parity/mirrors/polkadot-sdk/.git/.artifacts/bench.json
// --pallet=pallet_broker
// --chain=coretime-rococo-dev
// --header=./cumulus/file_header.txt
// --output=./cumulus/parachains/runtimes/coretime/coretime-rococo/src/weights/
@@ -56,8 +54,8 @@ impl<T: frame_system::Config> pallet_broker::WeightInfo for WeightInfo<T> {
// Proof Size summary in bytes:
// Measured: `0`
// Estimated: `0`
// Minimum execution time: 2_462_000 picoseconds.
Weight::from_parts(2_552_000, 0)
// Minimum execution time: 1_918_000 picoseconds.
Weight::from_parts(2_092_000, 0)
.saturating_add(Weight::from_parts(0, 0))
.saturating_add(T::DbWeight::get().writes(1))
}
@@ -67,8 +65,8 @@ impl<T: frame_system::Config> pallet_broker::WeightInfo for WeightInfo<T> {
// Proof Size summary in bytes:
// Measured: `10888`
// Estimated: `13506`
// Minimum execution time: 25_494_000 picoseconds.
Weight::from_parts(26_063_000, 0)
// Minimum execution time: 21_943_000 picoseconds.
Weight::from_parts(22_570_000, 0)
.saturating_add(Weight::from_parts(0, 13506))
.saturating_add(T::DbWeight::get().reads(1))
.saturating_add(T::DbWeight::get().writes(1))
@@ -79,8 +77,8 @@ impl<T: frame_system::Config> pallet_broker::WeightInfo for WeightInfo<T> {
// Proof Size summary in bytes:
// Measured: `12090`
// Estimated: `13506`
// Minimum execution time: 22_299_000 picoseconds.
Weight::from_parts(22_911_000, 0)
// Minimum execution time: 20_923_000 picoseconds.
Weight::from_parts(21_354_000, 0)
.saturating_add(Weight::from_parts(0, 13506))
.saturating_add(T::DbWeight::get().reads(1))
.saturating_add(T::DbWeight::get().writes(1))
@@ -95,8 +93,8 @@ impl<T: frame_system::Config> pallet_broker::WeightInfo for WeightInfo<T> {
// Proof Size summary in bytes:
// Measured: `466`
// Estimated: `1951`
// Minimum execution time: 11_590_000 picoseconds.
Weight::from_parts(12_007_000, 0)
// Minimum execution time: 10_687_000 picoseconds.
Weight::from_parts(11_409_000, 0)
.saturating_add(Weight::from_parts(0, 1951))
.saturating_add(T::DbWeight::get().reads(3))
.saturating_add(T::DbWeight::get().writes(1))
@@ -124,11 +122,11 @@ impl<T: frame_system::Config> pallet_broker::WeightInfo for WeightInfo<T> {
// Proof Size summary in bytes:
// Measured: `12567`
// Estimated: `14052`
// Minimum execution time: 120_928_000 picoseconds.
Weight::from_parts(124_947_252, 0)
// Minimum execution time: 111_288_000 picoseconds.
Weight::from_parts(117_804_282, 0)
.saturating_add(Weight::from_parts(0, 14052))
// Standard Error: 435
.saturating_add(Weight::from_parts(1_246, 0).saturating_mul(n.into()))
// Standard Error: 391
.saturating_add(Weight::from_parts(1_243, 0).saturating_mul(n.into()))
.saturating_add(T::DbWeight::get().reads(8))
.saturating_add(T::DbWeight::get().writes(66))
}
@@ -144,8 +142,8 @@ impl<T: frame_system::Config> pallet_broker::WeightInfo for WeightInfo<T> {
// Proof Size summary in bytes:
// Measured: `316`
// Estimated: `3593`
// Minimum execution time: 32_826_000 picoseconds.
Weight::from_parts(33_889_000, 0)
// Minimum execution time: 33_006_000 picoseconds.
Weight::from_parts(34_256_000, 0)
.saturating_add(Weight::from_parts(0, 3593))
.saturating_add(T::DbWeight::get().reads(3))
.saturating_add(T::DbWeight::get().writes(2))
@@ -166,8 +164,8 @@ impl<T: frame_system::Config> pallet_broker::WeightInfo for WeightInfo<T> {
// Proof Size summary in bytes:
// Measured: `434`
// Estimated: `4698`
// Minimum execution time: 57_362_000 picoseconds.
Weight::from_parts(58_994_000, 0)
// Minimum execution time: 61_473_000 picoseconds.
Weight::from_parts(66_476_000, 0)
.saturating_add(Weight::from_parts(0, 4698))
.saturating_add(T::DbWeight::get().reads(5))
.saturating_add(T::DbWeight::get().writes(4))
@@ -178,8 +176,8 @@ impl<T: frame_system::Config> pallet_broker::WeightInfo for WeightInfo<T> {
// Proof Size summary in bytes:
// Measured: `357`
// Estimated: `3550`
// Minimum execution time: 13_982_000 picoseconds.
Weight::from_parts(14_447_000, 0)
// Minimum execution time: 13_771_000 picoseconds.
Weight::from_parts(14_374_000, 0)
.saturating_add(Weight::from_parts(0, 3550))
.saturating_add(T::DbWeight::get().reads(1))
.saturating_add(T::DbWeight::get().writes(1))
@@ -190,8 +188,8 @@ impl<T: frame_system::Config> pallet_broker::WeightInfo for WeightInfo<T> {
// Proof Size summary in bytes:
// Measured: `357`
// Estimated: `3550`
// Minimum execution time: 15_070_000 picoseconds.
Weight::from_parts(15_735_000, 0)
// Minimum execution time: 15_162_000 picoseconds.
Weight::from_parts(15_742_000, 0)
.saturating_add(Weight::from_parts(0, 3550))
.saturating_add(T::DbWeight::get().reads(1))
.saturating_add(T::DbWeight::get().writes(2))
@@ -202,8 +200,8 @@ impl<T: frame_system::Config> pallet_broker::WeightInfo for WeightInfo<T> {
// Proof Size summary in bytes:
// Measured: `357`
// Estimated: `3550`
// Minimum execution time: 16_527_000 picoseconds.
Weight::from_parts(16_894_000, 0)
// Minimum execution time: 16_196_000 picoseconds.
Weight::from_parts(16_796_000, 0)
.saturating_add(Weight::from_parts(0, 3550))
.saturating_add(T::DbWeight::get().reads(1))
.saturating_add(T::DbWeight::get().writes(3))
@@ -220,8 +218,8 @@ impl<T: frame_system::Config> pallet_broker::WeightInfo for WeightInfo<T> {
// Proof Size summary in bytes:
// Measured: `936`
// Estimated: `4681`
// Minimum execution time: 25_493_000 picoseconds.
Weight::from_parts(26_091_000, 0)
// Minimum execution time: 25_653_000 picoseconds.
Weight::from_parts(27_006_000, 0)
.saturating_add(Weight::from_parts(0, 4681))
.saturating_add(T::DbWeight::get().reads(4))
.saturating_add(T::DbWeight::get().writes(2))
@@ -240,8 +238,8 @@ impl<T: frame_system::Config> pallet_broker::WeightInfo for WeightInfo<T> {
// Proof Size summary in bytes:
// Measured: `1002`
// Estimated: `5996`
// Minimum execution time: 31_498_000 picoseconds.
Weight::from_parts(32_560_000, 0)
// Minimum execution time: 31_114_000 picoseconds.
Weight::from_parts(32_235_000, 0)
.saturating_add(Weight::from_parts(0, 5996))
.saturating_add(T::DbWeight::get().reads(5))
.saturating_add(T::DbWeight::get().writes(5))
@@ -257,11 +255,11 @@ impl<T: frame_system::Config> pallet_broker::WeightInfo for WeightInfo<T> {
// Proof Size summary in bytes:
// Measured: `652`
// Estimated: `6196 + m * (2520 ±0)`
// Minimum execution time: 57_183_000 picoseconds.
Weight::from_parts(58_024_898, 0)
// Minimum execution time: 57_280_000 picoseconds.
Weight::from_parts(58_127_480, 0)
.saturating_add(Weight::from_parts(0, 6196))
// Standard Error: 35_831
.saturating_add(Weight::from_parts(1_384_446, 0).saturating_mul(m.into()))
// Standard Error: 41_670
.saturating_add(Weight::from_parts(1_203_066, 0).saturating_mul(m.into()))
.saturating_add(T::DbWeight::get().reads(3))
.saturating_add(T::DbWeight::get().reads((1_u64).saturating_mul(m.into())))
.saturating_add(T::DbWeight::get().writes(5))
@@ -283,8 +281,8 @@ impl<T: frame_system::Config> pallet_broker::WeightInfo for WeightInfo<T> {
// Proof Size summary in bytes:
// Measured: `215`
// Estimated: `3680`
// Minimum execution time: 59_762_000 picoseconds.
Weight::from_parts(61_114_000, 0)
// Minimum execution time: 59_968_000 picoseconds.
Weight::from_parts(62_315_000, 0)
.saturating_add(Weight::from_parts(0, 3680))
.saturating_add(T::DbWeight::get().reads(6))
.saturating_add(T::DbWeight::get().writes(3))
@@ -297,8 +295,8 @@ impl<T: frame_system::Config> pallet_broker::WeightInfo for WeightInfo<T> {
// Proof Size summary in bytes:
// Measured: `465`
// Estimated: `3550`
// Minimum execution time: 41_473_000 picoseconds.
Weight::from_parts(44_155_000, 0)
// Minimum execution time: 50_887_000 picoseconds.
Weight::from_parts(57_366_000, 0)
.saturating_add(Weight::from_parts(0, 3550))
.saturating_add(T::DbWeight::get().reads(2))
.saturating_add(T::DbWeight::get().writes(1))
@@ -313,8 +311,8 @@ impl<T: frame_system::Config> pallet_broker::WeightInfo for WeightInfo<T> {
// Proof Size summary in bytes:
// Measured: `463`
// Estimated: `3533`
// Minimum execution time: 56_672_000 picoseconds.
Weight::from_parts(58_086_000, 0)
// Minimum execution time: 84_472_000 picoseconds.
Weight::from_parts(96_536_000, 0)
.saturating_add(Weight::from_parts(0, 3533))
.saturating_add(T::DbWeight::get().reads(3))
.saturating_add(T::DbWeight::get().writes(1))
@@ -331,8 +329,8 @@ impl<T: frame_system::Config> pallet_broker::WeightInfo for WeightInfo<T> {
// Proof Size summary in bytes:
// Measured: `857`
// Estimated: `3593`
// Minimum execution time: 64_460_000 picoseconds.
Weight::from_parts(65_894_000, 0)
// Minimum execution time: 96_371_000 picoseconds.
Weight::from_parts(104_659_000, 0)
.saturating_add(Weight::from_parts(0, 3593))
.saturating_add(T::DbWeight::get().reads(4))
.saturating_add(T::DbWeight::get().writes(1))
@@ -345,8 +343,8 @@ impl<T: frame_system::Config> pallet_broker::WeightInfo for WeightInfo<T> {
// Proof Size summary in bytes:
// Measured: `957`
// Estimated: `4698`
// Minimum execution time: 37_447_000 picoseconds.
Weight::from_parts(42_318_000, 0)
// Minimum execution time: 51_741_000 picoseconds.
Weight::from_parts(54_461_000, 0)
.saturating_add(Weight::from_parts(0, 4698))
.saturating_add(T::DbWeight::get().reads(2))
.saturating_add(T::DbWeight::get().writes(1))
@@ -366,8 +364,8 @@ impl<T: frame_system::Config> pallet_broker::WeightInfo for WeightInfo<T> {
// Proof Size summary in bytes:
// Measured: `74`
// Estimated: `3539`
// Minimum execution time: 21_219_000 picoseconds.
Weight::from_parts(22_084_648, 0)
// Minimum execution time: 19_901_000 picoseconds.
Weight::from_parts(21_028_116, 0)
.saturating_add(Weight::from_parts(0, 3539))
.saturating_add(T::DbWeight::get().reads(5))
.saturating_add(T::DbWeight::get().writes(2))
@@ -379,11 +377,11 @@ impl<T: frame_system::Config> pallet_broker::WeightInfo for WeightInfo<T> {
// Proof Size summary in bytes:
// Measured: `266`
// Estimated: `1487`
// Minimum execution time: 5_792_000 picoseconds.
Weight::from_parts(6_358_588, 0)
// Minimum execution time: 5_987_000 picoseconds.
Weight::from_parts(6_412_478, 0)
.saturating_add(Weight::from_parts(0, 1487))
// Standard Error: 20
.saturating_add(Weight::from_parts(26, 0).saturating_mul(n.into()))
// Standard Error: 16
.saturating_add(Weight::from_parts(47, 0).saturating_mul(n.into()))
.saturating_add(T::DbWeight::get().reads(1))
.saturating_add(T::DbWeight::get().writes(1))
}
@@ -397,8 +395,8 @@ impl<T: frame_system::Config> pallet_broker::WeightInfo for WeightInfo<T> {
// Proof Size summary in bytes:
// Measured: `447`
// Estimated: `6196`
// Minimum execution time: 38_690_000 picoseconds.
Weight::from_parts(39_706_000, 0)
// Minimum execution time: 38_623_000 picoseconds.
Weight::from_parts(39_773_000, 0)
.saturating_add(Weight::from_parts(0, 6196))
.saturating_add(T::DbWeight::get().reads(4))
.saturating_add(T::DbWeight::get().writes(3))
@@ -414,15 +412,13 @@ impl<T: frame_system::Config> pallet_broker::WeightInfo for WeightInfo<T> {
/// Storage: `Broker::Workplan` (r:0 w:60)
/// Proof: `Broker::Workplan` (`max_values`: None, `max_size`: Some(1216), added: 3691, mode: `MaxEncodedLen`)
/// The range of component `n` is `[0, 1000]`.
fn rotate_sale(n: u32, ) -> Weight {
fn rotate_sale(_n: u32, ) -> Weight {
// Proof Size summary in bytes:
// Measured: `12514`
// Estimated: `13506`
// Minimum execution time: 93_531_000 picoseconds.
Weight::from_parts(95_836_318, 0)
// Minimum execution time: 97_074_000 picoseconds.
Weight::from_parts(101_247_740, 0)
.saturating_add(Weight::from_parts(0, 13506))
// Standard Error: 113
.saturating_add(Weight::from_parts(329, 0).saturating_mul(n.into()))
.saturating_add(T::DbWeight::get().reads(5))
.saturating_add(T::DbWeight::get().writes(65))
}
@@ -434,8 +430,8 @@ impl<T: frame_system::Config> pallet_broker::WeightInfo for WeightInfo<T> {
// Proof Size summary in bytes:
// Measured: `42`
// Estimated: `3493`
// Minimum execution time: 6_506_000 picoseconds.
Weight::from_parts(6_783_000, 0)
// Minimum execution time: 6_317_000 picoseconds.
Weight::from_parts(6_521_000, 0)
.saturating_add(Weight::from_parts(0, 3493))
.saturating_add(T::DbWeight::get().reads(1))
.saturating_add(T::DbWeight::get().writes(1))
@@ -458,8 +454,8 @@ impl<T: frame_system::Config> pallet_broker::WeightInfo for WeightInfo<T> {
// Proof Size summary in bytes:
// Measured: `1321`
// Estimated: `4786`
// Minimum execution time: 31_927_000 picoseconds.
Weight::from_parts(32_748_000, 0)
// Minimum execution time: 32_575_000 picoseconds.
Weight::from_parts(33_299_000, 0)
.saturating_add(Weight::from_parts(0, 4786))
.saturating_add(T::DbWeight::get().reads(7))
.saturating_add(T::DbWeight::get().writes(4))
@@ -478,8 +474,8 @@ impl<T: frame_system::Config> pallet_broker::WeightInfo for WeightInfo<T> {
// Proof Size summary in bytes:
// Measured: `74`
// Estimated: `3539`
// Minimum execution time: 15_682_000 picoseconds.
Weight::from_parts(16_012_000, 0)
// Minimum execution time: 15_256_000 picoseconds.
Weight::from_parts(15_927_000, 0)
.saturating_add(Weight::from_parts(0, 3539))
.saturating_add(T::DbWeight::get().reads(5))
.saturating_add(T::DbWeight::get().writes(2))
@@ -490,8 +486,8 @@ impl<T: frame_system::Config> pallet_broker::WeightInfo for WeightInfo<T> {
// Proof Size summary in bytes:
// Measured: `0`
// Estimated: `0`
// Minimum execution time: 2_147_000 picoseconds.
Weight::from_parts(2_281_000, 0)
// Minimum execution time: 1_783_000 picoseconds.
Weight::from_parts(1_904_000, 0)
.saturating_add(Weight::from_parts(0, 0))
.saturating_add(T::DbWeight::get().writes(1))
}
@@ -509,10 +505,22 @@ impl<T: frame_system::Config> pallet_broker::WeightInfo for WeightInfo<T> {
// Proof Size summary in bytes:
// Measured: `398`
// Estimated: `3863`
// Minimum execution time: 12_015_000 picoseconds.
Weight::from_parts(12_619_000, 0)
// Minimum execution time: 12_307_000 picoseconds.
Weight::from_parts(12_967_000, 0)
.saturating_add(Weight::from_parts(0, 3863))
.saturating_add(T::DbWeight::get().reads(5))
.saturating_add(T::DbWeight::get().writes(2))
}
/// Storage: `Broker::Leases` (r:1 w:1)
/// Proof: `Broker::Leases` (`max_values`: Some(1), `max_size`: Some(401), added: 896, mode: `MaxEncodedLen`)
fn swap_leases() -> Weight {
// Proof Size summary in bytes:
// Measured: `470`
// Estimated: `1886`
// Minimum execution time: 6_597_000 picoseconds.
Weight::from_parts(6_969_000, 0)
.saturating_add(Weight::from_parts(0, 1886))
.saturating_add(T::DbWeight::get().reads(1))
.saturating_add(T::DbWeight::get().writes(1))
}
}