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

Commit

Permalink
Add UpwardMessageSent event in parachain-system
Browse files Browse the repository at this point in the history
  • Loading branch information
girazoki committed May 9, 2022
1 parent 4453f08 commit fae4dd5
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 9 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.

11 changes: 8 additions & 3 deletions pallets/parachain-system/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,9 @@ pub mod pallet {
/// Downward messages were processed using the given weight.
/// \[ weight_used, result_mqc_head \]
DownwardMessagesProcessed(Weight, relay_chain::Hash),
/// An upward message was sent to the relay chain.
UpwardMessageSent(Option<XcmHash>),

}

#[pallet::error]
Expand Down Expand Up @@ -966,7 +969,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 @@ -997,12 +1000,14 @@ impl<T: Config> Pallet<T> {
},
};
<PendingUpwardMessages<T>>::append(message);
Ok(0)
let hash = message.using_encoded(sp_io::hashing::blake2_256);
Self::deposit_event(Event::UpwardMessageSent(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 @@ -274,8 +274,6 @@ pub mod pallet {
BadVersion(Option<XcmHash>),
/// Bad XCM format used.
BadFormat(Option<XcmHash>),
/// An upward message was sent to the relay chain.
UpwardMessageSent(Option<XcmHash>),
/// An HRMP message was sent to a sibling parachain.
XcmpMessageSent(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 @@ -18,6 +18,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
3 changes: 1 addition & 2 deletions primitives/utility/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,8 @@ 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

0 comments on commit fae4dd5

Please sign in to comment.