Yieldable queues for pallet MessageQueue (#13424)

* Add Yield message processing error

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Add NoopServiceQueues

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Implement temporary error aka Yield

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Make NoopMessageProcessor generic

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Mock pausable message processor

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Test paused queues

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Integration test paused queues

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Use WeightMeter instead of weight return

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* fix

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Make compile

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Add tests

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* ".git/.scripts/commands/bench/bench.sh" pallet dev pallet_message_queue

* Fix test

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

---------

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>
Co-authored-by: command-bot <>
This commit is contained in:
Oliver Tale-Yazdi
2023-02-25 17:13:20 +01:00
committed by GitHub
parent 84638524e7
commit 16773d3696
9 changed files with 479 additions and 173 deletions
+23 -4
View File
@@ -22,7 +22,7 @@ use scale_info::TypeInfo;
use sp_core::{ConstU32, Get, TypedGet};
use sp_runtime::{traits::Convert, BoundedSlice, RuntimeDebug};
use sp_std::{fmt::Debug, marker::PhantomData, prelude::*};
use sp_weights::Weight;
use sp_weights::{Weight, WeightMeter};
/// Errors that can happen when attempting to process a message with
/// [`ProcessMessage::process_message()`].
@@ -38,6 +38,13 @@ pub enum ProcessMessageError {
/// would be respected. The parameter gives the maximum weight which the message could take
/// to process.
Overweight(Weight),
/// The queue wants to give up its current processing slot.
///
/// Hints the message processor to cease servicing this queue and proceed to the next
/// one. This is seen as a *hint*, not an instruction. Implementations must therefore handle
/// the case that a queue is re-serviced within the same block after *yielding*. A queue is
/// not required to *yield* again when it is being re-serviced withing the same block.
Yield,
}
/// Can process messages from a specific origin.
@@ -45,12 +52,14 @@ pub trait ProcessMessage {
/// The transport from where a message originates.
type Origin: FullCodec + MaxEncodedLen + Clone + Eq + PartialEq + TypeInfo + Debug;
/// Process the given message, using no more than `weight_limit` in weight to do so.
/// Process the given message, using no more than the remaining `meter` weight to do so.
///
/// Returns whether the message was processed.
fn process_message(
message: &[u8],
origin: Self::Origin,
weight_limit: Weight,
) -> Result<(bool, Weight), ProcessMessageError>;
meter: &mut WeightMeter,
) -> Result<bool, ProcessMessageError>;
}
/// Errors that can happen when attempting to execute an overweight message with
@@ -85,6 +94,16 @@ pub trait ServiceQueues {
}
}
/// Services queues by doing nothing.
pub struct NoopServiceQueues<OverweightAddr>(PhantomData<OverweightAddr>);
impl<OverweightAddr> ServiceQueues for NoopServiceQueues<OverweightAddr> {
type OverweightMessageAddress = OverweightAddr;
fn service_queues(_: Weight) -> Weight {
Weight::zero()
}
}
/// The resource footprint of a queue.
#[derive(Default, Copy, Clone, Eq, PartialEq, RuntimeDebug)]
pub struct Footprint {