Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Open
1 change: 0 additions & 1 deletion Cargo.lock

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

6 changes: 4 additions & 2 deletions runtime/kusama/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1114,7 +1114,9 @@ impl parachains_ump::Config for Runtime {
type WeightInfo = weights::runtime_parachains_ump::WeightInfo<Runtime>;
}

impl parachains_dmp::Config for Runtime {}
impl parachains_dmp::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
}

impl parachains_hrmp::Config for Runtime {
type RuntimeOrigin = RuntimeOrigin;
Expand Down Expand Up @@ -1410,7 +1412,7 @@ construct_runtime! {
ParaScheduler: parachains_scheduler::{Pallet, Storage} = 55,
Paras: parachains_paras::{Pallet, Call, Storage, Event, Config, ValidateUnsigned} = 56,
Initializer: parachains_initializer::{Pallet, Call, Storage} = 57,
Dmp: parachains_dmp::{Pallet, Storage} = 58,
Dmp: parachains_dmp::{Pallet, Storage, Event} = 58,
Ump: parachains_ump::{Pallet, Call, Storage, Event} = 59,
Hrmp: parachains_hrmp::{Pallet, Call, Storage, Event<T>, Config} = 60,
ParaSessionInfo: parachains_session_info::{Pallet, Storage} = 61,
Expand Down
2 changes: 0 additions & 2 deletions runtime/parachains/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ frame-support = { git = "https://github.com/paritytech/substrate", branch = "mas
frame-system = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }

xcm = { package = "xcm", path = "../../xcm", default-features = false }
xcm-executor = { package = "xcm-executor", path = "../../xcm/xcm-executor", default-features = false }
primitives = { package = "polkadot-primitives", path = "../../primitives", default-features = false }

rand = { version = "0.8.5", default-features = false }
Expand Down Expand Up @@ -89,7 +88,6 @@ std = [
"pallet-vesting/std",
"frame-system/std",
"xcm/std",
"xcm-executor/std",
"log/std",
"polkadot-runtime-metrics/std",
]
Expand Down
25 changes: 24 additions & 1 deletion runtime/parachains/src/dmp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,15 @@ const THRESHOLD_FACTOR: u32 = 2;
const EXPONENTIAL_FEE_BASE: FixedU128 = FixedU128::from_rational(105, 100); // 1.05
const MESSAGE_SIZE_FEE_BASE: FixedU128 = FixedU128::from_rational(1, 1000); // 0.001

/// Simple type used to identify messages for the purpose of reporting events. Secure if and only
/// if the message content is unique.
pub type MessageId = [u8; 32];

/// Returns a [`MessageId`] for the given message payload.
pub fn message_id(data: &[u8]) -> MessageId {
sp_io::hashing::blake2_256(data)
}

/// An error sending a downward message.
#[cfg_attr(test, derive(Debug))]
pub enum QueueDownwardMessageError {
Expand Down Expand Up @@ -113,7 +122,10 @@ pub mod pallet {
pub struct Pallet<T>(_);

#[pallet::config]
pub trait Config: frame_system::Config + configuration::Config {}
pub trait Config: frame_system::Config + configuration::Config {
/// The aggregate event.
type RuntimeEvent: From<Event> + IsType<<Self as frame_system::Config>::RuntimeEvent>;
}

/// The downward messages addressed for a certain para.
#[pallet::storage]
Expand Down Expand Up @@ -146,7 +158,16 @@ pub mod pallet {
#[pallet::storage]
pub(crate) type DeliveryFeeFactor<T: Config> =
StorageMap<_, Twox64Concat, ParaId, FixedU128, ValueQuery, InitialFactor>;

#[pallet::event]
#[pallet::generate_deposit(pub(super) fn deposit_event)]
pub enum Event {
/// Downward message was sent to para.
/// \[para, id \]
DownwardMessageSent(ParaId, MessageId),
}
}

/// Routines and getters related to downward message passing.
impl<T: Config> Pallet<T> {
/// Block initialization logic, called by initializer.
Expand Down Expand Up @@ -223,6 +244,7 @@ impl<T: Config> Pallet<T> {
return Err(QueueDownwardMessageError::ExceedsMaxMessageSize)
}

let id = message_id(&msg);
let inbound =
InboundDownwardMessage { msg, sent_at: <frame_system::Pallet<T>>::block_number() };

Expand All @@ -247,6 +269,7 @@ impl<T: Config> Pallet<T> {
Self::increment_fee_factor(para, message_size_factor);
}

Self::deposit_event(Event::DownwardMessageSent(para, id));
Ok(())
}

Expand Down
4 changes: 3 additions & 1 deletion runtime/parachains/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,9 @@ impl crate::paras::Config for Test {
type NextSessionRotation = TestNextSessionRotation;
}

impl crate::dmp::Config for Test {}
impl crate::dmp::Config for Test {
type RuntimeEvent = RuntimeEvent;
}

parameter_types! {
pub const FirstMessageFactorPercent: u64 = 100;
Expand Down
12 changes: 6 additions & 6 deletions runtime/parachains/src/ump.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,18 +85,18 @@ impl UmpSink for () {
/// if the message content is unique.
pub type MessageId = [u8; 32];

/// Returns a [`MessageId`] for the given message payload.
pub fn message_id(data: &[u8]) -> MessageId {
sp_io::hashing::blake2_256(data)
}

/// Index used to identify overweight messages.
pub type OverweightIndex = u64;

/// A specific implementation of a `UmpSink` where messages are in the XCM format
/// and will be forwarded to the XCM Executor.
pub struct XcmSink<XcmExecutor, Config>(PhantomData<(XcmExecutor, Config)>);

/// Returns a [`MessageId`] for the given upward message payload.
fn upward_message_id(data: &[u8]) -> MessageId {
sp_io::hashing::blake2_256(data)
}

impl<XcmExecutor: xcm::latest::ExecuteXcm<C::RuntimeCall>, C: Config> UmpSink
for XcmSink<XcmExecutor, C>
{
Expand All @@ -111,7 +111,7 @@ impl<XcmExecutor: xcm::latest::ExecuteXcm<C::RuntimeCall>, C: Config> UmpSink
VersionedXcm,
};

let id = upward_message_id(data);
let id = message_id(data);
let maybe_msg_and_weight = VersionedXcm::<C::RuntimeCall>::decode_all_with_depth_limit(
xcm::MAX_XCM_DECODE_DEPTH,
&mut data,
Expand Down
2 changes: 1 addition & 1 deletion runtime/parachains/src/ump/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ frame_benchmarking::benchmarks! {
queue_upward_msg::<T>(&host_conf, para, msg.clone());
Ump::<T>::process_pending_upward_messages();
assert_last_event_type::<T>(
Event::OverweightEnqueued(para, upward_message_id(&msg), 0, Weight::zero()).into()
Event::OverweightEnqueued(para, message_id(&msg), 0, Weight::zero()).into()
);
}: _(RawOrigin::Root, 0, Weight::MAX)
verify {
Expand Down
2 changes: 1 addition & 1 deletion runtime/parachains/src/ump/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ fn overweight_queue_works() {
assert_last_event(
Event::OverweightEnqueued(
para_a,
upward_message_id(&a_msg_3[..]),
message_id(&a_msg_3[..]),
0,
Weight::from_parts(500, 500),
)
Expand Down
6 changes: 4 additions & 2 deletions runtime/polkadot/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1123,7 +1123,9 @@ impl parachains_ump::Config for Runtime {
type WeightInfo = weights::runtime_parachains_ump::WeightInfo<Self>;
}

impl parachains_dmp::Config for Runtime {}
impl parachains_dmp::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
}

impl parachains_hrmp::Config for Runtime {
type RuntimeOrigin = RuntimeOrigin;
Expand Down Expand Up @@ -1367,7 +1369,7 @@ construct_runtime! {
ParaScheduler: parachains_scheduler::{Pallet, Storage} = 55,
Paras: parachains_paras::{Pallet, Call, Storage, Event, Config, ValidateUnsigned} = 56,
Initializer: parachains_initializer::{Pallet, Call, Storage} = 57,
Dmp: parachains_dmp::{Pallet, Storage} = 58,
Dmp: parachains_dmp::{Pallet, Storage, Event} = 58,
Ump: parachains_ump::{Pallet, Call, Storage, Event} = 59,
Hrmp: parachains_hrmp::{Pallet, Call, Storage, Event<T>, Config} = 60,
ParaSessionInfo: parachains_session_info::{Pallet, Storage} = 61,
Expand Down
6 changes: 4 additions & 2 deletions runtime/rococo/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1051,7 +1051,9 @@ impl parachains_ump::Config for Runtime {
type WeightInfo = weights::runtime_parachains_ump::WeightInfo<Runtime>;
}

impl parachains_dmp::Config for Runtime {}
impl parachains_dmp::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
}

impl parachains_hrmp::Config for Runtime {
type RuntimeOrigin = RuntimeOrigin;
Expand Down Expand Up @@ -1412,7 +1414,7 @@ construct_runtime! {
ParaScheduler: parachains_scheduler::{Pallet, Storage} = 55,
Paras: parachains_paras::{Pallet, Call, Storage, Event, Config, ValidateUnsigned} = 56,
Initializer: parachains_initializer::{Pallet, Call, Storage} = 57,
Dmp: parachains_dmp::{Pallet, Storage} = 58,
Dmp: parachains_dmp::{Pallet, Storage, Event} = 58,
Ump: parachains_ump::{Pallet, Call, Storage, Event} = 59,
Hrmp: parachains_hrmp::{Pallet, Call, Storage, Event<T>, Config} = 60,
ParaSessionInfo: parachains_session_info::{Pallet, Storage} = 61,
Expand Down
6 changes: 4 additions & 2 deletions runtime/test-runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -509,7 +509,9 @@ impl parachains_paras::Config for Runtime {
type NextSessionRotation = Babe;
}

impl parachains_dmp::Config for Runtime {}
impl parachains_dmp::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
}

parameter_types! {
pub const FirstMessageFactorPercent: u64 = 100;
Expand Down Expand Up @@ -671,7 +673,7 @@ construct_runtime! {
ParaSessionInfo: parachains_session_info::{Pallet, Storage},
Hrmp: parachains_hrmp::{Pallet, Call, Storage, Event<T>},
Ump: parachains_ump::{Pallet, Call, Storage, Event},
Dmp: parachains_dmp::{Pallet, Storage},
Dmp: parachains_dmp::{Pallet, Storage, Event},
Xcm: pallet_xcm::{Pallet, Call, Event<T>, Origin},
ParasDisputes: parachains_disputes::{Pallet, Storage, Event<T>},

Expand Down
6 changes: 4 additions & 2 deletions runtime/westend/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -920,7 +920,9 @@ impl parachains_ump::Config for Runtime {
type WeightInfo = weights::runtime_parachains_ump::WeightInfo<Runtime>;
}

impl parachains_dmp::Config for Runtime {}
impl parachains_dmp::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
}

impl parachains_hrmp::Config for Runtime {
type RuntimeOrigin = RuntimeOrigin;
Expand Down Expand Up @@ -1160,7 +1162,7 @@ construct_runtime! {
ParaScheduler: parachains_scheduler::{Pallet, Storage} = 46,
Paras: parachains_paras::{Pallet, Call, Storage, Event, Config, ValidateUnsigned} = 47,
Initializer: parachains_initializer::{Pallet, Call, Storage} = 48,
Dmp: parachains_dmp::{Pallet, Storage} = 49,
Dmp: parachains_dmp::{Pallet, Storage, Event} = 49,
Ump: parachains_ump::{Pallet, Call, Storage, Event} = 50,
Hrmp: parachains_hrmp::{Pallet, Call, Storage, Event<T>, Config} = 51,
ParaSessionInfo: parachains_session_info::{Pallet, Storage} = 52,
Expand Down