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

Add event for showing the hash of an UMP sent message #1228

Merged
Merged
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
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.

16 changes: 12 additions & 4 deletions pallets/parachain-system/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ use sp_runtime::{
},
};
use sp_std::{cmp, collections::btree_map::BTreeMap, prelude::*};
use xcm::latest::XcmHash;

mod migration;
mod relay_state_snapshot;
Expand Down Expand Up @@ -482,6 +483,8 @@ pub mod pallet {
DownwardMessagesReceived { count: u32 },
/// Downward messages were processed using the given weight.
DownwardMessagesProcessed { weight_used: Weight, dmq_head: relay_chain::Hash },
/// An upward message was sent to the relay chain.
UpwardMessageSent { message_hash: Option<XcmHash> },
}

#[pallet::error]
Expand Down Expand Up @@ -1034,7 +1037,7 @@ impl<T: Config> frame_system::SetCode<T> for ParachainSetCode<T> {
}

impl<T: Config> Pallet<T> {
pub fn send_upward_message(message: UpwardMessage) -> Result<u32, MessageSendError> {
pub fn send_upward_message(message: UpwardMessage) -> Result<(u32, XcmHash), MessageSendError> {
// Check if the message fits into the relay-chain constraints.
//
// Note, that we are using `host_configuration` here which may be from the previous
Expand Down Expand Up @@ -1064,13 +1067,18 @@ impl<T: Config> Pallet<T> {
// Thus fall through here.
},
};
<PendingUpwardMessages<T>>::append(message);
Ok(0)
<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))
}
}

impl<T: Config> UpwardMessageSender for Pallet<T> {
fn send_upward_message(message: UpwardMessage) -> Result<u32, MessageSendError> {
fn send_upward_message(message: UpwardMessage) -> Result<(u32, XcmHash), MessageSendError> {
Self::send_upward_message(message)
}
}
Expand Down
2 changes: 0 additions & 2 deletions pallets/xcmp-queue/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -290,8 +290,6 @@ pub mod pallet {
BadVersion { message_hash: Option<XcmHash> },
/// Bad XCM format used.
BadFormat { message_hash: Option<XcmHash> },
/// An upward message was sent to the relay chain.
UpwardMessageSent { message_hash: Option<XcmHash> },
/// An HRMP message was sent to a sibling parachain.
XcmpMessageSent { message_hash: Option<XcmHash> },
/// An XCM exceeded the individual message weight budget.
Expand Down
1 change: 1 addition & 0 deletions primitives/core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ 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" ]
Expand Down
7 changes: 5 additions & 2 deletions primitives/core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ pub use polkadot_primitives::v2::{
AbridgedHostConfiguration, AbridgedHrmpChannel, PersistedValidationData,
};

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 @@ -94,10 +96,11 @@ pub trait GetChannelInfo {
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.
fn send_upward_message(msg: UpwardMessage) -> Result<u32, MessageSendError>;
/// return the hash of the message sent
fn send_upward_message(msg: UpwardMessage) -> Result<(u32, XcmHash), MessageSendError>;
}
impl UpwardMessageSender for () {
fn send_upward_message(_msg: UpwardMessage) -> Result<u32, MessageSendError> {
fn send_upward_message(_msg: UpwardMessage) -> Result<(u32, XcmHash), MessageSendError> {
Err(MessageSendError::NoChannel)
}
}
Expand Down
4 changes: 1 addition & 3 deletions primitives/utility/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,7 @@ where
}

fn deliver(data: Vec<u8>) -> Result<XcmHash, SendError> {
let hash = data.using_encoded(sp_io::hashing::blake2_256);

T::send_upward_message(data).map_err(|e| match e {
let (_, hash) = T::send_upward_message(data).map_err(|e| match e {
MessageSendError::TooBig => SendError::ExceedsMaxMessageSize,
e => SendError::Transport(e.into()),
})?;
Expand Down