Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions substrate/frame/message-queue/src/integration_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ impl Config for Test {
type HeapSize = HeapSize;
type MaxStale = MaxStale;
type ServiceWeight = ServiceWeight;
type IdleMaxServiceWeight = ServiceWeight;
}

/// Simulates heavy usage by enqueueing and processing large amounts of messages.
Expand Down
20 changes: 19 additions & 1 deletion substrate/frame/message-queue/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
#[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.
///
/// This may be legitimately `None` in the case that you will call
/// `ServiceQueues::service_queues` manually.
#[pallet::constant]
type IdleMaxServiceWeight: Get<Option<Weight>>;
}

#[pallet::event]
Expand Down Expand Up @@ -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()
Expand Down
1 change: 1 addition & 0 deletions substrate/frame/message-queue/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ impl Config for Test {
type HeapSize = HeapSize;
type MaxStale = MaxStale;
type ServiceWeight = ServiceWeight;
type IdleMaxServiceWeight = ServiceWeight;
}

/// Mocked `WeightInfo` impl with allows to set the weight per call.
Expand Down