diff --git a/Cargo.lock b/Cargo.lock index 0f06c5125b5..25f07a89f48 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2527,7 +2527,6 @@ dependencies = [ "frame-system", "parity-scale-codec", "scale-info", - "sp-io", "sp-runtime", "sp-std", "xcm", @@ -2582,10 +2581,10 @@ dependencies = [ "polkadot-primitives", "scale-info", "sp-api", + "sp-io", "sp-runtime", "sp-std", "sp-trie", - "xcm", ] [[package]] diff --git a/pallets/dmp-queue/src/lib.rs b/pallets/dmp-queue/src/lib.rs index 082fceaf14c..37359c0726b 100644 --- a/pallets/dmp-queue/src/lib.rs +++ b/pallets/dmp-queue/src/lib.rs @@ -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::{ + message_id, relay_chain::BlockNumber as RelayBlockNumber, DmpMessageHandler, +}; use frame_support::{ traits::EnsureOrigin, weights::{constants::WEIGHT_REF_TIME_PER_MILLIS, Weight}, @@ -251,7 +253,7 @@ pub mod pallet { _sent_at: RelayBlockNumber, mut data: &[u8], ) -> Result { - let message_id = sp_io::hashing::blake2_256(data); + let message_id = message_id(data); let maybe_msg = VersionedXcm::::decode_all_with_depth_limit( MAX_XCM_DECODE_DEPTH, &mut data, @@ -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. diff --git a/pallets/parachain-system/src/lib.rs b/pallets/parachain-system/src/lib.rs index b841820acfc..9c3040f4a74 100644 --- a/pallets/parachain-system/src/lib.rs +++ b/pallets/parachain-system/src/lib.rs @@ -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::{ @@ -1112,13 +1112,16 @@ impl Pallet { // // Thus fall through here. }; - >::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 + >::append(message); + + Self::deposit_event(Event::UpwardMessageSent { message_hash: Some(id) }); + Ok((0, id)) } } diff --git a/pallets/xcm/Cargo.toml b/pallets/xcm/Cargo.toml index 841c862557a..c8616ce2045 100644 --- a/pallets/xcm/Cargo.toml +++ b/pallets/xcm/Cargo.toml @@ -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" } diff --git a/pallets/xcm/src/lib.rs b/pallets/xcm/src/lib.rs index f230ced5dc5..f285e1ab6d7 100644 --- a/pallets/xcm/src/lib.rs +++ b/pallets/xcm/src/lib.rs @@ -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::*; @@ -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::*; @@ -66,13 +67,13 @@ pub mod pallet { pub enum Event { /// 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. @@ -112,7 +113,7 @@ impl DmpMessageHandler for UnlimitedDmpExecution { ) -> 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::::decode_all_with_depth_limit( MAX_XCM_DECODE_DEPTH, &mut data.as_slice(), @@ -145,7 +146,7 @@ impl DmpMessageHandler for LimitAndDropDmpExecution { ) -> 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::::decode_all_with_depth_limit( MAX_XCM_DECODE_DEPTH, &mut data.as_slice(), diff --git a/primitives/core/Cargo.toml b/primitives/core/Cargo.toml index b2adf290db1..eb85eecb9c6 100644 --- a/primitives/core/Cargo.toml +++ b/primitives/core/Cargo.toml @@ -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" } @@ -18,7 +19,6 @@ 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" ] @@ -26,6 +26,7 @@ std = [ "codec/std", "scale-info/std", "sp-api/std", + "sp-io/std", "sp-runtime/std", "sp-std/std", "sp-trie/std", diff --git a/primitives/core/src/lib.rs b/primitives/core/src/lib.rs index 752e1aee474..624418aaf2a 100644 --- a/primitives/core/src/lib.rs +++ b/primitives/core/src/lib.rs @@ -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::{ @@ -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::*; @@ -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) } }