Skip to content

Commit

Permalink
[mq pallet] Custom next queue selectors (paritytech#6059)
Browse files Browse the repository at this point in the history
Changes:
- Expose a `force_set_head` function from the `MessageQueue` pallet via
a new trait: `ForceSetHead`. This can be used to force the MQ pallet to
process this queue next.
- The change only exposes an internal function through a trait, no audit
is required.

## Context

For the Asset Hub Migration (AHM) we need a mechanism to prioritize the
inbound upward messages and the inbound downward messages on the AH. To
achieve this, a minimal (and no breaking) change is done to the MQ
pallet in the form of adding the `force_set_head` function.

An example use of how to achieve prioritization is then demonstrated in
`integration_test.rs::AhmPrioritizer`. Normally, all queues are
scheduled round-robin like this:

`| Relay | Para(1) | Para(2) | ... | Relay | ... `

The prioritizer listens to changes to its queue and triggers if either:
- The queue processed in the last block (to keep the general round-robin
scheduling)
- The queue did not process since `n` blocks (to prevent starvation if
there are too many other queues)

In either situation, it schedules the queue for a streak of three
consecutive blocks, such that it would become:

`| Relay | Relay | Relay | Para(1) | Para(2) | ... | Relay | Relay |
Relay | ... `

It basically transforms the round-robin into an elongated round robin.
Although different strategies can be injected into the pallet at
runtime, this one seems to strike a good balance between general service
level and prioritization.

---------

Signed-off-by: Oliver Tale-Yazdi <[email protected]>
Co-authored-by: cmd[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: muharem <[email protected]>
  • Loading branch information
3 people authored Feb 14, 2025
1 parent d114004 commit 7aac886
Show file tree
Hide file tree
Showing 22 changed files with 1,922 additions and 977 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,164 +15,185 @@

//! Autogenerated weights for `pallet_message_queue`
//!
//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev
//! DATE: 2023-03-24, STEPS: `2`, REPEAT: `1`, LOW RANGE: `[]`, HIGH RANGE: `[]`
//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 32.0.0
//! DATE: 2025-02-12, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]`
//! WORST CASE MAP SIZE: `1000000`
//! HOSTNAME: `i9`, CPU: `13th Gen Intel(R) Core(TM) i9-13900K`
//! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("statemine-dev"), DB CACHE: 1024
//! HOSTNAME: `793863dddfdf`, CPU: `Intel(R) Xeon(R) CPU @ 2.60GHz`
//! WASM-EXECUTION: `Compiled`, CHAIN: `None`, DB CACHE: 1024
// Executed Command:
// ./target/release/polkadot-parachain
// frame-omni-bencher
// v1
// benchmark
// pallet
// --chain
// statemine-dev
// --pallet
// pallet_message_queue
// --extrinsic
// *
// --execution
// wasm
// --wasm-execution
// compiled
// --output
// parachains/runtimes/assets/statemine/src/weights
// --extrinsic=*
// --runtime=target/production/wbuild/asset-hub-rococo-runtime/asset_hub_rococo_runtime.wasm
// --pallet=pallet_message_queue
// --header=/__w/polkadot-sdk/polkadot-sdk/cumulus/file_header.txt
// --output=./cumulus/parachains/runtimes/assets/asset-hub-rococo/src/weights
// --wasm-execution=compiled
// --steps=50
// --repeat=20
// --heap-pages=4096
// --no-storage-info
// --no-min-squares
// --no-median-slopes

#![cfg_attr(rustfmt, rustfmt_skip)]
#![allow(unused_parens)]
#![allow(unused_imports)]
#![allow(missing_docs)]

use frame_support::{traits::Get, weights::Weight};
use core::marker::PhantomData;

/// Weight functions for `pallet_message_queue`.
pub struct WeightInfo<T>(PhantomData<T>);
impl<T: frame_system::Config> pallet_message_queue::WeightInfo for WeightInfo<T> {
/// Storage: MessageQueue ServiceHead (r:1 w:0)
/// Proof: MessageQueue ServiceHead (max_values: Some(1), max_size: Some(5), added: 500, mode: MaxEncodedLen)
/// Storage: MessageQueue BookStateFor (r:2 w:2)
/// Proof: MessageQueue BookStateFor (max_values: None, max_size: Some(52), added: 2527, mode: MaxEncodedLen)
/// Storage: `MessageQueue::ServiceHead` (r:1 w:0)
/// Proof: `MessageQueue::ServiceHead` (`max_values`: Some(1), `max_size`: Some(5), added: 500, mode: `MaxEncodedLen`)
/// Storage: `MessageQueue::BookStateFor` (r:2 w:2)
/// Proof: `MessageQueue::BookStateFor` (`max_values`: None, `max_size`: Some(52), added: 2527, mode: `MaxEncodedLen`)
fn ready_ring_knit() -> Weight {
// Proof Size summary in bytes:
// Measured: `189`
// Estimated: `7534`
// Minimum execution time: 13_668_000 picoseconds.
Weight::from_parts(13_668_000, 0)
.saturating_add(Weight::from_parts(0, 7534))
// Measured: `260`
// Estimated: `6044`
// Minimum execution time: 14_658_000 picoseconds.
Weight::from_parts(14_990_000, 0)
.saturating_add(Weight::from_parts(0, 6044))
.saturating_add(T::DbWeight::get().reads(3))
.saturating_add(T::DbWeight::get().writes(2))
}
/// Storage: MessageQueue BookStateFor (r:2 w:2)
/// Proof: MessageQueue BookStateFor (max_values: None, max_size: Some(52), added: 2527, mode: MaxEncodedLen)
/// Storage: MessageQueue ServiceHead (r:1 w:1)
/// Proof: MessageQueue ServiceHead (max_values: Some(1), max_size: Some(5), added: 500, mode: MaxEncodedLen)
/// Storage: `MessageQueue::BookStateFor` (r:2 w:2)
/// Proof: `MessageQueue::BookStateFor` (`max_values`: None, `max_size`: Some(52), added: 2527, mode: `MaxEncodedLen`)
/// Storage: `MessageQueue::ServiceHead` (r:1 w:1)
/// Proof: `MessageQueue::ServiceHead` (`max_values`: Some(1), `max_size`: Some(5), added: 500, mode: `MaxEncodedLen`)
fn ready_ring_unknit() -> Weight {
// Proof Size summary in bytes:
// Measured: `184`
// Estimated: `7534`
// Minimum execution time: 11_106_000 picoseconds.
Weight::from_parts(11_106_000, 0)
.saturating_add(Weight::from_parts(0, 7534))
// Measured: `255`
// Estimated: `6044`
// Minimum execution time: 13_260_000 picoseconds.
Weight::from_parts(13_568_000, 0)
.saturating_add(Weight::from_parts(0, 6044))
.saturating_add(T::DbWeight::get().reads(3))
.saturating_add(T::DbWeight::get().writes(3))
}
/// Storage: MessageQueue BookStateFor (r:1 w:1)
/// Proof: MessageQueue BookStateFor (max_values: None, max_size: Some(52), added: 2527, mode: MaxEncodedLen)
/// Storage: `MessageQueue::BookStateFor` (r:1 w:1)
/// Proof: `MessageQueue::BookStateFor` (`max_values`: None, `max_size`: Some(52), added: 2527, mode: `MaxEncodedLen`)
fn service_queue_base() -> Weight {
// Proof Size summary in bytes:
// Measured: `6`
// Measured: `42`
// Estimated: `3517`
// Minimum execution time: 4_921_000 picoseconds.
Weight::from_parts(4_921_000, 0)
// Minimum execution time: 4_874_000 picoseconds.
Weight::from_parts(5_076_000, 0)
.saturating_add(Weight::from_parts(0, 3517))
.saturating_add(T::DbWeight::get().reads(1))
.saturating_add(T::DbWeight::get().writes(1))
}
/// Storage: MessageQueue Pages (r:1 w:1)
/// Proof: MessageQueue Pages (max_values: None, max_size: Some(65585), added: 68060, mode: MaxEncodedLen)
/// Storage: `MessageQueue::Pages` (r:1 w:1)
/// Proof: `MessageQueue::Pages` (`max_values`: None, `max_size`: Some(105521), added: 107996, mode: `MaxEncodedLen`)
fn service_page_base_completion() -> Weight {
// Proof Size summary in bytes:
// Measured: `72`
// Estimated: `69050`
// Minimum execution time: 6_879_000 picoseconds.
Weight::from_parts(6_879_000, 0)
.saturating_add(Weight::from_parts(0, 69050))
// Measured: `109`
// Estimated: `108986`
// Minimum execution time: 7_154_000 picoseconds.
Weight::from_parts(7_424_000, 0)
.saturating_add(Weight::from_parts(0, 108986))
.saturating_add(T::DbWeight::get().reads(1))
.saturating_add(T::DbWeight::get().writes(1))
}
/// Storage: MessageQueue Pages (r:1 w:1)
/// Proof: MessageQueue Pages (max_values: None, max_size: Some(65585), added: 68060, mode: MaxEncodedLen)
/// Storage: `MessageQueue::Pages` (r:1 w:1)
/// Proof: `MessageQueue::Pages` (`max_values`: None, `max_size`: Some(105521), added: 107996, mode: `MaxEncodedLen`)
fn service_page_base_no_completion() -> Weight {
// Proof Size summary in bytes:
// Measured: `72`
// Estimated: `69050`
// Minimum execution time: 7_564_000 picoseconds.
Weight::from_parts(7_564_000, 0)
.saturating_add(Weight::from_parts(0, 69050))
// Measured: `109`
// Estimated: `108986`
// Minimum execution time: 7_372_000 picoseconds.
Weight::from_parts(7_549_000, 0)
.saturating_add(Weight::from_parts(0, 108986))
.saturating_add(T::DbWeight::get().reads(1))
.saturating_add(T::DbWeight::get().writes(1))
}
/// Storage: `MessageQueue::BookStateFor` (r:0 w:1)
/// Proof: `MessageQueue::BookStateFor` (`max_values`: None, `max_size`: Some(52), added: 2527, mode: `MaxEncodedLen`)
/// Storage: `MessageQueue::Pages` (r:0 w:1)
/// Proof: `MessageQueue::Pages` (`max_values`: None, `max_size`: Some(105521), added: 107996, mode: `MaxEncodedLen`)
fn service_page_item() -> Weight {
// Proof Size summary in bytes:
// Measured: `0`
// Estimated: `0`
// Minimum execution time: 59_963_000 picoseconds.
Weight::from_parts(59_963_000, 0)
// Minimum execution time: 268_796_000 picoseconds.
Weight::from_parts(275_170_000, 0)
.saturating_add(Weight::from_parts(0, 0))
.saturating_add(T::DbWeight::get().writes(2))
}
/// Storage: MessageQueue ServiceHead (r:1 w:1)
/// Proof: MessageQueue ServiceHead (max_values: Some(1), max_size: Some(5), added: 500, mode: MaxEncodedLen)
/// Storage: MessageQueue BookStateFor (r:1 w:0)
/// Proof: MessageQueue BookStateFor (max_values: None, max_size: Some(52), added: 2527, mode: MaxEncodedLen)
/// Storage: `MessageQueue::ServiceHead` (r:1 w:1)
/// Proof: `MessageQueue::ServiceHead` (`max_values`: Some(1), `max_size`: Some(5), added: 500, mode: `MaxEncodedLen`)
/// Storage: `MessageQueue::BookStateFor` (r:1 w:0)
/// Proof: `MessageQueue::BookStateFor` (`max_values`: None, `max_size`: Some(52), added: 2527, mode: `MaxEncodedLen`)
fn bump_service_head() -> Weight {
// Proof Size summary in bytes:
// Measured: `99`
// Estimated: `5007`
// Minimum execution time: 7_200_000 picoseconds.
Weight::from_parts(7_200_000, 0)
.saturating_add(Weight::from_parts(0, 5007))
// Measured: `208`
// Estimated: `3517`
// Minimum execution time: 8_531_000 picoseconds.
Weight::from_parts(8_923_000, 0)
.saturating_add(Weight::from_parts(0, 3517))
.saturating_add(T::DbWeight::get().reads(2))
.saturating_add(T::DbWeight::get().writes(1))
}
/// Storage: MessageQueue BookStateFor (r:1 w:1)
/// Proof: MessageQueue BookStateFor (max_values: None, max_size: Some(52), added: 2527, mode: MaxEncodedLen)
/// Storage: MessageQueue Pages (r:1 w:1)
/// Proof: MessageQueue Pages (max_values: None, max_size: Some(65585), added: 68060, mode: MaxEncodedLen)
/// Storage: `MessageQueue::BookStateFor` (r:1 w:0)
/// Proof: `MessageQueue::BookStateFor` (`max_values`: None, `max_size`: Some(52), added: 2527, mode: `MaxEncodedLen`)
/// Storage: `MessageQueue::ServiceHead` (r:0 w:1)
/// Proof: `MessageQueue::ServiceHead` (`max_values`: Some(1), `max_size`: Some(5), added: 500, mode: `MaxEncodedLen`)
fn set_service_head() -> Weight {
// Proof Size summary in bytes:
// Measured: `198`
// Estimated: `3517`
// Minimum execution time: 7_083_000 picoseconds.
Weight::from_parts(7_351_000, 0)
.saturating_add(Weight::from_parts(0, 3517))
.saturating_add(T::DbWeight::get().reads(1))
.saturating_add(T::DbWeight::get().writes(1))
}
/// Storage: `MessageQueue::BookStateFor` (r:1 w:1)
/// Proof: `MessageQueue::BookStateFor` (`max_values`: None, `max_size`: Some(52), added: 2527, mode: `MaxEncodedLen`)
/// Storage: `MessageQueue::Pages` (r:1 w:1)
/// Proof: `MessageQueue::Pages` (`max_values`: None, `max_size`: Some(105521), added: 107996, mode: `MaxEncodedLen`)
fn reap_page() -> Weight {
// Proof Size summary in bytes:
// Measured: `65667`
// Estimated: `72567`
// Minimum execution time: 41_366_000 picoseconds.
Weight::from_parts(41_366_000, 0)
.saturating_add(Weight::from_parts(0, 72567))
// Measured: `105646`
// Estimated: `108986`
// Minimum execution time: 88_053_000 picoseconds.
Weight::from_parts(89_630_000, 0)
.saturating_add(Weight::from_parts(0, 108986))
.saturating_add(T::DbWeight::get().reads(2))
.saturating_add(T::DbWeight::get().writes(2))
}
/// Storage: MessageQueue BookStateFor (r:1 w:1)
/// Proof: MessageQueue BookStateFor (max_values: None, max_size: Some(52), added: 2527, mode: MaxEncodedLen)
/// Storage: MessageQueue Pages (r:1 w:1)
/// Proof: MessageQueue Pages (max_values: None, max_size: Some(65585), added: 68060, mode: MaxEncodedLen)
/// Storage: `MessageQueue::BookStateFor` (r:1 w:1)
/// Proof: `MessageQueue::BookStateFor` (`max_values`: None, `max_size`: Some(52), added: 2527, mode: `MaxEncodedLen`)
/// Storage: `MessageQueue::Pages` (r:1 w:1)
/// Proof: `MessageQueue::Pages` (`max_values`: None, `max_size`: Some(105521), added: 107996, mode: `MaxEncodedLen`)
fn execute_overweight_page_removed() -> Weight {
// Proof Size summary in bytes:
// Measured: `65667`
// Estimated: `72567`
// Minimum execution time: 60_538_000 picoseconds.
Weight::from_parts(60_538_000, 0)
.saturating_add(Weight::from_parts(0, 72567))
// Measured: `105646`
// Estimated: `108986`
// Minimum execution time: 113_929_000 picoseconds.
Weight::from_parts(117_331_000, 0)
.saturating_add(Weight::from_parts(0, 108986))
.saturating_add(T::DbWeight::get().reads(2))
.saturating_add(T::DbWeight::get().writes(2))
}
/// Storage: MessageQueue BookStateFor (r:1 w:1)
/// Proof: MessageQueue BookStateFor (max_values: None, max_size: Some(52), added: 2527, mode: MaxEncodedLen)
/// Storage: MessageQueue Pages (r:1 w:1)
/// Proof: MessageQueue Pages (max_values: None, max_size: Some(65585), added: 68060, mode: MaxEncodedLen)
/// Storage: `MessageQueue::BookStateFor` (r:1 w:1)
/// Proof: `MessageQueue::BookStateFor` (`max_values`: None, `max_size`: Some(52), added: 2527, mode: `MaxEncodedLen`)
/// Storage: `MessageQueue::Pages` (r:1 w:1)
/// Proof: `MessageQueue::Pages` (`max_values`: None, `max_size`: Some(105521), added: 107996, mode: `MaxEncodedLen`)
fn execute_overweight_page_updated() -> Weight {
// Proof Size summary in bytes:
// Measured: `65667`
// Estimated: `72567`
// Minimum execution time: 73_665_000 picoseconds.
Weight::from_parts(73_665_000, 0)
.saturating_add(Weight::from_parts(0, 72567))
// Measured: `105646`
// Estimated: `108986`
// Minimum execution time: 181_265_000 picoseconds.
Weight::from_parts(191_245_000, 0)
.saturating_add(Weight::from_parts(0, 108986))
.saturating_add(T::DbWeight::get().reads(2))
.saturating_add(T::DbWeight::get().writes(2))
}
Expand Down
Loading

0 comments on commit 7aac886

Please sign in to comment.