Skip to content

Commit

Permalink
test-relay: Add message queue
Browse files Browse the repository at this point in the history
  • Loading branch information
cdamian committed Jun 5, 2024
1 parent 9b60f42 commit 2c896e0
Show file tree
Hide file tree
Showing 5 changed files with 324 additions and 18 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions core/src/tests/test-relay/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ frame-system-rpc-runtime-api = { git = "https://github.com/paritytech/polkadot-s
pallet-timestamp = { git = "https://github.com/paritytech/polkadot-sdk", default-features = false, branch = "release-polkadot-v1.7.2" }
pallet-sudo = { git = "https://github.com/paritytech/polkadot-sdk", default-features = false, branch = "release-polkadot-v1.7.2" }
pallet-vesting = { git = "https://github.com/paritytech/polkadot-sdk", default-features = false, branch = "release-polkadot-v1.7.2" }
pallet-message-queue = { git = "https://github.com/paritytech/polkadot-sdk", default-features = false, branch = "release-polkadot-v1.7.2" }

runtime-common = { package = "polkadot-runtime-common", git = "https://github.com/paritytech/polkadot-sdk", default-features = false, branch = "release-polkadot-v1.7.2" }
primitives = { package = "polkadot-primitives", git = "https://github.com/paritytech/polkadot-sdk", default-features = false, branch = "release-polkadot-v1.7.2" }
Expand Down
71 changes: 63 additions & 8 deletions core/src/tests/test-relay/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ use frame_support::{
construct_runtime, derive_impl,
genesis_builder_helper::{build_config, create_default_config},
parameter_types,
traits::{KeyOwnerProofSystem, WithdrawReasons},
traits::{KeyOwnerProofSystem, ProcessMessage, ProcessMessageError, WithdrawReasons},
weights::WeightMeter,
};
pub use pallet_balances::Call as BalancesCall;
use pallet_grandpa::{fg_primitives, AuthorityId as GrandpaId};
Expand All @@ -46,12 +47,15 @@ use parity_scale_codec::Encode;
use polkadot_runtime_parachains::{
assigner_parachains as parachains_assigner_parachains,
configuration as parachains_configuration, disputes as parachains_disputes,
disputes::slashing as parachains_slashing, dmp as parachains_dmp, hrmp as parachains_hrmp,
inclusion as parachains_inclusion, initializer as parachains_initializer,
origin as parachains_origin, paras as parachains_paras,
paras_inherent as parachains_paras_inherent, reward_points::RewardValidatorsWithEraPoints,
runtime_api_impl::v7 as runtime_impl, scheduler as parachains_scheduler,
session_info as parachains_session_info, shared as parachains_shared,
disputes::slashing as parachains_slashing,
dmp as parachains_dmp, hrmp as parachains_hrmp, inclusion as parachains_inclusion,
inclusion::{AggregateMessageOrigin, UmpQueueId},
initializer as parachains_initializer, origin as parachains_origin, paras as parachains_paras,
paras_inherent as parachains_paras_inherent,
reward_points::RewardValidatorsWithEraPoints,
runtime_api_impl::v7 as runtime_impl,
scheduler as parachains_scheduler, session_info as parachains_session_info,
shared as parachains_shared,
};
use primitives::{
slashing, AccountId, AccountIndex, Balance, BlockNumber, CandidateEvent, CandidateHash,
Expand Down Expand Up @@ -87,6 +91,7 @@ use sp_version::NativeVersion;
use sp_version::RuntimeVersion;
/// Constant values used within the runtime.
use test_relay_constants::{currency::*, time::*};
use xcm::v4::Junction;

pub mod governance;
use governance::pallet_custom_origins;
Expand Down Expand Up @@ -476,6 +481,55 @@ impl pallet_sudo::Config for Runtime {
type WeightInfo = ();
}

parameter_types! {
/// Amount of weight that can be spent per block to service messages.
///
/// # WARNING
///
/// This is not a good value for para-chains since the `Scheduler` already uses up to 80% block weight.
pub MessageQueueServiceWeight: Weight = Perbill::from_percent(20) * BlockWeights::get().max_block;
pub const MessageQueueHeapSize: u32 = 65_536;
pub const MessageQueueMaxStale: u32 = 8;
}

/// Message processor to handle any messages that were enqueued into the `MessageQueue` pallet.
pub struct MessageProcessor;
impl ProcessMessage for MessageProcessor {
type Origin = AggregateMessageOrigin;

fn process_message(
message: &[u8],
origin: Self::Origin,
meter: &mut WeightMeter,
id: &mut [u8; 32],
) -> Result<bool, ProcessMessageError> {
let para = match origin {
AggregateMessageOrigin::Ump(UmpQueueId::Para(para)) => para,
};
xcm_builder::ProcessXcmMessage::<
Junction,
xcm_executor::XcmExecutor<xcm_config::XcmConfig>,
RuntimeCall,
>::process_message(message, Junction::Parachain(para.into()), meter, id)
}
}

impl pallet_message_queue::Config for Runtime {
type HeapSize = MessageQueueHeapSize;
type MaxStale = MessageQueueMaxStale;
#[cfg(not(feature = "runtime-benchmarks"))]
type MessageProcessor = MessageProcessor;
#[cfg(feature = "runtime-benchmarks")]
type MessageProcessor =
pallet_message_queue::mock_helpers::NoopMessageProcessor<AggregateMessageOrigin>;
type QueueChangeHandler = ParaInclusion;
type QueuePausedQuery = ();
type RuntimeEvent = RuntimeEvent;
type ServiceWeight = MessageQueueServiceWeight;
type Size = u32;
type WeightInfo = weights::pallet_message_queue::WeightInfo<Runtime>;
}

impl parachains_configuration::Config for Runtime {
type WeightInfo = parachains_configuration::TestWeightInfo;
}
Expand All @@ -486,7 +540,7 @@ impl parachains_shared::Config for Runtime {

impl parachains_inclusion::Config for Runtime {
type DisputesHandler = ParasDisputes;
type MessageQueue = ();
type MessageQueue = MessageQueue;
type RewardValidators = RewardValidatorsWithEraPoints<Runtime>;
type RuntimeEvent = RuntimeEvent;
type WeightInfo = ();
Expand Down Expand Up @@ -719,6 +773,7 @@ construct_runtime! {
ParasDisputes: parachains_disputes,
ParasSlashing: parachains_slashing,
ParaAssignmentProvider: parachains_assigner_parachains,
MessageQueue: pallet_message_queue,

Sudo: pallet_sudo,

Expand Down
Loading

0 comments on commit 2c896e0

Please sign in to comment.