mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-30 10:47:55 +00:00
process enqueued messages on idle (#3844)
This will make it possible to use remaining weight on idle for processing enqueued messages. More context here https://github.com/paritytech/polkadot-sdk/issues/3709 --------- Co-authored-by: Adrian Catangiu <adrian@parity.io>
This commit is contained in:
@@ -525,12 +525,21 @@ pub mod pallet {
|
||||
type MaxStale: Get<u32>;
|
||||
|
||||
/// The amount of weight (if any) which should be provided to the message queue for
|
||||
/// servicing enqueued items.
|
||||
/// servicing enqueued items `on_initialize`.
|
||||
///
|
||||
/// This may be legitimately `None` in the case that you will call
|
||||
/// `ServiceQueues::service_queues` manually.
|
||||
/// `ServiceQueues::service_queues` manually or set [`Self::IdleMaxServiceWeight`] to have
|
||||
/// it run in `on_idle`.
|
||||
#[pallet::constant]
|
||||
type ServiceWeight: Get<Option<Weight>>;
|
||||
|
||||
/// The maximum amount of weight (if any) to be used from remaining weight `on_idle` which
|
||||
/// should be provided to the message queue for servicing enqueued items `on_idle`.
|
||||
/// Useful for parachains to process messages at the same block they are received.
|
||||
///
|
||||
/// If `None`, it will not call `ServiceQueues::service_queues` in `on_idle`.
|
||||
#[pallet::constant]
|
||||
type IdleMaxServiceWeight: Get<Option<Weight>>;
|
||||
}
|
||||
|
||||
#[pallet::event]
|
||||
@@ -643,6 +652,15 @@ pub mod pallet {
|
||||
}
|
||||
}
|
||||
|
||||
fn on_idle(_n: BlockNumberFor<T>, remaining_weight: Weight) -> Weight {
|
||||
if let Some(weight_limit) = T::IdleMaxServiceWeight::get() {
|
||||
// Make use of the remaining weight to process enqueued messages.
|
||||
Self::service_queues(weight_limit.min(remaining_weight))
|
||||
} else {
|
||||
Weight::zero()
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "try-runtime")]
|
||||
fn try_state(_: BlockNumberFor<T>) -> Result<(), sp_runtime::TryRuntimeError> {
|
||||
Self::do_try_state()
|
||||
|
||||
Reference in New Issue
Block a user