diff --git a/Cargo.lock b/Cargo.lock index 7d8c37e9728c..2b3a39d58fa1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -662,9 +662,9 @@ checksum = "8d696c370c750c948ada61c69a0ee2cbbb9c50b1019ddb86d9317157a99c2cae" [[package]] name = "bounded-collections" -version = "0.1.4" +version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "de2aff4807e40f478132150d80b031f2461d88f061851afcab537d7600c24120" +checksum = "a071c348a5ef6da1d3a87166b408170b46002382b1dda83992b5c2208cefb370" dependencies = [ "log", "parity-scale-codec", @@ -7171,6 +7171,7 @@ dependencies = [ "sp-core", "sp-keystore", "sp-maybe-compressed-blob", + "sp-runtime", "thiserror", "zstd", ] @@ -7295,6 +7296,7 @@ dependencies = [ name = "polkadot-parachain" version = "0.9.37" dependencies = [ + "bounded-collections", "derive_more", "frame-support", "parity-scale-codec", @@ -7585,6 +7587,7 @@ dependencies = [ "pallet-timestamp", "pallet-vesting", "parity-scale-codec", + "polkadot-parachain", "polkadot-primitives", "polkadot-primitives-test-helpers", "polkadot-runtime-metrics", diff --git a/node/collation-generation/src/tests.rs b/node/collation-generation/src/tests.rs index 05961582a222..9640f07b80e2 100644 --- a/node/collation-generation/src/tests.rs +++ b/node/collation-generation/src/tests.rs @@ -39,8 +39,8 @@ mod handle_new_activations { fn test_collation() -> Collation { Collation { - upward_messages: vec![], - horizontal_messages: vec![], + upward_messages: Default::default(), + horizontal_messages: Default::default(), new_validation_code: None, head_data: dummy_head_data(), proof_of_validity: MaybeCompressedPoV::Raw(PoV { block_data: BlockData(Vec::new()) }), diff --git a/node/core/backing/src/tests.rs b/node/core/backing/src/tests.rs index 9249d204ddca..c4aac0700d42 100644 --- a/node/core/backing/src/tests.rs +++ b/node/core/backing/src/tests.rs @@ -202,8 +202,8 @@ impl TestCandidateBuilder { }, commitments: CandidateCommitments { head_data: self.head_data, - upward_messages: vec![], - horizontal_messages: vec![], + upward_messages: Default::default(), + horizontal_messages: Default::default(), new_validation_code: None, processed_downward_messages: 0, hrmp_watermark: 0_u32, @@ -311,8 +311,8 @@ fn backing_second_works() { tx.send(Ok( ValidationResult::Valid(CandidateCommitments { head_data: expected_head_data.clone(), - horizontal_messages: Vec::new(), - upward_messages: Vec::new(), + horizontal_messages: Default::default(), + upward_messages: Default::default(), new_validation_code: None, processed_downward_messages: 0, hrmp_watermark: 0, @@ -457,8 +457,8 @@ fn backing_works() { tx.send(Ok( ValidationResult::Valid(CandidateCommitments { head_data: expected_head_data.clone(), - upward_messages: Vec::new(), - horizontal_messages: Vec::new(), + upward_messages: Default::default(), + horizontal_messages: Default::default(), new_validation_code: None, processed_downward_messages: 0, hrmp_watermark: 0, @@ -781,8 +781,8 @@ fn backing_misbehavior_works() { tx.send(Ok( ValidationResult::Valid(CandidateCommitments { head_data: expected_head_data.clone(), - upward_messages: Vec::new(), - horizontal_messages: Vec::new(), + upward_messages: Default::default(), + horizontal_messages: Default::default(), new_validation_code: None, processed_downward_messages: 0, hrmp_watermark: 0, @@ -954,8 +954,8 @@ fn backing_dont_second_invalid() { tx.send(Ok( ValidationResult::Valid(CandidateCommitments { head_data: expected_head_data.clone(), - upward_messages: Vec::new(), - horizontal_messages: Vec::new(), + upward_messages: Default::default(), + horizontal_messages: Default::default(), new_validation_code: None, processed_downward_messages: 0, hrmp_watermark: 0, diff --git a/node/core/candidate-validation/src/tests.rs b/node/core/candidate-validation/src/tests.rs index 6bab57097dae..f69fc924e659 100644 --- a/node/core/candidate-validation/src/tests.rs +++ b/node/core/candidate-validation/src/tests.rs @@ -446,8 +446,8 @@ fn candidate_validation_ok_is_ok() { let validation_result = WasmValidationResult { head_data, new_validation_code: Some(vec![2, 2, 2].into()), - upward_messages: Vec::new(), - horizontal_messages: Vec::new(), + upward_messages: Default::default(), + horizontal_messages: Default::default(), processed_downward_messages: 0, hrmp_watermark: 0, }; @@ -573,8 +573,8 @@ fn candidate_validation_one_ambiguous_error_is_valid() { let validation_result = WasmValidationResult { head_data, new_validation_code: Some(vec![2, 2, 2].into()), - upward_messages: Vec::new(), - horizontal_messages: Vec::new(), + upward_messages: Default::default(), + horizontal_messages: Default::default(), processed_downward_messages: 0, hrmp_watermark: 0, }; @@ -751,8 +751,8 @@ fn candidate_validation_commitment_hash_mismatch_is_invalid() { let validation_result = WasmValidationResult { head_data, new_validation_code: None, - upward_messages: Vec::new(), - horizontal_messages: Vec::new(), + upward_messages: Default::default(), + horizontal_messages: Default::default(), processed_downward_messages: 0, hrmp_watermark: 12345, }; @@ -854,8 +854,8 @@ fn compressed_code_works() { let validation_result = WasmValidationResult { head_data, new_validation_code: None, - upward_messages: Vec::new(), - horizontal_messages: Vec::new(), + upward_messages: Default::default(), + horizontal_messages: Default::default(), processed_downward_messages: 0, hrmp_watermark: 0, }; @@ -918,8 +918,8 @@ fn code_decompression_failure_is_error() { let validation_result = WasmValidationResult { head_data, new_validation_code: None, - upward_messages: Vec::new(), - horizontal_messages: Vec::new(), + upward_messages: Default::default(), + horizontal_messages: Default::default(), processed_downward_messages: 0, hrmp_watermark: 0, }; @@ -971,8 +971,8 @@ fn pov_decompression_failure_is_invalid() { let validation_result = WasmValidationResult { head_data, new_validation_code: None, - upward_messages: Vec::new(), - horizontal_messages: Vec::new(), + upward_messages: Default::default(), + horizontal_messages: Default::default(), processed_downward_messages: 0, hrmp_watermark: 0, }; diff --git a/node/malus/src/variants/common.rs b/node/malus/src/variants/common.rs index 3a3cc19aef12..e491b1081281 100644 --- a/node/malus/src/variants/common.rs +++ b/node/malus/src/variants/common.rs @@ -163,8 +163,8 @@ pub fn create_fake_candidate_commitments( persisted_validation_data: &PersistedValidationData, ) -> CandidateCommitments { CandidateCommitments { - upward_messages: Vec::new(), - horizontal_messages: Vec::new(), + upward_messages: Default::default(), + horizontal_messages: Default::default(), new_validation_code: None, head_data: persisted_validation_data.parent_head.clone(), processed_downward_messages: 0, diff --git a/node/primitives/Cargo.toml b/node/primitives/Cargo.toml index c6812d2cc02c..9b165a2e7330 100644 --- a/node/primitives/Cargo.toml +++ b/node/primitives/Cargo.toml @@ -16,6 +16,7 @@ sp-consensus-vrf = { git = "https://github.com/paritytech/substrate", branch = " sp-consensus-babe = { git = "https://github.com/paritytech/substrate", branch = "master" } sp-keystore = { git = "https://github.com/paritytech/substrate", branch = "master" } sp-maybe-compressed-blob = { git = "https://github.com/paritytech/substrate", branch = "master" } +sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "master" } polkadot-parachain = { path = "../../parachain", default-features = false } schnorrkel = "0.9.1" thiserror = "1.0.31" diff --git a/node/primitives/src/lib.rs b/node/primitives/src/lib.rs index 4c141e622e0c..46964e119b33 100644 --- a/node/primitives/src/lib.rs +++ b/node/primitives/src/lib.rs @@ -32,14 +32,14 @@ use serde::{de, Deserialize, Deserializer, Serialize, Serializer}; use polkadot_primitives::{ BlakeTwo256, BlockNumber, CandidateCommitments, CandidateHash, CollatorPair, CommittedCandidateReceipt, CompactStatement, EncodeAs, Hash, HashT, HeadData, Id as ParaId, - OutboundHrmpMessage, PersistedValidationData, SessionIndex, Signed, UncheckedSigned, - UpwardMessage, ValidationCode, ValidatorIndex, MAX_CODE_SIZE, MAX_POV_SIZE, + PersistedValidationData, SessionIndex, Signed, UncheckedSigned, ValidationCode, ValidatorIndex, + MAX_CODE_SIZE, MAX_POV_SIZE, }; pub use sp_consensus_babe::{ AllowedSlots as BabeAllowedSlots, BabeEpochConfiguration, Epoch as BabeEpoch, }; -pub use polkadot_parachain::primitives::BlockData; +pub use polkadot_parachain::primitives::{BlockData, HorizontalMessages, UpwardMessages}; pub mod approval; @@ -312,9 +312,9 @@ impl MaybeCompressedPoV { #[cfg(not(target_os = "unknown"))] pub struct Collation { /// Messages destined to be interpreted by the Relay chain itself. - pub upward_messages: Vec, + pub upward_messages: UpwardMessages, /// The horizontal messages sent by the parachain. - pub horizontal_messages: Vec>, + pub horizontal_messages: HorizontalMessages, /// New validation code. pub new_validation_code: Option, /// The head-data produced as a result of execution. diff --git a/parachain/Cargo.toml b/parachain/Cargo.toml index 88200269ea08..3e750e9df3b9 100644 --- a/parachain/Cargo.toml +++ b/parachain/Cargo.toml @@ -17,6 +17,7 @@ sp-core = { git = "https://github.com/paritytech/substrate", branch = "master", frame-support = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } polkadot-core-primitives = { path = "../core-primitives", default-features = false } derive_more = "0.99.11" +bounded-collections = { version = "0.1.5", default-features = false } # all optional crates. serde = { version = "1.0.137", default-features = false, features = [ "derive" ], optional = true } @@ -25,6 +26,7 @@ serde = { version = "1.0.137", default-features = false, features = [ "derive" ] default = ["std"] wasm-api = [] std = [ + "bounded-collections/std", "parity-scale-codec/std", "scale-info/std", "serde/std", diff --git a/parachain/src/primitives.rs b/parachain/src/primitives.rs index e638b83c2d7c..00b36bb545a3 100644 --- a/parachain/src/primitives.rs +++ b/parachain/src/primitives.rs @@ -19,6 +19,7 @@ use sp_std::vec::Vec; +use bounded_collections::{BoundedVec, ConstU32}; use frame_support::weights::Weight; use parity_scale_codec::{CompactAs, Decode, Encode, MaxEncodedLen}; use scale_info::TypeInfo; @@ -361,6 +362,22 @@ pub struct ValidationParams { pub relay_parent_storage_root: Hash, } +/// Maximum number of HRMP messages allowed per candidate. +/// +/// We also use this as a generous limit, which still prevents possible memory exhaustion, from +/// malicious parachains that may otherwise return a huge amount of messages in `ValidationResult`. +pub const MAX_HORIZONTAL_MESSAGE_NUM: u32 = 16 * 1024; +/// Maximum number of UMP messages allowed per candidate. +/// +/// We also use this as a generous limit, which still prevents possible memory exhaustion, from +/// malicious parachains that may otherwise return a huge amount of messages in `ValidationResult`. +pub const MAX_UPWARD_MESSAGE_NUM: u32 = 16 * 1024; + +pub type UpwardMessages = BoundedVec>; + +pub type HorizontalMessages = + BoundedVec, ConstU32>; + /// The result of parachain validation. // TODO: balance uploads (https://github.com/paritytech/polkadot/issues/220) #[derive(PartialEq, Eq, Clone, Encode)] @@ -371,9 +388,9 @@ pub struct ValidationResult { /// An update to the validation code that should be scheduled in the relay chain. pub new_validation_code: Option, /// Upward messages send by the Parachain. - pub upward_messages: Vec, + pub upward_messages: UpwardMessages, /// Outbound horizontal messages sent by the parachain. - pub horizontal_messages: Vec>, + pub horizontal_messages: HorizontalMessages, /// Number of downward messages that were processed by the Parachain. /// /// It is expected that the Parachain processes them from first to last. diff --git a/parachain/test-parachains/adder/collator/src/lib.rs b/parachain/test-parachains/adder/collator/src/lib.rs index 701f08a2b87a..ae5596e1ce55 100644 --- a/parachain/test-parachains/adder/collator/src/lib.rs +++ b/parachain/test-parachains/adder/collator/src/lib.rs @@ -172,8 +172,8 @@ impl Collator { let pov = PoV { block_data: block_data.encode().into() }; let collation = Collation { - upward_messages: Vec::new(), - horizontal_messages: Vec::new(), + upward_messages: Default::default(), + horizontal_messages: Default::default(), new_validation_code: None, head_data: head_data.encode().into(), proof_of_validity: MaybeCompressedPoV::Raw(pov.clone()), diff --git a/parachain/test-parachains/adder/src/wasm_validation.rs b/parachain/test-parachains/adder/src/wasm_validation.rs index 240df6cb2c01..69c383a48796 100644 --- a/parachain/test-parachains/adder/src/wasm_validation.rs +++ b/parachain/test-parachains/adder/src/wasm_validation.rs @@ -37,8 +37,10 @@ pub extern "C" fn validate_block(params: *const u8, len: usize) -> u64 { parachain::write_result(&ValidationResult { head_data: GenericHeadData(new_head.encode()), new_validation_code: None, - upward_messages: sp_std::vec::Vec::new(), - horizontal_messages: sp_std::vec::Vec::new(), + upward_messages: sp_std::vec::Vec::new().try_into().expect("empty vec fits into bounds"), + horizontal_messages: sp_std::vec::Vec::new() + .try_into() + .expect("empty vec fits into bounds"), processed_downward_messages: 0, hrmp_watermark: params.relay_parent_number, }) diff --git a/parachain/test-parachains/undying/collator/src/lib.rs b/parachain/test-parachains/undying/collator/src/lib.rs index 2f4799c001de..317b85d3d492 100644 --- a/parachain/test-parachains/undying/collator/src/lib.rs +++ b/parachain/test-parachains/undying/collator/src/lib.rs @@ -247,8 +247,8 @@ impl Collator { let pov = PoV { block_data: block_data.encode().into() }; let collation = Collation { - upward_messages: Vec::new(), - horizontal_messages: Vec::new(), + upward_messages: Default::default(), + horizontal_messages: Default::default(), new_validation_code: None, head_data: head_data.encode().into(), proof_of_validity: MaybeCompressedPoV::Raw(pov.clone()), diff --git a/parachain/test-parachains/undying/src/wasm_validation.rs b/parachain/test-parachains/undying/src/wasm_validation.rs index 73dda396d81a..873819ad2b1e 100644 --- a/parachain/test-parachains/undying/src/wasm_validation.rs +++ b/parachain/test-parachains/undying/src/wasm_validation.rs @@ -37,8 +37,10 @@ pub extern "C" fn validate_block(params: *const u8, len: usize) -> u64 { parachain::write_result(&ValidationResult { head_data: GenericHeadData(new_head.encode()), new_validation_code: None, - upward_messages: sp_std::vec::Vec::new(), - horizontal_messages: sp_std::vec::Vec::new(), + upward_messages: sp_std::vec::Vec::new().try_into().expect("empty vec fits within bounds"), + horizontal_messages: sp_std::vec::Vec::new() + .try_into() + .expect("empty vec fits within bounds"), processed_downward_messages: 0, hrmp_watermark: params.relay_parent_number, }) diff --git a/primitives/src/v2/mod.rs b/primitives/src/v2/mod.rs index 606ffd59920c..c8e03a7ad5fa 100644 --- a/primitives/src/v2/mod.rs +++ b/primitives/src/v2/mod.rs @@ -43,8 +43,8 @@ pub use polkadot_core_primitives::v2::{ // Export some polkadot-parachain primitives pub use polkadot_parachain::primitives::{ - HeadData, HrmpChannelId, Id, UpwardMessage, ValidationCode, ValidationCodeHash, - LOWEST_PUBLIC_ID, LOWEST_USER_ID, + HeadData, HorizontalMessages, HrmpChannelId, Id, UpwardMessage, UpwardMessages, ValidationCode, + ValidationCodeHash, LOWEST_PUBLIC_ID, LOWEST_USER_ID, }; #[cfg(feature = "std")] @@ -593,12 +593,12 @@ impl PersistedValidationData { /// Commitments made in a `CandidateReceipt`. Many of these are outputs of validation. #[derive(PartialEq, Eq, Clone, Encode, Decode, TypeInfo, RuntimeDebug)] -#[cfg_attr(feature = "std", derive(Hash, Default))] +#[cfg_attr(feature = "std", derive(Default, Hash))] pub struct CandidateCommitments { /// Messages destined to be interpreted by the Relay chain itself. - pub upward_messages: Vec, + pub upward_messages: UpwardMessages, /// Horizontal messages sent by the parachain. - pub horizontal_messages: Vec>, + pub horizontal_messages: HorizontalMessages, /// New validation code. pub new_validation_code: Option, /// The head-data produced as a result of execution. diff --git a/primitives/test-helpers/src/lib.rs b/primitives/test-helpers/src/lib.rs index e734caeb35ba..f1603a53bf2a 100644 --- a/primitives/test-helpers/src/lib.rs +++ b/primitives/test-helpers/src/lib.rs @@ -70,9 +70,9 @@ pub fn dummy_candidate_receipt_bad_sig( pub fn dummy_candidate_commitments(head_data: impl Into>) -> CandidateCommitments { CandidateCommitments { head_data: head_data.into().unwrap_or(dummy_head_data()), - upward_messages: vec![], + upward_messages: vec![].try_into().expect("empty vec fits within bounds"), new_validation_code: None, - horizontal_messages: vec![], + horizontal_messages: vec![].try_into().expect("empty vec fits within bounds"), processed_downward_messages: 0, hrmp_watermark: 0_u32, } diff --git a/runtime/parachains/Cargo.toml b/runtime/parachains/Cargo.toml index 6ec4c6dbe2f2..2bd485c7fa55 100644 --- a/runtime/parachains/Cargo.toml +++ b/runtime/parachains/Cargo.toml @@ -45,6 +45,7 @@ primitives = { package = "polkadot-primitives", path = "../../primitives", defau rand = { version = "0.8.5", default-features = false } rand_chacha = { version = "0.3.1", default-features = false } static_assertions = { version = "1.1.0", optional = true } +polkadot-parachain = { path = "../../parachain", default-features = false } polkadot-runtime-metrics = { path = "../metrics", default-features = false} [dev-dependencies] diff --git a/runtime/parachains/src/builder.rs b/runtime/parachains/src/builder.rs index 9fa954066c1c..97be7681e4ef 100644 --- a/runtime/parachains/src/builder.rs +++ b/runtime/parachains/src/builder.rs @@ -292,8 +292,8 @@ impl BenchBuilder { availability_votes, ); let commitments = CandidateCommitments:: { - upward_messages: vec![], - horizontal_messages: vec![], + upward_messages: Default::default(), + horizontal_messages: Default::default(), new_validation_code: None, head_data: Self::mock_head_data(), processed_downward_messages: 0, @@ -535,8 +535,8 @@ impl BenchBuilder { validation_code_hash, }, commitments: CandidateCommitments:: { - upward_messages: Vec::new(), - horizontal_messages: Vec::new(), + upward_messages: Default::default(), + horizontal_messages: Default::default(), new_validation_code: includes_code_upgrade .map(|v| ValidationCode(vec![42u8; v as usize])), head_data, diff --git a/runtime/parachains/src/configuration.rs b/runtime/parachains/src/configuration.rs index 1c918d9d7cd5..9bc061f071a9 100644 --- a/runtime/parachains/src/configuration.rs +++ b/runtime/parachains/src/configuration.rs @@ -22,6 +22,7 @@ use crate::shared; use frame_support::{pallet_prelude::*, weights::constants::WEIGHT_REF_TIME_PER_MILLIS}; use frame_system::pallet_prelude::*; use parity_scale_codec::{Decode, Encode}; +use polkadot_parachain::primitives::{MAX_HORIZONTAL_MESSAGE_NUM, MAX_UPWARD_MESSAGE_NUM}; use primitives::{Balance, SessionIndex, MAX_CODE_SIZE, MAX_HEAD_DATA_SIZE, MAX_POV_SIZE}; use sp_runtime::traits::Zero; use sp_std::prelude::*; @@ -322,8 +323,12 @@ pub enum InconsistentError { }, /// `validation_upgrade_delay` is less than or equal 1. ValidationUpgradeDelayIsTooLow { validation_upgrade_delay: BlockNumber }, - /// Maximum UMP message size (`MAX_UPWARD_MESSAGE_SIZE_BOUND`) exceeded. + /// Maximum UMP message size ([`MAX_UPWARD_MESSAGE_SIZE_BOUND`]) exceeded. MaxUpwardMessageSizeExceeded { max_message_size: u32 }, + /// Maximum HRMP message num ([`MAX_HORIZONTAL_MESSAGE_NUM`]) exceeded. + MaxHorizontalMessageNumExceeded { max_message_num: u32 }, + /// Maximum UMP message num ([`MAX_UPWARD_MESSAGE_NUM`]) exceeded. + MaxUpwardMessageNumExceeded { max_message_num: u32 }, /// Maximum number of HRMP outbound channels exceeded. MaxHrmpOutboundChannelsExceeded, /// Maximum number of HRMP inbound channels exceeded. @@ -396,6 +401,18 @@ where }) } + if self.hrmp_max_message_num_per_candidate > MAX_HORIZONTAL_MESSAGE_NUM { + return Err(MaxHorizontalMessageNumExceeded { + max_message_num: self.hrmp_max_message_num_per_candidate, + }) + } + + if self.max_upward_message_num_per_candidate > MAX_UPWARD_MESSAGE_NUM { + return Err(MaxUpwardMessageNumExceeded { + max_message_num: self.max_upward_message_num_per_candidate, + }) + } + if self.hrmp_max_parachain_outbound_channels > crate::hrmp::HRMP_MAX_OUTBOUND_CHANNELS_BOUND { return Err(MaxHrmpOutboundChannelsExceeded) diff --git a/runtime/parachains/src/hrmp.rs b/runtime/parachains/src/hrmp.rs index d72043dcd3ae..396ba1f5f73b 100644 --- a/runtime/parachains/src/hrmp.rs +++ b/runtime/parachains/src/hrmp.rs @@ -21,6 +21,7 @@ use crate::{ use frame_support::{pallet_prelude::*, traits::ReservableCurrency}; use frame_system::pallet_prelude::*; use parity_scale_codec::{Decode, Encode}; +use polkadot_parachain::primitives::HorizontalMessages; use primitives::{ Balance, Hash, HrmpChannelId, Id as ParaId, InboundHrmpMessage, OutboundHrmpMessage, SessionIndex, @@ -1057,10 +1058,7 @@ impl Pallet { /// Process the outbound HRMP messages by putting them into the appropriate recipient queues. /// /// Returns the amount of weight consumed. - pub(crate) fn queue_outbound_hrmp( - sender: ParaId, - out_hrmp_msgs: Vec>, - ) -> Weight { + pub(crate) fn queue_outbound_hrmp(sender: ParaId, out_hrmp_msgs: HorizontalMessages) -> Weight { let mut weight = Weight::zero(); let now = >::block_number(); diff --git a/runtime/parachains/src/hrmp/tests.rs b/runtime/parachains/src/hrmp/tests.rs index ec91b1c47378..3c9fedaa9dcb 100644 --- a/runtime/parachains/src/hrmp/tests.rs +++ b/runtime/parachains/src/hrmp/tests.rs @@ -278,8 +278,10 @@ fn send_recv_messages() { // A sends a message to B run_to_block(6, Some(vec![6])); assert!(channel_exists(para_a, para_b)); - let msgs = - vec![OutboundHrmpMessage { recipient: para_b, data: b"this is an emergency".to_vec() }]; + let msgs: HorizontalMessages = + vec![OutboundHrmpMessage { recipient: para_b, data: b"this is an emergency".to_vec() }] + .try_into() + .unwrap(); let config = Configuration::config(); assert!(Hrmp::check_outbound_hrmp(&config, para_a, &msgs).is_ok()); let _ = Hrmp::queue_outbound_hrmp(para_a, msgs); @@ -313,13 +315,17 @@ fn hrmp_mqc_head_fixture() { run_to_block(3, Some(vec![3])); let _ = Hrmp::queue_outbound_hrmp( para_a, - vec![OutboundHrmpMessage { recipient: para_b, data: vec![1, 2, 3] }], + vec![OutboundHrmpMessage { recipient: para_b, data: vec![1, 2, 3] }] + .try_into() + .unwrap(), ); run_to_block(4, None); let _ = Hrmp::queue_outbound_hrmp( para_a, - vec![OutboundHrmpMessage { recipient: para_b, data: vec![4, 5, 6] }], + vec![OutboundHrmpMessage { recipient: para_b, data: vec![4, 5, 6] }] + .try_into() + .unwrap(), ); assert_eq!( @@ -381,7 +387,10 @@ fn check_sent_messages() { run_to_block(6, Some(vec![6])); assert!(Paras::is_valid_para(para_a)); - let msgs = vec![OutboundHrmpMessage { recipient: para_b, data: b"knock".to_vec() }]; + let msgs: HorizontalMessages = + vec![OutboundHrmpMessage { recipient: para_b, data: b"knock".to_vec() }] + .try_into() + .unwrap(); let config = Configuration::config(); assert!(Hrmp::check_outbound_hrmp(&config, para_a, &msgs).is_ok()); let _ = Hrmp::queue_outbound_hrmp(para_a, msgs.clone()); diff --git a/runtime/parachains/src/ump.rs b/runtime/parachains/src/ump.rs index 6a5f8b96b4cf..992392c8b500 100644 --- a/runtime/parachains/src/ump.rs +++ b/runtime/parachains/src/ump.rs @@ -20,6 +20,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 sp_std::{collections::btree_map::BTreeMap, fmt, marker::PhantomData, mem, prelude::*}; use xcm::latest::Outcome; @@ -28,7 +29,7 @@ pub use pallet::*; /// Maximum value that `config.max_upward_message_size` can be set to /// -/// This is used for benchmarking sanely bounding relevant storate items. It is expected from the `configurations` +/// This is used for benchmarking sanely bounding relevant storage items. It is expected from the `configurations` /// pallet to check these values before setting. pub const MAX_UPWARD_MESSAGE_SIZE_BOUND: u32 = 50 * 1024; /// Maximum amount of overweight messages that can exist in the queue at any given time. @@ -470,10 +471,7 @@ impl Pallet { } /// Enqueues `upward_messages` from a `para`'s accepted candidate block. - pub(crate) fn receive_upward_messages( - para: ParaId, - upward_messages: Vec, - ) -> Weight { + pub(crate) fn receive_upward_messages(para: ParaId, upward_messages: UpwardMessages) -> Weight { let mut weight = Weight::zero(); if !upward_messages.is_empty() { diff --git a/runtime/parachains/src/ump/benchmarking.rs b/runtime/parachains/src/ump/benchmarking.rs index 91f3d4ac7ec2..22860d2abbfc 100644 --- a/runtime/parachains/src/ump/benchmarking.rs +++ b/runtime/parachains/src/ump/benchmarking.rs @@ -32,7 +32,7 @@ fn queue_upward_msg( msg: UpwardMessage, ) { let len = msg.len() as u32; - let msgs = vec![msg]; + let msgs: UpwardMessages = vec![msg].try_into().unwrap(); Ump::::check_upward_messages(host_conf, para, &msgs).unwrap(); let _ = Ump::::receive_upward_messages(para, msgs); assert_last_event_type::(Event::UpwardMessagesReceived(para, 1, len).into()); diff --git a/runtime/parachains/src/ump/tests.rs b/runtime/parachains/src/ump/tests.rs index 37e166d811a1..39f78c8eba99 100644 --- a/runtime/parachains/src/ump/tests.rs +++ b/runtime/parachains/src/ump/tests.rs @@ -72,7 +72,7 @@ fn default_genesis_config() -> MockGenesisConfig { } fn queue_upward_msg(para: ParaId, msg: UpwardMessage) { - let msgs = vec![msg]; + let msgs: UpwardMessages = vec![msg].try_into().unwrap(); assert!(Ump::check_upward_messages(&Configuration::config(), para, &msgs).is_ok()); let _ = Ump::receive_upward_messages(para, msgs); } diff --git a/xcm/Cargo.toml b/xcm/Cargo.toml index 804fcedd3dd0..73690a9a0945 100644 --- a/xcm/Cargo.toml +++ b/xcm/Cargo.toml @@ -6,7 +6,7 @@ authors.workspace = true edition.workspace = true [dependencies] -bounded-collections = { version = "0.1.4", default-features = false } +bounded-collections = { version = "0.1.5", default-features = false } derivative = { version = "2.2.0", default-features = false, features = [ "use_core" ] } impl-trait-for-tuples = "0.2.2" log = { version = "0.4.17", default-features = false } diff --git a/xcm/pallet-xcm/Cargo.toml b/xcm/pallet-xcm/Cargo.toml index b84537e56c2c..8aaeb522aa5d 100644 --- a/xcm/pallet-xcm/Cargo.toml +++ b/xcm/pallet-xcm/Cargo.toml @@ -6,7 +6,7 @@ version.workspace = true [dependencies] -bounded-collections = { version = "0.1.4", default-features = false } +bounded-collections = { version = "0.1.5", default-features = false } codec = { package = "parity-scale-codec", version = "3.3.0", default-features = false, features = ["derive"] } scale-info = { version = "2.1.2", default-features = false, features = ["derive"] } serde = { version = "1.0.137", optional = true, features = ["derive"] } diff --git a/xcm/xcm-builder/src/tests/querying.rs b/xcm/xcm-builder/src/tests/querying.rs index 014bbe713cf9..9bd81763fed4 100644 --- a/xcm/xcm-builder/src/tests/querying.rs +++ b/xcm/xcm-builder/src/tests/querying.rs @@ -41,7 +41,7 @@ fn pallet_query_should_work() { let expected_msg = Xcm::<()>(vec![QueryResponse { query_id: 1, max_weight: Weight::from_parts(50, 50), - response: Response::PalletsInfo(vec![].try_into().unwrap()), + response: Response::PalletsInfo(Default::default()), querier: Some(Here.into()), }]); let expected_hash = fake_message_hash(&expected_msg);