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

Companion: MessageId (ump, dmp) #2504

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
3 changes: 1 addition & 2 deletions Cargo.lock

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

8 changes: 5 additions & 3 deletions pallets/dmp-queue/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@
pub mod migration;

use codec::{Decode, DecodeLimit, Encode};
use cumulus_primitives_core::{relay_chain::BlockNumber as RelayBlockNumber, DmpMessageHandler};
use cumulus_primitives_core::{
Copy link
Member

@ggwpez ggwpez May 2, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The dmp-queue pallet is being deleted here #2157
Not sure if that is relevant to you, just pointing it out.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, thank you, then better :),
I will check

message_id, relay_chain::BlockNumber as RelayBlockNumber, DmpMessageHandler,
};
use frame_support::{
traits::EnsureOrigin,
weights::{constants::WEIGHT_REF_TIME_PER_MILLIS, Weight},
Expand Down Expand Up @@ -251,7 +253,7 @@ pub mod pallet {
_sent_at: RelayBlockNumber,
mut data: &[u8],
) -> Result<Weight, (MessageId, Weight)> {
let message_id = sp_io::hashing::blake2_256(data);
let message_id = message_id(data);
let maybe_msg = VersionedXcm::<T::RuntimeCall>::decode_all_with_depth_limit(
MAX_XCM_DECODE_DEPTH,
&mut data,
Expand Down Expand Up @@ -314,7 +316,7 @@ pub mod pallet {
maybe_enqueue_page = Some(Vec::with_capacity(item_count_left));

Self::deposit_event(Event::MaxMessagesExhausted {
message_id: sp_io::hashing::blake2_256(&data),
message_id: message_id(&data),
});
} else {
// We're not currently enqueuing - try to execute inline.
Expand Down
19 changes: 11 additions & 8 deletions pallets/parachain-system/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@

use codec::{Decode, Encode, MaxEncodedLen};
use cumulus_primitives_core::{
relay_chain, AbridgedHostConfiguration, ChannelStatus, CollationInfo, DmpMessageHandler,
GetChannelInfo, InboundDownwardMessage, InboundHrmpMessage, MessageSendError,
OutboundHrmpMessage, ParaId, PersistedValidationData, UpwardMessage, UpwardMessageSender,
XcmpMessageHandler, XcmpMessageSource,
message_id, relay_chain, AbridgedHostConfiguration, ChannelStatus, CollationInfo,
DmpMessageHandler, GetChannelInfo, InboundDownwardMessage, InboundHrmpMessage,
MessageSendError, OutboundHrmpMessage, ParaId, PersistedValidationData, UpwardMessage,
UpwardMessageSender, XcmpMessageHandler, XcmpMessageSource,
};
use cumulus_primitives_parachain_inherent::{MessageQueueChain, ParachainInherentData};
use frame_support::{
Expand Down Expand Up @@ -1112,13 +1112,16 @@ impl<T: Config> Pallet<T> {
//
// Thus fall through here.
};
<PendingUpwardMessages<T>>::append(message.clone());

// The relay ump does not use using_encoded
// We apply the same this to use the same hash
let hash = sp_io::hashing::blake2_256(&message);
Self::deposit_event(Event::UpwardMessageSent { message_hash: Some(hash) });
Ok((0, hash))
let id = message_id(&message);

// Store message
<PendingUpwardMessages<T>>::append(message);

Self::deposit_event(Event::UpwardMessageSent { message_hash: Some(id) });
Ok((0, id))
}
}

Expand Down
1 change: 0 additions & 1 deletion pallets/xcm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ codec = { package = "parity-scale-codec", version = "3.0.0", default-features =
scale-info = { version = "2.6.0", default-features = false, features = ["derive"] }

sp-std = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" }
sp-io = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" }
sp-runtime = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" }
frame-support = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" }
frame-system = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" }
Expand Down
13 changes: 7 additions & 6 deletions pallets/xcm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

use codec::{Decode, DecodeLimit, Encode};
use cumulus_primitives_core::{
relay_chain::BlockNumber as RelayBlockNumber, DmpMessageHandler, ParaId,
message_id, relay_chain::BlockNumber as RelayBlockNumber, DmpMessageHandler, ParaId,
};
use frame_support::dispatch::Weight;
pub use pallet::*;
Expand All @@ -37,6 +37,7 @@ use xcm::{
#[frame_support::pallet]
pub mod pallet {
use super::*;
use cumulus_primitives_core::MessageId;
use frame_support::pallet_prelude::*;
use frame_system::pallet_prelude::*;

Expand Down Expand Up @@ -66,13 +67,13 @@ pub mod pallet {
pub enum Event<T: Config> {
/// Downward message is invalid XCM.
/// \[ id \]
InvalidFormat([u8; 32]),
InvalidFormat(MessageId),
/// Downward message is unsupported version of XCM.
/// \[ id \]
UnsupportedVersion([u8; 32]),
UnsupportedVersion(MessageId),
/// Downward message executed with the given outcome.
/// \[ id, outcome \]
ExecutedDownward([u8; 32], Outcome),
ExecutedDownward(MessageId, Outcome),
}

/// Origin for the parachains module.
Expand Down Expand Up @@ -112,7 +113,7 @@ impl<T: Config> DmpMessageHandler for UnlimitedDmpExecution<T> {
) -> Weight {
let mut used = Weight::zero();
for (_sent_at, data) in iter {
let id = sp_io::hashing::blake2_256(&data[..]);
let id = message_id(&data[..]);
let msg = VersionedXcm::<T::RuntimeCall>::decode_all_with_depth_limit(
MAX_XCM_DECODE_DEPTH,
&mut data.as_slice(),
Expand Down Expand Up @@ -145,7 +146,7 @@ impl<T: Config> DmpMessageHandler for LimitAndDropDmpExecution<T> {
) -> Weight {
let mut used = Weight::zero();
for (_sent_at, data) in iter {
let id = sp_io::hashing::blake2_256(&data[..]);
let id = message_id(&data[..]);
let msg = VersionedXcm::<T::RuntimeCall>::decode_all_with_depth_limit(
MAX_XCM_DECODE_DEPTH,
&mut data.as_slice(),
Expand Down
3 changes: 2 additions & 1 deletion primitives/core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ scale-info = { version = "2.6.0", default-features = false, features = ["derive"

# Substrate
sp-api = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" }
sp-io = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" }
sp-runtime = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" }
sp-std = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" }
sp-trie = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" }
Expand All @@ -18,14 +19,14 @@ sp-trie = { git = "https://github.com/paritytech/substrate", default-features =
polkadot-core-primitives = { git = "https://github.com/paritytech/polkadot", default-features = false, branch = "master" }
polkadot-parachain = { git = "https://github.com/paritytech/polkadot", default-features = false, branch = "master" }
polkadot-primitives = { git = "https://github.com/paritytech/polkadot", default-features = false, branch = "master" }
xcm = { git = "https://github.com/paritytech/polkadot", default-features = false, branch = "master" }

[features]
default = [ "std" ]
std = [
"codec/std",
"scale-info/std",
"sp-api/std",
"sp-io/std",
"sp-runtime/std",
"sp-std/std",
"sp-trie/std",
Expand Down
8 changes: 3 additions & 5 deletions primitives/core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ pub use polkadot_parachain::primitives::{
XcmpMessageHandler,
};
pub use polkadot_primitives::{
AbridgedHostConfiguration, AbridgedHrmpChannel, PersistedValidationData,
message_id, AbridgedHostConfiguration, AbridgedHrmpChannel, MessageId, PersistedValidationData,
};

pub use sp_runtime::{
Expand All @@ -39,8 +39,6 @@ pub use sp_runtime::{
ConsensusEngineId,
};

pub use xcm::latest::prelude::*;

/// A module that re-exports relevant relay chain definitions.
pub mod relay_chain {
pub use polkadot_core_primitives::*;
Expand Down Expand Up @@ -104,10 +102,10 @@ pub trait UpwardMessageSender {
/// Send the given UMP message; return the expected number of blocks before the message will
/// be dispatched or an error if the message cannot be sent.
/// return the hash of the message sent
fn send_upward_message(msg: UpwardMessage) -> Result<(u32, XcmHash), MessageSendError>;
fn send_upward_message(msg: UpwardMessage) -> Result<(u32, MessageId), MessageSendError>;
}
impl UpwardMessageSender for () {
fn send_upward_message(_msg: UpwardMessage) -> Result<(u32, XcmHash), MessageSendError> {
fn send_upward_message(_msg: UpwardMessage) -> Result<(u32, MessageId), MessageSendError> {
Err(MessageSendError::NoChannel)
}
}
Expand Down