Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Introduced events for dmp DownwardMessageSent + refactor to common MessageId for events (ump, dmp) #7161

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
2 changes: 1 addition & 1 deletion Cargo.lock

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

24 changes: 12 additions & 12 deletions primitives/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,18 @@ pub mod runtime_api;
// Current primitives not requiring versioning are exported here.
// Primitives requiring versioning must not be exported and must be referred by an exact version.
pub use v4::{
byzantine_threshold, check_candidate_backing, collator_signature_payload, metric_definitions,
supermajority_threshold, well_known_keys, AbridgedHostConfiguration, AbridgedHrmpChannel,
AccountId, AccountIndex, AccountPublic, ApprovalVote, AssignmentId, AuthorityDiscoveryId,
AvailabilityBitfield, BackedCandidate, Balance, BlakeTwo256, Block, BlockId, BlockNumber,
CandidateCommitments, CandidateDescriptor, CandidateEvent, CandidateHash, CandidateIndex,
CandidateReceipt, CheckedDisputeStatementSet, CheckedMultiDisputeStatementSet, CollatorId,
CollatorSignature, CommittedCandidateReceipt, CompactStatement, ConsensusLog, CoreIndex,
CoreOccupied, CoreState, DisputeState, DisputeStatement, DisputeStatementSet, DownwardMessage,
EncodeAs, ExecutorParam, ExecutorParams, ExecutorParamsHash, ExplicitDisputeStatement,
GroupIndex, GroupRotationInfo, Hash, HashT, HeadData, Header, HrmpChannelId, Id,
InboundDownwardMessage, InboundHrmpMessage, IndexedVec, InherentData,
InvalidDisputeStatementKind, Moment, MultiDisputeStatementSet, Nonce, OccupiedCore,
byzantine_threshold, check_candidate_backing, collator_signature_payload, message_id,
metric_definitions, supermajority_threshold, well_known_keys, AbridgedHostConfiguration,
AbridgedHrmpChannel, AccountId, AccountIndex, AccountPublic, ApprovalVote, AssignmentId,
AuthorityDiscoveryId, AvailabilityBitfield, BackedCandidate, Balance, BlakeTwo256, Block,
BlockId, BlockNumber, CandidateCommitments, CandidateDescriptor, CandidateEvent, CandidateHash,
CandidateIndex, CandidateReceipt, CheckedDisputeStatementSet, CheckedMultiDisputeStatementSet,
CollatorId, CollatorSignature, CommittedCandidateReceipt, CompactStatement, ConsensusLog,
CoreIndex, CoreOccupied, CoreState, DisputeState, DisputeStatement, DisputeStatementSet,
DownwardMessage, EncodeAs, ExecutorParam, ExecutorParams, ExecutorParamsHash,
ExplicitDisputeStatement, GroupIndex, GroupRotationInfo, Hash, HashT, HeadData, Header,
HrmpChannelId, Id, InboundDownwardMessage, InboundHrmpMessage, IndexedVec, InherentData,
InvalidDisputeStatementKind, MessageId, Moment, MultiDisputeStatementSet, Nonce, OccupiedCore,
OccupiedCoreAssumption, OutboundHrmpMessage, ParathreadClaim, ParathreadEntry,
PersistedValidationData, PvfCheckStatement, PvfExecTimeoutKind, PvfPrepTimeoutKind,
RuntimeMetricLabel, RuntimeMetricLabelValue, RuntimeMetricLabelValues, RuntimeMetricLabels,
Expand Down
9 changes: 9 additions & 0 deletions primitives/src/v4/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1738,6 +1738,15 @@ pub enum PvfExecTimeoutKind {
pub mod executor_params;
pub use executor_params::{ExecutorParam, ExecutorParams, ExecutorParamsHash};

/// 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)
}

#[cfg(test)]
mod tests {
use super::*;
Expand Down
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
18 changes: 16 additions & 2 deletions runtime/parachains/src/dmp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ use crate::{
initializer, FeeTracker,
};
use frame_support::pallet_prelude::*;
use primitives::{DownwardMessage, Hash, Id as ParaId, InboundDownwardMessage};
use primitives::{message_id, DownwardMessage, Hash, Id as ParaId, InboundDownwardMessage};
use sp_core::MAX_POSSIBLE_ALLOCATION;
use sp_runtime::{
traits::{BlakeTwo256, Hash as HashT, SaturatedConversion},
Expand Down Expand Up @@ -107,13 +107,17 @@ impl fmt::Debug for ProcessedDownwardMessagesAcceptanceErr {
#[frame_support::pallet]
pub mod pallet {
use super::*;
use primitives::MessageId;

#[pallet::pallet]
#[pallet::without_storage_info]
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 +150,15 @@ 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.
DownwardMessageSent { para_id: ParaId, message_id: 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 +235,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 +260,7 @@ impl<T: Config> Pallet<T> {
Self::increment_fee_factor(para, message_size_factor);
}

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

Expand Down
10 changes: 6 additions & 4 deletions runtime/parachains/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
use crate::{
configuration, disputes, dmp, hrmp, inclusion, initializer, origin, paras, paras_inherent,
scheduler, session_info, shared,
ump::{self, MessageId, UmpSink},
ump::{self, UmpSink},
ParaId,
};

Expand All @@ -31,8 +31,8 @@ use frame_support::{
use frame_support_test::TestRandomness;
use parity_scale_codec::Decode;
use primitives::{
AuthorityDiscoveryId, Balance, BlockNumber, CandidateHash, Header, Moment, SessionIndex,
UpwardMessage, ValidatorIndex,
AuthorityDiscoveryId, Balance, BlockNumber, CandidateHash, Header, MessageId, Moment,
SessionIndex, UpwardMessage, ValidatorIndex,
};
use sp_core::H256;
use sp_io::TestExternalities;
Expand Down 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
13 changes: 2 additions & 11 deletions runtime/parachains/src/ump.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use crate::{
use frame_support::{pallet_prelude::*, traits::EnsureOrigin};
use frame_system::pallet_prelude::*;
use polkadot_parachain::primitives::UpwardMessages;
use primitives::{Id as ParaId, UpwardMessage};
use primitives::{message_id, Id as ParaId, MessageId, UpwardMessage};
use sp_std::{collections::btree_map::BTreeMap, fmt, marker::PhantomData, mem, prelude::*};
use xcm::latest::Outcome;

Expand Down Expand Up @@ -81,22 +81,13 @@ impl UmpSink for () {
}
}

/// 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];

/// 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 +102,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 @@ -1124,7 +1124,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 @@ -1385,7 +1387,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 @@ -1413,7 +1415,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 @@ -511,7 +511,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 @@ -673,7 +675,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 @@ -921,7 +921,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 @@ -1161,7 +1163,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
1 change: 1 addition & 0 deletions xcm/xcm-simulator/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@ xcm-executor = { path = "../xcm-executor" }
polkadot-core-primitives = { path = "../../core-primitives"}
polkadot-parachain = { path = "../../parachain" }
polkadot-runtime-parachains = { path = "../../runtime/parachains" }
polkadot-primitives = { path = "../../primitives" }
3 changes: 2 additions & 1 deletion xcm/xcm-simulator/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,10 @@ pub use polkadot_parachain::primitives::{
DmpMessageHandler as DmpMessageHandlerT, Id as ParaId, XcmpMessageFormat,
XcmpMessageHandler as XcmpMessageHandlerT,
};
pub use polkadot_primitives::MessageId;
pub use polkadot_runtime_parachains::{
dmp,
ump::{self, MessageId, UmpSink, XcmSink},
ump::{self, UmpSink, XcmSink},
};
pub use xcm::{latest::prelude::*, VersionedXcm};
pub use xcm_executor::XcmExecutor;
Expand Down