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
@@ -17,25 +17,23 @@
//! Autogenerated weights for `pallet_broker`
//!
//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 32.0.0
//! DATE: 2024-02-08, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]`
//! DATE: 2024-03-20, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]`
//! WORST CASE MAP SIZE: `1000000`
//! HOSTNAME: `runner-bn-ce5rx-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-westend-dev")`, DB CACHE: 1024
// Executed Command:
// ./target/production/polkadot-parachain
// target/production/polkadot-parachain
// benchmark
// pallet
// --chain=coretime-westend-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-westend-dev
// --header=./cumulus/file_header.txt
// --output=./cumulus/parachains/runtimes/coretime/coretime-westend/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: 1_944_000 picoseconds.
Weight::from_parts(2_045_000, 0)
// Minimum execution time: 1_897_000 picoseconds.
Weight::from_parts(2_053_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: 21_158_000 picoseconds.
Weight::from_parts(21_572_000, 0)
// Minimum execution time: 22_550_000 picoseconds.
Weight::from_parts(22_871_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: 20_497_000 picoseconds.
Weight::from_parts(20_995_000, 0)
// Minimum execution time: 21_170_000 picoseconds.
Weight::from_parts(21_645_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: `146`
// Estimated: `1631`
// Minimum execution time: 10_280_000 picoseconds.
Weight::from_parts(10_686_000, 0)
// Minimum execution time: 10_494_000 picoseconds.
Weight::from_parts(10_942_000, 0)
.saturating_add(Weight::from_parts(0, 1631))
.saturating_add(T::DbWeight::get().reads(3))
.saturating_add(T::DbWeight::get().writes(1))
@@ -120,15 +118,13 @@ impl<T: frame_system::Config> pallet_broker::WeightInfo for WeightInfo<T> {
/// Storage: `Broker::Workplan` (r:0 w:20)
/// Proof: `Broker::Workplan` (`max_values`: None, `max_size`: Some(1216), added: 3691, mode: `MaxEncodedLen`)
/// The range of component `n` is `[0, 1000]`.
fn start_sales(n: u32, ) -> Weight {
fn start_sales(_n: u32, ) -> Weight {
// Proof Size summary in bytes:
// Measured: `12247`
// Estimated: `13732`
// Minimum execution time: 61_020_000 picoseconds.
Weight::from_parts(63_240_622, 0)
// Minimum execution time: 61_014_000 picoseconds.
Weight::from_parts(63_267_651, 0)
.saturating_add(Weight::from_parts(0, 13732))
// Standard Error: 102
.saturating_add(Weight::from_parts(255, 0).saturating_mul(n.into()))
.saturating_add(T::DbWeight::get().reads(8))
.saturating_add(T::DbWeight::get().writes(26))
}
@@ -144,8 +140,8 @@ impl<T: frame_system::Config> pallet_broker::WeightInfo for WeightInfo<T> {
// Proof Size summary in bytes:
// Measured: `316`
// Estimated: `3593`
// Minimum execution time: 30_627_000 picoseconds.
Weight::from_parts(31_648_000, 0)
// Minimum execution time: 30_931_000 picoseconds.
Weight::from_parts(31_941_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 +162,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_701_000 picoseconds.
Weight::from_parts(59_825_000, 0)
// Minimum execution time: 57_466_000 picoseconds.
Weight::from_parts(65_042_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 +174,8 @@ impl<T: frame_system::Config> pallet_broker::WeightInfo for WeightInfo<T> {
// Proof Size summary in bytes:
// Measured: `357`
// Estimated: `3550`
// Minimum execution time: 12_898_000 picoseconds.
Weight::from_parts(13_506_000, 0)
// Minimum execution time: 12_799_000 picoseconds.
Weight::from_parts(13_401_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 +186,8 @@ impl<T: frame_system::Config> pallet_broker::WeightInfo for WeightInfo<T> {
// Proof Size summary in bytes:
// Measured: `357`
// Estimated: `3550`
// Minimum execution time: 14_284_000 picoseconds.
Weight::from_parts(14_791_000, 0)
// Minimum execution time: 14_107_000 picoseconds.
Weight::from_parts(14_630_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 +198,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_570_000 picoseconds.
Weight::from_parts(16_158_000, 0)
// Minimum execution time: 15_254_000 picoseconds.
Weight::from_parts(16_062_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 +216,8 @@ impl<T: frame_system::Config> pallet_broker::WeightInfo for WeightInfo<T> {
// Proof Size summary in bytes:
// Measured: `735`
// Estimated: `4681`
// Minimum execution time: 23_329_000 picoseconds.
Weight::from_parts(24_196_000, 0)
// Minimum execution time: 23_557_000 picoseconds.
Weight::from_parts(24_382_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 +236,8 @@ impl<T: frame_system::Config> pallet_broker::WeightInfo for WeightInfo<T> {
// Proof Size summary in bytes:
// Measured: `801`
// Estimated: `5996`
// Minimum execution time: 29_288_000 picoseconds.
Weight::from_parts(30_066_000, 0)
// Minimum execution time: 29_371_000 picoseconds.
Weight::from_parts(30_200_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 +253,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: 54_833_000 picoseconds.
Weight::from_parts(55_577_423, 0)
// Minimum execution time: 54_331_000 picoseconds.
Weight::from_parts(55_322_165, 0)
.saturating_add(Weight::from_parts(0, 6196))
// Standard Error: 35_105
.saturating_add(Weight::from_parts(1_267_911, 0).saturating_mul(m.into()))
// Standard Error: 35_225
.saturating_add(Weight::from_parts(1_099_614, 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 +279,8 @@ impl<T: frame_system::Config> pallet_broker::WeightInfo for WeightInfo<T> {
// Proof Size summary in bytes:
// Measured: `215`
// Estimated: `3680`
// Minimum execution time: 55_289_000 picoseconds.
Weight::from_parts(56_552_000, 0)
// Minimum execution time: 53_789_000 picoseconds.
Weight::from_parts(55_439_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 +293,8 @@ impl<T: frame_system::Config> pallet_broker::WeightInfo for WeightInfo<T> {
// Proof Size summary in bytes:
// Measured: `465`
// Estimated: `3550`
// Minimum execution time: 39_736_000 picoseconds.
Weight::from_parts(41_346_000, 0)
// Minimum execution time: 43_941_000 picoseconds.
Weight::from_parts(49_776_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 +309,8 @@ impl<T: frame_system::Config> pallet_broker::WeightInfo for WeightInfo<T> {
// Proof Size summary in bytes:
// Measured: `463`
// Estimated: `3533`
// Minimum execution time: 57_319_000 picoseconds.
Weight::from_parts(60_204_000, 0)
// Minimum execution time: 64_917_000 picoseconds.
Weight::from_parts(70_403_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 +327,8 @@ impl<T: frame_system::Config> pallet_broker::WeightInfo for WeightInfo<T> {
// Proof Size summary in bytes:
// Measured: `857`
// Estimated: `3593`
// Minimum execution time: 85_216_000 picoseconds.
Weight::from_parts(91_144_000, 0)
// Minimum execution time: 72_633_000 picoseconds.
Weight::from_parts(79_305_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 +341,8 @@ impl<T: frame_system::Config> pallet_broker::WeightInfo for WeightInfo<T> {
// Proof Size summary in bytes:
// Measured: `556`
// Estimated: `4698`
// Minimum execution time: 32_331_000 picoseconds.
Weight::from_parts(39_877_000, 0)
// Minimum execution time: 36_643_000 picoseconds.
Weight::from_parts(48_218_000, 0)
.saturating_add(Weight::from_parts(0, 4698))
.saturating_add(T::DbWeight::get().reads(2))
.saturating_add(T::DbWeight::get().writes(1))
@@ -362,28 +358,28 @@ impl<T: frame_system::Config> pallet_broker::WeightInfo for WeightInfo<T> {
/// Storage: `ParachainSystem::PendingUpwardMessages` (r:1 w:1)
/// Proof: `ParachainSystem::PendingUpwardMessages` (`max_values`: Some(1), `max_size`: None, mode: `Measured`)
/// The range of component `n` is `[0, 1000]`.
fn request_core_count(n: u32, ) -> Weight {
fn request_core_count(_n: u32, ) -> Weight {
// Proof Size summary in bytes:
// Measured: `74`
// Estimated: `3539`
// Minimum execution time: 18_128_000 picoseconds.
Weight::from_parts(19_061_234, 0)
// Minimum execution time: 17_617_000 picoseconds.
Weight::from_parts(18_904_788, 0)
.saturating_add(Weight::from_parts(0, 3539))
// Standard Error: 48
.saturating_add(Weight::from_parts(141, 0).saturating_mul(n.into()))
.saturating_add(T::DbWeight::get().reads(5))
.saturating_add(T::DbWeight::get().writes(2))
}
/// Storage: `Broker::CoreCountInbox` (r:1 w:1)
/// Proof: `Broker::CoreCountInbox` (`max_values`: Some(1), `max_size`: Some(2), added: 497, mode: `MaxEncodedLen`)
/// The range of component `n` is `[0, 1000]`.
fn process_core_count(_n: u32, ) -> Weight {
fn process_core_count(n: u32, ) -> Weight {
// Proof Size summary in bytes:
// Measured: `266`
// Estimated: `1487`
// Minimum execution time: 5_368_000 picoseconds.
Weight::from_parts(5_837_005, 0)
// Minimum execution time: 5_575_000 picoseconds.
Weight::from_parts(5_887_598, 0)
.saturating_add(Weight::from_parts(0, 1487))
// Standard Error: 16
.saturating_add(Weight::from_parts(41, 0).saturating_mul(n.into()))
.saturating_add(T::DbWeight::get().reads(1))
.saturating_add(T::DbWeight::get().writes(1))
}
@@ -397,8 +393,8 @@ impl<T: frame_system::Config> pallet_broker::WeightInfo for WeightInfo<T> {
// Proof Size summary in bytes:
// Measured: `447`
// Estimated: `6196`
// Minimum execution time: 36_047_000 picoseconds.
Weight::from_parts(37_101_000, 0)
// Minimum execution time: 36_415_000 picoseconds.
Weight::from_parts(37_588_000, 0)
.saturating_add(Weight::from_parts(0, 6196))
.saturating_add(T::DbWeight::get().reads(4))
.saturating_add(T::DbWeight::get().writes(3))
@@ -414,13 +410,15 @@ impl<T: frame_system::Config> pallet_broker::WeightInfo for WeightInfo<T> {
/// Storage: `Broker::Workplan` (r:0 w:20)
/// 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: `12194`
// Estimated: `13506`
// Minimum execution time: 48_158_000 picoseconds.
Weight::from_parts(49_891_920, 0)
// Minimum execution time: 48_362_000 picoseconds.
Weight::from_parts(49_616_106, 0)
.saturating_add(Weight::from_parts(0, 13506))
// Standard Error: 61
.saturating_add(Weight::from_parts(59, 0).saturating_mul(n.into()))
.saturating_add(T::DbWeight::get().reads(5))
.saturating_add(T::DbWeight::get().writes(25))
}
@@ -432,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: 5_911_000 picoseconds.
Weight::from_parts(6_173_000, 0)
// Minimum execution time: 6_148_000 picoseconds.
Weight::from_parts(6_374_000, 0)
.saturating_add(Weight::from_parts(0, 3493))
.saturating_add(T::DbWeight::get().reads(1))
.saturating_add(T::DbWeight::get().writes(1))
@@ -456,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: 30_140_000 picoseconds.
Weight::from_parts(30_912_000, 0)
// Minimum execution time: 30_267_000 picoseconds.
Weight::from_parts(30_825_000, 0)
.saturating_add(Weight::from_parts(0, 4786))
.saturating_add(T::DbWeight::get().reads(7))
.saturating_add(T::DbWeight::get().writes(4))
@@ -476,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: 13_684_000 picoseconds.
Weight::from_parts(14_252_000, 0)
// Minimum execution time: 13_491_000 picoseconds.
Weight::from_parts(13_949_000, 0)
.saturating_add(Weight::from_parts(0, 3539))
.saturating_add(T::DbWeight::get().reads(5))
.saturating_add(T::DbWeight::get().writes(2))
@@ -488,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: 1_718_000 picoseconds.
Weight::from_parts(1_843_000, 0)
// Minimum execution time: 1_711_000 picoseconds.
Weight::from_parts(1_913_000, 0)
.saturating_add(Weight::from_parts(0, 0))
.saturating_add(T::DbWeight::get().writes(1))
}
@@ -507,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: 11_771_000 picoseconds.
Weight::from_parts(12_120_000, 0)
// Minimum execution time: 12_035_000 picoseconds.
Weight::from_parts(12_383_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(81), added: 576, mode: `MaxEncodedLen`)
fn swap_leases() -> Weight {
// Proof Size summary in bytes:
// Measured: `150`
// Estimated: `1566`
// Minimum execution time: 6_142_000 picoseconds.
Weight::from_parts(6_538_000, 0)
.saturating_add(Weight::from_parts(0, 1566))
.saturating_add(T::DbWeight::get().reads(1))
.saturating_add(T::DbWeight::get().writes(1))
}
}