From 743bbbe48594072ab6b505840ac47283c746cf2b Mon Sep 17 00:00:00 2001 From: kianenigma Date: Fri, 17 Sep 2021 14:26:06 +0200 Subject: [PATCH 01/36] wip template for hrmp benchmarks --- runtime/parachains/src/hrmp.rs | 77 ++++++++++++++++++++++------------ 1 file changed, 50 insertions(+), 27 deletions(-) diff --git a/runtime/parachains/src/hrmp.rs b/runtime/parachains/src/hrmp.rs index f087dfd3a405..e46ce2498efc 100644 --- a/runtime/parachains/src/hrmp.rs +++ b/runtime/parachains/src/hrmp.rs @@ -143,8 +143,9 @@ impl fmt::Debug for OutboundHrmpAcceptanceErr { "more HRMP messages than permitted by config ({} > {})", sent, permitted, ), - NotSorted { idx } => - write!(fmt, "the HRMP messages are not sorted (first unsorted is at index {})", idx,), + NotSorted { idx } => { + write!(fmt, "the HRMP messages are not sorted (first unsorted is at index {})", idx,) + } NoSuchChannel { idx, channel_id } => write!( fmt, "the HRMP message at index {} is sent to a non existent channel {:?}->{:?}", @@ -576,8 +577,8 @@ impl Pallet { Some(req_data) => req_data, None => { // Can't normally happen but no need to panic. - continue - }, + continue; + } }; // Return the deposit of the sender, but only if it is not the para being offboarded. @@ -632,7 +633,7 @@ impl Pallet { fn process_hrmp_open_channel_requests(config: &HostConfiguration) { let mut open_req_channels = ::HrmpOpenChannelRequestsList::get(); if open_req_channels.is_empty() { - return + return; } // iterate the vector starting from the end making our way to the beginning. This way we @@ -641,7 +642,7 @@ impl Pallet { loop { // bail if we've iterated over all items. if idx == 0 { - break + break; } idx -= 1; @@ -651,8 +652,8 @@ impl Pallet { ); if request.confirmed { - if >::is_valid_para(channel_id.sender) && - >::is_valid_para(channel_id.recipient) + if >::is_valid_para(channel_id.sender) + && >::is_valid_para(channel_id.recipient) { ::HrmpChannels::insert( &channel_id, @@ -752,14 +753,14 @@ impl Pallet { return Err(HrmpWatermarkAcceptanceErr::AdvancementRule { new_watermark: new_hrmp_watermark, last_watermark, - }) + }); } } if new_hrmp_watermark > relay_chain_parent_number { return Err(HrmpWatermarkAcceptanceErr::AheadRelayParent { new_watermark: new_hrmp_watermark, relay_chain_parent_number, - }) + }); } // Second, check where the watermark CAN land. It's one of the following: @@ -776,7 +777,7 @@ impl Pallet { { return Err(HrmpWatermarkAcceptanceErr::LandsOnBlockWithNoMessages { new_watermark: new_hrmp_watermark, - }) + }); } Ok(()) } @@ -791,7 +792,7 @@ impl Pallet { return Err(OutboundHrmpAcceptanceErr::MoreMessagesThanPermitted { sent: out_hrmp_msgs.len() as u32, permitted: config.hrmp_max_message_num_per_candidate, - }) + }); } let mut last_recipient = None::; @@ -803,8 +804,9 @@ impl Pallet { // the messages must be sorted in ascending order and there must be no two messages sent // to the same recipient. Thus we can check that every recipient is strictly greater than // the previous one. - Some(last_recipient) if out_msg.recipient <= last_recipient => - return Err(OutboundHrmpAcceptanceErr::NotSorted { idx }), + Some(last_recipient) if out_msg.recipient <= last_recipient => { + return Err(OutboundHrmpAcceptanceErr::NotSorted { idx }) + } _ => last_recipient = Some(out_msg.recipient), } @@ -821,7 +823,7 @@ impl Pallet { idx, msg_size, max_size: channel.max_message_size, - }) + }); } let new_total_size = channel.total_size + out_msg.data.len() as u32; @@ -830,7 +832,7 @@ impl Pallet { idx, total_size: new_total_size, limit: channel.max_total_size, - }) + }); } let new_msg_count = channel.msg_count + 1; @@ -839,7 +841,7 @@ impl Pallet { idx, count: new_msg_count, limit: channel.max_capacity, - }) + }); } } @@ -925,8 +927,8 @@ impl Pallet { None => { // apparently, that since acceptance of this candidate the recipient was // offboarded and the channel no longer exists. - continue - }, + continue; + } }; let inbound = InboundHrmpMessage { sent_at: now, data: out_msg.data }; @@ -1315,7 +1317,7 @@ mod tests { } #[derive(Debug)] - struct GenesisConfigBuilder { + pub(super) struct GenesisConfigBuilder { hrmp_channel_max_capacity: u32, hrmp_channel_max_message_size: u32, hrmp_max_parathread_outbound_channels: u32, @@ -1346,7 +1348,7 @@ mod tests { } impl GenesisConfigBuilder { - fn build(self) -> crate::mock::MockGenesisConfig { + pub(super) fn build(self) -> crate::mock::MockGenesisConfig { let mut genesis = default_genesis_config(); let config = &mut genesis.configuration.config; config.hrmp_channel_max_capacity = self.hrmp_channel_max_capacity; @@ -1579,13 +1581,13 @@ mod tests { run_to_block(5, Some(vec![4, 5])); Hrmp::hrmp_init_open_channel(para_a_origin.into(), para_b, 2, 8).unwrap(); assert_storage_consistency_exhaustive(); - assert!(System::events().iter().any(|record| record.event == - MockEvent::Hrmp(Event::OpenChannelRequested(para_a, para_b, 2, 8)))); + assert!(System::events().iter().any(|record| record.event + == MockEvent::Hrmp(Event::OpenChannelRequested(para_a, para_b, 2, 8)))); Hrmp::hrmp_accept_open_channel(para_b_origin.into(), para_a).unwrap(); assert_storage_consistency_exhaustive(); - assert!(System::events().iter().any(|record| record.event == - MockEvent::Hrmp(Event::OpenChannelAccepted(para_a, para_b)))); + assert!(System::events().iter().any(|record| record.event + == MockEvent::Hrmp(Event::OpenChannelAccepted(para_a, para_b)))); // Advance to a block 6, but without session change. That means that the channel has // not been created yet. @@ -1627,8 +1629,8 @@ mod tests { run_to_block(8, Some(vec![8])); assert!(!channel_exists(para_a, para_b)); assert_storage_consistency_exhaustive(); - assert!(System::events().iter().any(|record| record.event == - MockEvent::Hrmp(Event::ChannelClosed(para_b, channel_id.clone())))); + assert!(System::events().iter().any(|record| record.event + == MockEvent::Hrmp(Event::ChannelClosed(para_b, channel_id.clone())))); }); } @@ -2008,3 +2010,24 @@ mod tests { }); } } + +#[cfg(feature = "runtime-benchmarks")] +mod benchmarking { + use super::{Pallet as Hrmp, *}; + + frame_benchmarking::benchmarks! { + hrmp_init_open_channel {}: {} verify {} + hrmp_accept_open_channel {}: {} verify {} + hrmp_close_channel {}: {} verify {} + force_clean_hrmp {}: {} verify {} + force_process_hrmp_open {}: {} verify {} + force_process_hrmp_close {}: {} verify {} + hrmp_cancel_open_request {}: {} verify {} + } + + frame_benchmarking::impl_benchmark_test_suite!( + Hrmp, + crate::mock::new_test_ext(super::tests::GenesisConfigBuilder::default().build()), + crate::mock::Test + ); +} From 4c1e545c740da0ba6a002db70615d4c16fbcc911 Mon Sep 17 00:00:00 2001 From: kianenigma Date: Mon, 20 Sep 2021 19:18:45 +0200 Subject: [PATCH 02/36] add all of the benchmarks, first draft --- runtime/kusama/src/lib.rs | 4 + runtime/parachains/src/hrmp.rs | 293 ++++++++++++++++++++++++++++---- runtime/parachains/src/paras.rs | 13 ++ 3 files changed, 276 insertions(+), 34 deletions(-) diff --git a/runtime/kusama/src/lib.rs b/runtime/kusama/src/lib.rs index cd6f3fc2e277..4c5e99cf246b 100644 --- a/runtime/kusama/src/lib.rs +++ b/runtime/kusama/src/lib.rs @@ -2000,6 +2000,8 @@ sp_api::impl_runtime_apis! { list_benchmark!(list, extra, runtime_common::claims, Claims); list_benchmark!(list, extra, runtime_common::slots, Slots); list_benchmark!(list, extra, runtime_common::paras_registrar, Registrar); + list_benchmark!(list, extra, runtime_parachains::hrmp, Hrmp); + // Substrate list_benchmark!(list, extra, pallet_bags_list, BagsList); list_benchmark!(list, extra, pallet_balances, Balances); @@ -2074,6 +2076,8 @@ sp_api::impl_runtime_apis! { add_benchmark!(params, batches, runtime_common::claims, Claims); add_benchmark!(params, batches, runtime_common::slots, Slots); add_benchmark!(params, batches, runtime_common::paras_registrar, Registrar); + add_benchmark!(params, batches, runtime_parachains::hrmp, Hrmp); + // Substrate add_benchmark!(params, batches, pallet_balances, Balances); add_benchmark!(params, batches, pallet_bags_list, BagsList); diff --git a/runtime/parachains/src/hrmp.rs b/runtime/parachains/src/hrmp.rs index e46ce2498efc..9924e0894553 100644 --- a/runtime/parachains/src/hrmp.rs +++ b/runtime/parachains/src/hrmp.rs @@ -191,9 +191,9 @@ pub mod pallet { /// An interface for reserving deposits for opening channels. /// - /// NOTE that this Currency instance will be charged with the amounts defined in the `Configuration` - /// pallet. Specifically, that means that the `Balance` of the `Currency` implementation should - /// be the same as `Balance` as used in the `Configuration`. + /// NOTE that this Currency instance will be charged with the amounts defined in the + /// `Configuration` pallet. Specifically, that means that the `Balance` of the `Currency` + /// implementation should be the same as `Balance` as used in the `Configuration`. type Currency: ReservableCurrency; } @@ -267,8 +267,8 @@ pub mod pallet { StorageValue<_, Vec, ValueQuery>; /// This mapping tracks how many open channel requests are initiated by a given sender para. - /// Invariant: `HrmpOpenChannelRequests` should contain the same number of items that has `(X, _)` - /// as the number of `HrmpOpenChannelRequestCount` for `X`. + /// Invariant: `HrmpOpenChannelRequests` should contain the same number of items that has `(X, + /// _)` as the number of `HrmpOpenChannelRequestCount` for `X`. #[pallet::storage] pub type HrmpOpenChannelRequestCount = StorageMap<_, Twox64Concat, ParaId, u32, ValueQuery>; @@ -280,8 +280,8 @@ pub mod pallet { pub type HrmpAcceptedChannelRequestCount = StorageMap<_, Twox64Concat, ParaId, u32, ValueQuery>; - /// A set of pending HRMP close channel requests that are going to be closed during the session change. - /// Used for checking if a given channel is registered for closure. + /// A set of pending HRMP close channel requests that are going to be closed during the session + /// change. Used for checking if a given channel is registered for closure. /// /// The set is accompanied by a list for iteration. /// @@ -306,17 +306,17 @@ pub mod pallet { #[pallet::storage] pub type HrmpChannels = StorageMap<_, Twox64Concat, HrmpChannelId, HrmpChannel>; - /// Ingress/egress indexes allow to find all the senders and receivers given the opposite - /// side. I.e. + /// Ingress/egress indexes allow to find all the senders and receivers given the opposite side. + /// I.e. /// - /// (a) ingress index allows to find all the senders for a given recipient. - /// (b) egress index allows to find all the recipients for a given sender. + /// (a) ingress index allows to find all the senders for a given recipient. (b) egress index + /// allows to find all the recipients for a given sender. /// /// Invariants: - /// - for each ingress index entry for `P` each item `I` in the index should present in `HrmpChannels` - /// as `(I, P)`. - /// - for each egress index entry for `P` each item `E` in the index should present in `HrmpChannels` - /// as `(P, E)`. + /// - for each ingress index entry for `P` each item `I` in the index should present in + /// `HrmpChannels` as `(I, P)`. + /// - for each egress index entry for `P` each item `E` in the index should present in + /// `HrmpChannels` as `(P, E)`. /// - there should be no other dangling channels in `HrmpChannels`. /// - the vectors are sorted. #[pallet::storage] @@ -340,27 +340,27 @@ pub mod pallet { ValueQuery, >; - /// Maintains a mapping that can be used to answer the question: - /// What paras sent a message at the given block number for a given receiver. - /// Invariants: + /// Maintains a mapping that can be used to answer the question: What paras sent a message at + /// the given block number for a given receiver. Invariants: /// - The inner `Vec` is never empty. /// - The inner `Vec` cannot store two same `ParaId`. - /// - The outer vector is sorted ascending by block number and cannot store two items with the same - /// block number. + /// - The outer vector is sorted ascending by block number and cannot store two items with the + /// same block number. #[pallet::storage] pub type HrmpChannelDigests = StorageMap<_, Twox64Concat, ParaId, Vec<(T::BlockNumber, Vec)>, ValueQuery>; /// Preopen the given HRMP channels. /// - /// The values in the tuple corresponds to `(sender, recipient, max_capacity, max_message_size)`, - /// i.e. similar to `init_open_channel`. In fact, the initialization is performed as if - /// the `init_open_channel` and `accept_open_channel` were called with the respective parameters - /// and the session change take place. + /// The values in the tuple corresponds to `(sender, recipient, max_capacity, + /// max_message_size)`, i.e. similar to `init_open_channel`. In fact, the initialization is + /// performed as if the `init_open_channel` and `accept_open_channel` were called with the + /// respective parameters and the session change take place. /// /// As such, each channel initializer should satisfy the same constraints, namely: /// - /// 1. `max_capacity` and `max_message_size` should be within the limits set by the configuration pallet. + /// 1. `max_capacity` and `max_message_size` should be within the limits set by the + /// configuration pallet. /// 2. `sender` and `recipient` must be valid paras. #[pallet::genesis_config] pub struct GenesisConfig { @@ -477,7 +477,7 @@ pub mod pallet { Ok(()) } - /// This cancels a pending open channel request. It can be canceled be either of the sender + /// This cancels a pending open channel request. It can be canceled by either of the sender /// or the recipient for that request. The origin must be either of those. /// /// The cancelling happens immediately. It is not possible to cancel the request if it is @@ -1037,6 +1037,8 @@ impl Pallet { config.hrmp_sender_deposit.unique_saturated_into(), )?; + // mutating storage -- shall not bail henceforth. + ::HrmpOpenChannelRequestCount::insert(&origin, open_req_cnt + 1); ::HrmpOpenChannelRequests::insert( &channel_id, @@ -1067,6 +1069,7 @@ impl Pallet { { // this should never happen unless the max downward message size is configured to an // jokingly small number. + log::error!(target: "runtime::hrmp", "sending 'init_open_channel::notification_bytes' failed."); debug_assert!(false); } @@ -1076,7 +1079,7 @@ impl Pallet { /// Accept a pending open channel request from the given sender. /// /// Basically the same as [`hrmp_accept_open_channel`](Pallet::hrmp_accept_open_channel) but - /// intendend for calling directly from other pallets rather than dispatched. + /// intended for calling directly from other pallets rather than dispatched. pub fn accept_open_channel(origin: ParaId, sender: ParaId) -> DispatchResult { let channel_id = HrmpChannelId { sender, recipient: origin }; let mut channel_req = ::HrmpOpenChannelRequests::get(&channel_id) @@ -1121,6 +1124,7 @@ impl Pallet { { // this should never happen unless the max downward message size is configured to an // jokingly small number. + log::error!(target: "runtime::hrmp", "sending 'accept_open_channel::notification_bytes' failed."); debug_assert!(false); } @@ -1195,6 +1199,7 @@ impl Pallet { { // this should never happen unless the max downward message size is configured to an // jokingly small number. + log::error!(target: "runtime::hrmp", "sending 'close_channel::notification_bytes' failed."); debug_assert!(false); } @@ -2014,15 +2019,235 @@ mod tests { #[cfg(feature = "runtime-benchmarks")] mod benchmarking { use super::{Pallet as Hrmp, *}; + use crate::{ + configuration::Pallet as Configuration, paras::Pallet as Paras, shared::Pallet as Shared, + }; + use frame_support::{assert_ok, traits::Currency}; + + type BalanceOf = + <::Currency as Currency<::AccountId>>::Balance; + + fn register_parachain_with_balance(id: ParaId, balance: BalanceOf) { + assert_ok!(Paras::::initialize_para_now( + id, + crate::paras::ParaGenesisArgs { + parachain: true, + genesis_head: vec![1].into(), + validation_code: vec![1].into(), + }, + )); + T::Currency::make_free_balance_be(&id.into_account(), balance); + } + + fn assert_last_event(generic_event: ::Event) { + let events = frame_system::Pallet::::events(); + let system_event: ::Event = generic_event.into(); + // compare to the last event record + let frame_system::EventRecord { event, .. } = &events[events.len() - 1]; + assert_eq!(event, &system_event); + } + + enum ParachainSetupStep { + /// A channel open has been requested + Requested, + /// A channel open has been requested and accepted. + Accepted, + /// A channel open has been requested and accepted, and a session has passed and is now open. + Established, + /// A channel open has been requested and accepted, and a session has passed and is now + /// open, and now it has been requested to close down. + CloseRequested, + } + + fn establish_para_connection( + from: u32, + to: u32, + until: ParachainSetupStep, + ) -> [(ParaId, crate::Origin); 2] + where + ::Origin: From, + { + let config = Configuration::::config(); + let deposit: BalanceOf = config.hrmp_sender_deposit.unique_saturated_into(); + let capacity = config.hrmp_channel_max_capacity; + let message_size = config.hrmp_channel_max_message_size; + + let sender: ParaId = from.into(); + let sender_origin: crate::Origin = from.into(); + + let recipient: ParaId = to.into(); + let recipient_origin: crate::Origin = to.into(); + + let output = [(sender, sender_origin.clone()), (recipient, recipient_origin.clone())]; + + // Make both a parachain if they are already not. + if !Paras::::is_parachain(sender) { + register_parachain_with_balance::(sender, deposit); + } + if !Paras::::is_parachain(recipient) { + register_parachain_with_balance::(recipient, deposit); + } + + assert_ok!(Hrmp::::hrmp_init_open_channel( + sender_origin.clone().into(), + recipient, + capacity, + message_size + )); + if matches!(until, ParachainSetupStep::Requested) { + return output; + } + + assert_ok!(Hrmp::::hrmp_accept_open_channel(recipient_origin.into(), sender)); + if matches!(until, ParachainSetupStep::Accepted) { + return output; + } + + Hrmp::::process_hrmp_open_channel_requests(&Configuration::::config()); + if matches!(until, ParachainSetupStep::Established) { + return output; + } + + let channel_id = HrmpChannelId { sender, recipient }; + assert_ok!(Hrmp::::hrmp_close_channel(sender_origin.clone().into(), channel_id)); + if matches!(until, ParachainSetupStep::CloseRequested) { + // NOTE: this is just for expressiveness, otherwise the if-statement could be omitted. + return output; + } + + output + } frame_benchmarking::benchmarks! { - hrmp_init_open_channel {}: {} verify {} - hrmp_accept_open_channel {}: {} verify {} - hrmp_close_channel {}: {} verify {} - force_clean_hrmp {}: {} verify {} - force_process_hrmp_open {}: {} verify {} - force_process_hrmp_close {}: {} verify {} - hrmp_cancel_open_request {}: {} verify {} + where_clause { where ::Origin: From } + + hrmp_init_open_channel { + let sender_id: ParaId = 1u32.into(); + let sender_origin: crate::Origin = 1u32.into(); + + let recipient_id: ParaId = 2u32.into(); + + // make sure para is registered, and has enough balance. + let deposit: BalanceOf = Configuration::::config().hrmp_sender_deposit.unique_saturated_into(); + register_parachain_with_balance::(sender_id, deposit); + register_parachain_with_balance::(recipient_id, deposit); + + let capacity = Configuration::::config().hrmp_channel_max_capacity; + let message_size = Configuration::::config().hrmp_channel_max_message_size; + }: _(sender_origin, recipient_id, capacity, message_size) + verify { + assert_last_event::( + Event::::OpenChannelRequested(sender_id, recipient_id, capacity, message_size).into() + ); + } + + hrmp_accept_open_channel { + let [(sender, _), (recipient, recipient_origin)] =establish_para_connection::(1, 2, ParachainSetupStep::Requested); + }: _(recipient_origin, sender) + verify { + assert_last_event::(Event::::OpenChannelAccepted(sender, recipient).into()); + } + + hrmp_close_channel { + let [(sender, sender_origin), (recipient, _)] = establish_para_connection::(1, 2, ParachainSetupStep::Established); + let channel_id = HrmpChannelId { sender, recipient }; + }: _(sender_origin, channel_id.clone()) + verify { + assert_last_event::(Event::::ChannelClosed(sender, channel_id).into()); + } + + force_clean_hrmp { + // TODO: reasonable constant/config for these. + // TODO: assert that `i` and `e` are well below 10k as prefix that we use. + // ingress channels to a single leaving parachain that need to be closed. + let i in 0..128; + // egress channels to a single leaving parachain that need to be closed. + let e in 0..128; + + // first, update the configs to support this many open channels... + assert_ok!(Configuration::::set_hrmp_max_parachain_outbound_channels(frame_system::RawOrigin::Root.into(), e + 1)); + assert_ok!(Configuration::::set_hrmp_max_parachain_inbound_channels(frame_system::RawOrigin::Root.into(), i + 1)); + // .. and enact it. + Configuration::::initializer_on_new_session(&Shared::::scheduled_session()); + + let config = Configuration::::config(); + let deposit: BalanceOf = config.hrmp_sender_deposit.unique_saturated_into(); + + let para: ParaId = 1u32.into(); + let para_origin: crate::Origin = 1u32.into(); + register_parachain_with_balance::(para, deposit); + T::Currency::make_free_balance_be(¶.into_account(), deposit * 256u32.into()); + + for ingress_para_id in 0..i { + // establish ingress channels to `para`. + let ingress_para_id = ingress_para_id + 10000; + let _ = establish_para_connection::(ingress_para_id, 1, ParachainSetupStep::Established); + } + + // nothing should be left unprocessed. + assert_eq!(HrmpOpenChannelRequestsList::::decode_len().unwrap_or_default(), 0); + + for egress_para_id in 0..e { + // establish egress channels to `para`. + let egress_para_id = egress_para_id + 20000; + let _ = establish_para_connection::(1, egress_para_id, ParachainSetupStep::Established); + } + + // nothing should be left unprocessed. + assert_eq!(HrmpOpenChannelRequestsList::::decode_len().unwrap_or_default(), 0); + + // all in all, we have created these many channels + assert_eq!(HrmpChannels::::iter().count() as u32, i + e); + }: _(frame_system::Origin::::Root, para) verify { + // all in all, all of them must be gone by now. + assert_eq!(HrmpChannels::::iter().count() as u32, 0); + } + + force_process_hrmp_open { + // number of channels that need to be processed. Worse case is an N-M relation: unique + // sender and recipients for all channels. + let c in 0 .. 128; + + for id in 0 .. c { + let _ = establish_para_connection::(10_000 + id, 20_000 + id, ParachainSetupStep::Accepted); + } + assert_eq!(HrmpOpenChannelRequestsList::::decode_len().unwrap_or_default() as u32, c); + }: _(frame_system::Origin::::Root) + verify { + assert_eq!(HrmpOpenChannelRequestsList::::decode_len().unwrap_or_default() as u32, 0); + } + + force_process_hrmp_close { + // number of channels that need to be processed. Worse case is an N-M relation: unique + // sender and recipients for all channels. + let c in 0 .. 128; + + for id in 0 .. c { + let _ = establish_para_connection::(10_000 + id, 20_000 + id, ParachainSetupStep::CloseRequested); + } + + assert_eq!(HrmpCloseChannelRequestsList::::decode_len().unwrap_or_default() as u32, c); + }: _(frame_system::Origin::::Root) + verify { + assert_eq!(HrmpCloseChannelRequestsList::::decode_len().unwrap_or_default() as u32, 0); + } + + hrmp_cancel_open_request { + // number of items already existing in the `HrmpOpenChannelRequestsList`, other than the + // one that we remove. + let c in 0 .. 128; + + for id in 0 .. c { + let _ = establish_para_connection::(10_000 + id, 20_000 + id, ParachainSetupStep::Requested); + } + + let [(sender, sender_origin), (recipient, _)] = establish_para_connection::(1, 2, ParachainSetupStep::Requested); + assert_eq!(HrmpOpenChannelRequestsList::::decode_len().unwrap_or_default() as u32, c + 1); + let channel_id = HrmpChannelId { sender, recipient }; + }: _(sender_origin, channel_id) + verify { + assert_eq!(HrmpOpenChannelRequestsList::::decode_len().unwrap_or_default() as u32, c); + } } frame_benchmarking::impl_benchmark_test_suite!( diff --git a/runtime/parachains/src/paras.rs b/runtime/parachains/src/paras.rs index 9a840837ae94..fce5b139219e 100644 --- a/runtime/parachains/src/paras.rs +++ b/runtime/parachains/src/paras.rs @@ -850,6 +850,19 @@ impl Pallet { Ok(()) } + #[cfg(feature = "runtime-benchmarks")] + pub(crate) fn initialize_para_now(id: ParaId, genesis: ParaGenesisArgs) -> DispatchResult { + // first queue this para actions.. + let _ = Self::schedule_para_initialize(id, genesis)?; + + // .. and immediately apply them. + let _ = Self::apply_actions_queue(Self::scheduled_session()); + + // ensure it has become a para. + assert_eq!(ParaLifecycles::::get(id), Some(ParaLifecycle::Parachain)); + Ok(()) + } + /// Schedule a para to be cleaned up at the start of the next session. /// /// Will return error if para is not a stable parachain or parathread. From 42ea875c4b5f111de4ab599a733f3c11c9da9e56 Mon Sep 17 00:00:00 2001 From: kianenigma Date: Mon, 20 Sep 2021 19:25:01 +0200 Subject: [PATCH 03/36] File was not saved :/ --- runtime/kusama/src/lib.rs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/runtime/kusama/src/lib.rs b/runtime/kusama/src/lib.rs index 461ac7fc59aa..17e25c536911 100644 --- a/runtime/kusama/src/lib.rs +++ b/runtime/kusama/src/lib.rs @@ -1082,22 +1082,22 @@ impl InstanceFilter for ProxyType { ), ProxyType::Governance => matches!( c, - Call::Democracy(..) | - Call::Council(..) | Call::TechnicalCommittee(..) | - Call::PhragmenElection(..) | - Call::Treasury(..) | Call::Bounties(..) | - Call::Tips(..) | Call::Utility(..) + Call::Democracy(..) + | Call::Council(..) | Call::TechnicalCommittee(..) + | Call::PhragmenElection(..) + | Call::Treasury(..) | Call::Bounties(..) + | Call::Tips(..) | Call::Utility(..) ), ProxyType::Staking => { matches!(c, Call::Staking(..) | Call::Session(..) | Call::Utility(..)) - }, + } ProxyType::IdentityJudgement => matches!( c, Call::Identity(pallet_identity::Call::provide_judgement { .. }) | Call::Utility(..) ), ProxyType::CancelProxy => { matches!(c, Call::Proxy(pallet_proxy::Call::reject_announcement { .. })) - }, + } ProxyType::Auction => matches!( c, Call::Auctions(..) | Call::Crowdloan(..) | Call::Registrar(..) | Call::Slots(..) @@ -2008,8 +2008,8 @@ sp_api::impl_runtime_apis! { list_benchmark!(list, extra, runtime_common::claims, Claims); list_benchmark!(list, extra, runtime_common::slots, Slots); list_benchmark!(list, extra, runtime_common::paras_registrar, Registrar); - list_benchmark!(list, extra, runtime_parachains::hrmp, Hrmp); list_benchmark!(list, extra, runtime_parachains::configuration, Configuration); + list_benchmark!(list, extra, runtime_parachains::hrmp, Hrmp); // Substrate list_benchmark!(list, extra, pallet_bags_list, BagsList); list_benchmark!(list, extra, pallet_balances, Balances); From 477731c4372f8979050be33a0aef86c53c3dda0f Mon Sep 17 00:00:00 2001 From: kianenigma Date: Mon, 20 Sep 2021 19:28:18 +0200 Subject: [PATCH 04/36] cargo +nightly fmt --- runtime/kusama/src/lib.rs | 14 ++++----- runtime/parachains/src/hrmp.rs | 57 +++++++++++++++++----------------- 2 files changed, 35 insertions(+), 36 deletions(-) diff --git a/runtime/kusama/src/lib.rs b/runtime/kusama/src/lib.rs index 17e25c536911..b3eb1539c3a1 100644 --- a/runtime/kusama/src/lib.rs +++ b/runtime/kusama/src/lib.rs @@ -1082,22 +1082,22 @@ impl InstanceFilter for ProxyType { ), ProxyType::Governance => matches!( c, - Call::Democracy(..) - | Call::Council(..) | Call::TechnicalCommittee(..) - | Call::PhragmenElection(..) - | Call::Treasury(..) | Call::Bounties(..) - | Call::Tips(..) | Call::Utility(..) + Call::Democracy(..) | + Call::Council(..) | Call::TechnicalCommittee(..) | + Call::PhragmenElection(..) | + Call::Treasury(..) | Call::Bounties(..) | + Call::Tips(..) | Call::Utility(..) ), ProxyType::Staking => { matches!(c, Call::Staking(..) | Call::Session(..) | Call::Utility(..)) - } + }, ProxyType::IdentityJudgement => matches!( c, Call::Identity(pallet_identity::Call::provide_judgement { .. }) | Call::Utility(..) ), ProxyType::CancelProxy => { matches!(c, Call::Proxy(pallet_proxy::Call::reject_announcement { .. })) - } + }, ProxyType::Auction => matches!( c, Call::Auctions(..) | Call::Crowdloan(..) | Call::Registrar(..) | Call::Slots(..) diff --git a/runtime/parachains/src/hrmp.rs b/runtime/parachains/src/hrmp.rs index 9924e0894553..ebad001a4ab7 100644 --- a/runtime/parachains/src/hrmp.rs +++ b/runtime/parachains/src/hrmp.rs @@ -145,7 +145,7 @@ impl fmt::Debug for OutboundHrmpAcceptanceErr { ), NotSorted { idx } => { write!(fmt, "the HRMP messages are not sorted (first unsorted is at index {})", idx,) - } + }, NoSuchChannel { idx, channel_id } => write!( fmt, "the HRMP message at index {} is sent to a non existent channel {:?}->{:?}", @@ -577,8 +577,8 @@ impl Pallet { Some(req_data) => req_data, None => { // Can't normally happen but no need to panic. - continue; - } + continue + }, }; // Return the deposit of the sender, but only if it is not the para being offboarded. @@ -633,7 +633,7 @@ impl Pallet { fn process_hrmp_open_channel_requests(config: &HostConfiguration) { let mut open_req_channels = ::HrmpOpenChannelRequestsList::get(); if open_req_channels.is_empty() { - return; + return } // iterate the vector starting from the end making our way to the beginning. This way we @@ -642,7 +642,7 @@ impl Pallet { loop { // bail if we've iterated over all items. if idx == 0 { - break; + break } idx -= 1; @@ -652,8 +652,8 @@ impl Pallet { ); if request.confirmed { - if >::is_valid_para(channel_id.sender) - && >::is_valid_para(channel_id.recipient) + if >::is_valid_para(channel_id.sender) && + >::is_valid_para(channel_id.recipient) { ::HrmpChannels::insert( &channel_id, @@ -753,14 +753,14 @@ impl Pallet { return Err(HrmpWatermarkAcceptanceErr::AdvancementRule { new_watermark: new_hrmp_watermark, last_watermark, - }); + }) } } if new_hrmp_watermark > relay_chain_parent_number { return Err(HrmpWatermarkAcceptanceErr::AheadRelayParent { new_watermark: new_hrmp_watermark, relay_chain_parent_number, - }); + }) } // Second, check where the watermark CAN land. It's one of the following: @@ -777,7 +777,7 @@ impl Pallet { { return Err(HrmpWatermarkAcceptanceErr::LandsOnBlockWithNoMessages { new_watermark: new_hrmp_watermark, - }); + }) } Ok(()) } @@ -792,7 +792,7 @@ impl Pallet { return Err(OutboundHrmpAcceptanceErr::MoreMessagesThanPermitted { sent: out_hrmp_msgs.len() as u32, permitted: config.hrmp_max_message_num_per_candidate, - }); + }) } let mut last_recipient = None::; @@ -804,9 +804,8 @@ impl Pallet { // the messages must be sorted in ascending order and there must be no two messages sent // to the same recipient. Thus we can check that every recipient is strictly greater than // the previous one. - Some(last_recipient) if out_msg.recipient <= last_recipient => { - return Err(OutboundHrmpAcceptanceErr::NotSorted { idx }) - } + Some(last_recipient) if out_msg.recipient <= last_recipient => + return Err(OutboundHrmpAcceptanceErr::NotSorted { idx }), _ => last_recipient = Some(out_msg.recipient), } @@ -823,7 +822,7 @@ impl Pallet { idx, msg_size, max_size: channel.max_message_size, - }); + }) } let new_total_size = channel.total_size + out_msg.data.len() as u32; @@ -832,7 +831,7 @@ impl Pallet { idx, total_size: new_total_size, limit: channel.max_total_size, - }); + }) } let new_msg_count = channel.msg_count + 1; @@ -841,7 +840,7 @@ impl Pallet { idx, count: new_msg_count, limit: channel.max_capacity, - }); + }) } } @@ -927,8 +926,8 @@ impl Pallet { None => { // apparently, that since acceptance of this candidate the recipient was // offboarded and the channel no longer exists. - continue; - } + continue + }, }; let inbound = InboundHrmpMessage { sent_at: now, data: out_msg.data }; @@ -1586,13 +1585,13 @@ mod tests { run_to_block(5, Some(vec![4, 5])); Hrmp::hrmp_init_open_channel(para_a_origin.into(), para_b, 2, 8).unwrap(); assert_storage_consistency_exhaustive(); - assert!(System::events().iter().any(|record| record.event - == MockEvent::Hrmp(Event::OpenChannelRequested(para_a, para_b, 2, 8)))); + assert!(System::events().iter().any(|record| record.event == + MockEvent::Hrmp(Event::OpenChannelRequested(para_a, para_b, 2, 8)))); Hrmp::hrmp_accept_open_channel(para_b_origin.into(), para_a).unwrap(); assert_storage_consistency_exhaustive(); - assert!(System::events().iter().any(|record| record.event - == MockEvent::Hrmp(Event::OpenChannelAccepted(para_a, para_b)))); + assert!(System::events().iter().any(|record| record.event == + MockEvent::Hrmp(Event::OpenChannelAccepted(para_a, para_b)))); // Advance to a block 6, but without session change. That means that the channel has // not been created yet. @@ -1634,8 +1633,8 @@ mod tests { run_to_block(8, Some(vec![8])); assert!(!channel_exists(para_a, para_b)); assert_storage_consistency_exhaustive(); - assert!(System::events().iter().any(|record| record.event - == MockEvent::Hrmp(Event::ChannelClosed(para_b, channel_id.clone())))); + assert!(System::events().iter().any(|record| record.event == + MockEvent::Hrmp(Event::ChannelClosed(para_b, channel_id.clone())))); }); } @@ -2095,24 +2094,24 @@ mod benchmarking { message_size )); if matches!(until, ParachainSetupStep::Requested) { - return output; + return output } assert_ok!(Hrmp::::hrmp_accept_open_channel(recipient_origin.into(), sender)); if matches!(until, ParachainSetupStep::Accepted) { - return output; + return output } Hrmp::::process_hrmp_open_channel_requests(&Configuration::::config()); if matches!(until, ParachainSetupStep::Established) { - return output; + return output } let channel_id = HrmpChannelId { sender, recipient }; assert_ok!(Hrmp::::hrmp_close_channel(sender_origin.clone().into(), channel_id)); if matches!(until, ParachainSetupStep::CloseRequested) { // NOTE: this is just for expressiveness, otherwise the if-statement could be omitted. - return output; + return output } output From e7aadf5e2dd5a9ef4d2134c2999c4d6fe54a1008 Mon Sep 17 00:00:00 2001 From: kianenigma Date: Tue, 21 Sep 2021 12:07:40 +0200 Subject: [PATCH 05/36] Use configs --- Cargo.lock | 109 ++++++++++-------------- runtime/parachains/Cargo.toml | 1 + runtime/parachains/src/configuration.rs | 20 ++++- runtime/parachains/src/hrmp.rs | 76 +++++++++-------- runtime/parachains/src/mock.rs | 11 ++- 5 files changed, 116 insertions(+), 101 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 8d6986a73574..fb7cc6df4f20 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1953,7 +1953,7 @@ dependencies = [ "linregress", "log", "parity-scale-codec", - "paste 1.0.5", + "paste", "scale-info", "sp-api", "sp-io", @@ -2043,7 +2043,7 @@ dependencies = [ "log", "once_cell", "parity-scale-codec", - "paste 1.0.5", + "paste", "scale-info", "serde", "smallvec", @@ -2917,38 +2917,6 @@ version = "0.4.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dc6f3ad7b9d11a0c00842ff8de1b60ee58661048eb8049ed33c73594f359d7e6" -[[package]] -name = "jemalloc-ctl" -version = "0.3.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c502a5ff9dd2924f1ed32ba96e3b65735d837b4bfd978d3161b1702e66aca4b7" -dependencies = [ - "jemalloc-sys", - "libc", - "paste 0.1.18", -] - -[[package]] -name = "jemalloc-sys" -version = "0.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0d3b9f3f5c9b31aa0f5ed3260385ac205db665baa41d49bb8338008ae94ede45" -dependencies = [ - "cc", - "fs_extra", - "libc", -] - -[[package]] -name = "jemallocator" -version = "0.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "43ae63fcfc45e99ab3d1b29a46782ad679e98436c3169d15a167a1108a724b69" -dependencies = [ - "jemalloc-sys", - "libc", -] - [[package]] name = "jobserver" version = "0.1.21" @@ -5480,20 +5448,21 @@ dependencies = [ [[package]] name = "parity-util-mem" -version = "0.10.0" +version = "0.10.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7ad6f1acec69b95caf435bbd158d486e5a0a44fcf51531e84922c59ff09e8457" +checksum = "6f4cb4e169446179cbc6b8b6320cc9fca49bd2e94e8db25f25f200a8ea774770" dependencies = [ "cfg-if 1.0.0", "ethereum-types", "hashbrown", "impl-trait-for-tuples", - "jemallocator", "lru", "parity-util-mem-derive", "parking_lot 0.11.1", "primitive-types", "smallvec", + "tikv-jemalloc-ctl", + "tikv-jemallocator", "winapi 0.3.9", ] @@ -5597,31 +5566,12 @@ dependencies = [ "winapi 0.3.9", ] -[[package]] -name = "paste" -version = "0.1.18" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "45ca20c77d80be666aef2b45486da86238fabe33e38306bd3118fe4af33fa880" -dependencies = [ - "paste-impl", - "proc-macro-hack", -] - [[package]] name = "paste" version = "1.0.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "acbf547ad0c65e31259204bd90935776d1c693cec2f4ff7abb7a1bbbd40dfe58" -[[package]] -name = "paste-impl" -version = "0.1.18" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d95a7db200b97ef370c8e6de0088252f7e0dfff7d047a28528e47456c0fc98b6" -dependencies = [ - "proc-macro-hack", -] - [[package]] name = "pbkdf2" version = "0.3.0" @@ -6395,7 +6345,6 @@ version = "0.9.9" dependencies = [ "futures 0.3.17", "futures-timer 3.0.2", - "jemalloc-ctl", "metered-channel", "substrate-prometheus-endpoint", ] @@ -6524,6 +6473,7 @@ dependencies = [ "futures-timer 3.0.2", "lru", "metered-channel", + "parity-util-mem", "parking_lot 0.11.1", "polkadot-node-metrics", "polkadot-node-network-protocol", @@ -6821,6 +6771,7 @@ dependencies = [ "sp-session", "sp-staking", "sp-std", + "sp-tracing", "xcm", "xcm-executor", ] @@ -9290,7 +9241,7 @@ dependencies = [ "approx", "num-complex", "num-traits", - "paste 1.0.5", + "paste", ] [[package]] @@ -9314,7 +9265,7 @@ version = "0.9.9" dependencies = [ "enumn", "parity-scale-codec", - "paste 1.0.5", + "paste", "sp-runtime", "sp-std", ] @@ -9821,7 +9772,7 @@ dependencies = [ "log", "parity-scale-codec", "parity-util-mem", - "paste 1.0.5", + "paste", "rand 0.7.3", "scale-info", "serde", @@ -10089,7 +10040,7 @@ dependencies = [ "pallet-staking", "pallet-transaction-payment", "parity-scale-codec", - "paste 1.0.5", + "paste", "polkadot-core-primitives", "polkadot-runtime", "polkadot-runtime-common", @@ -10596,6 +10547,38 @@ dependencies = [ "threadpool", ] +[[package]] +name = "tikv-jemalloc-ctl" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eb833c46ecbf8b6daeccb347cefcabf9c1beb5c9b0f853e1cec45632d9963e69" +dependencies = [ + "libc", + "paste", + "tikv-jemalloc-sys", +] + +[[package]] +name = "tikv-jemalloc-sys" +version = "0.4.2+5.2.1-patched.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5844e429d797c62945a566f8da4e24c7fe3fbd5d6617fd8bf7a0b7dc1ee0f22e" +dependencies = [ + "cc", + "fs_extra", + "libc", +] + +[[package]] +name = "tikv-jemallocator" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c14a5a604eb8715bc5785018a37d00739b180bcf609916ddf4393d33d49ccdf" +dependencies = [ + "libc", + "tikv-jemalloc-sys", +] + [[package]] name = "time" version = "0.1.43" @@ -11307,7 +11290,7 @@ dependencies = [ "lazy_static", "libc", "log", - "paste 1.0.5", + "paste", "psm", "region", "rustc-demangle", @@ -11786,7 +11769,7 @@ version = "0.9.9" dependencies = [ "frame-support", "parity-scale-codec", - "paste 1.0.5", + "paste", "polkadot-core-primitives", "polkadot-parachain", "polkadot-runtime-parachains", diff --git a/runtime/parachains/Cargo.toml b/runtime/parachains/Cargo.toml index 3b75b95619fe..bf5e2c202f77 100644 --- a/runtime/parachains/Cargo.toml +++ b/runtime/parachains/Cargo.toml @@ -48,6 +48,7 @@ hex-literal = "0.3.3" keyring = { package = "sp-keyring", git = "https://github.com/paritytech/substrate", branch = "master" } frame-support-test = { git = "https://github.com/paritytech/substrate", branch = "master" } sc-keystore = { git = "https://github.com/paritytech/substrate", branch = "master" } +sp-tracing = { git = "https://github.com/paritytech/substrate", branch = "master" } [features] diff --git a/runtime/parachains/src/configuration.rs b/runtime/parachains/src/configuration.rs index bcfc05e1a6c5..c61dc5ce4e31 100644 --- a/runtime/parachains/src/configuration.rs +++ b/runtime/parachains/src/configuration.rs @@ -284,6 +284,18 @@ pub mod pallet { pub trait Config: frame_system::Config + shared::Config { /// Weight information for extrinsics in this pallet. type WeightInfo: WeightInfo; + + /// Maximum value that `hrmp_max_parachain_outbound_channels` or + /// `hrmp_max_parathread_outbound_channels` can be set to. + /// + /// This is used for benchmarking sanely bounding relevant storage items. + type HrmpMaxOutboundChannelsBound: Get; + + /// Maximum value that `hrmp_max_parachain_inbound_channels` or + /// `hrmp_max_parathread_inbound_channels` can be set to. + /// + /// This is used for benchmarking sanely bounding relevant storage items. + type HrmpMaxInboundChannelsBound: Get; } #[pallet::error] @@ -515,8 +527,8 @@ pub mod pallet { ) -> DispatchResult { ensure_root(origin)?; Self::update_config_member(|config| { - sp_std::mem::replace(&mut config.dispute_post_conclusion_acceptance_period, new) != - new + sp_std::mem::replace(&mut config.dispute_post_conclusion_acceptance_period, new) + != new }); Ok(()) } @@ -717,6 +729,7 @@ pub mod pallet { new: u32, ) -> DispatchResult { ensure_root(origin)?; + ensure!(new <= T::HrmpMaxInboundChannelsBound::get(), Error::::InvalidNewValue); Self::update_config_member(|config| { sp_std::mem::replace(&mut config.hrmp_max_parachain_inbound_channels, new) != new }); @@ -730,6 +743,7 @@ pub mod pallet { new: u32, ) -> DispatchResult { ensure_root(origin)?; + ensure!(new <= T::HrmpMaxInboundChannelsBound::get(), Error::::InvalidNewValue); Self::update_config_member(|config| { sp_std::mem::replace(&mut config.hrmp_max_parathread_inbound_channels, new) != new }); @@ -753,6 +767,7 @@ pub mod pallet { new: u32, ) -> DispatchResult { ensure_root(origin)?; + ensure!(new <= T::HrmpMaxOutboundChannelsBound::get(), Error::::InvalidNewValue); Self::update_config_member(|config| { sp_std::mem::replace(&mut config.hrmp_max_parachain_outbound_channels, new) != new }); @@ -766,6 +781,7 @@ pub mod pallet { new: u32, ) -> DispatchResult { ensure_root(origin)?; + ensure!(new <= T::HrmpMaxOutboundChannelsBound::get(), Error::::InvalidNewValue); Self::update_config_member(|config| { sp_std::mem::replace(&mut config.hrmp_max_parathread_outbound_channels, new) != new }); diff --git a/runtime/parachains/src/hrmp.rs b/runtime/parachains/src/hrmp.rs index ebad001a4ab7..88f5c5777e27 100644 --- a/runtime/parachains/src/hrmp.rs +++ b/runtime/parachains/src/hrmp.rs @@ -145,7 +145,7 @@ impl fmt::Debug for OutboundHrmpAcceptanceErr { ), NotSorted { idx } => { write!(fmt, "the HRMP messages are not sorted (first unsorted is at index {})", idx,) - }, + } NoSuchChannel { idx, channel_id } => write!( fmt, "the HRMP message at index {} is sent to a non existent channel {:?}->{:?}", @@ -262,6 +262,9 @@ pub mod pallet { pub type HrmpOpenChannelRequests = StorageMap<_, Twox64Concat, HrmpChannelId, HrmpOpenChannelRequest>; + // NOTE: could become bounded, but we don't have a global maximum for this. + // `HrmpMaxOutboundChannelsBound` are per parachain/parathread, while this storage tracks the + // global state. #[pallet::storage] pub type HrmpOpenChannelRequestsList = StorageValue<_, Vec, ValueQuery>; @@ -577,8 +580,8 @@ impl Pallet { Some(req_data) => req_data, None => { // Can't normally happen but no need to panic. - continue - }, + continue; + } }; // Return the deposit of the sender, but only if it is not the para being offboarded. @@ -633,7 +636,7 @@ impl Pallet { fn process_hrmp_open_channel_requests(config: &HostConfiguration) { let mut open_req_channels = ::HrmpOpenChannelRequestsList::get(); if open_req_channels.is_empty() { - return + return; } // iterate the vector starting from the end making our way to the beginning. This way we @@ -642,7 +645,7 @@ impl Pallet { loop { // bail if we've iterated over all items. if idx == 0 { - break + break; } idx -= 1; @@ -652,8 +655,8 @@ impl Pallet { ); if request.confirmed { - if >::is_valid_para(channel_id.sender) && - >::is_valid_para(channel_id.recipient) + if >::is_valid_para(channel_id.sender) + && >::is_valid_para(channel_id.recipient) { ::HrmpChannels::insert( &channel_id, @@ -753,14 +756,14 @@ impl Pallet { return Err(HrmpWatermarkAcceptanceErr::AdvancementRule { new_watermark: new_hrmp_watermark, last_watermark, - }) + }); } } if new_hrmp_watermark > relay_chain_parent_number { return Err(HrmpWatermarkAcceptanceErr::AheadRelayParent { new_watermark: new_hrmp_watermark, relay_chain_parent_number, - }) + }); } // Second, check where the watermark CAN land. It's one of the following: @@ -777,7 +780,7 @@ impl Pallet { { return Err(HrmpWatermarkAcceptanceErr::LandsOnBlockWithNoMessages { new_watermark: new_hrmp_watermark, - }) + }); } Ok(()) } @@ -792,7 +795,7 @@ impl Pallet { return Err(OutboundHrmpAcceptanceErr::MoreMessagesThanPermitted { sent: out_hrmp_msgs.len() as u32, permitted: config.hrmp_max_message_num_per_candidate, - }) + }); } let mut last_recipient = None::; @@ -804,8 +807,9 @@ impl Pallet { // the messages must be sorted in ascending order and there must be no two messages sent // to the same recipient. Thus we can check that every recipient is strictly greater than // the previous one. - Some(last_recipient) if out_msg.recipient <= last_recipient => - return Err(OutboundHrmpAcceptanceErr::NotSorted { idx }), + Some(last_recipient) if out_msg.recipient <= last_recipient => { + return Err(OutboundHrmpAcceptanceErr::NotSorted { idx }) + } _ => last_recipient = Some(out_msg.recipient), } @@ -822,7 +826,7 @@ impl Pallet { idx, msg_size, max_size: channel.max_message_size, - }) + }); } let new_total_size = channel.total_size + out_msg.data.len() as u32; @@ -831,7 +835,7 @@ impl Pallet { idx, total_size: new_total_size, limit: channel.max_total_size, - }) + }); } let new_msg_count = channel.msg_count + 1; @@ -840,7 +844,7 @@ impl Pallet { idx, count: new_msg_count, limit: channel.max_capacity, - }) + }); } } @@ -926,8 +930,8 @@ impl Pallet { None => { // apparently, that since acceptance of this candidate the recipient was // offboarded and the channel no longer exists. - continue - }, + continue; + } }; let inbound = InboundHrmpMessage { sent_at: now, data: out_msg.data }; @@ -1585,13 +1589,13 @@ mod tests { run_to_block(5, Some(vec![4, 5])); Hrmp::hrmp_init_open_channel(para_a_origin.into(), para_b, 2, 8).unwrap(); assert_storage_consistency_exhaustive(); - assert!(System::events().iter().any(|record| record.event == - MockEvent::Hrmp(Event::OpenChannelRequested(para_a, para_b, 2, 8)))); + assert!(System::events().iter().any(|record| record.event + == MockEvent::Hrmp(Event::OpenChannelRequested(para_a, para_b, 2, 8)))); Hrmp::hrmp_accept_open_channel(para_b_origin.into(), para_a).unwrap(); assert_storage_consistency_exhaustive(); - assert!(System::events().iter().any(|record| record.event == - MockEvent::Hrmp(Event::OpenChannelAccepted(para_a, para_b)))); + assert!(System::events().iter().any(|record| record.event + == MockEvent::Hrmp(Event::OpenChannelAccepted(para_a, para_b)))); // Advance to a block 6, but without session change. That means that the channel has // not been created yet. @@ -1633,8 +1637,8 @@ mod tests { run_to_block(8, Some(vec![8])); assert!(!channel_exists(para_a, para_b)); assert_storage_consistency_exhaustive(); - assert!(System::events().iter().any(|record| record.event == - MockEvent::Hrmp(Event::ChannelClosed(para_b, channel_id.clone())))); + assert!(System::events().iter().any(|record| record.event + == MockEvent::Hrmp(Event::ChannelClosed(para_b, channel_id.clone())))); }); } @@ -2094,24 +2098,24 @@ mod benchmarking { message_size )); if matches!(until, ParachainSetupStep::Requested) { - return output + return output; } assert_ok!(Hrmp::::hrmp_accept_open_channel(recipient_origin.into(), sender)); if matches!(until, ParachainSetupStep::Accepted) { - return output + return output; } Hrmp::::process_hrmp_open_channel_requests(&Configuration::::config()); if matches!(until, ParachainSetupStep::Established) { - return output + return output; } let channel_id = HrmpChannelId { sender, recipient }; assert_ok!(Hrmp::::hrmp_close_channel(sender_origin.clone().into(), channel_id)); if matches!(until, ParachainSetupStep::CloseRequested) { // NOTE: this is just for expressiveness, otherwise the if-statement could be omitted. - return output + return output; } output @@ -2156,12 +2160,16 @@ mod benchmarking { } force_clean_hrmp { - // TODO: reasonable constant/config for these. - // TODO: assert that `i` and `e` are well below 10k as prefix that we use. // ingress channels to a single leaving parachain that need to be closed. - let i in 0..128; + let i in 0 .. (::HrmpMaxInboundChannelsBound::get() - 1); // egress channels to a single leaving parachain that need to be closed. - let e in 0..128; + let e in 0 .. (::HrmpMaxOutboundChannelsBound::get() - 1); + + // we use 10_000 in this benchmark as the prefix of accounts. The components must be + //than that to keep accounts sane. + let prefix = 10_000; + assert!(::HrmpMaxInboundChannelsBound::get() < prefix); + assert!(::HrmpMaxOutboundChannelsBound::get() < prefix); // first, update the configs to support this many open channels... assert_ok!(Configuration::::set_hrmp_max_parachain_outbound_channels(frame_system::RawOrigin::Root.into(), e + 1)); @@ -2179,7 +2187,7 @@ mod benchmarking { for ingress_para_id in 0..i { // establish ingress channels to `para`. - let ingress_para_id = ingress_para_id + 10000; + let ingress_para_id = ingress_para_id + prefix; let _ = establish_para_connection::(ingress_para_id, 1, ParachainSetupStep::Established); } @@ -2188,7 +2196,7 @@ mod benchmarking { for egress_para_id in 0..e { // establish egress channels to `para`. - let egress_para_id = egress_para_id + 20000; + let egress_para_id = egress_para_id + prefix * 2; let _ = establish_para_connection::(1, egress_para_id, ParachainSetupStep::Established); } diff --git a/runtime/parachains/src/mock.rs b/runtime/parachains/src/mock.rs index c4da0991de18..4d8c01237190 100644 --- a/runtime/parachains/src/mock.rs +++ b/runtime/parachains/src/mock.rs @@ -22,7 +22,11 @@ use crate::{ ump::{self, MessageId, UmpSink}, ParaId, }; -use frame_support::{parameter_types, traits::GenesisBuild, weights::Weight}; +use frame_support::{ + parameter_types, + traits::{ConstU32, GenesisBuild}, + weights::Weight, +}; use frame_support_test::TestRandomness; use parity_scale_codec::Decode; use primitives::v1::{ @@ -116,6 +120,8 @@ impl crate::initializer::Config for Test { impl crate::configuration::Config for Test { type WeightInfo = crate::configuration::weights::WeightInfo; + type HrmpMaxOutboundChannelsBound = ConstU32<128>; + type HrmpMaxInboundChannelsBound = ConstU32<128>; } impl crate::shared::Config for Test {} @@ -264,7 +270,7 @@ impl UmpSink for TestUmpSink { }; if weight > max_weight { let id = sp_io::hashing::blake2_256(actual_msg); - return Err((id, weight)) + return Err((id, weight)); } PROCESSED.with(|opt_hook| { opt_hook.borrow_mut().push((actual_origin, actual_msg.to_owned())); @@ -296,6 +302,7 @@ impl inclusion::RewardValidators for TestRewardValidators { /// Create a new set of test externalities. pub fn new_test_ext(state: MockGenesisConfig) -> TestExternalities { + sp_tracing::try_init_simple(); BACKING_REWARDS.with(|r| r.borrow_mut().clear()); AVAILABILITY_REWARDS.with(|r| r.borrow_mut().clear()); From 9f0d5251262fbf2e6c36d4afc86700dbb7bb26c1 Mon Sep 17 00:00:00 2001 From: kianenigma Date: Tue, 21 Sep 2021 12:11:22 +0200 Subject: [PATCH 06/36] add configs --- runtime/kusama/src/lib.rs | 2 + runtime/parachains/src/configuration.rs | 4 +- runtime/parachains/src/hrmp.rs | 57 ++++++++++++------------- runtime/parachains/src/mock.rs | 2 +- runtime/rococo/src/lib.rs | 15 ++++--- 5 files changed, 42 insertions(+), 38 deletions(-) diff --git a/runtime/kusama/src/lib.rs b/runtime/kusama/src/lib.rs index b3eb1539c3a1..ca6574c34477 100644 --- a/runtime/kusama/src/lib.rs +++ b/runtime/kusama/src/lib.rs @@ -1134,6 +1134,8 @@ impl parachains_origin::Config for Runtime {} impl parachains_configuration::Config for Runtime { type WeightInfo = weights::runtime_parachains_configuration::WeightInfo; + type HrmpMaxOutboundChannelsBound = ConstU32<128>; + type HrmpMaxInboundChannelsBound = ConstU32<128>; } impl parachains_shared::Config for Runtime {} diff --git a/runtime/parachains/src/configuration.rs b/runtime/parachains/src/configuration.rs index c61dc5ce4e31..2bf83340e24d 100644 --- a/runtime/parachains/src/configuration.rs +++ b/runtime/parachains/src/configuration.rs @@ -527,8 +527,8 @@ pub mod pallet { ) -> DispatchResult { ensure_root(origin)?; Self::update_config_member(|config| { - sp_std::mem::replace(&mut config.dispute_post_conclusion_acceptance_period, new) - != new + sp_std::mem::replace(&mut config.dispute_post_conclusion_acceptance_period, new) != + new }); Ok(()) } diff --git a/runtime/parachains/src/hrmp.rs b/runtime/parachains/src/hrmp.rs index 88f5c5777e27..c2905e02b9d4 100644 --- a/runtime/parachains/src/hrmp.rs +++ b/runtime/parachains/src/hrmp.rs @@ -145,7 +145,7 @@ impl fmt::Debug for OutboundHrmpAcceptanceErr { ), NotSorted { idx } => { write!(fmt, "the HRMP messages are not sorted (first unsorted is at index {})", idx,) - } + }, NoSuchChannel { idx, channel_id } => write!( fmt, "the HRMP message at index {} is sent to a non existent channel {:?}->{:?}", @@ -580,8 +580,8 @@ impl Pallet { Some(req_data) => req_data, None => { // Can't normally happen but no need to panic. - continue; - } + continue + }, }; // Return the deposit of the sender, but only if it is not the para being offboarded. @@ -636,7 +636,7 @@ impl Pallet { fn process_hrmp_open_channel_requests(config: &HostConfiguration) { let mut open_req_channels = ::HrmpOpenChannelRequestsList::get(); if open_req_channels.is_empty() { - return; + return } // iterate the vector starting from the end making our way to the beginning. This way we @@ -645,7 +645,7 @@ impl Pallet { loop { // bail if we've iterated over all items. if idx == 0 { - break; + break } idx -= 1; @@ -655,8 +655,8 @@ impl Pallet { ); if request.confirmed { - if >::is_valid_para(channel_id.sender) - && >::is_valid_para(channel_id.recipient) + if >::is_valid_para(channel_id.sender) && + >::is_valid_para(channel_id.recipient) { ::HrmpChannels::insert( &channel_id, @@ -756,14 +756,14 @@ impl Pallet { return Err(HrmpWatermarkAcceptanceErr::AdvancementRule { new_watermark: new_hrmp_watermark, last_watermark, - }); + }) } } if new_hrmp_watermark > relay_chain_parent_number { return Err(HrmpWatermarkAcceptanceErr::AheadRelayParent { new_watermark: new_hrmp_watermark, relay_chain_parent_number, - }); + }) } // Second, check where the watermark CAN land. It's one of the following: @@ -780,7 +780,7 @@ impl Pallet { { return Err(HrmpWatermarkAcceptanceErr::LandsOnBlockWithNoMessages { new_watermark: new_hrmp_watermark, - }); + }) } Ok(()) } @@ -795,7 +795,7 @@ impl Pallet { return Err(OutboundHrmpAcceptanceErr::MoreMessagesThanPermitted { sent: out_hrmp_msgs.len() as u32, permitted: config.hrmp_max_message_num_per_candidate, - }); + }) } let mut last_recipient = None::; @@ -807,9 +807,8 @@ impl Pallet { // the messages must be sorted in ascending order and there must be no two messages sent // to the same recipient. Thus we can check that every recipient is strictly greater than // the previous one. - Some(last_recipient) if out_msg.recipient <= last_recipient => { - return Err(OutboundHrmpAcceptanceErr::NotSorted { idx }) - } + Some(last_recipient) if out_msg.recipient <= last_recipient => + return Err(OutboundHrmpAcceptanceErr::NotSorted { idx }), _ => last_recipient = Some(out_msg.recipient), } @@ -826,7 +825,7 @@ impl Pallet { idx, msg_size, max_size: channel.max_message_size, - }); + }) } let new_total_size = channel.total_size + out_msg.data.len() as u32; @@ -835,7 +834,7 @@ impl Pallet { idx, total_size: new_total_size, limit: channel.max_total_size, - }); + }) } let new_msg_count = channel.msg_count + 1; @@ -844,7 +843,7 @@ impl Pallet { idx, count: new_msg_count, limit: channel.max_capacity, - }); + }) } } @@ -930,8 +929,8 @@ impl Pallet { None => { // apparently, that since acceptance of this candidate the recipient was // offboarded and the channel no longer exists. - continue; - } + continue + }, }; let inbound = InboundHrmpMessage { sent_at: now, data: out_msg.data }; @@ -1589,13 +1588,13 @@ mod tests { run_to_block(5, Some(vec![4, 5])); Hrmp::hrmp_init_open_channel(para_a_origin.into(), para_b, 2, 8).unwrap(); assert_storage_consistency_exhaustive(); - assert!(System::events().iter().any(|record| record.event - == MockEvent::Hrmp(Event::OpenChannelRequested(para_a, para_b, 2, 8)))); + assert!(System::events().iter().any(|record| record.event == + MockEvent::Hrmp(Event::OpenChannelRequested(para_a, para_b, 2, 8)))); Hrmp::hrmp_accept_open_channel(para_b_origin.into(), para_a).unwrap(); assert_storage_consistency_exhaustive(); - assert!(System::events().iter().any(|record| record.event - == MockEvent::Hrmp(Event::OpenChannelAccepted(para_a, para_b)))); + assert!(System::events().iter().any(|record| record.event == + MockEvent::Hrmp(Event::OpenChannelAccepted(para_a, para_b)))); // Advance to a block 6, but without session change. That means that the channel has // not been created yet. @@ -1637,8 +1636,8 @@ mod tests { run_to_block(8, Some(vec![8])); assert!(!channel_exists(para_a, para_b)); assert_storage_consistency_exhaustive(); - assert!(System::events().iter().any(|record| record.event - == MockEvent::Hrmp(Event::ChannelClosed(para_b, channel_id.clone())))); + assert!(System::events().iter().any(|record| record.event == + MockEvent::Hrmp(Event::ChannelClosed(para_b, channel_id.clone())))); }); } @@ -2098,24 +2097,24 @@ mod benchmarking { message_size )); if matches!(until, ParachainSetupStep::Requested) { - return output; + return output } assert_ok!(Hrmp::::hrmp_accept_open_channel(recipient_origin.into(), sender)); if matches!(until, ParachainSetupStep::Accepted) { - return output; + return output } Hrmp::::process_hrmp_open_channel_requests(&Configuration::::config()); if matches!(until, ParachainSetupStep::Established) { - return output; + return output } let channel_id = HrmpChannelId { sender, recipient }; assert_ok!(Hrmp::::hrmp_close_channel(sender_origin.clone().into(), channel_id)); if matches!(until, ParachainSetupStep::CloseRequested) { // NOTE: this is just for expressiveness, otherwise the if-statement could be omitted. - return output; + return output } output diff --git a/runtime/parachains/src/mock.rs b/runtime/parachains/src/mock.rs index 4d8c01237190..0dc5a4564334 100644 --- a/runtime/parachains/src/mock.rs +++ b/runtime/parachains/src/mock.rs @@ -270,7 +270,7 @@ impl UmpSink for TestUmpSink { }; if weight > max_weight { let id = sp_io::hashing::blake2_256(actual_msg); - return Err((id, weight)); + return Err((id, weight)) } PROCESSED.with(|opt_hook| { opt_hook.borrow_mut().push((actual_origin, actual_msg.to_owned())); diff --git a/runtime/rococo/src/lib.rs b/runtime/rococo/src/lib.rs index b86314c50b9f..c7abf154c66d 100644 --- a/runtime/rococo/src/lib.rs +++ b/runtime/rococo/src/lib.rs @@ -568,6 +568,8 @@ impl parachains_origin::Config for Runtime {} impl parachains_configuration::Config for Runtime { type WeightInfo = parachains_configuration::weights::WeightInfo; + type HrmpMaxOutboundChannelsBound = ConstU32<128>; + type HrmpMaxInboundChannelsBound = ConstU32<128>; } impl parachains_shared::Config for Runtime {} @@ -1069,14 +1071,15 @@ impl InstanceFilter for ProxyType { fn filter(&self, c: &Call) -> bool { match self { ProxyType::Any => true, - ProxyType::CancelProxy => - matches!(c, Call::Proxy(pallet_proxy::Call::reject_announcement { .. })), + ProxyType::CancelProxy => { + matches!(c, Call::Proxy(pallet_proxy::Call::reject_announcement { .. })) + } ProxyType::Auction => matches!( c, - Call::Auctions { .. } | - Call::Crowdloan { .. } | - Call::Registrar { .. } | - Call::Slots { .. } + Call::Auctions { .. } + | Call::Crowdloan { .. } + | Call::Registrar { .. } + | Call::Slots { .. } ), } } From 21b2cf586808f9aa4652d978726711afd4b96c5e Mon Sep 17 00:00:00 2001 From: kianenigma Date: Tue, 21 Sep 2021 12:12:32 +0200 Subject: [PATCH 07/36] Fix rococo --- runtime/rococo/src/lib.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/runtime/rococo/src/lib.rs b/runtime/rococo/src/lib.rs index c7abf154c66d..f7f47c482a99 100644 --- a/runtime/rococo/src/lib.rs +++ b/runtime/rococo/src/lib.rs @@ -568,8 +568,8 @@ impl parachains_origin::Config for Runtime {} impl parachains_configuration::Config for Runtime { type WeightInfo = parachains_configuration::weights::WeightInfo; - type HrmpMaxOutboundChannelsBound = ConstU32<128>; - type HrmpMaxInboundChannelsBound = ConstU32<128>; + type HrmpMaxOutboundChannelsBound = frame_support::traits::ConstU32<128>; + type HrmpMaxInboundChannelsBound = frame_support::traits::ConstU32<128>; } impl parachains_shared::Config for Runtime {} From 40eb5ca5a3a942d457581d4146efb8691c664dd8 Mon Sep 17 00:00:00 2001 From: kianenigma Date: Tue, 21 Sep 2021 12:22:03 +0200 Subject: [PATCH 08/36] Final touches --- runtime/parachains/src/hrmp.rs | 82 +++++++++++++++++---------------- runtime/parachains/src/paras.rs | 50 +++++++++++--------- 2 files changed, 70 insertions(+), 62 deletions(-) diff --git a/runtime/parachains/src/hrmp.rs b/runtime/parachains/src/hrmp.rs index c2905e02b9d4..0ea3db430c7a 100644 --- a/runtime/parachains/src/hrmp.rs +++ b/runtime/parachains/src/hrmp.rs @@ -145,7 +145,7 @@ impl fmt::Debug for OutboundHrmpAcceptanceErr { ), NotSorted { idx } => { write!(fmt, "the HRMP messages are not sorted (first unsorted is at index {})", idx,) - }, + } NoSuchChannel { idx, channel_id } => write!( fmt, "the HRMP message at index {} is sent to a non existent channel {:?}->{:?}", @@ -580,8 +580,8 @@ impl Pallet { Some(req_data) => req_data, None => { // Can't normally happen but no need to panic. - continue - }, + continue; + } }; // Return the deposit of the sender, but only if it is not the para being offboarded. @@ -636,7 +636,7 @@ impl Pallet { fn process_hrmp_open_channel_requests(config: &HostConfiguration) { let mut open_req_channels = ::HrmpOpenChannelRequestsList::get(); if open_req_channels.is_empty() { - return + return; } // iterate the vector starting from the end making our way to the beginning. This way we @@ -645,7 +645,7 @@ impl Pallet { loop { // bail if we've iterated over all items. if idx == 0 { - break + break; } idx -= 1; @@ -655,8 +655,8 @@ impl Pallet { ); if request.confirmed { - if >::is_valid_para(channel_id.sender) && - >::is_valid_para(channel_id.recipient) + if >::is_valid_para(channel_id.sender) + && >::is_valid_para(channel_id.recipient) { ::HrmpChannels::insert( &channel_id, @@ -756,14 +756,14 @@ impl Pallet { return Err(HrmpWatermarkAcceptanceErr::AdvancementRule { new_watermark: new_hrmp_watermark, last_watermark, - }) + }); } } if new_hrmp_watermark > relay_chain_parent_number { return Err(HrmpWatermarkAcceptanceErr::AheadRelayParent { new_watermark: new_hrmp_watermark, relay_chain_parent_number, - }) + }); } // Second, check where the watermark CAN land. It's one of the following: @@ -780,7 +780,7 @@ impl Pallet { { return Err(HrmpWatermarkAcceptanceErr::LandsOnBlockWithNoMessages { new_watermark: new_hrmp_watermark, - }) + }); } Ok(()) } @@ -795,7 +795,7 @@ impl Pallet { return Err(OutboundHrmpAcceptanceErr::MoreMessagesThanPermitted { sent: out_hrmp_msgs.len() as u32, permitted: config.hrmp_max_message_num_per_candidate, - }) + }); } let mut last_recipient = None::; @@ -807,8 +807,9 @@ impl Pallet { // the messages must be sorted in ascending order and there must be no two messages sent // to the same recipient. Thus we can check that every recipient is strictly greater than // the previous one. - Some(last_recipient) if out_msg.recipient <= last_recipient => - return Err(OutboundHrmpAcceptanceErr::NotSorted { idx }), + Some(last_recipient) if out_msg.recipient <= last_recipient => { + return Err(OutboundHrmpAcceptanceErr::NotSorted { idx }) + } _ => last_recipient = Some(out_msg.recipient), } @@ -825,7 +826,7 @@ impl Pallet { idx, msg_size, max_size: channel.max_message_size, - }) + }); } let new_total_size = channel.total_size + out_msg.data.len() as u32; @@ -834,7 +835,7 @@ impl Pallet { idx, total_size: new_total_size, limit: channel.max_total_size, - }) + }); } let new_msg_count = channel.msg_count + 1; @@ -843,7 +844,7 @@ impl Pallet { idx, count: new_msg_count, limit: channel.max_capacity, - }) + }); } } @@ -929,8 +930,8 @@ impl Pallet { None => { // apparently, that since acceptance of this candidate the recipient was // offboarded and the channel no longer exists. - continue - }, + continue; + } }; let inbound = InboundHrmpMessage { sent_at: now, data: out_msg.data }; @@ -1588,13 +1589,13 @@ mod tests { run_to_block(5, Some(vec![4, 5])); Hrmp::hrmp_init_open_channel(para_a_origin.into(), para_b, 2, 8).unwrap(); assert_storage_consistency_exhaustive(); - assert!(System::events().iter().any(|record| record.event == - MockEvent::Hrmp(Event::OpenChannelRequested(para_a, para_b, 2, 8)))); + assert!(System::events().iter().any(|record| record.event + == MockEvent::Hrmp(Event::OpenChannelRequested(para_a, para_b, 2, 8)))); Hrmp::hrmp_accept_open_channel(para_b_origin.into(), para_a).unwrap(); assert_storage_consistency_exhaustive(); - assert!(System::events().iter().any(|record| record.event == - MockEvent::Hrmp(Event::OpenChannelAccepted(para_a, para_b)))); + assert!(System::events().iter().any(|record| record.event + == MockEvent::Hrmp(Event::OpenChannelAccepted(para_a, para_b)))); // Advance to a block 6, but without session change. That means that the channel has // not been created yet. @@ -1636,8 +1637,8 @@ mod tests { run_to_block(8, Some(vec![8])); assert!(!channel_exists(para_a, para_b)); assert_storage_consistency_exhaustive(); - assert!(System::events().iter().any(|record| record.event == - MockEvent::Hrmp(Event::ChannelClosed(para_b, channel_id.clone())))); + assert!(System::events().iter().any(|record| record.event + == MockEvent::Hrmp(Event::ChannelClosed(para_b, channel_id.clone())))); }); } @@ -2097,29 +2098,33 @@ mod benchmarking { message_size )); if matches!(until, ParachainSetupStep::Requested) { - return output + return output; } assert_ok!(Hrmp::::hrmp_accept_open_channel(recipient_origin.into(), sender)); if matches!(until, ParachainSetupStep::Accepted) { - return output + return output; } Hrmp::::process_hrmp_open_channel_requests(&Configuration::::config()); if matches!(until, ParachainSetupStep::Established) { - return output + return output; } let channel_id = HrmpChannelId { sender, recipient }; assert_ok!(Hrmp::::hrmp_close_channel(sender_origin.clone().into(), channel_id)); if matches!(until, ParachainSetupStep::CloseRequested) { // NOTE: this is just for expressiveness, otherwise the if-statement could be omitted. - return output + return output; } output } + const PREFIX_0: u32 = 10_000; + const PREFIX_1: u32 = PREFIX_0 * 2; + const MAX_UNIQUE_CHANNELS: u32 = 128; + frame_benchmarking::benchmarks! { where_clause { where ::Origin: From } @@ -2166,9 +2171,8 @@ mod benchmarking { // we use 10_000 in this benchmark as the prefix of accounts. The components must be //than that to keep accounts sane. - let prefix = 10_000; - assert!(::HrmpMaxInboundChannelsBound::get() < prefix); - assert!(::HrmpMaxOutboundChannelsBound::get() < prefix); + assert!(::HrmpMaxInboundChannelsBound::get() < PREFIX_0); + assert!(::HrmpMaxOutboundChannelsBound::get() < PREFIX_0); // first, update the configs to support this many open channels... assert_ok!(Configuration::::set_hrmp_max_parachain_outbound_channels(frame_system::RawOrigin::Root.into(), e + 1)); @@ -2186,7 +2190,7 @@ mod benchmarking { for ingress_para_id in 0..i { // establish ingress channels to `para`. - let ingress_para_id = ingress_para_id + prefix; + let ingress_para_id = ingress_para_id + PREFIX_0; let _ = establish_para_connection::(ingress_para_id, 1, ParachainSetupStep::Established); } @@ -2195,7 +2199,7 @@ mod benchmarking { for egress_para_id in 0..e { // establish egress channels to `para`. - let egress_para_id = egress_para_id + prefix * 2; + let egress_para_id = egress_para_id + PREFIX_1; let _ = establish_para_connection::(1, egress_para_id, ParachainSetupStep::Established); } @@ -2212,10 +2216,10 @@ mod benchmarking { force_process_hrmp_open { // number of channels that need to be processed. Worse case is an N-M relation: unique // sender and recipients for all channels. - let c in 0 .. 128; + let c in 0 .. MAX_UNIQUE_CHANNELS; for id in 0 .. c { - let _ = establish_para_connection::(10_000 + id, 20_000 + id, ParachainSetupStep::Accepted); + let _ = establish_para_connection::(PREFIX_0 + id, PREFIX_1 + id, ParachainSetupStep::Accepted); } assert_eq!(HrmpOpenChannelRequestsList::::decode_len().unwrap_or_default() as u32, c); }: _(frame_system::Origin::::Root) @@ -2226,10 +2230,10 @@ mod benchmarking { force_process_hrmp_close { // number of channels that need to be processed. Worse case is an N-M relation: unique // sender and recipients for all channels. - let c in 0 .. 128; + let c in 0 .. MAX_UNIQUE_CHANNELS; for id in 0 .. c { - let _ = establish_para_connection::(10_000 + id, 20_000 + id, ParachainSetupStep::CloseRequested); + let _ = establish_para_connection::(PREFIX_0 + id, PREFIX_1 + id, ParachainSetupStep::CloseRequested); } assert_eq!(HrmpCloseChannelRequestsList::::decode_len().unwrap_or_default() as u32, c); @@ -2241,10 +2245,10 @@ mod benchmarking { hrmp_cancel_open_request { // number of items already existing in the `HrmpOpenChannelRequestsList`, other than the // one that we remove. - let c in 0 .. 128; + let c in 0 .. MAX_UNIQUE_CHANNELS; for id in 0 .. c { - let _ = establish_para_connection::(10_000 + id, 20_000 + id, ParachainSetupStep::Requested); + let _ = establish_para_connection::(PREFIX_0 + id, PREFIX_1 + id, ParachainSetupStep::Requested); } let [(sender, sender_origin), (recipient, _)] = establish_para_connection::(1, 2, ParachainSetupStep::Requested); diff --git a/runtime/parachains/src/paras.rs b/runtime/parachains/src/paras.rs index fce5b139219e..ee359a183918 100644 --- a/runtime/parachains/src/paras.rs +++ b/runtime/parachains/src/paras.rs @@ -126,9 +126,9 @@ impl ParaLifecycle { pub fn is_parachain(&self) -> bool { matches!( self, - ParaLifecycle::Parachain | - ParaLifecycle::DowngradingParachain | - ParaLifecycle::OffboardingParachain + ParaLifecycle::Parachain + | ParaLifecycle::DowngradingParachain + | ParaLifecycle::OffboardingParachain ) } @@ -138,9 +138,9 @@ impl ParaLifecycle { pub fn is_parathread(&self) -> bool { matches!( self, - ParaLifecycle::Parathread | - ParaLifecycle::UpgradingParathread | - ParaLifecycle::OffboardingParathread + ParaLifecycle::Parathread + | ParaLifecycle::UpgradingParathread + | ParaLifecycle::OffboardingParathread ) } @@ -621,7 +621,7 @@ impl Pallet { let lifecycle = ParaLifecycles::::get(¶); match lifecycle { None | Some(ParaLifecycle::Parathread) | Some(ParaLifecycle::Parachain) => { /* Nothing to do... */ - }, + } // Onboard a new parathread or parachain. Some(ParaLifecycle::Onboarding) => { if let Some(genesis_data) = ::UpcomingParasGenesis::take(¶) { @@ -639,24 +639,24 @@ impl Pallet { Self::increase_code_ref(&code_hash, &genesis_data.validation_code); ::CurrentCodeHash::insert(¶, code_hash); } - }, + } // Upgrade a parathread to a parachain Some(ParaLifecycle::UpgradingParathread) => { if let Err(i) = parachains.binary_search(¶) { parachains.insert(i, para); } ParaLifecycles::::insert(¶, ParaLifecycle::Parachain); - }, + } // Downgrade a parachain to a parathread Some(ParaLifecycle::DowngradingParachain) => { if let Ok(i) = parachains.binary_search(¶) { parachains.remove(i); } ParaLifecycles::::insert(¶, ParaLifecycle::Parathread); - }, + } // Offboard a parathread or parachain from the system - Some(ParaLifecycle::OffboardingParachain) | - Some(ParaLifecycle::OffboardingParathread) => { + Some(ParaLifecycle::OffboardingParachain) + | Some(ParaLifecycle::OffboardingParathread) => { if let Ok(i) = parachains.binary_search(¶) { parachains.remove(i); } @@ -677,7 +677,7 @@ impl Pallet { } outgoing.push(para); - }, + } } } @@ -705,7 +705,7 @@ impl Pallet { // Place the new parachains set in storage. ::Parachains::set(parachains); - return outgoing + return outgoing; } // note replacement of the code of para with given `id`, which occured in the @@ -744,7 +744,7 @@ impl Pallet { let code_retention_period = config.code_retention_period; if now <= code_retention_period { let weight = T::DbWeight::get().reads_writes(1, 0); - return weight + return weight; } // The height of any changes we no longer should keep around. @@ -856,10 +856,13 @@ impl Pallet { let _ = Self::schedule_para_initialize(id, genesis)?; // .. and immediately apply them. - let _ = Self::apply_actions_queue(Self::scheduled_session()); + Self::apply_actions_queue(Self::scheduled_session()); // ensure it has become a para. - assert_eq!(ParaLifecycles::::get(id), Some(ParaLifecycle::Parachain)); + ensure!( + ParaLifecycles::::get(id) == Some(ParaLifecycle::Parachain), + "Parachain not created properly" + ); Ok(()) } @@ -875,10 +878,10 @@ impl Pallet { None => return Ok(()), Some(ParaLifecycle::Parathread) => { ParaLifecycles::::insert(&id, ParaLifecycle::OffboardingParathread); - }, + } Some(ParaLifecycle::Parachain) => { ParaLifecycles::::insert(&id, ParaLifecycle::OffboardingParachain); - }, + } _ => return Err(Error::::CannotOffboard)?, } @@ -1035,7 +1038,7 @@ impl Pallet { assume_intermediate: Option, ) -> Option { if assume_intermediate.as_ref().map_or(false, |i| &at <= i) { - return None + return None; } let planned_upgrade = ::FutureCodeUpgrades::get(&id); @@ -1050,8 +1053,9 @@ impl Pallet { match Self::past_code_meta(&id).code_at(at) { None => None, Some(UseCodeAt::Current) => CurrentCodeHash::::get(&id), - Some(UseCodeAt::ReplacedAt(replaced)) => - ::PastCodeHash::get(&(id, replaced)), + Some(UseCodeAt::ReplacedAt(replaced)) => { + ::PastCodeHash::get(&(id, replaced)) + } } } } @@ -1099,7 +1103,7 @@ impl Pallet { pub(crate) fn last_code_upgrade(id: ParaId, include_future: bool) -> Option { if include_future { if let Some(at) = Self::future_code_upgrade_at(id) { - return Some(at) + return Some(at); } } From a6a1af2211e965e9f4d708140acb746283294a0c Mon Sep 17 00:00:00 2001 From: kianenigma Date: Tue, 21 Sep 2021 14:31:26 +0200 Subject: [PATCH 09/36] revert fmt changes, one last time --- runtime/parachains/src/hrmp.rs | 57 ++++++++++++++++----------------- runtime/parachains/src/mock.rs | 1 + runtime/parachains/src/paras.rs | 43 ++++++++++++------------- runtime/rococo/src/lib.rs | 10 +++--- 4 files changed, 55 insertions(+), 56 deletions(-) diff --git a/runtime/parachains/src/hrmp.rs b/runtime/parachains/src/hrmp.rs index 0ea3db430c7a..a81b52c0363d 100644 --- a/runtime/parachains/src/hrmp.rs +++ b/runtime/parachains/src/hrmp.rs @@ -145,7 +145,7 @@ impl fmt::Debug for OutboundHrmpAcceptanceErr { ), NotSorted { idx } => { write!(fmt, "the HRMP messages are not sorted (first unsorted is at index {})", idx,) - } + }, NoSuchChannel { idx, channel_id } => write!( fmt, "the HRMP message at index {} is sent to a non existent channel {:?}->{:?}", @@ -580,8 +580,8 @@ impl Pallet { Some(req_data) => req_data, None => { // Can't normally happen but no need to panic. - continue; - } + continue + }, }; // Return the deposit of the sender, but only if it is not the para being offboarded. @@ -636,7 +636,7 @@ impl Pallet { fn process_hrmp_open_channel_requests(config: &HostConfiguration) { let mut open_req_channels = ::HrmpOpenChannelRequestsList::get(); if open_req_channels.is_empty() { - return; + return } // iterate the vector starting from the end making our way to the beginning. This way we @@ -645,7 +645,7 @@ impl Pallet { loop { // bail if we've iterated over all items. if idx == 0 { - break; + break } idx -= 1; @@ -655,8 +655,8 @@ impl Pallet { ); if request.confirmed { - if >::is_valid_para(channel_id.sender) - && >::is_valid_para(channel_id.recipient) + if >::is_valid_para(channel_id.sender) && + >::is_valid_para(channel_id.recipient) { ::HrmpChannels::insert( &channel_id, @@ -756,14 +756,14 @@ impl Pallet { return Err(HrmpWatermarkAcceptanceErr::AdvancementRule { new_watermark: new_hrmp_watermark, last_watermark, - }); + }) } } if new_hrmp_watermark > relay_chain_parent_number { return Err(HrmpWatermarkAcceptanceErr::AheadRelayParent { new_watermark: new_hrmp_watermark, relay_chain_parent_number, - }); + }) } // Second, check where the watermark CAN land. It's one of the following: @@ -780,7 +780,7 @@ impl Pallet { { return Err(HrmpWatermarkAcceptanceErr::LandsOnBlockWithNoMessages { new_watermark: new_hrmp_watermark, - }); + }) } Ok(()) } @@ -795,7 +795,7 @@ impl Pallet { return Err(OutboundHrmpAcceptanceErr::MoreMessagesThanPermitted { sent: out_hrmp_msgs.len() as u32, permitted: config.hrmp_max_message_num_per_candidate, - }); + }) } let mut last_recipient = None::; @@ -807,9 +807,8 @@ impl Pallet { // the messages must be sorted in ascending order and there must be no two messages sent // to the same recipient. Thus we can check that every recipient is strictly greater than // the previous one. - Some(last_recipient) if out_msg.recipient <= last_recipient => { - return Err(OutboundHrmpAcceptanceErr::NotSorted { idx }) - } + Some(last_recipient) if out_msg.recipient <= last_recipient => + return Err(OutboundHrmpAcceptanceErr::NotSorted { idx }), _ => last_recipient = Some(out_msg.recipient), } @@ -826,7 +825,7 @@ impl Pallet { idx, msg_size, max_size: channel.max_message_size, - }); + }) } let new_total_size = channel.total_size + out_msg.data.len() as u32; @@ -835,7 +834,7 @@ impl Pallet { idx, total_size: new_total_size, limit: channel.max_total_size, - }); + }) } let new_msg_count = channel.msg_count + 1; @@ -844,7 +843,7 @@ impl Pallet { idx, count: new_msg_count, limit: channel.max_capacity, - }); + }) } } @@ -930,8 +929,8 @@ impl Pallet { None => { // apparently, that since acceptance of this candidate the recipient was // offboarded and the channel no longer exists. - continue; - } + continue + }, }; let inbound = InboundHrmpMessage { sent_at: now, data: out_msg.data }; @@ -1589,13 +1588,13 @@ mod tests { run_to_block(5, Some(vec![4, 5])); Hrmp::hrmp_init_open_channel(para_a_origin.into(), para_b, 2, 8).unwrap(); assert_storage_consistency_exhaustive(); - assert!(System::events().iter().any(|record| record.event - == MockEvent::Hrmp(Event::OpenChannelRequested(para_a, para_b, 2, 8)))); + assert!(System::events().iter().any(|record| record.event == + MockEvent::Hrmp(Event::OpenChannelRequested(para_a, para_b, 2, 8)))); Hrmp::hrmp_accept_open_channel(para_b_origin.into(), para_a).unwrap(); assert_storage_consistency_exhaustive(); - assert!(System::events().iter().any(|record| record.event - == MockEvent::Hrmp(Event::OpenChannelAccepted(para_a, para_b)))); + assert!(System::events().iter().any(|record| record.event == + MockEvent::Hrmp(Event::OpenChannelAccepted(para_a, para_b)))); // Advance to a block 6, but without session change. That means that the channel has // not been created yet. @@ -1637,8 +1636,8 @@ mod tests { run_to_block(8, Some(vec![8])); assert!(!channel_exists(para_a, para_b)); assert_storage_consistency_exhaustive(); - assert!(System::events().iter().any(|record| record.event - == MockEvent::Hrmp(Event::ChannelClosed(para_b, channel_id.clone())))); + assert!(System::events().iter().any(|record| record.event == + MockEvent::Hrmp(Event::ChannelClosed(para_b, channel_id.clone())))); }); } @@ -2098,24 +2097,24 @@ mod benchmarking { message_size )); if matches!(until, ParachainSetupStep::Requested) { - return output; + return output } assert_ok!(Hrmp::::hrmp_accept_open_channel(recipient_origin.into(), sender)); if matches!(until, ParachainSetupStep::Accepted) { - return output; + return output } Hrmp::::process_hrmp_open_channel_requests(&Configuration::::config()); if matches!(until, ParachainSetupStep::Established) { - return output; + return output } let channel_id = HrmpChannelId { sender, recipient }; assert_ok!(Hrmp::::hrmp_close_channel(sender_origin.clone().into(), channel_id)); if matches!(until, ParachainSetupStep::CloseRequested) { // NOTE: this is just for expressiveness, otherwise the if-statement could be omitted. - return output; + return output } output diff --git a/runtime/parachains/src/mock.rs b/runtime/parachains/src/mock.rs index 0dc5a4564334..5c68d9a3ad93 100644 --- a/runtime/parachains/src/mock.rs +++ b/runtime/parachains/src/mock.rs @@ -272,6 +272,7 @@ impl UmpSink for TestUmpSink { let id = sp_io::hashing::blake2_256(actual_msg); return Err((id, weight)) } + PROCESSED.with(|opt_hook| { opt_hook.borrow_mut().push((actual_origin, actual_msg.to_owned())); }); diff --git a/runtime/parachains/src/paras.rs b/runtime/parachains/src/paras.rs index ee359a183918..c7394e981311 100644 --- a/runtime/parachains/src/paras.rs +++ b/runtime/parachains/src/paras.rs @@ -126,9 +126,9 @@ impl ParaLifecycle { pub fn is_parachain(&self) -> bool { matches!( self, - ParaLifecycle::Parachain - | ParaLifecycle::DowngradingParachain - | ParaLifecycle::OffboardingParachain + ParaLifecycle::Parachain | + ParaLifecycle::DowngradingParachain | + ParaLifecycle::OffboardingParachain ) } @@ -138,9 +138,9 @@ impl ParaLifecycle { pub fn is_parathread(&self) -> bool { matches!( self, - ParaLifecycle::Parathread - | ParaLifecycle::UpgradingParathread - | ParaLifecycle::OffboardingParathread + ParaLifecycle::Parathread | + ParaLifecycle::UpgradingParathread | + ParaLifecycle::OffboardingParathread ) } @@ -621,7 +621,7 @@ impl Pallet { let lifecycle = ParaLifecycles::::get(¶); match lifecycle { None | Some(ParaLifecycle::Parathread) | Some(ParaLifecycle::Parachain) => { /* Nothing to do... */ - } + }, // Onboard a new parathread or parachain. Some(ParaLifecycle::Onboarding) => { if let Some(genesis_data) = ::UpcomingParasGenesis::take(¶) { @@ -639,24 +639,24 @@ impl Pallet { Self::increase_code_ref(&code_hash, &genesis_data.validation_code); ::CurrentCodeHash::insert(¶, code_hash); } - } + }, // Upgrade a parathread to a parachain Some(ParaLifecycle::UpgradingParathread) => { if let Err(i) = parachains.binary_search(¶) { parachains.insert(i, para); } ParaLifecycles::::insert(¶, ParaLifecycle::Parachain); - } + }, // Downgrade a parachain to a parathread Some(ParaLifecycle::DowngradingParachain) => { if let Ok(i) = parachains.binary_search(¶) { parachains.remove(i); } ParaLifecycles::::insert(¶, ParaLifecycle::Parathread); - } + }, // Offboard a parathread or parachain from the system - Some(ParaLifecycle::OffboardingParachain) - | Some(ParaLifecycle::OffboardingParathread) => { + Some(ParaLifecycle::OffboardingParachain) | + Some(ParaLifecycle::OffboardingParathread) => { if let Ok(i) = parachains.binary_search(¶) { parachains.remove(i); } @@ -677,7 +677,7 @@ impl Pallet { } outgoing.push(para); - } + }, } } @@ -705,7 +705,7 @@ impl Pallet { // Place the new parachains set in storage. ::Parachains::set(parachains); - return outgoing; + return outgoing } // note replacement of the code of para with given `id`, which occured in the @@ -744,7 +744,7 @@ impl Pallet { let code_retention_period = config.code_retention_period; if now <= code_retention_period { let weight = T::DbWeight::get().reads_writes(1, 0); - return weight; + return weight } // The height of any changes we no longer should keep around. @@ -878,10 +878,10 @@ impl Pallet { None => return Ok(()), Some(ParaLifecycle::Parathread) => { ParaLifecycles::::insert(&id, ParaLifecycle::OffboardingParathread); - } + }, Some(ParaLifecycle::Parachain) => { ParaLifecycles::::insert(&id, ParaLifecycle::OffboardingParachain); - } + }, _ => return Err(Error::::CannotOffboard)?, } @@ -1038,7 +1038,7 @@ impl Pallet { assume_intermediate: Option, ) -> Option { if assume_intermediate.as_ref().map_or(false, |i| &at <= i) { - return None; + return None } let planned_upgrade = ::FutureCodeUpgrades::get(&id); @@ -1053,9 +1053,8 @@ impl Pallet { match Self::past_code_meta(&id).code_at(at) { None => None, Some(UseCodeAt::Current) => CurrentCodeHash::::get(&id), - Some(UseCodeAt::ReplacedAt(replaced)) => { - ::PastCodeHash::get(&(id, replaced)) - } + Some(UseCodeAt::ReplacedAt(replaced)) => + ::PastCodeHash::get(&(id, replaced)), } } } @@ -1103,7 +1102,7 @@ impl Pallet { pub(crate) fn last_code_upgrade(id: ParaId, include_future: bool) -> Option { if include_future { if let Some(at) = Self::future_code_upgrade_at(id) { - return Some(at); + return Some(at) } } diff --git a/runtime/rococo/src/lib.rs b/runtime/rococo/src/lib.rs index f7f47c482a99..d3be7a0dd214 100644 --- a/runtime/rococo/src/lib.rs +++ b/runtime/rococo/src/lib.rs @@ -1073,13 +1073,13 @@ impl InstanceFilter for ProxyType { ProxyType::Any => true, ProxyType::CancelProxy => { matches!(c, Call::Proxy(pallet_proxy::Call::reject_announcement { .. })) - } + }, ProxyType::Auction => matches!( c, - Call::Auctions { .. } - | Call::Crowdloan { .. } - | Call::Registrar { .. } - | Call::Slots { .. } + Call::Auctions { .. } | + Call::Crowdloan { .. } | + Call::Registrar { .. } | + Call::Slots { .. } ), } } From 948c03d113fb58daee0d85fe24b7712f99f35bc5 Mon Sep 17 00:00:00 2001 From: kianenigma Date: Tue, 21 Sep 2021 15:01:14 +0200 Subject: [PATCH 10/36] Fix wrappings --- runtime/parachains/src/hrmp.rs | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/runtime/parachains/src/hrmp.rs b/runtime/parachains/src/hrmp.rs index a81b52c0363d..876c35b98d80 100644 --- a/runtime/parachains/src/hrmp.rs +++ b/runtime/parachains/src/hrmp.rs @@ -270,8 +270,8 @@ pub mod pallet { StorageValue<_, Vec, ValueQuery>; /// This mapping tracks how many open channel requests are initiated by a given sender para. - /// Invariant: `HrmpOpenChannelRequests` should contain the same number of items that has `(X, - /// _)` as the number of `HrmpOpenChannelRequestCount` for `X`. + /// Invariant: `HrmpOpenChannelRequests` should contain the same number of items that has + /// `(X, _)` as the number of `HrmpOpenChannelRequestCount` for `X`. #[pallet::storage] pub type HrmpOpenChannelRequestCount = StorageMap<_, Twox64Concat, ParaId, u32, ValueQuery>; @@ -312,8 +312,8 @@ pub mod pallet { /// Ingress/egress indexes allow to find all the senders and receivers given the opposite side. /// I.e. /// - /// (a) ingress index allows to find all the senders for a given recipient. (b) egress index - /// allows to find all the recipients for a given sender. + /// (a) ingress index allows to find all the senders for a given recipient. + /// (b) egress index allows to find all the recipients for a given sender. /// /// Invariants: /// - for each ingress index entry for `P` each item `I` in the index should present in @@ -355,10 +355,11 @@ pub mod pallet { /// Preopen the given HRMP channels. /// - /// The values in the tuple corresponds to `(sender, recipient, max_capacity, - /// max_message_size)`, i.e. similar to `init_open_channel`. In fact, the initialization is - /// performed as if the `init_open_channel` and `accept_open_channel` were called with the - /// respective parameters and the session change take place. + /// The values in the tuple corresponds to + /// `(sender, recipient, max_capacity, max_message_size)`, i.e. similar to `init_open_channel`. + /// In fact, the initialization is performed as if the `init_open_channel` and + /// `accept_open_channel` were called with the respective parameters and the session change take + /// place. /// /// As such, each channel initializer should satisfy the same constraints, namely: /// @@ -985,8 +986,8 @@ impl Pallet { /// Initiate opening a channel from a parachain to a given recipient with given channel /// parameters. /// - /// Basically the same as [`hrmp_init_open_channel`](Pallet::hrmp_init_open_channel) but intendend for calling directly from - /// other pallets rather than dispatched. + /// Basically the same as [`hrmp_init_open_channel`](Pallet::hrmp_init_open_channel) but + /// intended for calling directly from other pallets rather than dispatched. pub fn init_open_channel( origin: ParaId, recipient: ParaId, @@ -2148,7 +2149,7 @@ mod benchmarking { } hrmp_accept_open_channel { - let [(sender, _), (recipient, recipient_origin)] =establish_para_connection::(1, 2, ParachainSetupStep::Requested); + let [(sender, _), (recipient, recipient_origin)] = establish_para_connection::(1, 2, ParachainSetupStep::Requested); }: _(recipient_origin, sender) verify { assert_last_event::(Event::::OpenChannelAccepted(sender, recipient).into()); @@ -2169,7 +2170,7 @@ mod benchmarking { let e in 0 .. (::HrmpMaxOutboundChannelsBound::get() - 1); // we use 10_000 in this benchmark as the prefix of accounts. The components must be - //than that to keep accounts sane. + // than that to keep accounts sane. assert!(::HrmpMaxInboundChannelsBound::get() < PREFIX_0); assert!(::HrmpMaxOutboundChannelsBound::get() < PREFIX_0); From d253c7b0580c3bd702b35503e6f7b13dbf54efe2 Mon Sep 17 00:00:00 2001 From: kianenigma Date: Tue, 21 Sep 2021 16:24:54 +0200 Subject: [PATCH 11/36] Fix a bunch of tests --- runtime/common/src/integration_tests.rs | 2 ++ runtime/common/src/paras_registrar.rs | 2 ++ runtime/kusama/src/lib.rs | 4 ++-- runtime/parachains/src/configuration.rs | 8 ++++---- runtime/test-runtime/src/lib.rs | 2 ++ runtime/westend/src/lib.rs | 2 ++ xcm/xcm-builder/tests/mock/mod.rs | 2 ++ xcm/xcm-simulator/example/src/relay_chain.rs | 2 ++ 8 files changed, 18 insertions(+), 6 deletions(-) diff --git a/runtime/common/src/integration_tests.rs b/runtime/common/src/integration_tests.rs index c0e1615599e7..1f957d61e9ad 100644 --- a/runtime/common/src/integration_tests.rs +++ b/runtime/common/src/integration_tests.rs @@ -158,6 +158,8 @@ impl pallet_balances::Config for Test { impl configuration::Config for Test { type WeightInfo = configuration::weights::WeightInfo; + type HrmpMaxOutboundChannelsBound = frame_support::traits::ConstU32<128>; + type HrmpMaxInboundChannelsBound = frame_support::traits::ConstU32<128>; } impl shared::Config for Test {} diff --git a/runtime/common/src/paras_registrar.rs b/runtime/common/src/paras_registrar.rs index ee595cd0df05..59081d01522d 100644 --- a/runtime/common/src/paras_registrar.rs +++ b/runtime/common/src/paras_registrar.rs @@ -661,6 +661,8 @@ mod tests { impl configuration::Config for Test { type WeightInfo = configuration::weights::WeightInfo; + type HrmpMaxOutboundChannelsBound = frame_support::traits::ConstU32<128>; + type HrmpMaxInboundChannelsBound = frame_support::traits::ConstU32<128>; } parameter_types! { diff --git a/runtime/kusama/src/lib.rs b/runtime/kusama/src/lib.rs index f6ccf4d54ec1..afae2fa9eb5a 100644 --- a/runtime/kusama/src/lib.rs +++ b/runtime/kusama/src/lib.rs @@ -1134,8 +1134,8 @@ impl parachains_origin::Config for Runtime {} impl parachains_configuration::Config for Runtime { type WeightInfo = weights::runtime_parachains_configuration::WeightInfo; - type HrmpMaxOutboundChannelsBound = ConstU32<128>; - type HrmpMaxInboundChannelsBound = ConstU32<128>; + type HrmpMaxOutboundChannelsBound = frame_support::traits::ConstU32<128>; + type HrmpMaxInboundChannelsBound = frame_support::traits::ConstU32<128>; } impl parachains_shared::Config for Runtime {} diff --git a/runtime/parachains/src/configuration.rs b/runtime/parachains/src/configuration.rs index 2bf83340e24d..6a9d2dfa01a4 100644 --- a/runtime/parachains/src/configuration.rs +++ b/runtime/parachains/src/configuration.rs @@ -942,11 +942,11 @@ mod tests { hrmp_recipient_deposit: 4905, hrmp_channel_max_capacity: 3921, hrmp_channel_max_total_size: 7687, - hrmp_max_parachain_inbound_channels: 3722, - hrmp_max_parathread_inbound_channels: 1967, + hrmp_max_parachain_inbound_channels: 37, + hrmp_max_parathread_inbound_channels: 19, hrmp_channel_max_message_size: 8192, - hrmp_max_parachain_outbound_channels: 100, - hrmp_max_parathread_outbound_channels: 200, + hrmp_max_parachain_outbound_channels: 10, + hrmp_max_parathread_outbound_channels: 20, hrmp_max_message_num_per_candidate: 20, ump_max_individual_weight: 909, }; diff --git a/runtime/test-runtime/src/lib.rs b/runtime/test-runtime/src/lib.rs index 58ccea45c249..a2717c257b33 100644 --- a/runtime/test-runtime/src/lib.rs +++ b/runtime/test-runtime/src/lib.rs @@ -456,6 +456,8 @@ impl pallet_sudo::Config for Runtime { impl parachains_configuration::Config for Runtime { type WeightInfo = parachains_configuration::weights::WeightInfo; + type HrmpMaxOutboundChannelsBound = frame_support::traits::ConstU32<128>; + type HrmpMaxInboundChannelsBound = frame_support::traits::ConstU32<128>; } impl parachains_shared::Config for Runtime {} diff --git a/runtime/westend/src/lib.rs b/runtime/westend/src/lib.rs index 3ce1ef1defc0..492fb343de42 100644 --- a/runtime/westend/src/lib.rs +++ b/runtime/westend/src/lib.rs @@ -803,6 +803,8 @@ impl parachains_origin::Config for Runtime {} impl parachains_configuration::Config for Runtime { type WeightInfo = parachains_configuration::weights::WeightInfo; + type HrmpMaxOutboundChannelsBound = frame_support::traits::ConstU32<128>; + type HrmpMaxInboundChannelsBound = frame_support::traits::ConstU32<128>; } impl parachains_shared::Config for Runtime {} diff --git a/xcm/xcm-builder/tests/mock/mod.rs b/xcm/xcm-builder/tests/mock/mod.rs index bcdac942a30a..6bb5795002bc 100644 --- a/xcm/xcm-builder/tests/mock/mod.rs +++ b/xcm/xcm-builder/tests/mock/mod.rs @@ -109,6 +109,8 @@ impl shared::Config for Runtime {} impl configuration::Config for Runtime { type WeightInfo = configuration::weights::WeightInfo; + type HrmpMaxOutboundChannelsBound = frame_support::traits::ConstU32<128>; + type HrmpMaxInboundChannelsBound = frame_support::traits::ConstU32<128>; } // aims to closely emulate the Kusama XcmConfig diff --git a/xcm/xcm-simulator/example/src/relay_chain.rs b/xcm/xcm-simulator/example/src/relay_chain.rs index cc50aec90d18..17892e63335b 100644 --- a/xcm/xcm-simulator/example/src/relay_chain.rs +++ b/xcm/xcm-simulator/example/src/relay_chain.rs @@ -90,6 +90,8 @@ impl shared::Config for Runtime {} impl configuration::Config for Runtime { type WeightInfo = configuration::weights::WeightInfo; + type HrmpMaxOutboundChannelsBound = frame_support::traits::ConstU32<128>; + type HrmpMaxInboundChannelsBound = frame_support::traits::ConstU32<128>; } parameter_types! { From 7d830d996a4374bf5159363eed0ac4e43a7f09c1 Mon Sep 17 00:00:00 2001 From: Parity Bot Date: Tue, 21 Sep 2021 15:35:11 +0000 Subject: [PATCH 12/36] cargo run --quiet --release --features=runtime-benchmarks -- benchmark --chain=kusama-dev --steps=50 --repeat=20 --pallet=runtime_parachains::hrmp --extrinsic=* --execution=wasm --wasm-execution=compiled --heap-pages=4096 --header=./file_header.txt --output=./runtime/kusama/src/weights/runtime_parachains_hrmp.rs --- .../src/weights/runtime_parachains_hrmp.rs | 146 ++++++++++++++++++ 1 file changed, 146 insertions(+) create mode 100644 runtime/kusama/src/weights/runtime_parachains_hrmp.rs diff --git a/runtime/kusama/src/weights/runtime_parachains_hrmp.rs b/runtime/kusama/src/weights/runtime_parachains_hrmp.rs new file mode 100644 index 000000000000..a57cc91b8f97 --- /dev/null +++ b/runtime/kusama/src/weights/runtime_parachains_hrmp.rs @@ -0,0 +1,146 @@ +// Copyright 2017-2021 Parity Technologies (UK) Ltd. +// This file is part of Polkadot. + +// Polkadot is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// Polkadot is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with Polkadot. If not, see . +//! Autogenerated weights for `runtime_parachains::hrmp` +//! +//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev +//! DATE: 2021-09-21, STEPS: `50`, REPEAT: 20, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("kusama-dev"), DB CACHE: 128 + +// Executed Command: +// target/release/polkadot +// benchmark +// --chain=kusama-dev +// --steps=50 +// --repeat=20 +// --pallet=runtime_parachains::hrmp +// --extrinsic=* +// --execution=wasm +// --wasm-execution=compiled +// --heap-pages=4096 +// --header=./file_header.txt +// --output=./runtime/kusama/src/weights/runtime_parachains_hrmp.rs + + +#![cfg_attr(rustfmt, rustfmt_skip)] +#![allow(unused_parens)] +#![allow(unused_imports)] + +use frame_support::{traits::Get, weights::Weight}; +use sp_std::marker::PhantomData; + +/// Weight functions for `runtime_parachains::hrmp`. +pub struct WeightInfo(PhantomData); +impl runtime_parachains::hrmp::WeightInfo for WeightInfo { + // Storage: Paras ParaLifecycles (r:2 w:0) + // Storage: Configuration ActiveConfig (r:1 w:0) + // Storage: Hrmp HrmpOpenChannelRequests (r:1 w:1) + // Storage: Hrmp HrmpChannels (r:1 w:0) + // Storage: Hrmp HrmpEgressChannelsIndex (r:1 w:0) + // Storage: Hrmp HrmpOpenChannelRequestCount (r:1 w:1) + // Storage: Hrmp HrmpOpenChannelRequestsList (r:1 w:1) + // Storage: Dmp DownwardMessageQueueHeads (r:1 w:1) + // Storage: Dmp DownwardMessageQueues (r:1 w:1) + fn hrmp_init_open_channel() -> Weight { + (61_914_000 as Weight) + .saturating_add(T::DbWeight::get().reads(10 as Weight)) + .saturating_add(T::DbWeight::get().writes(5 as Weight)) + } + // Storage: Hrmp HrmpOpenChannelRequests (r:1 w:1) + // Storage: Configuration ActiveConfig (r:1 w:0) + // Storage: Paras ParaLifecycles (r:1 w:0) + // Storage: Hrmp HrmpIngressChannelsIndex (r:1 w:0) + // Storage: Hrmp HrmpAcceptedChannelRequestCount (r:1 w:1) + // Storage: Dmp DownwardMessageQueueHeads (r:1 w:1) + // Storage: Dmp DownwardMessageQueues (r:1 w:1) + fn hrmp_accept_open_channel() -> Weight { + (53_022_000 as Weight) + .saturating_add(T::DbWeight::get().reads(7 as Weight)) + .saturating_add(T::DbWeight::get().writes(4 as Weight)) + } + // Storage: Hrmp HrmpChannels (r:1 w:0) + // Storage: Hrmp HrmpCloseChannelRequests (r:1 w:1) + // Storage: Hrmp HrmpCloseChannelRequestsList (r:1 w:1) + // Storage: Configuration ActiveConfig (r:1 w:0) + // Storage: Dmp DownwardMessageQueueHeads (r:1 w:1) + // Storage: Dmp DownwardMessageQueues (r:1 w:1) + fn hrmp_close_channel() -> Weight { + (47_548_000 as Weight) + .saturating_add(T::DbWeight::get().reads(6 as Weight)) + .saturating_add(T::DbWeight::get().writes(4 as Weight)) + } + // Storage: Hrmp HrmpIngressChannelsIndex (r:128 w:127) + // Storage: Hrmp HrmpEgressChannelsIndex (r:1 w:1) + // Storage: Hrmp HrmpChannels (r:127 w:127) + // Storage: Hrmp HrmpAcceptedChannelRequestCount (r:0 w:1) + // Storage: Hrmp HrmpChannelContents (r:0 w:127) + // Storage: Hrmp HrmpOpenChannelRequestCount (r:0 w:1) + fn force_clean_hrmp(i: u32, e: u32, ) -> Weight { + (0 as Weight) + // Standard Error: 19_000 + .saturating_add((17_052_000 as Weight).saturating_mul(i as Weight)) + // Standard Error: 19_000 + .saturating_add((16_998_000 as Weight).saturating_mul(e as Weight)) + .saturating_add(T::DbWeight::get().reads(2 as Weight)) + .saturating_add(T::DbWeight::get().reads((2 as Weight).saturating_mul(i as Weight))) + .saturating_add(T::DbWeight::get().reads((2 as Weight).saturating_mul(e as Weight))) + .saturating_add(T::DbWeight::get().writes(4 as Weight)) + .saturating_add(T::DbWeight::get().writes((3 as Weight).saturating_mul(i as Weight))) + .saturating_add(T::DbWeight::get().writes((3 as Weight).saturating_mul(e as Weight))) + } + // Storage: Configuration ActiveConfig (r:1 w:0) + // Storage: Hrmp HrmpOpenChannelRequestsList (r:1 w:0) + // Storage: Hrmp HrmpOpenChannelRequests (r:2 w:2) + // Storage: Paras ParaLifecycles (r:4 w:0) + // Storage: Hrmp HrmpIngressChannelsIndex (r:2 w:2) + // Storage: Hrmp HrmpEgressChannelsIndex (r:2 w:2) + // Storage: Hrmp HrmpOpenChannelRequestCount (r:2 w:2) + // Storage: Hrmp HrmpAcceptedChannelRequestCount (r:2 w:2) + // Storage: Hrmp HrmpChannels (r:0 w:2) + fn force_process_hrmp_open(c: u32, ) -> Weight { + (0 as Weight) + // Standard Error: 28_000 + .saturating_add((37_628_000 as Weight).saturating_mul(c as Weight)) + .saturating_add(T::DbWeight::get().reads(2 as Weight)) + .saturating_add(T::DbWeight::get().reads((7 as Weight).saturating_mul(c as Weight))) + .saturating_add(T::DbWeight::get().writes(1 as Weight)) + .saturating_add(T::DbWeight::get().writes((6 as Weight).saturating_mul(c as Weight))) + } + // Storage: Hrmp HrmpCloseChannelRequestsList (r:1 w:0) + // Storage: Hrmp HrmpChannels (r:2 w:2) + // Storage: Hrmp HrmpEgressChannelsIndex (r:2 w:2) + // Storage: Hrmp HrmpIngressChannelsIndex (r:2 w:2) + // Storage: Hrmp HrmpCloseChannelRequests (r:0 w:2) + // Storage: Hrmp HrmpChannelContents (r:0 w:2) + fn force_process_hrmp_close(c: u32, ) -> Weight { + (0 as Weight) + // Standard Error: 17_000 + .saturating_add((21_825_000 as Weight).saturating_mul(c as Weight)) + .saturating_add(T::DbWeight::get().reads(1 as Weight)) + .saturating_add(T::DbWeight::get().reads((3 as Weight).saturating_mul(c as Weight))) + .saturating_add(T::DbWeight::get().writes(1 as Weight)) + .saturating_add(T::DbWeight::get().writes((5 as Weight).saturating_mul(c as Weight))) + } + // Storage: Hrmp HrmpOpenChannelRequests (r:1 w:1) + // Storage: Hrmp HrmpOpenChannelRequestsList (r:1 w:1) + // Storage: Hrmp HrmpOpenChannelRequestCount (r:1 w:1) + fn hrmp_cancel_open_request(c: u32, ) -> Weight { + (35_031_000 as Weight) + // Standard Error: 0 + .saturating_add((56_000 as Weight).saturating_mul(c as Weight)) + .saturating_add(T::DbWeight::get().reads(3 as Weight)) + .saturating_add(T::DbWeight::get().writes(3 as Weight)) + } +} From 7cbd3ea3b46c65b5fd340a57cd7c378188add858 Mon Sep 17 00:00:00 2001 From: kianenigma Date: Tue, 21 Sep 2021 19:57:36 +0200 Subject: [PATCH 13/36] add to westend --- runtime/westend/src/lib.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/runtime/westend/src/lib.rs b/runtime/westend/src/lib.rs index 492fb343de42..a6808f7594cb 100644 --- a/runtime/westend/src/lib.rs +++ b/runtime/westend/src/lib.rs @@ -1473,6 +1473,7 @@ sp_api::impl_runtime_apis! { list_benchmark!(list, extra, runtime_common::paras_registrar, Registrar); list_benchmark!(list, extra, runtime_common::slots, Slots); list_benchmark!(list, extra, runtime_parachains::configuration, Configuration); + list_benchmark!(list, extra, runtime_parachains::hrmp, Hrmp); // Substrate list_benchmark!(list, extra, pallet_bags_list, BagsList); list_benchmark!(list, extra, pallet_balances, Balances); @@ -1539,6 +1540,7 @@ sp_api::impl_runtime_apis! { add_benchmark!(params, batches, runtime_common::paras_registrar, Registrar); add_benchmark!(params, batches, runtime_common::slots, Slots); add_benchmark!(params, batches, runtime_parachains::configuration, Configuration); + add_benchmark!(params, batches, runtime_parachains::hrmp, Hrmp); // Substrate add_benchmark!(params, batches, pallet_bags_list, BagsList); add_benchmark!(params, batches, pallet_balances, Balances); From 2d08f7a34770f0d647b450d52133a137319cd913 Mon Sep 17 00:00:00 2001 From: kianenigma Date: Tue, 21 Sep 2021 20:21:58 +0200 Subject: [PATCH 14/36] actually use everything --- runtime/kusama/src/lib.rs | 1 + runtime/kusama/src/weights/mod.rs | 1 + runtime/parachains/src/hrmp.rs | 150 +++++++++++++++++++++++++++--- runtime/parachains/src/mock.rs | 1 + runtime/rococo/src/lib.rs | 1 + runtime/test-runtime/src/lib.rs | 1 + runtime/westend/src/lib.rs | 1 + 7 files changed, 142 insertions(+), 14 deletions(-) diff --git a/runtime/kusama/src/lib.rs b/runtime/kusama/src/lib.rs index afae2fa9eb5a..620422363915 100644 --- a/runtime/kusama/src/lib.rs +++ b/runtime/kusama/src/lib.rs @@ -1170,6 +1170,7 @@ impl parachains_hrmp::Config for Runtime { type Event = Event; type Origin = Origin; type Currency = Balances; + type WeightInfo = weights::runtime_parachains_hrmp::WeightInfo; } impl parachains_paras_inherent::Config for Runtime {} diff --git a/runtime/kusama/src/weights/mod.rs b/runtime/kusama/src/weights/mod.rs index adb103ad4eee..0b3bea93b85d 100644 --- a/runtime/kusama/src/weights/mod.rs +++ b/runtime/kusama/src/weights/mod.rs @@ -45,3 +45,4 @@ pub mod runtime_common_crowdloan; pub mod runtime_common_paras_registrar; pub mod runtime_common_slots; pub mod runtime_parachains_configuration; +pub mod runtime_parachains_hrmp; diff --git a/runtime/parachains/src/hrmp.rs b/runtime/parachains/src/hrmp.rs index 876c35b98d80..eb7db09fe049 100644 --- a/runtime/parachains/src/hrmp.rs +++ b/runtime/parachains/src/hrmp.rs @@ -35,6 +35,111 @@ use sp_std::{ pub use pallet::*; +pub trait WeightInfo { + fn hrmp_init_open_channel() -> Weight; + fn hrmp_accept_open_channel() -> Weight; + fn hrmp_close_channel() -> Weight; + fn force_clean_hrmp(i: u32, e: u32) -> Weight; + fn force_process_hrmp_open(c: u32) -> Weight; + fn force_process_hrmp_close(c: u32) -> Weight; + fn hrmp_cancel_open_request(c: u32) -> Weight; +} + +use frame_support::weights::constants::RocksDbWeight; + +impl WeightInfo for () { + fn hrmp_init_open_channel() -> Weight { + (61_914_000 as Weight) + .saturating_add(RocksDbWeight::get().reads(10 as Weight)) + .saturating_add(RocksDbWeight::get().writes(5 as Weight)) + } + // Storage: Hrmp HrmpOpenChannelRequests (r:1 w:1) + // Storage: Configuration ActiveConfig (r:1 w:0) + // Storage: Paras ParaLifecycles (r:1 w:0) + // Storage: Hrmp HrmpIngressChannelsIndex (r:1 w:0) + // Storage: Hrmp HrmpAcceptedChannelRequestCount (r:1 w:1) + // Storage: Dmp DownwardMessageQueueHeads (r:1 w:1) + // Storage: Dmp DownwardMessageQueues (r:1 w:1) + fn hrmp_accept_open_channel() -> Weight { + (53_022_000 as Weight) + .saturating_add(RocksDbWeight::get().reads(7 as Weight)) + .saturating_add(RocksDbWeight::get().writes(4 as Weight)) + } + // Storage: Hrmp HrmpChannels (r:1 w:0) + // Storage: Hrmp HrmpCloseChannelRequests (r:1 w:1) + // Storage: Hrmp HrmpCloseChannelRequestsList (r:1 w:1) + // Storage: Configuration ActiveConfig (r:1 w:0) + // Storage: Dmp DownwardMessageQueueHeads (r:1 w:1) + // Storage: Dmp DownwardMessageQueues (r:1 w:1) + fn hrmp_close_channel() -> Weight { + (47_548_000 as Weight) + .saturating_add(RocksDbWeight::get().reads(6 as Weight)) + .saturating_add(RocksDbWeight::get().writes(4 as Weight)) + } + // Storage: Hrmp HrmpIngressChannelsIndex (r:128 w:127) + // Storage: Hrmp HrmpEgressChannelsIndex (r:1 w:1) + // Storage: Hrmp HrmpChannels (r:127 w:127) + // Storage: Hrmp HrmpAcceptedChannelRequestCount (r:0 w:1) + // Storage: Hrmp HrmpChannelContents (r:0 w:127) + // Storage: Hrmp HrmpOpenChannelRequestCount (r:0 w:1) + fn force_clean_hrmp(i: u32, e: u32) -> Weight { + (0 as Weight) + // Standard Error: 19_000 + .saturating_add((17_052_000 as Weight).saturating_mul(i as Weight)) + // Standard Error: 19_000 + .saturating_add((16_998_000 as Weight).saturating_mul(e as Weight)) + .saturating_add(RocksDbWeight::get().reads(2 as Weight)) + .saturating_add(RocksDbWeight::get().reads((2 as Weight).saturating_mul(i as Weight))) + .saturating_add(RocksDbWeight::get().reads((2 as Weight).saturating_mul(e as Weight))) + .saturating_add(RocksDbWeight::get().writes(4 as Weight)) + .saturating_add(RocksDbWeight::get().writes((3 as Weight).saturating_mul(i as Weight))) + .saturating_add(RocksDbWeight::get().writes((3 as Weight).saturating_mul(e as Weight))) + } + // Storage: Configuration ActiveConfig (r:1 w:0) + // Storage: Hrmp HrmpOpenChannelRequestsList (r:1 w:0) + // Storage: Hrmp HrmpOpenChannelRequests (r:2 w:2) + // Storage: Paras ParaLifecycles (r:4 w:0) + // Storage: Hrmp HrmpIngressChannelsIndex (r:2 w:2) + // Storage: Hrmp HrmpEgressChannelsIndex (r:2 w:2) + // Storage: Hrmp HrmpOpenChannelRequestCount (r:2 w:2) + // Storage: Hrmp HrmpAcceptedChannelRequestCount (r:2 w:2) + // Storage: Hrmp HrmpChannels (r:0 w:2) + fn force_process_hrmp_open(c: u32) -> Weight { + (0 as Weight) + // Standard Error: 28_000 + .saturating_add((37_628_000 as Weight).saturating_mul(c as Weight)) + .saturating_add(RocksDbWeight::get().reads(2 as Weight)) + .saturating_add(RocksDbWeight::get().reads((7 as Weight).saturating_mul(c as Weight))) + .saturating_add(RocksDbWeight::get().writes(1 as Weight)) + .saturating_add(RocksDbWeight::get().writes((6 as Weight).saturating_mul(c as Weight))) + } + // Storage: Hrmp HrmpCloseChannelRequestsList (r:1 w:0) + // Storage: Hrmp HrmpChannels (r:2 w:2) + // Storage: Hrmp HrmpEgressChannelsIndex (r:2 w:2) + // Storage: Hrmp HrmpIngressChannelsIndex (r:2 w:2) + // Storage: Hrmp HrmpCloseChannelRequests (r:0 w:2) + // Storage: Hrmp HrmpChannelContents (r:0 w:2) + fn force_process_hrmp_close(c: u32) -> Weight { + (0 as Weight) + // Standard Error: 17_000 + .saturating_add((21_825_000 as Weight).saturating_mul(c as Weight)) + .saturating_add(RocksDbWeight::get().reads(1 as Weight)) + .saturating_add(RocksDbWeight::get().reads((3 as Weight).saturating_mul(c as Weight))) + .saturating_add(RocksDbWeight::get().writes(1 as Weight)) + .saturating_add(RocksDbWeight::get().writes((5 as Weight).saturating_mul(c as Weight))) + } + // Storage: Hrmp HrmpOpenChannelRequests (r:1 w:1) + // Storage: Hrmp HrmpOpenChannelRequestsList (r:1 w:1) + // Storage: Hrmp HrmpOpenChannelRequestCount (r:1 w:1) + fn hrmp_cancel_open_request(c: u32) -> Weight { + (35_031_000 as Weight) + // Standard Error: 0 + .saturating_add((56_000 as Weight).saturating_mul(c as Weight)) + .saturating_add(RocksDbWeight::get().reads(3 as Weight)) + .saturating_add(RocksDbWeight::get().writes(3 as Weight)) + } +} + /// A description of a request to open an HRMP channel. #[derive(Encode, Decode, TypeInfo)] pub struct HrmpOpenChannelRequest { @@ -195,6 +300,9 @@ pub mod pallet { /// `Configuration` pallet. Specifically, that means that the `Balance` of the `Currency` /// implementation should be the same as `Balance` as used in the `Configuration`. type Currency: ReservableCurrency; + + /// Something that provides the weight of this pallet. + type WeightInfo: WeightInfo; } #[pallet::event] @@ -397,7 +505,7 @@ pub mod pallet { /// /// The channel can be opened only after the recipient confirms it and only on a session /// change. - #[pallet::weight(0)] + #[pallet::weight(::WeightInfo::hrmp_init_open_channel())] pub fn hrmp_init_open_channel( origin: OriginFor, recipient: ParaId, @@ -423,7 +531,7 @@ pub mod pallet { /// Accept a pending open channel request from the given sender. /// /// The channel will be opened only on the next session boundary. - #[pallet::weight(0)] + #[pallet::weight(::WeightInfo::hrmp_accept_open_channel())] pub fn hrmp_accept_open_channel(origin: OriginFor, sender: ParaId) -> DispatchResult { let origin = ensure_parachain(::Origin::from(origin))?; Self::accept_open_channel(origin, sender)?; @@ -435,7 +543,7 @@ pub mod pallet { /// recipient in the channel being closed. /// /// The closure can only happen on a session change. - #[pallet::weight(0)] + #[pallet::weight(::WeightInfo::hrmp_close_channel())] pub fn hrmp_close_channel( origin: OriginFor, channel_id: HrmpChannelId, @@ -451,8 +559,15 @@ pub mod pallet { /// you to trigger the cleanup immediately for a specific parachain. /// /// Origin must be Root. - #[pallet::weight(0)] - pub fn force_clean_hrmp(origin: OriginFor, para: ParaId) -> DispatchResult { + /// + /// Number of inbound and outbound channels for `para` must be provided as witness data. + #[pallet::weight(::WeightInfo::force_clean_hrmp(*_inbound, *_outbound))] + pub fn force_clean_hrmp( + origin: OriginFor, + para: ParaId, + _inbound: u32, + _outbound: u32, + ) -> DispatchResult { ensure_root(origin)?; Self::clean_hrmp_after_outgoing(¶); Ok(()) @@ -462,8 +577,10 @@ pub mod pallet { /// /// If there are pending HRMP open channel requests, you can use this /// function process all of those requests immediately. - #[pallet::weight(0)] - pub fn force_process_hrmp_open(origin: OriginFor) -> DispatchResult { + /// + /// Total number of opening channels must be provided as witness data. + #[pallet::weight(::WeightInfo::force_process_hrmp_open(*_channels))] + pub fn force_process_hrmp_open(origin: OriginFor, _channels: u32) -> DispatchResult { ensure_root(origin)?; let host_config = configuration::Pallet::::config(); Self::process_hrmp_open_channel_requests(&host_config); @@ -474,8 +591,10 @@ pub mod pallet { /// /// If there are pending HRMP close channel requests, you can use this /// function process all of those requests immediately. - #[pallet::weight(0)] - pub fn force_process_hrmp_close(origin: OriginFor) -> DispatchResult { + /// + /// Total number of closing channels must be provided as witness data. + #[pallet::weight(::WeightInfo::force_process_hrmp_close(*_channels))] + pub fn force_process_hrmp_close(origin: OriginFor, _channels: u32) -> DispatchResult { ensure_root(origin)?; Self::process_hrmp_close_channel_requests(); Ok(()) @@ -486,10 +605,13 @@ pub mod pallet { /// /// The cancelling happens immediately. It is not possible to cancel the request if it is /// already accepted. - #[pallet::weight(0)] + /// + /// Total number of opening channels must be provided as witness data. + #[pallet::weight(::WeightInfo::hrmp_cancel_open_request(*_channels))] pub fn hrmp_cancel_open_request( origin: OriginFor, channel_id: HrmpChannelId, + _channels: u32, ) -> DispatchResult { let origin = ensure_parachain(::Origin::from(origin))?; Self::cancel_open_request(origin, channel_id.clone())?; @@ -2208,7 +2330,7 @@ mod benchmarking { // all in all, we have created these many channels assert_eq!(HrmpChannels::::iter().count() as u32, i + e); - }: _(frame_system::Origin::::Root, para) verify { + }: _(frame_system::Origin::::Root, para, i, e) verify { // all in all, all of them must be gone by now. assert_eq!(HrmpChannels::::iter().count() as u32, 0); } @@ -2222,7 +2344,7 @@ mod benchmarking { let _ = establish_para_connection::(PREFIX_0 + id, PREFIX_1 + id, ParachainSetupStep::Accepted); } assert_eq!(HrmpOpenChannelRequestsList::::decode_len().unwrap_or_default() as u32, c); - }: _(frame_system::Origin::::Root) + }: _(frame_system::Origin::::Root, c) verify { assert_eq!(HrmpOpenChannelRequestsList::::decode_len().unwrap_or_default() as u32, 0); } @@ -2237,7 +2359,7 @@ mod benchmarking { } assert_eq!(HrmpCloseChannelRequestsList::::decode_len().unwrap_or_default() as u32, c); - }: _(frame_system::Origin::::Root) + }: _(frame_system::Origin::::Root, c) verify { assert_eq!(HrmpCloseChannelRequestsList::::decode_len().unwrap_or_default() as u32, 0); } @@ -2254,7 +2376,7 @@ mod benchmarking { let [(sender, sender_origin), (recipient, _)] = establish_para_connection::(1, 2, ParachainSetupStep::Requested); assert_eq!(HrmpOpenChannelRequestsList::::decode_len().unwrap_or_default() as u32, c + 1); let channel_id = HrmpChannelId { sender, recipient }; - }: _(sender_origin, channel_id) + }: _(sender_origin, channel_id, c) verify { assert_eq!(HrmpOpenChannelRequestsList::::decode_len().unwrap_or_default() as u32, c); } diff --git a/runtime/parachains/src/mock.rs b/runtime/parachains/src/mock.rs index 5c68d9a3ad93..3001f986e14d 100644 --- a/runtime/parachains/src/mock.rs +++ b/runtime/parachains/src/mock.rs @@ -148,6 +148,7 @@ impl crate::hrmp::Config for Test { type Event = Event; type Origin = Origin; type Currency = pallet_balances::Pallet; + type WeightInfo = (); } impl crate::disputes::Config for Test { diff --git a/runtime/rococo/src/lib.rs b/runtime/rococo/src/lib.rs index d3be7a0dd214..5ce22351192b 100644 --- a/runtime/rococo/src/lib.rs +++ b/runtime/rococo/src/lib.rs @@ -738,6 +738,7 @@ impl parachains_hrmp::Config for Runtime { type Event = Event; type Origin = Origin; type Currency = Balances; + type WeightInfo = (); } impl parachains_paras_inherent::Config for Runtime {} diff --git a/runtime/test-runtime/src/lib.rs b/runtime/test-runtime/src/lib.rs index a2717c257b33..f222232732a3 100644 --- a/runtime/test-runtime/src/lib.rs +++ b/runtime/test-runtime/src/lib.rs @@ -532,6 +532,7 @@ impl parachains_hrmp::Config for Runtime { type Event = Event; type Origin = Origin; type Currency = Balances; + type WeightInfo = (); } impl parachains_scheduler::Config for Runtime {} diff --git a/runtime/westend/src/lib.rs b/runtime/westend/src/lib.rs index a6808f7594cb..45be175d6eb6 100644 --- a/runtime/westend/src/lib.rs +++ b/runtime/westend/src/lib.rs @@ -839,6 +839,7 @@ impl parachains_hrmp::Config for Runtime { type Event = Event; type Origin = Origin; type Currency = Balances; + type WeightInfo = (); } impl parachains_paras_inherent::Config for Runtime {} From 0c06dcea1000b388443e40c886fb720a4fc002f3 Mon Sep 17 00:00:00 2001 From: Parity Bot Date: Tue, 21 Sep 2021 19:25:44 +0000 Subject: [PATCH 15/36] cargo run --quiet --release --features=runtime-benchmarks -- benchmark --chain=westend-dev --steps=50 --repeat=20 --pallet=runtime_parachains::hrmp --extrinsic=* --execution=wasm --wasm-execution=compiled --heap-pages=4096 --header=./file_header.txt --output=./runtime/westend/src/weights/runtime_parachains_hrmp.rs --- .../src/weights/runtime_parachains_hrmp.rs | 146 ++++++++++++++++++ 1 file changed, 146 insertions(+) create mode 100644 runtime/westend/src/weights/runtime_parachains_hrmp.rs diff --git a/runtime/westend/src/weights/runtime_parachains_hrmp.rs b/runtime/westend/src/weights/runtime_parachains_hrmp.rs new file mode 100644 index 000000000000..1925eabdf9dc --- /dev/null +++ b/runtime/westend/src/weights/runtime_parachains_hrmp.rs @@ -0,0 +1,146 @@ +// Copyright 2017-2021 Parity Technologies (UK) Ltd. +// This file is part of Polkadot. + +// Polkadot is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// Polkadot is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with Polkadot. If not, see . +//! Autogenerated weights for `runtime_parachains::hrmp` +//! +//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev +//! DATE: 2021-09-21, STEPS: `50`, REPEAT: 20, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("westend-dev"), DB CACHE: 128 + +// Executed Command: +// target/release/polkadot +// benchmark +// --chain=westend-dev +// --steps=50 +// --repeat=20 +// --pallet=runtime_parachains::hrmp +// --extrinsic=* +// --execution=wasm +// --wasm-execution=compiled +// --heap-pages=4096 +// --header=./file_header.txt +// --output=./runtime/westend/src/weights/runtime_parachains_hrmp.rs + + +#![cfg_attr(rustfmt, rustfmt_skip)] +#![allow(unused_parens)] +#![allow(unused_imports)] + +use frame_support::{traits::Get, weights::Weight}; +use sp_std::marker::PhantomData; + +/// Weight functions for `runtime_parachains::hrmp`. +pub struct WeightInfo(PhantomData); +impl runtime_parachains::hrmp::WeightInfo for WeightInfo { + // Storage: Paras ParaLifecycles (r:2 w:0) + // Storage: Configuration ActiveConfig (r:1 w:0) + // Storage: Hrmp HrmpOpenChannelRequests (r:1 w:1) + // Storage: Hrmp HrmpChannels (r:1 w:0) + // Storage: Hrmp HrmpEgressChannelsIndex (r:1 w:0) + // Storage: Hrmp HrmpOpenChannelRequestCount (r:1 w:1) + // Storage: Hrmp HrmpOpenChannelRequestsList (r:1 w:1) + // Storage: Dmp DownwardMessageQueueHeads (r:1 w:1) + // Storage: Dmp DownwardMessageQueues (r:1 w:1) + fn hrmp_init_open_channel() -> Weight { + (60_060_000 as Weight) + .saturating_add(T::DbWeight::get().reads(10 as Weight)) + .saturating_add(T::DbWeight::get().writes(5 as Weight)) + } + // Storage: Hrmp HrmpOpenChannelRequests (r:1 w:1) + // Storage: Configuration ActiveConfig (r:1 w:0) + // Storage: Paras ParaLifecycles (r:1 w:0) + // Storage: Hrmp HrmpIngressChannelsIndex (r:1 w:0) + // Storage: Hrmp HrmpAcceptedChannelRequestCount (r:1 w:1) + // Storage: Dmp DownwardMessageQueueHeads (r:1 w:1) + // Storage: Dmp DownwardMessageQueues (r:1 w:1) + fn hrmp_accept_open_channel() -> Weight { + (52_262_000 as Weight) + .saturating_add(T::DbWeight::get().reads(7 as Weight)) + .saturating_add(T::DbWeight::get().writes(4 as Weight)) + } + // Storage: Hrmp HrmpChannels (r:1 w:0) + // Storage: Hrmp HrmpCloseChannelRequests (r:1 w:1) + // Storage: Hrmp HrmpCloseChannelRequestsList (r:1 w:1) + // Storage: Configuration ActiveConfig (r:1 w:0) + // Storage: Dmp DownwardMessageQueueHeads (r:1 w:1) + // Storage: Dmp DownwardMessageQueues (r:1 w:1) + fn hrmp_close_channel() -> Weight { + (46_844_000 as Weight) + .saturating_add(T::DbWeight::get().reads(6 as Weight)) + .saturating_add(T::DbWeight::get().writes(4 as Weight)) + } + // Storage: Hrmp HrmpIngressChannelsIndex (r:128 w:127) + // Storage: Hrmp HrmpEgressChannelsIndex (r:1 w:1) + // Storage: Hrmp HrmpChannels (r:127 w:127) + // Storage: Hrmp HrmpAcceptedChannelRequestCount (r:0 w:1) + // Storage: Hrmp HrmpChannelContents (r:0 w:127) + // Storage: Hrmp HrmpOpenChannelRequestCount (r:0 w:1) + fn force_clean_hrmp(i: u32, e: u32, ) -> Weight { + (0 as Weight) + // Standard Error: 19_000 + .saturating_add((16_896_000 as Weight).saturating_mul(i as Weight)) + // Standard Error: 19_000 + .saturating_add((17_023_000 as Weight).saturating_mul(e as Weight)) + .saturating_add(T::DbWeight::get().reads(2 as Weight)) + .saturating_add(T::DbWeight::get().reads((2 as Weight).saturating_mul(i as Weight))) + .saturating_add(T::DbWeight::get().reads((2 as Weight).saturating_mul(e as Weight))) + .saturating_add(T::DbWeight::get().writes(4 as Weight)) + .saturating_add(T::DbWeight::get().writes((3 as Weight).saturating_mul(i as Weight))) + .saturating_add(T::DbWeight::get().writes((3 as Weight).saturating_mul(e as Weight))) + } + // Storage: Configuration ActiveConfig (r:1 w:0) + // Storage: Hrmp HrmpOpenChannelRequestsList (r:1 w:0) + // Storage: Hrmp HrmpOpenChannelRequests (r:2 w:2) + // Storage: Paras ParaLifecycles (r:4 w:0) + // Storage: Hrmp HrmpIngressChannelsIndex (r:2 w:2) + // Storage: Hrmp HrmpEgressChannelsIndex (r:2 w:2) + // Storage: Hrmp HrmpOpenChannelRequestCount (r:2 w:2) + // Storage: Hrmp HrmpAcceptedChannelRequestCount (r:2 w:2) + // Storage: Hrmp HrmpChannels (r:0 w:2) + fn force_process_hrmp_open(c: u32, ) -> Weight { + (0 as Weight) + // Standard Error: 29_000 + .saturating_add((37_245_000 as Weight).saturating_mul(c as Weight)) + .saturating_add(T::DbWeight::get().reads(2 as Weight)) + .saturating_add(T::DbWeight::get().reads((7 as Weight).saturating_mul(c as Weight))) + .saturating_add(T::DbWeight::get().writes(1 as Weight)) + .saturating_add(T::DbWeight::get().writes((6 as Weight).saturating_mul(c as Weight))) + } + // Storage: Hrmp HrmpCloseChannelRequestsList (r:1 w:0) + // Storage: Hrmp HrmpChannels (r:2 w:2) + // Storage: Hrmp HrmpEgressChannelsIndex (r:2 w:2) + // Storage: Hrmp HrmpIngressChannelsIndex (r:2 w:2) + // Storage: Hrmp HrmpCloseChannelRequests (r:0 w:2) + // Storage: Hrmp HrmpChannelContents (r:0 w:2) + fn force_process_hrmp_close(c: u32, ) -> Weight { + (0 as Weight) + // Standard Error: 15_000 + .saturating_add((21_682_000 as Weight).saturating_mul(c as Weight)) + .saturating_add(T::DbWeight::get().reads(1 as Weight)) + .saturating_add(T::DbWeight::get().reads((3 as Weight).saturating_mul(c as Weight))) + .saturating_add(T::DbWeight::get().writes(1 as Weight)) + .saturating_add(T::DbWeight::get().writes((5 as Weight).saturating_mul(c as Weight))) + } + // Storage: Hrmp HrmpOpenChannelRequests (r:1 w:1) + // Storage: Hrmp HrmpOpenChannelRequestsList (r:1 w:1) + // Storage: Hrmp HrmpOpenChannelRequestCount (r:1 w:1) + fn hrmp_cancel_open_request(c: u32, ) -> Weight { + (34_181_000 as Weight) + // Standard Error: 0 + .saturating_add((60_000 as Weight).saturating_mul(c as Weight)) + .saturating_add(T::DbWeight::get().reads(3 as Weight)) + .saturating_add(T::DbWeight::get().writes(3 as Weight)) + } +} From a3833630c506e9c5d0d5957ad5a30abcceacade7 Mon Sep 17 00:00:00 2001 From: Kian Paimani <5588131+kianenigma@users.noreply.github.com> Date: Wed, 22 Sep 2021 12:57:43 +0100 Subject: [PATCH 16/36] Update runtime/parachains/src/hrmp.rs Co-authored-by: Keith Yeung --- runtime/parachains/src/hrmp.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/runtime/parachains/src/hrmp.rs b/runtime/parachains/src/hrmp.rs index eb7db09fe049..9622a61eae9a 100644 --- a/runtime/parachains/src/hrmp.rs +++ b/runtime/parachains/src/hrmp.rs @@ -2360,9 +2360,9 @@ mod benchmarking { assert_eq!(HrmpCloseChannelRequestsList::::decode_len().unwrap_or_default() as u32, c); }: _(frame_system::Origin::::Root, c) - verify { - assert_eq!(HrmpCloseChannelRequestsList::::decode_len().unwrap_or_default() as u32, 0); - } + verify { + assert_eq!(HrmpCloseChannelRequestsList::::decode_len().unwrap_or_default() as u32, 0); + } hrmp_cancel_open_request { // number of items already existing in the `HrmpOpenChannelRequestsList`, other than the From 210fd056ff0eabfda323674a10ee69c72511e9a8 Mon Sep 17 00:00:00 2001 From: kianenigma Date: Wed, 22 Sep 2021 14:08:45 +0200 Subject: [PATCH 17/36] use real weight in wnd --- runtime/westend/src/lib.rs | 2 +- runtime/westend/src/weights/mod.rs | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/runtime/westend/src/lib.rs b/runtime/westend/src/lib.rs index 875e8c2a2602..2cb272f90655 100644 --- a/runtime/westend/src/lib.rs +++ b/runtime/westend/src/lib.rs @@ -841,7 +841,7 @@ impl parachains_hrmp::Config for Runtime { type Event = Event; type Origin = Origin; type Currency = Balances; - type WeightInfo = (); + type WeightInfo = weights::runtime_parachains_hrmp::WeightInfo; } impl parachains_paras_inherent::Config for Runtime {} diff --git a/runtime/westend/src/weights/mod.rs b/runtime/westend/src/weights/mod.rs index c7dba930ed49..d481c23536e9 100644 --- a/runtime/westend/src/weights/mod.rs +++ b/runtime/westend/src/weights/mod.rs @@ -35,4 +35,5 @@ pub mod runtime_common_crowdloan; pub mod runtime_common_paras_registrar; pub mod runtime_common_slots; pub mod runtime_parachains_configuration; +pub mod runtime_parachains_hrmp; pub mod runtime_parachains_paras; From dbd34676face98a254117afd2fc79f003551392c Mon Sep 17 00:00:00 2001 From: kianenigma Date: Wed, 22 Sep 2021 19:45:34 +0200 Subject: [PATCH 18/36] reorg --- runtime/parachains/src/hrmp.rs | 347 +------------------- runtime/parachains/src/hrmp/benchmarking.rs | 262 +++++++++++++++ runtime/parachains/src/hrmp/weights.rs | 110 +++++++ 3 files changed, 376 insertions(+), 343 deletions(-) create mode 100644 runtime/parachains/src/hrmp/benchmarking.rs create mode 100644 runtime/parachains/src/hrmp/weights.rs diff --git a/runtime/parachains/src/hrmp.rs b/runtime/parachains/src/hrmp.rs index 9622a61eae9a..cc65509a816a 100644 --- a/runtime/parachains/src/hrmp.rs +++ b/runtime/parachains/src/hrmp.rs @@ -35,6 +35,10 @@ use sp_std::{ pub use pallet::*; +#[cfg(feature = "runtime-benchmarks")] +mod benchmarking; +mod weights; + pub trait WeightInfo { fn hrmp_init_open_channel() -> Weight; fn hrmp_accept_open_channel() -> Weight; @@ -45,101 +49,6 @@ pub trait WeightInfo { fn hrmp_cancel_open_request(c: u32) -> Weight; } -use frame_support::weights::constants::RocksDbWeight; - -impl WeightInfo for () { - fn hrmp_init_open_channel() -> Weight { - (61_914_000 as Weight) - .saturating_add(RocksDbWeight::get().reads(10 as Weight)) - .saturating_add(RocksDbWeight::get().writes(5 as Weight)) - } - // Storage: Hrmp HrmpOpenChannelRequests (r:1 w:1) - // Storage: Configuration ActiveConfig (r:1 w:0) - // Storage: Paras ParaLifecycles (r:1 w:0) - // Storage: Hrmp HrmpIngressChannelsIndex (r:1 w:0) - // Storage: Hrmp HrmpAcceptedChannelRequestCount (r:1 w:1) - // Storage: Dmp DownwardMessageQueueHeads (r:1 w:1) - // Storage: Dmp DownwardMessageQueues (r:1 w:1) - fn hrmp_accept_open_channel() -> Weight { - (53_022_000 as Weight) - .saturating_add(RocksDbWeight::get().reads(7 as Weight)) - .saturating_add(RocksDbWeight::get().writes(4 as Weight)) - } - // Storage: Hrmp HrmpChannels (r:1 w:0) - // Storage: Hrmp HrmpCloseChannelRequests (r:1 w:1) - // Storage: Hrmp HrmpCloseChannelRequestsList (r:1 w:1) - // Storage: Configuration ActiveConfig (r:1 w:0) - // Storage: Dmp DownwardMessageQueueHeads (r:1 w:1) - // Storage: Dmp DownwardMessageQueues (r:1 w:1) - fn hrmp_close_channel() -> Weight { - (47_548_000 as Weight) - .saturating_add(RocksDbWeight::get().reads(6 as Weight)) - .saturating_add(RocksDbWeight::get().writes(4 as Weight)) - } - // Storage: Hrmp HrmpIngressChannelsIndex (r:128 w:127) - // Storage: Hrmp HrmpEgressChannelsIndex (r:1 w:1) - // Storage: Hrmp HrmpChannels (r:127 w:127) - // Storage: Hrmp HrmpAcceptedChannelRequestCount (r:0 w:1) - // Storage: Hrmp HrmpChannelContents (r:0 w:127) - // Storage: Hrmp HrmpOpenChannelRequestCount (r:0 w:1) - fn force_clean_hrmp(i: u32, e: u32) -> Weight { - (0 as Weight) - // Standard Error: 19_000 - .saturating_add((17_052_000 as Weight).saturating_mul(i as Weight)) - // Standard Error: 19_000 - .saturating_add((16_998_000 as Weight).saturating_mul(e as Weight)) - .saturating_add(RocksDbWeight::get().reads(2 as Weight)) - .saturating_add(RocksDbWeight::get().reads((2 as Weight).saturating_mul(i as Weight))) - .saturating_add(RocksDbWeight::get().reads((2 as Weight).saturating_mul(e as Weight))) - .saturating_add(RocksDbWeight::get().writes(4 as Weight)) - .saturating_add(RocksDbWeight::get().writes((3 as Weight).saturating_mul(i as Weight))) - .saturating_add(RocksDbWeight::get().writes((3 as Weight).saturating_mul(e as Weight))) - } - // Storage: Configuration ActiveConfig (r:1 w:0) - // Storage: Hrmp HrmpOpenChannelRequestsList (r:1 w:0) - // Storage: Hrmp HrmpOpenChannelRequests (r:2 w:2) - // Storage: Paras ParaLifecycles (r:4 w:0) - // Storage: Hrmp HrmpIngressChannelsIndex (r:2 w:2) - // Storage: Hrmp HrmpEgressChannelsIndex (r:2 w:2) - // Storage: Hrmp HrmpOpenChannelRequestCount (r:2 w:2) - // Storage: Hrmp HrmpAcceptedChannelRequestCount (r:2 w:2) - // Storage: Hrmp HrmpChannels (r:0 w:2) - fn force_process_hrmp_open(c: u32) -> Weight { - (0 as Weight) - // Standard Error: 28_000 - .saturating_add((37_628_000 as Weight).saturating_mul(c as Weight)) - .saturating_add(RocksDbWeight::get().reads(2 as Weight)) - .saturating_add(RocksDbWeight::get().reads((7 as Weight).saturating_mul(c as Weight))) - .saturating_add(RocksDbWeight::get().writes(1 as Weight)) - .saturating_add(RocksDbWeight::get().writes((6 as Weight).saturating_mul(c as Weight))) - } - // Storage: Hrmp HrmpCloseChannelRequestsList (r:1 w:0) - // Storage: Hrmp HrmpChannels (r:2 w:2) - // Storage: Hrmp HrmpEgressChannelsIndex (r:2 w:2) - // Storage: Hrmp HrmpIngressChannelsIndex (r:2 w:2) - // Storage: Hrmp HrmpCloseChannelRequests (r:0 w:2) - // Storage: Hrmp HrmpChannelContents (r:0 w:2) - fn force_process_hrmp_close(c: u32) -> Weight { - (0 as Weight) - // Standard Error: 17_000 - .saturating_add((21_825_000 as Weight).saturating_mul(c as Weight)) - .saturating_add(RocksDbWeight::get().reads(1 as Weight)) - .saturating_add(RocksDbWeight::get().reads((3 as Weight).saturating_mul(c as Weight))) - .saturating_add(RocksDbWeight::get().writes(1 as Weight)) - .saturating_add(RocksDbWeight::get().writes((5 as Weight).saturating_mul(c as Weight))) - } - // Storage: Hrmp HrmpOpenChannelRequests (r:1 w:1) - // Storage: Hrmp HrmpOpenChannelRequestsList (r:1 w:1) - // Storage: Hrmp HrmpOpenChannelRequestCount (r:1 w:1) - fn hrmp_cancel_open_request(c: u32) -> Weight { - (35_031_000 as Weight) - // Standard Error: 0 - .saturating_add((56_000 as Weight).saturating_mul(c as Weight)) - .saturating_add(RocksDbWeight::get().reads(3 as Weight)) - .saturating_add(RocksDbWeight::get().writes(3 as Weight)) - } -} - /// A description of a request to open an HRMP channel. #[derive(Encode, Decode, TypeInfo)] pub struct HrmpOpenChannelRequest { @@ -2140,251 +2049,3 @@ mod tests { }); } } - -#[cfg(feature = "runtime-benchmarks")] -mod benchmarking { - use super::{Pallet as Hrmp, *}; - use crate::{ - configuration::Pallet as Configuration, paras::Pallet as Paras, shared::Pallet as Shared, - }; - use frame_support::{assert_ok, traits::Currency}; - - type BalanceOf = - <::Currency as Currency<::AccountId>>::Balance; - - fn register_parachain_with_balance(id: ParaId, balance: BalanceOf) { - assert_ok!(Paras::::initialize_para_now( - id, - crate::paras::ParaGenesisArgs { - parachain: true, - genesis_head: vec![1].into(), - validation_code: vec![1].into(), - }, - )); - T::Currency::make_free_balance_be(&id.into_account(), balance); - } - - fn assert_last_event(generic_event: ::Event) { - let events = frame_system::Pallet::::events(); - let system_event: ::Event = generic_event.into(); - // compare to the last event record - let frame_system::EventRecord { event, .. } = &events[events.len() - 1]; - assert_eq!(event, &system_event); - } - - enum ParachainSetupStep { - /// A channel open has been requested - Requested, - /// A channel open has been requested and accepted. - Accepted, - /// A channel open has been requested and accepted, and a session has passed and is now open. - Established, - /// A channel open has been requested and accepted, and a session has passed and is now - /// open, and now it has been requested to close down. - CloseRequested, - } - - fn establish_para_connection( - from: u32, - to: u32, - until: ParachainSetupStep, - ) -> [(ParaId, crate::Origin); 2] - where - ::Origin: From, - { - let config = Configuration::::config(); - let deposit: BalanceOf = config.hrmp_sender_deposit.unique_saturated_into(); - let capacity = config.hrmp_channel_max_capacity; - let message_size = config.hrmp_channel_max_message_size; - - let sender: ParaId = from.into(); - let sender_origin: crate::Origin = from.into(); - - let recipient: ParaId = to.into(); - let recipient_origin: crate::Origin = to.into(); - - let output = [(sender, sender_origin.clone()), (recipient, recipient_origin.clone())]; - - // Make both a parachain if they are already not. - if !Paras::::is_parachain(sender) { - register_parachain_with_balance::(sender, deposit); - } - if !Paras::::is_parachain(recipient) { - register_parachain_with_balance::(recipient, deposit); - } - - assert_ok!(Hrmp::::hrmp_init_open_channel( - sender_origin.clone().into(), - recipient, - capacity, - message_size - )); - if matches!(until, ParachainSetupStep::Requested) { - return output - } - - assert_ok!(Hrmp::::hrmp_accept_open_channel(recipient_origin.into(), sender)); - if matches!(until, ParachainSetupStep::Accepted) { - return output - } - - Hrmp::::process_hrmp_open_channel_requests(&Configuration::::config()); - if matches!(until, ParachainSetupStep::Established) { - return output - } - - let channel_id = HrmpChannelId { sender, recipient }; - assert_ok!(Hrmp::::hrmp_close_channel(sender_origin.clone().into(), channel_id)); - if matches!(until, ParachainSetupStep::CloseRequested) { - // NOTE: this is just for expressiveness, otherwise the if-statement could be omitted. - return output - } - - output - } - - const PREFIX_0: u32 = 10_000; - const PREFIX_1: u32 = PREFIX_0 * 2; - const MAX_UNIQUE_CHANNELS: u32 = 128; - - frame_benchmarking::benchmarks! { - where_clause { where ::Origin: From } - - hrmp_init_open_channel { - let sender_id: ParaId = 1u32.into(); - let sender_origin: crate::Origin = 1u32.into(); - - let recipient_id: ParaId = 2u32.into(); - - // make sure para is registered, and has enough balance. - let deposit: BalanceOf = Configuration::::config().hrmp_sender_deposit.unique_saturated_into(); - register_parachain_with_balance::(sender_id, deposit); - register_parachain_with_balance::(recipient_id, deposit); - - let capacity = Configuration::::config().hrmp_channel_max_capacity; - let message_size = Configuration::::config().hrmp_channel_max_message_size; - }: _(sender_origin, recipient_id, capacity, message_size) - verify { - assert_last_event::( - Event::::OpenChannelRequested(sender_id, recipient_id, capacity, message_size).into() - ); - } - - hrmp_accept_open_channel { - let [(sender, _), (recipient, recipient_origin)] = establish_para_connection::(1, 2, ParachainSetupStep::Requested); - }: _(recipient_origin, sender) - verify { - assert_last_event::(Event::::OpenChannelAccepted(sender, recipient).into()); - } - - hrmp_close_channel { - let [(sender, sender_origin), (recipient, _)] = establish_para_connection::(1, 2, ParachainSetupStep::Established); - let channel_id = HrmpChannelId { sender, recipient }; - }: _(sender_origin, channel_id.clone()) - verify { - assert_last_event::(Event::::ChannelClosed(sender, channel_id).into()); - } - - force_clean_hrmp { - // ingress channels to a single leaving parachain that need to be closed. - let i in 0 .. (::HrmpMaxInboundChannelsBound::get() - 1); - // egress channels to a single leaving parachain that need to be closed. - let e in 0 .. (::HrmpMaxOutboundChannelsBound::get() - 1); - - // we use 10_000 in this benchmark as the prefix of accounts. The components must be - // than that to keep accounts sane. - assert!(::HrmpMaxInboundChannelsBound::get() < PREFIX_0); - assert!(::HrmpMaxOutboundChannelsBound::get() < PREFIX_0); - - // first, update the configs to support this many open channels... - assert_ok!(Configuration::::set_hrmp_max_parachain_outbound_channels(frame_system::RawOrigin::Root.into(), e + 1)); - assert_ok!(Configuration::::set_hrmp_max_parachain_inbound_channels(frame_system::RawOrigin::Root.into(), i + 1)); - // .. and enact it. - Configuration::::initializer_on_new_session(&Shared::::scheduled_session()); - - let config = Configuration::::config(); - let deposit: BalanceOf = config.hrmp_sender_deposit.unique_saturated_into(); - - let para: ParaId = 1u32.into(); - let para_origin: crate::Origin = 1u32.into(); - register_parachain_with_balance::(para, deposit); - T::Currency::make_free_balance_be(¶.into_account(), deposit * 256u32.into()); - - for ingress_para_id in 0..i { - // establish ingress channels to `para`. - let ingress_para_id = ingress_para_id + PREFIX_0; - let _ = establish_para_connection::(ingress_para_id, 1, ParachainSetupStep::Established); - } - - // nothing should be left unprocessed. - assert_eq!(HrmpOpenChannelRequestsList::::decode_len().unwrap_or_default(), 0); - - for egress_para_id in 0..e { - // establish egress channels to `para`. - let egress_para_id = egress_para_id + PREFIX_1; - let _ = establish_para_connection::(1, egress_para_id, ParachainSetupStep::Established); - } - - // nothing should be left unprocessed. - assert_eq!(HrmpOpenChannelRequestsList::::decode_len().unwrap_or_default(), 0); - - // all in all, we have created these many channels - assert_eq!(HrmpChannels::::iter().count() as u32, i + e); - }: _(frame_system::Origin::::Root, para, i, e) verify { - // all in all, all of them must be gone by now. - assert_eq!(HrmpChannels::::iter().count() as u32, 0); - } - - force_process_hrmp_open { - // number of channels that need to be processed. Worse case is an N-M relation: unique - // sender and recipients for all channels. - let c in 0 .. MAX_UNIQUE_CHANNELS; - - for id in 0 .. c { - let _ = establish_para_connection::(PREFIX_0 + id, PREFIX_1 + id, ParachainSetupStep::Accepted); - } - assert_eq!(HrmpOpenChannelRequestsList::::decode_len().unwrap_or_default() as u32, c); - }: _(frame_system::Origin::::Root, c) - verify { - assert_eq!(HrmpOpenChannelRequestsList::::decode_len().unwrap_or_default() as u32, 0); - } - - force_process_hrmp_close { - // number of channels that need to be processed. Worse case is an N-M relation: unique - // sender and recipients for all channels. - let c in 0 .. MAX_UNIQUE_CHANNELS; - - for id in 0 .. c { - let _ = establish_para_connection::(PREFIX_0 + id, PREFIX_1 + id, ParachainSetupStep::CloseRequested); - } - - assert_eq!(HrmpCloseChannelRequestsList::::decode_len().unwrap_or_default() as u32, c); - }: _(frame_system::Origin::::Root, c) - verify { - assert_eq!(HrmpCloseChannelRequestsList::::decode_len().unwrap_or_default() as u32, 0); - } - - hrmp_cancel_open_request { - // number of items already existing in the `HrmpOpenChannelRequestsList`, other than the - // one that we remove. - let c in 0 .. MAX_UNIQUE_CHANNELS; - - for id in 0 .. c { - let _ = establish_para_connection::(PREFIX_0 + id, PREFIX_1 + id, ParachainSetupStep::Requested); - } - - let [(sender, sender_origin), (recipient, _)] = establish_para_connection::(1, 2, ParachainSetupStep::Requested); - assert_eq!(HrmpOpenChannelRequestsList::::decode_len().unwrap_or_default() as u32, c + 1); - let channel_id = HrmpChannelId { sender, recipient }; - }: _(sender_origin, channel_id, c) - verify { - assert_eq!(HrmpOpenChannelRequestsList::::decode_len().unwrap_or_default() as u32, c); - } - } - - frame_benchmarking::impl_benchmark_test_suite!( - Hrmp, - crate::mock::new_test_ext(super::tests::GenesisConfigBuilder::default().build()), - crate::mock::Test - ); -} diff --git a/runtime/parachains/src/hrmp/benchmarking.rs b/runtime/parachains/src/hrmp/benchmarking.rs new file mode 100644 index 000000000000..ac2e46873562 --- /dev/null +++ b/runtime/parachains/src/hrmp/benchmarking.rs @@ -0,0 +1,262 @@ +// Copyright 2021 Parity Technologies (UK) Ltd. +// This file is part of Polkadot. + +// Polkadot is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// Polkadot is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with Polkadot. If not, see . + +use crate::{ + configuration::Pallet as Configuration, + hrmp::{Pallet as Hrmp, *}, + paras::Pallet as Paras, + shared::Pallet as Shared, +}; +use frame_support::{assert_ok, traits::Currency}; + +type BalanceOf = + <::Currency as Currency<::AccountId>>::Balance; + +fn register_parachain_with_balance(id: ParaId, balance: BalanceOf) { + assert_ok!(Paras::::initialize_para_now( + id, + crate::paras::ParaGenesisArgs { + parachain: true, + genesis_head: vec![1].into(), + validation_code: vec![1].into(), + }, + )); + T::Currency::make_free_balance_be(&id.into_account(), balance); +} + +fn assert_last_event(generic_event: ::Event) { + let events = frame_system::Pallet::::events(); + let system_event: ::Event = generic_event.into(); + // compare to the last event record + let frame_system::EventRecord { event, .. } = &events[events.len() - 1]; + assert_eq!(event, &system_event); +} + +enum ParachainSetupStep { + /// A channel open has been requested + Requested, + /// A channel open has been requested and accepted. + Accepted, + /// A channel open has been requested and accepted, and a session has passed and is now open. + Established, + /// A channel open has been requested and accepted, and a session has passed and is now + /// open, and now it has been requested to close down. + CloseRequested, +} + +fn establish_para_connection( + from: u32, + to: u32, + until: ParachainSetupStep, +) -> [(ParaId, crate::Origin); 2] +where + ::Origin: From, +{ + let config = Configuration::::config(); + let deposit: BalanceOf = config.hrmp_sender_deposit.unique_saturated_into(); + let capacity = config.hrmp_channel_max_capacity; + let message_size = config.hrmp_channel_max_message_size; + + let sender: ParaId = from.into(); + let sender_origin: crate::Origin = from.into(); + + let recipient: ParaId = to.into(); + let recipient_origin: crate::Origin = to.into(); + + let output = [(sender, sender_origin.clone()), (recipient, recipient_origin.clone())]; + + // Make both a parachain if they are already not. + if !Paras::::is_parachain(sender) { + register_parachain_with_balance::(sender, deposit); + } + if !Paras::::is_parachain(recipient) { + register_parachain_with_balance::(recipient, deposit); + } + + assert_ok!(Hrmp::::hrmp_init_open_channel( + sender_origin.clone().into(), + recipient, + capacity, + message_size + )); + if matches!(until, ParachainSetupStep::Requested) { + return output + } + + assert_ok!(Hrmp::::hrmp_accept_open_channel(recipient_origin.into(), sender)); + if matches!(until, ParachainSetupStep::Accepted) { + return output + } + + Hrmp::::process_hrmp_open_channel_requests(&Configuration::::config()); + if matches!(until, ParachainSetupStep::Established) { + return output + } + + let channel_id = HrmpChannelId { sender, recipient }; + assert_ok!(Hrmp::::hrmp_close_channel(sender_origin.clone().into(), channel_id)); + if matches!(until, ParachainSetupStep::CloseRequested) { + // NOTE: this is just for expressiveness, otherwise the if-statement could be omitted. + return output + } + + output +} + +const PREFIX_0: u32 = 10_000; +const PREFIX_1: u32 = PREFIX_0 * 2; +const MAX_UNIQUE_CHANNELS: u32 = 128; + +frame_benchmarking::benchmarks! { + where_clause { where ::Origin: From } + + hrmp_init_open_channel { + let sender_id: ParaId = 1u32.into(); + let sender_origin: crate::Origin = 1u32.into(); + + let recipient_id: ParaId = 2u32.into(); + + // make sure para is registered, and has enough balance. + let deposit: BalanceOf = Configuration::::config().hrmp_sender_deposit.unique_saturated_into(); + register_parachain_with_balance::(sender_id, deposit); + register_parachain_with_balance::(recipient_id, deposit); + + let capacity = Configuration::::config().hrmp_channel_max_capacity; + let message_size = Configuration::::config().hrmp_channel_max_message_size; + }: _(sender_origin, recipient_id, capacity, message_size) + verify { + assert_last_event::( + Event::::OpenChannelRequested(sender_id, recipient_id, capacity, message_size).into() + ); + } + + hrmp_accept_open_channel { + let [(sender, _), (recipient, recipient_origin)] = establish_para_connection::(1, 2, ParachainSetupStep::Requested); + }: _(recipient_origin, sender) + verify { + assert_last_event::(Event::::OpenChannelAccepted(sender, recipient).into()); + } + + hrmp_close_channel { + let [(sender, sender_origin), (recipient, _)] = establish_para_connection::(1, 2, ParachainSetupStep::Established); + let channel_id = HrmpChannelId { sender, recipient }; + }: _(sender_origin, channel_id.clone()) + verify { + assert_last_event::(Event::::ChannelClosed(sender, channel_id).into()); + } + + force_clean_hrmp { + // ingress channels to a single leaving parachain that need to be closed. + let i in 0 .. (::HrmpMaxInboundChannelsBound::get() - 1); + // egress channels to a single leaving parachain that need to be closed. + let e in 0 .. (::HrmpMaxOutboundChannelsBound::get() - 1); + + // we use 10_000 in this benchmark as the prefix of accounts. The components must be + // than that to keep accounts sane. + assert!(::HrmpMaxInboundChannelsBound::get() < PREFIX_0); + assert!(::HrmpMaxOutboundChannelsBound::get() < PREFIX_0); + + // first, update the configs to support this many open channels... + assert_ok!(Configuration::::set_hrmp_max_parachain_outbound_channels(frame_system::RawOrigin::Root.into(), e + 1)); + assert_ok!(Configuration::::set_hrmp_max_parachain_inbound_channels(frame_system::RawOrigin::Root.into(), i + 1)); + // .. and enact it. + Configuration::::initializer_on_new_session(&Shared::::scheduled_session()); + + let config = Configuration::::config(); + let deposit: BalanceOf = config.hrmp_sender_deposit.unique_saturated_into(); + + let para: ParaId = 1u32.into(); + let para_origin: crate::Origin = 1u32.into(); + register_parachain_with_balance::(para, deposit); + T::Currency::make_free_balance_be(¶.into_account(), deposit * 256u32.into()); + + for ingress_para_id in 0..i { + // establish ingress channels to `para`. + let ingress_para_id = ingress_para_id + PREFIX_0; + let _ = establish_para_connection::(ingress_para_id, 1, ParachainSetupStep::Established); + } + + // nothing should be left unprocessed. + assert_eq!(HrmpOpenChannelRequestsList::::decode_len().unwrap_or_default(), 0); + + for egress_para_id in 0..e { + // establish egress channels to `para`. + let egress_para_id = egress_para_id + PREFIX_1; + let _ = establish_para_connection::(1, egress_para_id, ParachainSetupStep::Established); + } + + // nothing should be left unprocessed. + assert_eq!(HrmpOpenChannelRequestsList::::decode_len().unwrap_or_default(), 0); + + // all in all, we have created these many channels + assert_eq!(HrmpChannels::::iter().count() as u32, i + e); + }: _(frame_system::Origin::::Root, para, i, e) verify { + // all in all, all of them must be gone by now. + assert_eq!(HrmpChannels::::iter().count() as u32, 0); + } + + force_process_hrmp_open { + // number of channels that need to be processed. Worse case is an N-M relation: unique + // sender and recipients for all channels. + let c in 0 .. MAX_UNIQUE_CHANNELS; + + for id in 0 .. c { + let _ = establish_para_connection::(PREFIX_0 + id, PREFIX_1 + id, ParachainSetupStep::Accepted); + } + assert_eq!(HrmpOpenChannelRequestsList::::decode_len().unwrap_or_default() as u32, c); + }: _(frame_system::Origin::::Root, c) + verify { + assert_eq!(HrmpOpenChannelRequestsList::::decode_len().unwrap_or_default() as u32, 0); + } + + force_process_hrmp_close { + // number of channels that need to be processed. Worse case is an N-M relation: unique + // sender and recipients for all channels. + let c in 0 .. MAX_UNIQUE_CHANNELS; + + for id in 0 .. c { + let _ = establish_para_connection::(PREFIX_0 + id, PREFIX_1 + id, ParachainSetupStep::CloseRequested); + } + + assert_eq!(HrmpCloseChannelRequestsList::::decode_len().unwrap_or_default() as u32, c); + }: _(frame_system::Origin::::Root, c) + verify { + assert_eq!(HrmpCloseChannelRequestsList::::decode_len().unwrap_or_default() as u32, 0); + } + + hrmp_cancel_open_request { + // number of items already existing in the `HrmpOpenChannelRequestsList`, other than the + // one that we remove. + let c in 0 .. MAX_UNIQUE_CHANNELS; + + for id in 0 .. c { + let _ = establish_para_connection::(PREFIX_0 + id, PREFIX_1 + id, ParachainSetupStep::Requested); + } + + let [(sender, sender_origin), (recipient, _)] = establish_para_connection::(1, 2, ParachainSetupStep::Requested); + assert_eq!(HrmpOpenChannelRequestsList::::decode_len().unwrap_or_default() as u32, c + 1); + let channel_id = HrmpChannelId { sender, recipient }; + }: _(sender_origin, channel_id, c) + verify { + assert_eq!(HrmpOpenChannelRequestsList::::decode_len().unwrap_or_default() as u32, c); + } +} + +frame_benchmarking::impl_benchmark_test_suite!( + Hrmp, + crate::mock::new_test_ext(crate::hrmp::tests::GenesisConfigBuilder::default().build()), + crate::mock::Test +); diff --git a/runtime/parachains/src/hrmp/weights.rs b/runtime/parachains/src/hrmp/weights.rs new file mode 100644 index 000000000000..24be7c556bf5 --- /dev/null +++ b/runtime/parachains/src/hrmp/weights.rs @@ -0,0 +1,110 @@ +// Copyright 2021 Parity Technologies (UK) Ltd. +// This file is part of Polkadot. + +// Polkadot is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// Polkadot is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with Polkadot. If not, see . + +use frame_support::weights::{constants::RocksDbWeight, Weight}; + +impl crate::hrmp::WeightInfo for () { + fn hrmp_init_open_channel() -> Weight { + (61_914_000 as Weight) + .saturating_add(RocksDbWeight::get().reads(10 as Weight)) + .saturating_add(RocksDbWeight::get().writes(5 as Weight)) + } + // Storage: Hrmp HrmpOpenChannelRequests (r:1 w:1) + // Storage: Configuration ActiveConfig (r:1 w:0) + // Storage: Paras ParaLifecycles (r:1 w:0) + // Storage: Hrmp HrmpIngressChannelsIndex (r:1 w:0) + // Storage: Hrmp HrmpAcceptedChannelRequestCount (r:1 w:1) + // Storage: Dmp DownwardMessageQueueHeads (r:1 w:1) + // Storage: Dmp DownwardMessageQueues (r:1 w:1) + fn hrmp_accept_open_channel() -> Weight { + (53_022_000 as Weight) + .saturating_add(RocksDbWeight::get().reads(7 as Weight)) + .saturating_add(RocksDbWeight::get().writes(4 as Weight)) + } + // Storage: Hrmp HrmpChannels (r:1 w:0) + // Storage: Hrmp HrmpCloseChannelRequests (r:1 w:1) + // Storage: Hrmp HrmpCloseChannelRequestsList (r:1 w:1) + // Storage: Configuration ActiveConfig (r:1 w:0) + // Storage: Dmp DownwardMessageQueueHeads (r:1 w:1) + // Storage: Dmp DownwardMessageQueues (r:1 w:1) + fn hrmp_close_channel() -> Weight { + (47_548_000 as Weight) + .saturating_add(RocksDbWeight::get().reads(6 as Weight)) + .saturating_add(RocksDbWeight::get().writes(4 as Weight)) + } + // Storage: Hrmp HrmpIngressChannelsIndex (r:128 w:127) + // Storage: Hrmp HrmpEgressChannelsIndex (r:1 w:1) + // Storage: Hrmp HrmpChannels (r:127 w:127) + // Storage: Hrmp HrmpAcceptedChannelRequestCount (r:0 w:1) + // Storage: Hrmp HrmpChannelContents (r:0 w:127) + // Storage: Hrmp HrmpOpenChannelRequestCount (r:0 w:1) + fn force_clean_hrmp(i: u32, e: u32) -> Weight { + (0 as Weight) + // Standard Error: 19_000 + .saturating_add((17_052_000 as Weight).saturating_mul(i as Weight)) + // Standard Error: 19_000 + .saturating_add((16_998_000 as Weight).saturating_mul(e as Weight)) + .saturating_add(RocksDbWeight::get().reads(2 as Weight)) + .saturating_add(RocksDbWeight::get().reads((2 as Weight).saturating_mul(i as Weight))) + .saturating_add(RocksDbWeight::get().reads((2 as Weight).saturating_mul(e as Weight))) + .saturating_add(RocksDbWeight::get().writes(4 as Weight)) + .saturating_add(RocksDbWeight::get().writes((3 as Weight).saturating_mul(i as Weight))) + .saturating_add(RocksDbWeight::get().writes((3 as Weight).saturating_mul(e as Weight))) + } + // Storage: Configuration ActiveConfig (r:1 w:0) + // Storage: Hrmp HrmpOpenChannelRequestsList (r:1 w:0) + // Storage: Hrmp HrmpOpenChannelRequests (r:2 w:2) + // Storage: Paras ParaLifecycles (r:4 w:0) + // Storage: Hrmp HrmpIngressChannelsIndex (r:2 w:2) + // Storage: Hrmp HrmpEgressChannelsIndex (r:2 w:2) + // Storage: Hrmp HrmpOpenChannelRequestCount (r:2 w:2) + // Storage: Hrmp HrmpAcceptedChannelRequestCount (r:2 w:2) + // Storage: Hrmp HrmpChannels (r:0 w:2) + fn force_process_hrmp_open(c: u32) -> Weight { + (0 as Weight) + // Standard Error: 28_000 + .saturating_add((37_628_000 as Weight).saturating_mul(c as Weight)) + .saturating_add(RocksDbWeight::get().reads(2 as Weight)) + .saturating_add(RocksDbWeight::get().reads((7 as Weight).saturating_mul(c as Weight))) + .saturating_add(RocksDbWeight::get().writes(1 as Weight)) + .saturating_add(RocksDbWeight::get().writes((6 as Weight).saturating_mul(c as Weight))) + } + // Storage: Hrmp HrmpCloseChannelRequestsList (r:1 w:0) + // Storage: Hrmp HrmpChannels (r:2 w:2) + // Storage: Hrmp HrmpEgressChannelsIndex (r:2 w:2) + // Storage: Hrmp HrmpIngressChannelsIndex (r:2 w:2) + // Storage: Hrmp HrmpCloseChannelRequests (r:0 w:2) + // Storage: Hrmp HrmpChannelContents (r:0 w:2) + fn force_process_hrmp_close(c: u32) -> Weight { + (0 as Weight) + // Standard Error: 17_000 + .saturating_add((21_825_000 as Weight).saturating_mul(c as Weight)) + .saturating_add(RocksDbWeight::get().reads(1 as Weight)) + .saturating_add(RocksDbWeight::get().reads((3 as Weight).saturating_mul(c as Weight))) + .saturating_add(RocksDbWeight::get().writes(1 as Weight)) + .saturating_add(RocksDbWeight::get().writes((5 as Weight).saturating_mul(c as Weight))) + } + // Storage: Hrmp HrmpOpenChannelRequests (r:1 w:1) + // Storage: Hrmp HrmpOpenChannelRequestsList (r:1 w:1) + // Storage: Hrmp HrmpOpenChannelRequestCount (r:1 w:1) + fn hrmp_cancel_open_request(c: u32) -> Weight { + (35_031_000 as Weight) + // Standard Error: 0 + .saturating_add((56_000 as Weight).saturating_mul(c as Weight)) + .saturating_add(RocksDbWeight::get().reads(3 as Weight)) + .saturating_add(RocksDbWeight::get().writes(3 as Weight)) + } +} From 80501a07a24fb3fc9ee9046f3ab83a6f02cf4169 Mon Sep 17 00:00:00 2001 From: kianenigma Date: Thu, 4 Nov 2021 17:05:25 +0100 Subject: [PATCH 19/36] minor cleanup --- runtime/parachains/src/hrmp/benchmarking.rs | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/runtime/parachains/src/hrmp/benchmarking.rs b/runtime/parachains/src/hrmp/benchmarking.rs index ac2e46873562..cf047903b09c 100644 --- a/runtime/parachains/src/hrmp/benchmarking.rs +++ b/runtime/parachains/src/hrmp/benchmarking.rs @@ -45,6 +45,7 @@ fn assert_last_event(generic_event: ::Event) { assert_eq!(event, &system_event); } +/// Enumerates the phase in the setup process of a channel between two parachains. enum ParachainSetupStep { /// A channel open has been requested Requested, @@ -92,6 +93,7 @@ where capacity, message_size )); + if matches!(until, ParachainSetupStep::Requested) { return output } @@ -109,7 +111,7 @@ where let channel_id = HrmpChannelId { sender, recipient }; assert_ok!(Hrmp::::hrmp_close_channel(sender_origin.clone().into(), channel_id)); if matches!(until, ParachainSetupStep::CloseRequested) { - // NOTE: this is just for expressiveness, otherwise the if-statement could be omitted. + // NOTE: this is just for expressiveness, otherwise the if-statement is 100% useless. return output } @@ -158,14 +160,16 @@ frame_benchmarking::benchmarks! { assert_last_event::(Event::::ChannelClosed(sender, channel_id).into()); } + // NOTE: a single parachain should have the maximum number of allowed ingress and egress + // channels. force_clean_hrmp { // ingress channels to a single leaving parachain that need to be closed. let i in 0 .. (::HrmpMaxInboundChannelsBound::get() - 1); // egress channels to a single leaving parachain that need to be closed. let e in 0 .. (::HrmpMaxOutboundChannelsBound::get() - 1); - // we use 10_000 in this benchmark as the prefix of accounts. The components must be - // than that to keep accounts sane. + // we use 10_000 in this benchmark as the prefix of accounts. The components must be greater + // than the configured bounds to keep accounts sane. assert!(::HrmpMaxInboundChannelsBound::get() < PREFIX_0); assert!(::HrmpMaxOutboundChannelsBound::get() < PREFIX_0); @@ -201,7 +205,7 @@ frame_benchmarking::benchmarks! { // nothing should be left unprocessed. assert_eq!(HrmpOpenChannelRequestsList::::decode_len().unwrap_or_default(), 0); - // all in all, we have created these many channels + // all in all, we have created this many channels. assert_eq!(HrmpChannels::::iter().count() as u32, i + e); }: _(frame_system::Origin::::Root, para, i, e) verify { // all in all, all of them must be gone by now. @@ -213,6 +217,7 @@ frame_benchmarking::benchmarks! { // sender and recipients for all channels. let c in 0 .. MAX_UNIQUE_CHANNELS; + assert!(MAX_UNIQUE_CHANNELS < PREFIX_0, "PREFIX_0 must always be more than MAX_UNIQUE_CHANNELS"); for id in 0 .. c { let _ = establish_para_connection::(PREFIX_0 + id, PREFIX_1 + id, ParachainSetupStep::Accepted); } @@ -227,6 +232,7 @@ frame_benchmarking::benchmarks! { // sender and recipients for all channels. let c in 0 .. MAX_UNIQUE_CHANNELS; + assert!(MAX_UNIQUE_CHANNELS < PREFIX_0, "PREFIX_0 must always be more than MAX_UNIQUE_CHANNELS"); for id in 0 .. c { let _ = establish_para_connection::(PREFIX_0 + id, PREFIX_1 + id, ParachainSetupStep::CloseRequested); } @@ -242,6 +248,7 @@ frame_benchmarking::benchmarks! { // one that we remove. let c in 0 .. MAX_UNIQUE_CHANNELS; + assert!(MAX_UNIQUE_CHANNELS < PREFIX_0, "PREFIX_0 must always be more than MAX_UNIQUE_CHANNELS"); for id in 0 .. c { let _ = establish_para_connection::(PREFIX_0 + id, PREFIX_1 + id, ParachainSetupStep::Requested); } From 2b05e62b91c5029299adbd6a347d4e34d3cbf7e1 Mon Sep 17 00:00:00 2001 From: kianenigma Date: Thu, 4 Nov 2021 18:43:59 +0100 Subject: [PATCH 20/36] weigh some of the internal stuff as well --- .../src/weights/runtime_parachains_hrmp.rs | 4 +++ runtime/parachains/src/hrmp.rs | 36 +++++++++++++++---- runtime/parachains/src/hrmp/benchmarking.rs | 20 +++++++++++ runtime/parachains/src/hrmp/weights.rs | 4 +++ runtime/polkadot/src/lib.rs | 2 +- .../src/weights/runtime_parachains_hrmp.rs | 3 ++ 6 files changed, 62 insertions(+), 7 deletions(-) diff --git a/runtime/kusama/src/weights/runtime_parachains_hrmp.rs b/runtime/kusama/src/weights/runtime_parachains_hrmp.rs index a57cc91b8f97..366819f1906d 100644 --- a/runtime/kusama/src/weights/runtime_parachains_hrmp.rs +++ b/runtime/kusama/src/weights/runtime_parachains_hrmp.rs @@ -143,4 +143,8 @@ impl runtime_parachains::hrmp::WeightInfo for WeightInf .saturating_add(T::DbWeight::get().reads(3 as Weight)) .saturating_add(T::DbWeight::get().writes(3 as Weight)) } + + fn clean_open_channel_requests(_: u32) -> Weight { + 0 + } } diff --git a/runtime/parachains/src/hrmp.rs b/runtime/parachains/src/hrmp.rs index 266201936ccf..8a42c60a682e 100644 --- a/runtime/parachains/src/hrmp.rs +++ b/runtime/parachains/src/hrmp.rs @@ -47,6 +47,7 @@ pub trait WeightInfo { fn force_process_hrmp_open(c: u32) -> Weight; fn force_process_hrmp_close(c: u32) -> Weight; fn hrmp_cancel_open_request(c: u32) -> Weight; + fn clean_open_channel_requests(c: u32) -> Weight; } pub struct TestWeightInfo; @@ -72,6 +73,9 @@ impl WeightInfo for TestWeightInfo { fn hrmp_init_open_channel() -> Weight { 1000_000_000 } + fn clean_open_channel_requests(_: u32) -> Weight { + 1000_000_000 + } } /// A description of a request to open an HRMP channel. @@ -594,10 +598,16 @@ impl Pallet { pub(crate) fn initializer_on_new_session( notification: &initializer::SessionChangeNotification, outgoing_paras: &[ParaId], - ) { - Self::perform_outgoing_para_cleanup(¬ification.prev_config, outgoing_paras); + ) -> Weight { + let w1 = Self::perform_outgoing_para_cleanup(¬ification.prev_config, outgoing_paras); Self::process_hrmp_open_channel_requests(¬ification.prev_config); Self::process_hrmp_close_channel_requests(); + w1.saturating_add(::WeightInfo::force_process_hrmp_open( + outgoing_paras.len() as u32 + )) + .saturating_add(::WeightInfo::force_process_hrmp_close( + outgoing_paras.len() as u32 + )) } /// Iterate over all paras that were noted for offboarding and remove all the data @@ -605,20 +615,32 @@ impl Pallet { fn perform_outgoing_para_cleanup( config: &HostConfiguration, outgoing: &[ParaId], - ) { - Self::clean_open_channel_requests(config, outgoing); + ) -> Weight { + let mut w = Self::clean_open_channel_requests(config, outgoing); for outgoing_para in outgoing { Self::clean_hrmp_after_outgoing(outgoing_para); + + // we need a few extra bits of data to weigh this -- all of this is read internally + // anyways, so no overhead. + let ingress_count = + ::HrmpIngressChannelsIndex::get(outgoing_para).len() as u32; + let egress_count = + ::HrmpEgressChannelsIndex::get(outgoing_para).len() as u32; + w = w.saturating_add(::WeightInfo::force_clean_hrmp( + ingress_count, + egress_count, + )); } + w } // Go over the HRMP open channel requests and remove all in which offboarding paras participate. // // This will also perform the refunds for the counterparty if it doesn't offboard. - fn clean_open_channel_requests( + pub fn clean_open_channel_requests( config: &HostConfiguration, outgoing: &[ParaId], - ) { + ) -> Weight { // First collect all the channel ids of the open requests in which there is at least one // party presents in the outgoing list. // @@ -664,6 +686,8 @@ impl Pallet { Self::decrease_accepted_channel_request_count(req_id.recipient); } } + + ::WeightInfo::clean_open_channel_requests(outgoing.len() as u32) } /// Remove all storage entries associated with the given para. diff --git a/runtime/parachains/src/hrmp/benchmarking.rs b/runtime/parachains/src/hrmp/benchmarking.rs index cf047903b09c..d082289870f8 100644 --- a/runtime/parachains/src/hrmp/benchmarking.rs +++ b/runtime/parachains/src/hrmp/benchmarking.rs @@ -260,6 +260,26 @@ frame_benchmarking::benchmarks! { verify { assert_eq!(HrmpOpenChannelRequestsList::::decode_len().unwrap_or_default() as u32, c); } + + // worse case will be `n` parachain channel requests, where in all of them either the sender or + // the recipient need to be cleaned. This enforces the deposit of at least one to be processed. + // No code path for triggering two deposit process exists. + clean_open_channel_requests { + let c in 0 .. MAX_UNIQUE_CHANNELS; + + assert!(MAX_UNIQUE_CHANNELS < PREFIX_0, "PREFIX_0 must always be more than MAX_UNIQUE_CHANNELS"); + for id in 0 .. c { + let _ = establish_para_connection::(PREFIX_0 + id, PREFIX_1 + id, ParachainSetupStep::Requested); + } + + assert_eq!(HrmpOpenChannelRequestsList::::decode_len().unwrap_or_default() as u32, c); + let outgoing = (0..c).map(|id| (id + PREFIX_1).into()).collect::>(); + let config = Configuration::::config(); + }: { + Hrmp::::clean_open_channel_requests(&config, &outgoing); + } verify { + assert_eq!(HrmpOpenChannelRequestsList::::decode_len().unwrap_or_default() as u32, 0); + } } frame_benchmarking::impl_benchmark_test_suite!( diff --git a/runtime/parachains/src/hrmp/weights.rs b/runtime/parachains/src/hrmp/weights.rs index 24be7c556bf5..09d87d396f63 100644 --- a/runtime/parachains/src/hrmp/weights.rs +++ b/runtime/parachains/src/hrmp/weights.rs @@ -107,4 +107,8 @@ impl crate::hrmp::WeightInfo for () { .saturating_add(RocksDbWeight::get().reads(3 as Weight)) .saturating_add(RocksDbWeight::get().writes(3 as Weight)) } + + fn clean_open_channel_requests(_: u32) -> Weight { + 0 + } } diff --git a/runtime/polkadot/src/lib.rs b/runtime/polkadot/src/lib.rs index c2662068ff67..c52e0cdf10fa 100644 --- a/runtime/polkadot/src/lib.rs +++ b/runtime/polkadot/src/lib.rs @@ -44,7 +44,7 @@ use frame_support::{ weights::Weight, PalletId, RuntimeDebug, }; -use frame_system::{EnsureOneOf, EnsureRoot, WeightInfo}; +use frame_system::{EnsureOneOf, EnsureRoot}; use pallet_grandpa::{fg_primitives, AuthorityId as GrandpaId}; use pallet_im_online::sr25519::AuthorityId as ImOnlineId; use pallet_mmr_primitives as mmr; diff --git a/runtime/westend/src/weights/runtime_parachains_hrmp.rs b/runtime/westend/src/weights/runtime_parachains_hrmp.rs index 1925eabdf9dc..d628d5109a52 100644 --- a/runtime/westend/src/weights/runtime_parachains_hrmp.rs +++ b/runtime/westend/src/weights/runtime_parachains_hrmp.rs @@ -143,4 +143,7 @@ impl runtime_parachains::hrmp::WeightInfo for WeightInf .saturating_add(T::DbWeight::get().reads(3 as Weight)) .saturating_add(T::DbWeight::get().writes(3 as Weight)) } + fn clean_open_channel_requests(_: u32) -> Weight { + 0 + } } From 7e0c420fd80a8d957a61c262659f6c37609d9ac3 Mon Sep 17 00:00:00 2001 From: Parity Bot Date: Fri, 5 Nov 2021 08:37:29 +0000 Subject: [PATCH 21/36] cargo run --quiet --release --features=runtime-benchmarks -- benchmark --chain=kusama-dev --steps=50 --repeat=20 --pallet=runtime_parachains::hrmp --extrinsic=* --execution=wasm --wasm-execution=compiled --heap-pages=4096 --header=./file_header.txt --output=./runtime/kusama/src/weights/runtime_parachains_hrmp.rs --- .../src/weights/runtime_parachains_hrmp.rs | 41 +++++++++++-------- 1 file changed, 24 insertions(+), 17 deletions(-) diff --git a/runtime/kusama/src/weights/runtime_parachains_hrmp.rs b/runtime/kusama/src/weights/runtime_parachains_hrmp.rs index 366819f1906d..de6e57873b8a 100644 --- a/runtime/kusama/src/weights/runtime_parachains_hrmp.rs +++ b/runtime/kusama/src/weights/runtime_parachains_hrmp.rs @@ -16,7 +16,7 @@ //! Autogenerated weights for `runtime_parachains::hrmp` //! //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev -//! DATE: 2021-09-21, STEPS: `50`, REPEAT: 20, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! DATE: 2021-11-05, STEPS: `50`, REPEAT: 20, LOW RANGE: `[]`, HIGH RANGE: `[]` //! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("kusama-dev"), DB CACHE: 128 // Executed Command: @@ -54,7 +54,7 @@ impl runtime_parachains::hrmp::WeightInfo for WeightInf // Storage: Dmp DownwardMessageQueueHeads (r:1 w:1) // Storage: Dmp DownwardMessageQueues (r:1 w:1) fn hrmp_init_open_channel() -> Weight { - (61_914_000 as Weight) + (54_952_000 as Weight) .saturating_add(T::DbWeight::get().reads(10 as Weight)) .saturating_add(T::DbWeight::get().writes(5 as Weight)) } @@ -66,7 +66,7 @@ impl runtime_parachains::hrmp::WeightInfo for WeightInf // Storage: Dmp DownwardMessageQueueHeads (r:1 w:1) // Storage: Dmp DownwardMessageQueues (r:1 w:1) fn hrmp_accept_open_channel() -> Weight { - (53_022_000 as Weight) + (47_965_000 as Weight) .saturating_add(T::DbWeight::get().reads(7 as Weight)) .saturating_add(T::DbWeight::get().writes(4 as Weight)) } @@ -77,7 +77,7 @@ impl runtime_parachains::hrmp::WeightInfo for WeightInf // Storage: Dmp DownwardMessageQueueHeads (r:1 w:1) // Storage: Dmp DownwardMessageQueues (r:1 w:1) fn hrmp_close_channel() -> Weight { - (47_548_000 as Weight) + (44_369_000 as Weight) .saturating_add(T::DbWeight::get().reads(6 as Weight)) .saturating_add(T::DbWeight::get().writes(4 as Weight)) } @@ -89,10 +89,10 @@ impl runtime_parachains::hrmp::WeightInfo for WeightInf // Storage: Hrmp HrmpOpenChannelRequestCount (r:0 w:1) fn force_clean_hrmp(i: u32, e: u32, ) -> Weight { (0 as Weight) - // Standard Error: 19_000 - .saturating_add((17_052_000 as Weight).saturating_mul(i as Weight)) - // Standard Error: 19_000 - .saturating_add((16_998_000 as Weight).saturating_mul(e as Weight)) + // Standard Error: 17_000 + .saturating_add((15_959_000 as Weight).saturating_mul(i as Weight)) + // Standard Error: 17_000 + .saturating_add((16_048_000 as Weight).saturating_mul(e as Weight)) .saturating_add(T::DbWeight::get().reads(2 as Weight)) .saturating_add(T::DbWeight::get().reads((2 as Weight).saturating_mul(i as Weight))) .saturating_add(T::DbWeight::get().reads((2 as Weight).saturating_mul(e as Weight))) @@ -111,8 +111,8 @@ impl runtime_parachains::hrmp::WeightInfo for WeightInf // Storage: Hrmp HrmpChannels (r:0 w:2) fn force_process_hrmp_open(c: u32, ) -> Weight { (0 as Weight) - // Standard Error: 28_000 - .saturating_add((37_628_000 as Weight).saturating_mul(c as Weight)) + // Standard Error: 26_000 + .saturating_add((35_598_000 as Weight).saturating_mul(c as Weight)) .saturating_add(T::DbWeight::get().reads(2 as Weight)) .saturating_add(T::DbWeight::get().reads((7 as Weight).saturating_mul(c as Weight))) .saturating_add(T::DbWeight::get().writes(1 as Weight)) @@ -126,8 +126,8 @@ impl runtime_parachains::hrmp::WeightInfo for WeightInf // Storage: Hrmp HrmpChannelContents (r:0 w:2) fn force_process_hrmp_close(c: u32, ) -> Weight { (0 as Weight) - // Standard Error: 17_000 - .saturating_add((21_825_000 as Weight).saturating_mul(c as Weight)) + // Standard Error: 15_000 + .saturating_add((20_510_000 as Weight).saturating_mul(c as Weight)) .saturating_add(T::DbWeight::get().reads(1 as Weight)) .saturating_add(T::DbWeight::get().reads((3 as Weight).saturating_mul(c as Weight))) .saturating_add(T::DbWeight::get().writes(1 as Weight)) @@ -137,14 +137,21 @@ impl runtime_parachains::hrmp::WeightInfo for WeightInf // Storage: Hrmp HrmpOpenChannelRequestsList (r:1 w:1) // Storage: Hrmp HrmpOpenChannelRequestCount (r:1 w:1) fn hrmp_cancel_open_request(c: u32, ) -> Weight { - (35_031_000 as Weight) + (32_749_000 as Weight) // Standard Error: 0 - .saturating_add((56_000 as Weight).saturating_mul(c as Weight)) + .saturating_add((59_000 as Weight).saturating_mul(c as Weight)) .saturating_add(T::DbWeight::get().reads(3 as Weight)) .saturating_add(T::DbWeight::get().writes(3 as Weight)) } - - fn clean_open_channel_requests(_: u32) -> Weight { - 0 + // Storage: Hrmp HrmpOpenChannelRequestsList (r:1 w:1) + // Storage: Hrmp HrmpOpenChannelRequests (r:2 w:2) + fn clean_open_channel_requests(c: u32, ) -> Weight { + (0 as Weight) + // Standard Error: 6_000 + .saturating_add((5_781_000 as Weight).saturating_mul(c as Weight)) + .saturating_add(T::DbWeight::get().reads(1 as Weight)) + .saturating_add(T::DbWeight::get().reads((1 as Weight).saturating_mul(c as Weight))) + .saturating_add(T::DbWeight::get().writes(1 as Weight)) + .saturating_add(T::DbWeight::get().writes((1 as Weight).saturating_mul(c as Weight))) } } From 6a2f9917b4bb162134aa226a79c29ac401fd7525 Mon Sep 17 00:00:00 2001 From: Parity Bot Date: Fri, 5 Nov 2021 08:50:11 +0000 Subject: [PATCH 22/36] cargo run --quiet --release --features=runtime-benchmarks -- benchmark --chain=westend-dev --steps=50 --repeat=20 --pallet=runtime_parachains::hrmp --extrinsic=* --execution=wasm --wasm-execution=compiled --heap-pages=4096 --header=./file_header.txt --output=./runtime/westend/src/weights/runtime_parachains_hrmp.rs --- .../src/weights/runtime_parachains_hrmp.rs | 52 ++++++++++--------- 1 file changed, 28 insertions(+), 24 deletions(-) diff --git a/runtime/westend/src/weights/runtime_parachains_hrmp.rs b/runtime/westend/src/weights/runtime_parachains_hrmp.rs index d628d5109a52..72a12c67e879 100644 --- a/runtime/westend/src/weights/runtime_parachains_hrmp.rs +++ b/runtime/westend/src/weights/runtime_parachains_hrmp.rs @@ -16,7 +16,7 @@ //! Autogenerated weights for `runtime_parachains::hrmp` //! //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev -//! DATE: 2021-09-21, STEPS: `50`, REPEAT: 20, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! DATE: 2021-11-05, STEPS: `50`, REPEAT: 20, LOW RANGE: `[]`, HIGH RANGE: `[]` //! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("westend-dev"), DB CACHE: 128 // Executed Command: @@ -45,7 +45,6 @@ use sp_std::marker::PhantomData; pub struct WeightInfo(PhantomData); impl runtime_parachains::hrmp::WeightInfo for WeightInfo { // Storage: Paras ParaLifecycles (r:2 w:0) - // Storage: Configuration ActiveConfig (r:1 w:0) // Storage: Hrmp HrmpOpenChannelRequests (r:1 w:1) // Storage: Hrmp HrmpChannels (r:1 w:0) // Storage: Hrmp HrmpEgressChannelsIndex (r:1 w:0) @@ -54,31 +53,29 @@ impl runtime_parachains::hrmp::WeightInfo for WeightInf // Storage: Dmp DownwardMessageQueueHeads (r:1 w:1) // Storage: Dmp DownwardMessageQueues (r:1 w:1) fn hrmp_init_open_channel() -> Weight { - (60_060_000 as Weight) - .saturating_add(T::DbWeight::get().reads(10 as Weight)) + (55_142_000 as Weight) + .saturating_add(T::DbWeight::get().reads(9 as Weight)) .saturating_add(T::DbWeight::get().writes(5 as Weight)) } // Storage: Hrmp HrmpOpenChannelRequests (r:1 w:1) - // Storage: Configuration ActiveConfig (r:1 w:0) // Storage: Paras ParaLifecycles (r:1 w:0) // Storage: Hrmp HrmpIngressChannelsIndex (r:1 w:0) // Storage: Hrmp HrmpAcceptedChannelRequestCount (r:1 w:1) // Storage: Dmp DownwardMessageQueueHeads (r:1 w:1) // Storage: Dmp DownwardMessageQueues (r:1 w:1) fn hrmp_accept_open_channel() -> Weight { - (52_262_000 as Weight) - .saturating_add(T::DbWeight::get().reads(7 as Weight)) + (47_170_000 as Weight) + .saturating_add(T::DbWeight::get().reads(6 as Weight)) .saturating_add(T::DbWeight::get().writes(4 as Weight)) } // Storage: Hrmp HrmpChannels (r:1 w:0) // Storage: Hrmp HrmpCloseChannelRequests (r:1 w:1) // Storage: Hrmp HrmpCloseChannelRequestsList (r:1 w:1) - // Storage: Configuration ActiveConfig (r:1 w:0) // Storage: Dmp DownwardMessageQueueHeads (r:1 w:1) // Storage: Dmp DownwardMessageQueues (r:1 w:1) fn hrmp_close_channel() -> Weight { - (46_844_000 as Weight) - .saturating_add(T::DbWeight::get().reads(6 as Weight)) + (43_586_000 as Weight) + .saturating_add(T::DbWeight::get().reads(5 as Weight)) .saturating_add(T::DbWeight::get().writes(4 as Weight)) } // Storage: Hrmp HrmpIngressChannelsIndex (r:128 w:127) @@ -89,10 +86,10 @@ impl runtime_parachains::hrmp::WeightInfo for WeightInf // Storage: Hrmp HrmpOpenChannelRequestCount (r:0 w:1) fn force_clean_hrmp(i: u32, e: u32, ) -> Weight { (0 as Weight) - // Standard Error: 19_000 - .saturating_add((16_896_000 as Weight).saturating_mul(i as Weight)) - // Standard Error: 19_000 - .saturating_add((17_023_000 as Weight).saturating_mul(e as Weight)) + // Standard Error: 21_000 + .saturating_add((15_726_000 as Weight).saturating_mul(i as Weight)) + // Standard Error: 21_000 + .saturating_add((15_859_000 as Weight).saturating_mul(e as Weight)) .saturating_add(T::DbWeight::get().reads(2 as Weight)) .saturating_add(T::DbWeight::get().reads((2 as Weight).saturating_mul(i as Weight))) .saturating_add(T::DbWeight::get().reads((2 as Weight).saturating_mul(e as Weight))) @@ -100,7 +97,6 @@ impl runtime_parachains::hrmp::WeightInfo for WeightInf .saturating_add(T::DbWeight::get().writes((3 as Weight).saturating_mul(i as Weight))) .saturating_add(T::DbWeight::get().writes((3 as Weight).saturating_mul(e as Weight))) } - // Storage: Configuration ActiveConfig (r:1 w:0) // Storage: Hrmp HrmpOpenChannelRequestsList (r:1 w:0) // Storage: Hrmp HrmpOpenChannelRequests (r:2 w:2) // Storage: Paras ParaLifecycles (r:4 w:0) @@ -111,9 +107,9 @@ impl runtime_parachains::hrmp::WeightInfo for WeightInf // Storage: Hrmp HrmpChannels (r:0 w:2) fn force_process_hrmp_open(c: u32, ) -> Weight { (0 as Weight) - // Standard Error: 29_000 - .saturating_add((37_245_000 as Weight).saturating_mul(c as Weight)) - .saturating_add(T::DbWeight::get().reads(2 as Weight)) + // Standard Error: 24_000 + .saturating_add((35_104_000 as Weight).saturating_mul(c as Weight)) + .saturating_add(T::DbWeight::get().reads(1 as Weight)) .saturating_add(T::DbWeight::get().reads((7 as Weight).saturating_mul(c as Weight))) .saturating_add(T::DbWeight::get().writes(1 as Weight)) .saturating_add(T::DbWeight::get().writes((6 as Weight).saturating_mul(c as Weight))) @@ -126,8 +122,8 @@ impl runtime_parachains::hrmp::WeightInfo for WeightInf // Storage: Hrmp HrmpChannelContents (r:0 w:2) fn force_process_hrmp_close(c: u32, ) -> Weight { (0 as Weight) - // Standard Error: 15_000 - .saturating_add((21_682_000 as Weight).saturating_mul(c as Weight)) + // Standard Error: 14_000 + .saturating_add((20_295_000 as Weight).saturating_mul(c as Weight)) .saturating_add(T::DbWeight::get().reads(1 as Weight)) .saturating_add(T::DbWeight::get().reads((3 as Weight).saturating_mul(c as Weight))) .saturating_add(T::DbWeight::get().writes(1 as Weight)) @@ -137,13 +133,21 @@ impl runtime_parachains::hrmp::WeightInfo for WeightInf // Storage: Hrmp HrmpOpenChannelRequestsList (r:1 w:1) // Storage: Hrmp HrmpOpenChannelRequestCount (r:1 w:1) fn hrmp_cancel_open_request(c: u32, ) -> Weight { - (34_181_000 as Weight) + (32_796_000 as Weight) // Standard Error: 0 - .saturating_add((60_000 as Weight).saturating_mul(c as Weight)) + .saturating_add((58_000 as Weight).saturating_mul(c as Weight)) .saturating_add(T::DbWeight::get().reads(3 as Weight)) .saturating_add(T::DbWeight::get().writes(3 as Weight)) } - fn clean_open_channel_requests(_: u32) -> Weight { - 0 + // Storage: Hrmp HrmpOpenChannelRequestsList (r:1 w:1) + // Storage: Hrmp HrmpOpenChannelRequests (r:2 w:2) + fn clean_open_channel_requests(c: u32, ) -> Weight { + (0 as Weight) + // Standard Error: 6_000 + .saturating_add((5_748_000 as Weight).saturating_mul(c as Weight)) + .saturating_add(T::DbWeight::get().reads(1 as Weight)) + .saturating_add(T::DbWeight::get().reads((1 as Weight).saturating_mul(c as Weight))) + .saturating_add(T::DbWeight::get().writes(1 as Weight)) + .saturating_add(T::DbWeight::get().writes((1 as Weight).saturating_mul(c as Weight))) } } From 35f028f4a86d052efd56c297113a844d151f4dfa Mon Sep 17 00:00:00 2001 From: kianenigma Date: Fri, 5 Nov 2021 12:02:46 +0100 Subject: [PATCH 23/36] add files --- runtime/polkadot/src/lib.rs | 2 +- runtime/polkadot/src/weights/mod.rs | 1 + .../src/weights/runtime_parachains_hrmp.rs | 150 ++++++++++++++++++ 3 files changed, 152 insertions(+), 1 deletion(-) create mode 100644 runtime/polkadot/src/weights/runtime_parachains_hrmp.rs diff --git a/runtime/polkadot/src/lib.rs b/runtime/polkadot/src/lib.rs index c52e0cdf10fa..173985632244 100644 --- a/runtime/polkadot/src/lib.rs +++ b/runtime/polkadot/src/lib.rs @@ -1181,7 +1181,7 @@ impl parachains_hrmp::Config for Runtime { type Event = Event; type Origin = Origin; type Currency = Balances; - type WeightInfo = parachains_hrmp::TestWeightInfo; + type WeightInfo = weights::runtime_parachains_hrmp::WeightInfo; } impl parachains_paras_inherent::Config for Runtime {} diff --git a/runtime/polkadot/src/weights/mod.rs b/runtime/polkadot/src/weights/mod.rs index c913094df553..e0471c74ecf4 100644 --- a/runtime/polkadot/src/weights/mod.rs +++ b/runtime/polkadot/src/weights/mod.rs @@ -44,5 +44,6 @@ pub mod runtime_common_crowdloan; pub mod runtime_common_paras_registrar; pub mod runtime_common_slots; pub mod runtime_parachains_configuration; +pub mod runtime_parachains_hrmp; pub mod runtime_parachains_initializer; pub mod runtime_parachains_paras; diff --git a/runtime/polkadot/src/weights/runtime_parachains_hrmp.rs b/runtime/polkadot/src/weights/runtime_parachains_hrmp.rs new file mode 100644 index 000000000000..366819f1906d --- /dev/null +++ b/runtime/polkadot/src/weights/runtime_parachains_hrmp.rs @@ -0,0 +1,150 @@ +// Copyright 2017-2021 Parity Technologies (UK) Ltd. +// This file is part of Polkadot. + +// Polkadot is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// Polkadot is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with Polkadot. If not, see . +//! Autogenerated weights for `runtime_parachains::hrmp` +//! +//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev +//! DATE: 2021-09-21, STEPS: `50`, REPEAT: 20, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("kusama-dev"), DB CACHE: 128 + +// Executed Command: +// target/release/polkadot +// benchmark +// --chain=kusama-dev +// --steps=50 +// --repeat=20 +// --pallet=runtime_parachains::hrmp +// --extrinsic=* +// --execution=wasm +// --wasm-execution=compiled +// --heap-pages=4096 +// --header=./file_header.txt +// --output=./runtime/kusama/src/weights/runtime_parachains_hrmp.rs + + +#![cfg_attr(rustfmt, rustfmt_skip)] +#![allow(unused_parens)] +#![allow(unused_imports)] + +use frame_support::{traits::Get, weights::Weight}; +use sp_std::marker::PhantomData; + +/// Weight functions for `runtime_parachains::hrmp`. +pub struct WeightInfo(PhantomData); +impl runtime_parachains::hrmp::WeightInfo for WeightInfo { + // Storage: Paras ParaLifecycles (r:2 w:0) + // Storage: Configuration ActiveConfig (r:1 w:0) + // Storage: Hrmp HrmpOpenChannelRequests (r:1 w:1) + // Storage: Hrmp HrmpChannels (r:1 w:0) + // Storage: Hrmp HrmpEgressChannelsIndex (r:1 w:0) + // Storage: Hrmp HrmpOpenChannelRequestCount (r:1 w:1) + // Storage: Hrmp HrmpOpenChannelRequestsList (r:1 w:1) + // Storage: Dmp DownwardMessageQueueHeads (r:1 w:1) + // Storage: Dmp DownwardMessageQueues (r:1 w:1) + fn hrmp_init_open_channel() -> Weight { + (61_914_000 as Weight) + .saturating_add(T::DbWeight::get().reads(10 as Weight)) + .saturating_add(T::DbWeight::get().writes(5 as Weight)) + } + // Storage: Hrmp HrmpOpenChannelRequests (r:1 w:1) + // Storage: Configuration ActiveConfig (r:1 w:0) + // Storage: Paras ParaLifecycles (r:1 w:0) + // Storage: Hrmp HrmpIngressChannelsIndex (r:1 w:0) + // Storage: Hrmp HrmpAcceptedChannelRequestCount (r:1 w:1) + // Storage: Dmp DownwardMessageQueueHeads (r:1 w:1) + // Storage: Dmp DownwardMessageQueues (r:1 w:1) + fn hrmp_accept_open_channel() -> Weight { + (53_022_000 as Weight) + .saturating_add(T::DbWeight::get().reads(7 as Weight)) + .saturating_add(T::DbWeight::get().writes(4 as Weight)) + } + // Storage: Hrmp HrmpChannels (r:1 w:0) + // Storage: Hrmp HrmpCloseChannelRequests (r:1 w:1) + // Storage: Hrmp HrmpCloseChannelRequestsList (r:1 w:1) + // Storage: Configuration ActiveConfig (r:1 w:0) + // Storage: Dmp DownwardMessageQueueHeads (r:1 w:1) + // Storage: Dmp DownwardMessageQueues (r:1 w:1) + fn hrmp_close_channel() -> Weight { + (47_548_000 as Weight) + .saturating_add(T::DbWeight::get().reads(6 as Weight)) + .saturating_add(T::DbWeight::get().writes(4 as Weight)) + } + // Storage: Hrmp HrmpIngressChannelsIndex (r:128 w:127) + // Storage: Hrmp HrmpEgressChannelsIndex (r:1 w:1) + // Storage: Hrmp HrmpChannels (r:127 w:127) + // Storage: Hrmp HrmpAcceptedChannelRequestCount (r:0 w:1) + // Storage: Hrmp HrmpChannelContents (r:0 w:127) + // Storage: Hrmp HrmpOpenChannelRequestCount (r:0 w:1) + fn force_clean_hrmp(i: u32, e: u32, ) -> Weight { + (0 as Weight) + // Standard Error: 19_000 + .saturating_add((17_052_000 as Weight).saturating_mul(i as Weight)) + // Standard Error: 19_000 + .saturating_add((16_998_000 as Weight).saturating_mul(e as Weight)) + .saturating_add(T::DbWeight::get().reads(2 as Weight)) + .saturating_add(T::DbWeight::get().reads((2 as Weight).saturating_mul(i as Weight))) + .saturating_add(T::DbWeight::get().reads((2 as Weight).saturating_mul(e as Weight))) + .saturating_add(T::DbWeight::get().writes(4 as Weight)) + .saturating_add(T::DbWeight::get().writes((3 as Weight).saturating_mul(i as Weight))) + .saturating_add(T::DbWeight::get().writes((3 as Weight).saturating_mul(e as Weight))) + } + // Storage: Configuration ActiveConfig (r:1 w:0) + // Storage: Hrmp HrmpOpenChannelRequestsList (r:1 w:0) + // Storage: Hrmp HrmpOpenChannelRequests (r:2 w:2) + // Storage: Paras ParaLifecycles (r:4 w:0) + // Storage: Hrmp HrmpIngressChannelsIndex (r:2 w:2) + // Storage: Hrmp HrmpEgressChannelsIndex (r:2 w:2) + // Storage: Hrmp HrmpOpenChannelRequestCount (r:2 w:2) + // Storage: Hrmp HrmpAcceptedChannelRequestCount (r:2 w:2) + // Storage: Hrmp HrmpChannels (r:0 w:2) + fn force_process_hrmp_open(c: u32, ) -> Weight { + (0 as Weight) + // Standard Error: 28_000 + .saturating_add((37_628_000 as Weight).saturating_mul(c as Weight)) + .saturating_add(T::DbWeight::get().reads(2 as Weight)) + .saturating_add(T::DbWeight::get().reads((7 as Weight).saturating_mul(c as Weight))) + .saturating_add(T::DbWeight::get().writes(1 as Weight)) + .saturating_add(T::DbWeight::get().writes((6 as Weight).saturating_mul(c as Weight))) + } + // Storage: Hrmp HrmpCloseChannelRequestsList (r:1 w:0) + // Storage: Hrmp HrmpChannels (r:2 w:2) + // Storage: Hrmp HrmpEgressChannelsIndex (r:2 w:2) + // Storage: Hrmp HrmpIngressChannelsIndex (r:2 w:2) + // Storage: Hrmp HrmpCloseChannelRequests (r:0 w:2) + // Storage: Hrmp HrmpChannelContents (r:0 w:2) + fn force_process_hrmp_close(c: u32, ) -> Weight { + (0 as Weight) + // Standard Error: 17_000 + .saturating_add((21_825_000 as Weight).saturating_mul(c as Weight)) + .saturating_add(T::DbWeight::get().reads(1 as Weight)) + .saturating_add(T::DbWeight::get().reads((3 as Weight).saturating_mul(c as Weight))) + .saturating_add(T::DbWeight::get().writes(1 as Weight)) + .saturating_add(T::DbWeight::get().writes((5 as Weight).saturating_mul(c as Weight))) + } + // Storage: Hrmp HrmpOpenChannelRequests (r:1 w:1) + // Storage: Hrmp HrmpOpenChannelRequestsList (r:1 w:1) + // Storage: Hrmp HrmpOpenChannelRequestCount (r:1 w:1) + fn hrmp_cancel_open_request(c: u32, ) -> Weight { + (35_031_000 as Weight) + // Standard Error: 0 + .saturating_add((56_000 as Weight).saturating_mul(c as Weight)) + .saturating_add(T::DbWeight::get().reads(3 as Weight)) + .saturating_add(T::DbWeight::get().writes(3 as Weight)) + } + + fn clean_open_channel_requests(_: u32) -> Weight { + 0 + } +} From 05da9358428d2cc7016224b7e827a02fb59a600f Mon Sep 17 00:00:00 2001 From: kianenigma Date: Fri, 5 Nov 2021 12:03:33 +0100 Subject: [PATCH 24/36] Master.into() --- .../src/weights/runtime_parachains_hrmp.rs | 41 +++++++++++-------- 1 file changed, 24 insertions(+), 17 deletions(-) diff --git a/runtime/polkadot/src/weights/runtime_parachains_hrmp.rs b/runtime/polkadot/src/weights/runtime_parachains_hrmp.rs index 366819f1906d..de6e57873b8a 100644 --- a/runtime/polkadot/src/weights/runtime_parachains_hrmp.rs +++ b/runtime/polkadot/src/weights/runtime_parachains_hrmp.rs @@ -16,7 +16,7 @@ //! Autogenerated weights for `runtime_parachains::hrmp` //! //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev -//! DATE: 2021-09-21, STEPS: `50`, REPEAT: 20, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! DATE: 2021-11-05, STEPS: `50`, REPEAT: 20, LOW RANGE: `[]`, HIGH RANGE: `[]` //! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("kusama-dev"), DB CACHE: 128 // Executed Command: @@ -54,7 +54,7 @@ impl runtime_parachains::hrmp::WeightInfo for WeightInf // Storage: Dmp DownwardMessageQueueHeads (r:1 w:1) // Storage: Dmp DownwardMessageQueues (r:1 w:1) fn hrmp_init_open_channel() -> Weight { - (61_914_000 as Weight) + (54_952_000 as Weight) .saturating_add(T::DbWeight::get().reads(10 as Weight)) .saturating_add(T::DbWeight::get().writes(5 as Weight)) } @@ -66,7 +66,7 @@ impl runtime_parachains::hrmp::WeightInfo for WeightInf // Storage: Dmp DownwardMessageQueueHeads (r:1 w:1) // Storage: Dmp DownwardMessageQueues (r:1 w:1) fn hrmp_accept_open_channel() -> Weight { - (53_022_000 as Weight) + (47_965_000 as Weight) .saturating_add(T::DbWeight::get().reads(7 as Weight)) .saturating_add(T::DbWeight::get().writes(4 as Weight)) } @@ -77,7 +77,7 @@ impl runtime_parachains::hrmp::WeightInfo for WeightInf // Storage: Dmp DownwardMessageQueueHeads (r:1 w:1) // Storage: Dmp DownwardMessageQueues (r:1 w:1) fn hrmp_close_channel() -> Weight { - (47_548_000 as Weight) + (44_369_000 as Weight) .saturating_add(T::DbWeight::get().reads(6 as Weight)) .saturating_add(T::DbWeight::get().writes(4 as Weight)) } @@ -89,10 +89,10 @@ impl runtime_parachains::hrmp::WeightInfo for WeightInf // Storage: Hrmp HrmpOpenChannelRequestCount (r:0 w:1) fn force_clean_hrmp(i: u32, e: u32, ) -> Weight { (0 as Weight) - // Standard Error: 19_000 - .saturating_add((17_052_000 as Weight).saturating_mul(i as Weight)) - // Standard Error: 19_000 - .saturating_add((16_998_000 as Weight).saturating_mul(e as Weight)) + // Standard Error: 17_000 + .saturating_add((15_959_000 as Weight).saturating_mul(i as Weight)) + // Standard Error: 17_000 + .saturating_add((16_048_000 as Weight).saturating_mul(e as Weight)) .saturating_add(T::DbWeight::get().reads(2 as Weight)) .saturating_add(T::DbWeight::get().reads((2 as Weight).saturating_mul(i as Weight))) .saturating_add(T::DbWeight::get().reads((2 as Weight).saturating_mul(e as Weight))) @@ -111,8 +111,8 @@ impl runtime_parachains::hrmp::WeightInfo for WeightInf // Storage: Hrmp HrmpChannels (r:0 w:2) fn force_process_hrmp_open(c: u32, ) -> Weight { (0 as Weight) - // Standard Error: 28_000 - .saturating_add((37_628_000 as Weight).saturating_mul(c as Weight)) + // Standard Error: 26_000 + .saturating_add((35_598_000 as Weight).saturating_mul(c as Weight)) .saturating_add(T::DbWeight::get().reads(2 as Weight)) .saturating_add(T::DbWeight::get().reads((7 as Weight).saturating_mul(c as Weight))) .saturating_add(T::DbWeight::get().writes(1 as Weight)) @@ -126,8 +126,8 @@ impl runtime_parachains::hrmp::WeightInfo for WeightInf // Storage: Hrmp HrmpChannelContents (r:0 w:2) fn force_process_hrmp_close(c: u32, ) -> Weight { (0 as Weight) - // Standard Error: 17_000 - .saturating_add((21_825_000 as Weight).saturating_mul(c as Weight)) + // Standard Error: 15_000 + .saturating_add((20_510_000 as Weight).saturating_mul(c as Weight)) .saturating_add(T::DbWeight::get().reads(1 as Weight)) .saturating_add(T::DbWeight::get().reads((3 as Weight).saturating_mul(c as Weight))) .saturating_add(T::DbWeight::get().writes(1 as Weight)) @@ -137,14 +137,21 @@ impl runtime_parachains::hrmp::WeightInfo for WeightInf // Storage: Hrmp HrmpOpenChannelRequestsList (r:1 w:1) // Storage: Hrmp HrmpOpenChannelRequestCount (r:1 w:1) fn hrmp_cancel_open_request(c: u32, ) -> Weight { - (35_031_000 as Weight) + (32_749_000 as Weight) // Standard Error: 0 - .saturating_add((56_000 as Weight).saturating_mul(c as Weight)) + .saturating_add((59_000 as Weight).saturating_mul(c as Weight)) .saturating_add(T::DbWeight::get().reads(3 as Weight)) .saturating_add(T::DbWeight::get().writes(3 as Weight)) } - - fn clean_open_channel_requests(_: u32) -> Weight { - 0 + // Storage: Hrmp HrmpOpenChannelRequestsList (r:1 w:1) + // Storage: Hrmp HrmpOpenChannelRequests (r:2 w:2) + fn clean_open_channel_requests(c: u32, ) -> Weight { + (0 as Weight) + // Standard Error: 6_000 + .saturating_add((5_781_000 as Weight).saturating_mul(c as Weight)) + .saturating_add(T::DbWeight::get().reads(1 as Weight)) + .saturating_add(T::DbWeight::get().reads((1 as Weight).saturating_mul(c as Weight))) + .saturating_add(T::DbWeight::get().writes(1 as Weight)) + .saturating_add(T::DbWeight::get().writes((1 as Weight).saturating_mul(c as Weight))) } } From e79d7f7359afcb266c9a5304c26f60d286069068 Mon Sep 17 00:00:00 2001 From: kianenigma Date: Wed, 10 Nov 2021 10:27:15 +0100 Subject: [PATCH 25/36] add validation --- Cargo.lock | 1 + runtime/parachains/Cargo.toml | 2 ++ runtime/parachains/src/hrmp.rs | 14 +++++++++++--- runtime/parachains/src/hrmp/benchmarking.rs | 8 +++----- 4 files changed, 17 insertions(+), 8 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 3060de9bafc2..82092c106512 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -6903,6 +6903,7 @@ dependencies = [ "sp-staking", "sp-std", "sp-tracing", + "static_assertions", "xcm", "xcm-executor", ] diff --git a/runtime/parachains/Cargo.toml b/runtime/parachains/Cargo.toml index 025ff137db08..5311323dc1a8 100644 --- a/runtime/parachains/Cargo.toml +++ b/runtime/parachains/Cargo.toml @@ -41,6 +41,7 @@ primitives = { package = "polkadot-primitives", path = "../../primitives", defau rand = { version = "0.8.3", default-features = false } rand_chacha = { version = "0.3.1", default-features = false } +static_assertions = { version = "1.1.0", optional = true } [dev-dependencies] futures = "0.3.17" @@ -86,6 +87,7 @@ runtime-benchmarks = [ "frame-benchmarking", "frame-support/runtime-benchmarks", "frame-system/runtime-benchmarks", + "static_assertions", ] try-runtime = [ "frame-support/try-runtime", diff --git a/runtime/parachains/src/hrmp.rs b/runtime/parachains/src/hrmp.rs index 8a42c60a682e..2aeb8039fac4 100644 --- a/runtime/parachains/src/hrmp.rs +++ b/runtime/parachains/src/hrmp.rs @@ -296,6 +296,8 @@ pub mod pallet { OpenHrmpChannelDoesntExist, /// Cannot cancel an HRMP open channel request because it is already confirmed. OpenHrmpChannelAlreadyConfirmed, + /// The provided witness data is wrong. + WrongWitness, } /// The set of pending HRMP open channel requests. @@ -544,14 +546,20 @@ pub mod pallet { /// The cancellation happens immediately. It is not possible to cancel the request if it is /// already accepted. /// - /// Total number of opening channels must be provided as witness data. - #[pallet::weight(::WeightInfo::hrmp_cancel_open_request(*_channels))] + /// Total number of open requests (i.e. `HrmpOpenChannelRequestsList`) must be provided as + /// witness data. + #[pallet::weight(::WeightInfo::hrmp_cancel_open_request(*open_requests))] pub fn hrmp_cancel_open_request( origin: OriginFor, channel_id: HrmpChannelId, - _channels: u32, + open_requests: u32, ) -> DispatchResult { let origin = ensure_parachain(::Origin::from(origin))?; + ensure!( + ::HrmpOpenChannelRequestsList::decode_len().unwrap_or_default() as u32 == + open_requests, + Error::::WrongWitness + ); Self::cancel_open_request(origin, channel_id.clone())?; Self::deposit_event(Event::OpenChannelCanceled(origin, channel_id)); Ok(()) diff --git a/runtime/parachains/src/hrmp/benchmarking.rs b/runtime/parachains/src/hrmp/benchmarking.rs index d082289870f8..967284a36fb8 100644 --- a/runtime/parachains/src/hrmp/benchmarking.rs +++ b/runtime/parachains/src/hrmp/benchmarking.rs @@ -122,6 +122,8 @@ const PREFIX_0: u32 = 10_000; const PREFIX_1: u32 = PREFIX_0 * 2; const MAX_UNIQUE_CHANNELS: u32 = 128; +static_assertions::const_assert!(MAX_UNIQUE_CHANNELS < PREFIX_0); + frame_benchmarking::benchmarks! { where_clause { where ::Origin: From } @@ -217,7 +219,6 @@ frame_benchmarking::benchmarks! { // sender and recipients for all channels. let c in 0 .. MAX_UNIQUE_CHANNELS; - assert!(MAX_UNIQUE_CHANNELS < PREFIX_0, "PREFIX_0 must always be more than MAX_UNIQUE_CHANNELS"); for id in 0 .. c { let _ = establish_para_connection::(PREFIX_0 + id, PREFIX_1 + id, ParachainSetupStep::Accepted); } @@ -232,7 +233,6 @@ frame_benchmarking::benchmarks! { // sender and recipients for all channels. let c in 0 .. MAX_UNIQUE_CHANNELS; - assert!(MAX_UNIQUE_CHANNELS < PREFIX_0, "PREFIX_0 must always be more than MAX_UNIQUE_CHANNELS"); for id in 0 .. c { let _ = establish_para_connection::(PREFIX_0 + id, PREFIX_1 + id, ParachainSetupStep::CloseRequested); } @@ -248,7 +248,6 @@ frame_benchmarking::benchmarks! { // one that we remove. let c in 0 .. MAX_UNIQUE_CHANNELS; - assert!(MAX_UNIQUE_CHANNELS < PREFIX_0, "PREFIX_0 must always be more than MAX_UNIQUE_CHANNELS"); for id in 0 .. c { let _ = establish_para_connection::(PREFIX_0 + id, PREFIX_1 + id, ParachainSetupStep::Requested); } @@ -256,7 +255,7 @@ frame_benchmarking::benchmarks! { let [(sender, sender_origin), (recipient, _)] = establish_para_connection::(1, 2, ParachainSetupStep::Requested); assert_eq!(HrmpOpenChannelRequestsList::::decode_len().unwrap_or_default() as u32, c + 1); let channel_id = HrmpChannelId { sender, recipient }; - }: _(sender_origin, channel_id, c) + }: _(sender_origin, channel_id, c + 1) verify { assert_eq!(HrmpOpenChannelRequestsList::::decode_len().unwrap_or_default() as u32, c); } @@ -267,7 +266,6 @@ frame_benchmarking::benchmarks! { clean_open_channel_requests { let c in 0 .. MAX_UNIQUE_CHANNELS; - assert!(MAX_UNIQUE_CHANNELS < PREFIX_0, "PREFIX_0 must always be more than MAX_UNIQUE_CHANNELS"); for id in 0 .. c { let _ = establish_para_connection::(PREFIX_0 + id, PREFIX_1 + id, ParachainSetupStep::Requested); } From 33c0fbb1024978ad83814f750b5c7849a28230f7 Mon Sep 17 00:00:00 2001 From: kianenigma Date: Wed, 10 Nov 2021 10:56:50 +0100 Subject: [PATCH 26/36] fmt --- node/network/availability-distribution/src/requester/mod.rs | 2 +- node/network/collator-protocol/src/validator_side/mod.rs | 2 +- node/network/statement-distribution/src/tests.rs | 2 +- runtime/parachains/src/hrmp.rs | 4 ++-- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/node/network/availability-distribution/src/requester/mod.rs b/node/network/availability-distribution/src/requester/mod.rs index f678a768d61f..53804aae8723 100644 --- a/node/network/availability-distribution/src/requester/mod.rs +++ b/node/network/availability-distribution/src/requester/mod.rs @@ -159,7 +159,7 @@ impl Requester { // Just book keeping - we are already requesting that chunk: { e.get_mut().add_leaf(leaf); - } + }, Entry::Vacant(e) => { let tx = self.tx.clone(); let metrics = self.metrics.clone(); diff --git a/node/network/collator-protocol/src/validator_side/mod.rs b/node/network/collator-protocol/src/validator_side/mod.rs index f7672d932dcd..6eb92f5f81e7 100644 --- a/node/network/collator-protocol/src/validator_side/mod.rs +++ b/node/network/collator-protocol/src/validator_side/mod.rs @@ -1462,7 +1462,7 @@ async fn poll_collation_response( ); CollationFetchResult::Error(COST_WRONG_PARA) - } + }, Ok(CollationFetchingResponse::Collation(receipt, pov)) => { tracing::debug!( target: LOG_TARGET, diff --git a/node/network/statement-distribution/src/tests.rs b/node/network/statement-distribution/src/tests.rs index 2c41d5e7ddf0..80fdb50a4f26 100644 --- a/node/network/statement-distribution/src/tests.rs +++ b/node/network/statement-distribution/src/tests.rs @@ -1814,7 +1814,7 @@ fn peer_cant_flood_with_large_statements() { if p == peer_a && r == COST_APPARENT_FLOOD => { punished = true; - } + }, m => panic!("Unexpected message: {:?}", m), } diff --git a/runtime/parachains/src/hrmp.rs b/runtime/parachains/src/hrmp.rs index 2aeb8039fac4..c0a2e9a8fb24 100644 --- a/runtime/parachains/src/hrmp.rs +++ b/runtime/parachains/src/hrmp.rs @@ -556,8 +556,8 @@ pub mod pallet { ) -> DispatchResult { let origin = ensure_parachain(::Origin::from(origin))?; ensure!( - ::HrmpOpenChannelRequestsList::decode_len().unwrap_or_default() as u32 == - open_requests, + ::HrmpOpenChannelRequestsList::decode_len().unwrap_or_default() + as u32 == open_requests, Error::::WrongWitness ); Self::cancel_open_request(origin, channel_id.clone())?; From 323c238d073030f1a0ddba0907ef425bcd87ca28 Mon Sep 17 00:00:00 2001 From: Sergey Shulepov Date: Thu, 18 Nov 2021 12:24:05 +0000 Subject: [PATCH 27/36] fmt --- runtime/parachains/src/mock.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/runtime/parachains/src/mock.rs b/runtime/parachains/src/mock.rs index 8a04f56eb4c0..ac1be0e9948d 100644 --- a/runtime/parachains/src/mock.rs +++ b/runtime/parachains/src/mock.rs @@ -25,7 +25,7 @@ use crate::{ use frame_support::{ parameter_types, - traits::{GenesisBuild, ConstU32, KeyOwnerProofSystem}, + traits::{ConstU32, GenesisBuild, KeyOwnerProofSystem}, weights::Weight, }; use frame_support_test::TestRandomness; From 7a3d6fec0ac7607f4179c6d9704c253607de1498 Mon Sep 17 00:00:00 2001 From: kianenigma Date: Thu, 20 Jan 2022 08:17:16 +0000 Subject: [PATCH 28/36] final fixes --- runtime/common/src/assigned_slots.rs | 2 ++ runtime/parachains/src/hrmp.rs | 2 -- runtime/test-runtime/src/lib.rs | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/runtime/common/src/assigned_slots.rs b/runtime/common/src/assigned_slots.rs index 85775883d07a..5f8ac3e6a36d 100644 --- a/runtime/common/src/assigned_slots.rs +++ b/runtime/common/src/assigned_slots.rs @@ -634,6 +634,8 @@ mod tests { impl parachains_configuration::Config for Test { type WeightInfo = parachains_configuration::TestWeightInfo; + type HrmpMaxOutboundChannelsBound = ConstU32<128>; + type HrmpMaxInboundChannelsBound = ConstU32<128>; } parameter_types! { diff --git a/runtime/parachains/src/hrmp.rs b/runtime/parachains/src/hrmp.rs index 7332e99bdffe..c8b8a4ec6133 100644 --- a/runtime/parachains/src/hrmp.rs +++ b/runtime/parachains/src/hrmp.rs @@ -50,10 +50,8 @@ pub trait WeightInfo { } /// A weight info that is only suitable for testing. -#[cfg(feature = "std")] pub struct TestWeightInfo; -#[cfg(feature = "std")] impl WeightInfo for TestWeightInfo { fn hrmp_accept_open_channel() -> Weight { Weight::MAX diff --git a/runtime/test-runtime/src/lib.rs b/runtime/test-runtime/src/lib.rs index ff2771e78763..0792f3ddbdb3 100644 --- a/runtime/test-runtime/src/lib.rs +++ b/runtime/test-runtime/src/lib.rs @@ -551,7 +551,7 @@ impl parachains_hrmp::Config for Runtime { type Event = Event; type Origin = Origin; type Currency = Balances; - type WeightInfo = (); + type WeightInfo = parachains_hrmp::TestWeightInfo; } impl parachains_scheduler::Config for Runtime {} From 0558cdf201dfa1f56a9163a778ebe207434f7296 Mon Sep 17 00:00:00 2001 From: kianenigma Date: Thu, 20 Jan 2022 08:24:27 +0000 Subject: [PATCH 29/36] all runtimes build --- runtime/rococo/src/lib.rs | 2 +- runtime/rococo/src/weights/mod.rs | 1 + .../src/weights/runtime_parachains_hrmp.rs | 157 ++++++++++++++++++ 3 files changed, 159 insertions(+), 1 deletion(-) create mode 100644 runtime/rococo/src/weights/runtime_parachains_hrmp.rs diff --git a/runtime/rococo/src/lib.rs b/runtime/rococo/src/lib.rs index f5955ccce94b..0596645b2065 100644 --- a/runtime/rococo/src/lib.rs +++ b/runtime/rococo/src/lib.rs @@ -647,7 +647,7 @@ impl parachains_hrmp::Config for Runtime { type Event = Event; type Origin = Origin; type Currency = Balances; - type WeightInfo = (); + type WeightInfo = weights::runtime_parachains_hrmp::WeightInfo; } impl parachains_paras_inherent::Config for Runtime { diff --git a/runtime/rococo/src/weights/mod.rs b/runtime/rococo/src/weights/mod.rs index ccd1e3b0cda4..b8931b180a26 100644 --- a/runtime/rococo/src/weights/mod.rs +++ b/runtime/rococo/src/weights/mod.rs @@ -17,5 +17,6 @@ pub mod runtime_parachains_configuration; pub mod runtime_parachains_disputes; +pub mod runtime_parachains_hrmp; pub mod runtime_parachains_paras; pub mod runtime_parachains_paras_inherent; diff --git a/runtime/rococo/src/weights/runtime_parachains_hrmp.rs b/runtime/rococo/src/weights/runtime_parachains_hrmp.rs new file mode 100644 index 000000000000..de6e57873b8a --- /dev/null +++ b/runtime/rococo/src/weights/runtime_parachains_hrmp.rs @@ -0,0 +1,157 @@ +// Copyright 2017-2021 Parity Technologies (UK) Ltd. +// This file is part of Polkadot. + +// Polkadot is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// Polkadot is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with Polkadot. If not, see . +//! Autogenerated weights for `runtime_parachains::hrmp` +//! +//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev +//! DATE: 2021-11-05, STEPS: `50`, REPEAT: 20, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("kusama-dev"), DB CACHE: 128 + +// Executed Command: +// target/release/polkadot +// benchmark +// --chain=kusama-dev +// --steps=50 +// --repeat=20 +// --pallet=runtime_parachains::hrmp +// --extrinsic=* +// --execution=wasm +// --wasm-execution=compiled +// --heap-pages=4096 +// --header=./file_header.txt +// --output=./runtime/kusama/src/weights/runtime_parachains_hrmp.rs + + +#![cfg_attr(rustfmt, rustfmt_skip)] +#![allow(unused_parens)] +#![allow(unused_imports)] + +use frame_support::{traits::Get, weights::Weight}; +use sp_std::marker::PhantomData; + +/// Weight functions for `runtime_parachains::hrmp`. +pub struct WeightInfo(PhantomData); +impl runtime_parachains::hrmp::WeightInfo for WeightInfo { + // Storage: Paras ParaLifecycles (r:2 w:0) + // Storage: Configuration ActiveConfig (r:1 w:0) + // Storage: Hrmp HrmpOpenChannelRequests (r:1 w:1) + // Storage: Hrmp HrmpChannels (r:1 w:0) + // Storage: Hrmp HrmpEgressChannelsIndex (r:1 w:0) + // Storage: Hrmp HrmpOpenChannelRequestCount (r:1 w:1) + // Storage: Hrmp HrmpOpenChannelRequestsList (r:1 w:1) + // Storage: Dmp DownwardMessageQueueHeads (r:1 w:1) + // Storage: Dmp DownwardMessageQueues (r:1 w:1) + fn hrmp_init_open_channel() -> Weight { + (54_952_000 as Weight) + .saturating_add(T::DbWeight::get().reads(10 as Weight)) + .saturating_add(T::DbWeight::get().writes(5 as Weight)) + } + // Storage: Hrmp HrmpOpenChannelRequests (r:1 w:1) + // Storage: Configuration ActiveConfig (r:1 w:0) + // Storage: Paras ParaLifecycles (r:1 w:0) + // Storage: Hrmp HrmpIngressChannelsIndex (r:1 w:0) + // Storage: Hrmp HrmpAcceptedChannelRequestCount (r:1 w:1) + // Storage: Dmp DownwardMessageQueueHeads (r:1 w:1) + // Storage: Dmp DownwardMessageQueues (r:1 w:1) + fn hrmp_accept_open_channel() -> Weight { + (47_965_000 as Weight) + .saturating_add(T::DbWeight::get().reads(7 as Weight)) + .saturating_add(T::DbWeight::get().writes(4 as Weight)) + } + // Storage: Hrmp HrmpChannels (r:1 w:0) + // Storage: Hrmp HrmpCloseChannelRequests (r:1 w:1) + // Storage: Hrmp HrmpCloseChannelRequestsList (r:1 w:1) + // Storage: Configuration ActiveConfig (r:1 w:0) + // Storage: Dmp DownwardMessageQueueHeads (r:1 w:1) + // Storage: Dmp DownwardMessageQueues (r:1 w:1) + fn hrmp_close_channel() -> Weight { + (44_369_000 as Weight) + .saturating_add(T::DbWeight::get().reads(6 as Weight)) + .saturating_add(T::DbWeight::get().writes(4 as Weight)) + } + // Storage: Hrmp HrmpIngressChannelsIndex (r:128 w:127) + // Storage: Hrmp HrmpEgressChannelsIndex (r:1 w:1) + // Storage: Hrmp HrmpChannels (r:127 w:127) + // Storage: Hrmp HrmpAcceptedChannelRequestCount (r:0 w:1) + // Storage: Hrmp HrmpChannelContents (r:0 w:127) + // Storage: Hrmp HrmpOpenChannelRequestCount (r:0 w:1) + fn force_clean_hrmp(i: u32, e: u32, ) -> Weight { + (0 as Weight) + // Standard Error: 17_000 + .saturating_add((15_959_000 as Weight).saturating_mul(i as Weight)) + // Standard Error: 17_000 + .saturating_add((16_048_000 as Weight).saturating_mul(e as Weight)) + .saturating_add(T::DbWeight::get().reads(2 as Weight)) + .saturating_add(T::DbWeight::get().reads((2 as Weight).saturating_mul(i as Weight))) + .saturating_add(T::DbWeight::get().reads((2 as Weight).saturating_mul(e as Weight))) + .saturating_add(T::DbWeight::get().writes(4 as Weight)) + .saturating_add(T::DbWeight::get().writes((3 as Weight).saturating_mul(i as Weight))) + .saturating_add(T::DbWeight::get().writes((3 as Weight).saturating_mul(e as Weight))) + } + // Storage: Configuration ActiveConfig (r:1 w:0) + // Storage: Hrmp HrmpOpenChannelRequestsList (r:1 w:0) + // Storage: Hrmp HrmpOpenChannelRequests (r:2 w:2) + // Storage: Paras ParaLifecycles (r:4 w:0) + // Storage: Hrmp HrmpIngressChannelsIndex (r:2 w:2) + // Storage: Hrmp HrmpEgressChannelsIndex (r:2 w:2) + // Storage: Hrmp HrmpOpenChannelRequestCount (r:2 w:2) + // Storage: Hrmp HrmpAcceptedChannelRequestCount (r:2 w:2) + // Storage: Hrmp HrmpChannels (r:0 w:2) + fn force_process_hrmp_open(c: u32, ) -> Weight { + (0 as Weight) + // Standard Error: 26_000 + .saturating_add((35_598_000 as Weight).saturating_mul(c as Weight)) + .saturating_add(T::DbWeight::get().reads(2 as Weight)) + .saturating_add(T::DbWeight::get().reads((7 as Weight).saturating_mul(c as Weight))) + .saturating_add(T::DbWeight::get().writes(1 as Weight)) + .saturating_add(T::DbWeight::get().writes((6 as Weight).saturating_mul(c as Weight))) + } + // Storage: Hrmp HrmpCloseChannelRequestsList (r:1 w:0) + // Storage: Hrmp HrmpChannels (r:2 w:2) + // Storage: Hrmp HrmpEgressChannelsIndex (r:2 w:2) + // Storage: Hrmp HrmpIngressChannelsIndex (r:2 w:2) + // Storage: Hrmp HrmpCloseChannelRequests (r:0 w:2) + // Storage: Hrmp HrmpChannelContents (r:0 w:2) + fn force_process_hrmp_close(c: u32, ) -> Weight { + (0 as Weight) + // Standard Error: 15_000 + .saturating_add((20_510_000 as Weight).saturating_mul(c as Weight)) + .saturating_add(T::DbWeight::get().reads(1 as Weight)) + .saturating_add(T::DbWeight::get().reads((3 as Weight).saturating_mul(c as Weight))) + .saturating_add(T::DbWeight::get().writes(1 as Weight)) + .saturating_add(T::DbWeight::get().writes((5 as Weight).saturating_mul(c as Weight))) + } + // Storage: Hrmp HrmpOpenChannelRequests (r:1 w:1) + // Storage: Hrmp HrmpOpenChannelRequestsList (r:1 w:1) + // Storage: Hrmp HrmpOpenChannelRequestCount (r:1 w:1) + fn hrmp_cancel_open_request(c: u32, ) -> Weight { + (32_749_000 as Weight) + // Standard Error: 0 + .saturating_add((59_000 as Weight).saturating_mul(c as Weight)) + .saturating_add(T::DbWeight::get().reads(3 as Weight)) + .saturating_add(T::DbWeight::get().writes(3 as Weight)) + } + // Storage: Hrmp HrmpOpenChannelRequestsList (r:1 w:1) + // Storage: Hrmp HrmpOpenChannelRequests (r:2 w:2) + fn clean_open_channel_requests(c: u32, ) -> Weight { + (0 as Weight) + // Standard Error: 6_000 + .saturating_add((5_781_000 as Weight).saturating_mul(c as Weight)) + .saturating_add(T::DbWeight::get().reads(1 as Weight)) + .saturating_add(T::DbWeight::get().reads((1 as Weight).saturating_mul(c as Weight))) + .saturating_add(T::DbWeight::get().writes(1 as Weight)) + .saturating_add(T::DbWeight::get().writes((1 as Weight).saturating_mul(c as Weight))) + } +} From a91ce3f100c257ba33423752d0bf1aac3aa25cb5 Mon Sep 17 00:00:00 2001 From: kianenigma Date: Thu, 20 Jan 2022 08:27:39 +0000 Subject: [PATCH 30/36] undo formatting --- runtime/common/src/paras_registrar.rs | 132 +++++++++++++------------- 1 file changed, 66 insertions(+), 66 deletions(-) diff --git a/runtime/common/src/paras_registrar.rs b/runtime/common/src/paras_registrar.rs index ced4faf3864e..6e258d68c6ba 100644 --- a/runtime/common/src/paras_registrar.rs +++ b/runtime/common/src/paras_registrar.rs @@ -1108,81 +1108,81 @@ mod benchmarking { } benchmarks! { - where_clause { where ParaOrigin: Into<::Origin> } - - reserve { - let caller: T::AccountId = whitelisted_caller(); - T::Currency::make_free_balance_be(&caller, BalanceOf::::max_value()); - }: _(RawOrigin::Signed(caller.clone())) - verify { - assert_last_event::(Event::::Reserved(LOWEST_PUBLIC_ID, caller).into()); - assert!(Paras::::get(LOWEST_PUBLIC_ID).is_some()); - assert_eq!(paras::Pallet::::lifecycle(LOWEST_PUBLIC_ID), None); - } + where_clause { where ParaOrigin: Into<::Origin> } + + reserve { + let caller: T::AccountId = whitelisted_caller(); + T::Currency::make_free_balance_be(&caller, BalanceOf::::max_value()); + }: _(RawOrigin::Signed(caller.clone())) + verify { + assert_last_event::(Event::::Reserved(LOWEST_PUBLIC_ID, caller).into()); + assert!(Paras::::get(LOWEST_PUBLIC_ID).is_some()); + assert_eq!(paras::Pallet::::lifecycle(LOWEST_PUBLIC_ID), None); + } - register { - let para = LOWEST_PUBLIC_ID; - let genesis_head = Registrar::::worst_head_data(); - let validation_code = Registrar::::worst_validation_code(); - let caller: T::AccountId = whitelisted_caller(); - T::Currency::make_free_balance_be(&caller, BalanceOf::::max_value()); - assert_ok!(Registrar::::reserve(RawOrigin::Signed(caller.clone()).into())); - }: _(RawOrigin::Signed(caller.clone()), para, genesis_head, validation_code) - verify { - assert_last_event::(Event::::Registered(para, caller).into()); - assert_eq!(paras::Pallet::::lifecycle(para), Some(ParaLifecycle::Onboarding)); - next_scheduled_session::(); - assert_eq!(paras::Pallet::::lifecycle(para), Some(ParaLifecycle::Parathread)); - } + register { + let para = LOWEST_PUBLIC_ID; + let genesis_head = Registrar::::worst_head_data(); + let validation_code = Registrar::::worst_validation_code(); + let caller: T::AccountId = whitelisted_caller(); + T::Currency::make_free_balance_be(&caller, BalanceOf::::max_value()); + assert_ok!(Registrar::::reserve(RawOrigin::Signed(caller.clone()).into())); + }: _(RawOrigin::Signed(caller.clone()), para, genesis_head, validation_code) + verify { + assert_last_event::(Event::::Registered(para, caller).into()); + assert_eq!(paras::Pallet::::lifecycle(para), Some(ParaLifecycle::Onboarding)); + next_scheduled_session::(); + assert_eq!(paras::Pallet::::lifecycle(para), Some(ParaLifecycle::Parathread)); + } - force_register { - let manager: T::AccountId = account("manager", 0, 0); - let deposit = 0u32.into(); - let para = ParaId::from(69); - let genesis_head = Registrar::::worst_head_data(); - let validation_code = Registrar::::worst_validation_code(); - }: _(RawOrigin::Root, manager.clone(), deposit, para, genesis_head, validation_code) - verify { - assert_last_event::(Event::::Registered(para, manager).into()); - assert_eq!(paras::Pallet::::lifecycle(para), Some(ParaLifecycle::Onboarding)); - next_scheduled_session::(); - assert_eq!(paras::Pallet::::lifecycle(para), Some(ParaLifecycle::Parathread)); - } + force_register { + let manager: T::AccountId = account("manager", 0, 0); + let deposit = 0u32.into(); + let para = ParaId::from(69); + let genesis_head = Registrar::::worst_head_data(); + let validation_code = Registrar::::worst_validation_code(); + }: _(RawOrigin::Root, manager.clone(), deposit, para, genesis_head, validation_code) + verify { + assert_last_event::(Event::::Registered(para, manager).into()); + assert_eq!(paras::Pallet::::lifecycle(para), Some(ParaLifecycle::Onboarding)); + next_scheduled_session::(); + assert_eq!(paras::Pallet::::lifecycle(para), Some(ParaLifecycle::Parathread)); + } - deregister { - let para = register_para::(LOWEST_PUBLIC_ID.into()); - next_scheduled_session::(); - let caller: T::AccountId = whitelisted_caller(); - }: _(RawOrigin::Signed(caller), para) - verify { - assert_last_event::(Event::::Deregistered(para).into()); - } + deregister { + let para = register_para::(LOWEST_PUBLIC_ID.into()); + next_scheduled_session::(); + let caller: T::AccountId = whitelisted_caller(); + }: _(RawOrigin::Signed(caller), para) + verify { + assert_last_event::(Event::::Deregistered(para).into()); + } - swap { - let parathread = register_para::(LOWEST_PUBLIC_ID.into()); - let parachain = register_para::((LOWEST_PUBLIC_ID + 1).into()); + swap { + let parathread = register_para::(LOWEST_PUBLIC_ID.into()); + let parachain = register_para::((LOWEST_PUBLIC_ID + 1).into()); - let parachain_origin = para_origin(parachain.into()); + let parachain_origin = para_origin(parachain.into()); - // Actually finish registration process - next_scheduled_session::(); + // Actually finish registration process + next_scheduled_session::(); - // Upgrade the parachain - Registrar::::make_parachain(parachain)?; - next_scheduled_session::(); + // Upgrade the parachain + Registrar::::make_parachain(parachain)?; + next_scheduled_session::(); - assert_eq!(paras::Pallet::::lifecycle(parachain), Some(ParaLifecycle::Parachain)); - assert_eq!(paras::Pallet::::lifecycle(parathread), Some(ParaLifecycle::Parathread)); + assert_eq!(paras::Pallet::::lifecycle(parachain), Some(ParaLifecycle::Parachain)); + assert_eq!(paras::Pallet::::lifecycle(parathread), Some(ParaLifecycle::Parathread)); - let caller: T::AccountId = whitelisted_caller(); - Registrar::::swap(parachain_origin.into(), parachain, parathread)?; - }: _(RawOrigin::Signed(caller.clone()), parathread, parachain) - verify { - next_scheduled_session::(); - // Swapped! - assert_eq!(paras::Pallet::::lifecycle(parachain), Some(ParaLifecycle::Parathread)); - assert_eq!(paras::Pallet::::lifecycle(parathread), Some(ParaLifecycle::Parachain)); - } + let caller: T::AccountId = whitelisted_caller(); + Registrar::::swap(parachain_origin.into(), parachain, parathread)?; + }: _(RawOrigin::Signed(caller.clone()), parathread, parachain) + verify { + next_scheduled_session::(); + // Swapped! + assert_eq!(paras::Pallet::::lifecycle(parachain), Some(ParaLifecycle::Parathread)); + assert_eq!(paras::Pallet::::lifecycle(parathread), Some(ParaLifecycle::Parachain)); + } impl_benchmark_test_suite!( Registrar, From ca91f066563a77f55c4f64ed14a2b07cc0b7b3db Mon Sep 17 00:00:00 2001 From: Kian Paimani <5588131+kianenigma@users.noreply.github.com> Date: Thu, 20 Jan 2022 19:33:45 +0100 Subject: [PATCH 31/36] Update runtime/parachains/src/hrmp.rs Co-authored-by: Zeke Mostov --- runtime/parachains/src/hrmp.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/runtime/parachains/src/hrmp.rs b/runtime/parachains/src/hrmp.rs index c8b8a4ec6133..12bf69e57be0 100644 --- a/runtime/parachains/src/hrmp.rs +++ b/runtime/parachains/src/hrmp.rs @@ -558,7 +558,7 @@ pub mod pallet { let origin = ensure_parachain(::Origin::from(origin))?; ensure!( ::HrmpOpenChannelRequestsList::decode_len().unwrap_or_default() - as u32 == open_requests, + as u32 <= open_requests, Error::::WrongWitness ); Self::cancel_open_request(origin, channel_id.clone())?; From 2cb4e6706697bfd70b9b2f4a807d5251d667a563 Mon Sep 17 00:00:00 2001 From: kianenigma Date: Fri, 21 Jan 2022 07:46:11 +0000 Subject: [PATCH 32/36] non-controversial changes --- runtime/parachains/src/hrmp.rs | 8 ++++---- runtime/parachains/src/hrmp/benchmarking.rs | 15 +++++++++++++-- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/runtime/parachains/src/hrmp.rs b/runtime/parachains/src/hrmp.rs index c8b8a4ec6133..fd94c4465f24 100644 --- a/runtime/parachains/src/hrmp.rs +++ b/runtime/parachains/src/hrmp.rs @@ -631,10 +631,10 @@ impl Pallet { // we need a few extra bits of data to weigh this -- all of this is read internally // anyways, so no overhead. - let ingress_count = - ::HrmpIngressChannelsIndex::get(outgoing_para).len() as u32; - let egress_count = - ::HrmpEgressChannelsIndex::get(outgoing_para).len() as u32; + let ingress_count = ::HrmpIngressChannelsIndex::decode_len(outgoing_para) + .unwrap_or_default() as u32; + let egress_count = ::HrmpEgressChannelsIndex::decode_len(outgoing_para) + .unwrap_or_default() as u32; w = w.saturating_add(::WeightInfo::force_clean_hrmp( ingress_count, egress_count, diff --git a/runtime/parachains/src/hrmp/benchmarking.rs b/runtime/parachains/src/hrmp/benchmarking.rs index 21acaf60456c..9f2d01873ac6 100644 --- a/runtime/parachains/src/hrmp/benchmarking.rs +++ b/runtime/parachains/src/hrmp/benchmarking.rs @@ -118,6 +118,17 @@ where output } +/// Prefix value for account generation. These numbers are used as seeds to crete distinct (para) +/// accounts. +/// +/// To maintain sensibility created accounts should always be unique and never overlap. For example, +/// if for some benchmarking component `c`, accounts are being created `for s in 0..c` with seed +/// `PREFIX_0 + s`, then we must assert that `c <= PREFIX_1`, meaning that it won't overlap with +/// `PREFIX_2`. +/// +/// These values are chosen large enough so that the likelihood of any clash is already very low. +/// Nonetheless, the value for `Config::HrmpMaxInboundChannelsBound` and +/// `Config::HrmpMaxOutboundChannelsBound` need to be checked in some places. const PREFIX_0: u32 = 10_000; const PREFIX_1: u32 = PREFIX_0 * 2; const MAX_UNIQUE_CHANNELS: u32 = 128; @@ -198,7 +209,7 @@ frame_benchmarking::benchmarks! { for ingress_para_id in 0..i { // establish ingress channels to `para`. let ingress_para_id = ingress_para_id + PREFIX_0; - let _ = establish_para_connection::(ingress_para_id, 1, ParachainSetupStep::Established); + let _ = establish_para_connection::(ingress_para_id, para.into(), ParachainSetupStep::Established); } // nothing should be left unprocessed. @@ -207,7 +218,7 @@ frame_benchmarking::benchmarks! { for egress_para_id in 0..e { // establish egress channels to `para`. let egress_para_id = egress_para_id + PREFIX_1; - let _ = establish_para_connection::(1, egress_para_id, ParachainSetupStep::Established); + let _ = establish_para_connection::(para.into(), egress_para_id, ParachainSetupStep::Established); } // nothing should be left unprocessed. From e22a79fd6afe8c955a96d0646071aea22017fc70 Mon Sep 17 00:00:00 2001 From: kianenigma Date: Fri, 21 Jan 2022 07:57:32 +0000 Subject: [PATCH 33/36] do it the parachain-way: use const instead of type configs for simplicity. --- runtime/common/src/assigned_slots.rs | 2 -- runtime/common/src/integration_tests.rs | 2 -- runtime/common/src/paras_registrar.rs | 2 -- runtime/kusama/src/lib.rs | 2 -- runtime/parachains/src/configuration.rs | 29 +++++++++----------- runtime/parachains/src/hrmp.rs | 10 ++++++- runtime/parachains/src/hrmp/benchmarking.rs | 13 +++------ runtime/parachains/src/mock.rs | 4 +-- runtime/polkadot/src/lib.rs | 2 -- runtime/rococo/src/lib.rs | 2 -- runtime/test-runtime/src/lib.rs | 2 -- runtime/westend/src/lib.rs | 2 -- xcm/xcm-builder/tests/mock/mod.rs | 2 -- xcm/xcm-simulator/example/src/relay_chain.rs | 2 -- xcm/xcm-simulator/fuzzer/src/relay_chain.rs | 2 -- 15 files changed, 27 insertions(+), 51 deletions(-) diff --git a/runtime/common/src/assigned_slots.rs b/runtime/common/src/assigned_slots.rs index 5f8ac3e6a36d..85775883d07a 100644 --- a/runtime/common/src/assigned_slots.rs +++ b/runtime/common/src/assigned_slots.rs @@ -634,8 +634,6 @@ mod tests { impl parachains_configuration::Config for Test { type WeightInfo = parachains_configuration::TestWeightInfo; - type HrmpMaxOutboundChannelsBound = ConstU32<128>; - type HrmpMaxInboundChannelsBound = ConstU32<128>; } parameter_types! { diff --git a/runtime/common/src/integration_tests.rs b/runtime/common/src/integration_tests.rs index be1637e8f369..370073fa4de0 100644 --- a/runtime/common/src/integration_tests.rs +++ b/runtime/common/src/integration_tests.rs @@ -175,8 +175,6 @@ impl pallet_balances::Config for Test { impl configuration::Config for Test { type WeightInfo = configuration::TestWeightInfo; - type HrmpMaxOutboundChannelsBound = frame_support::traits::ConstU32<128>; - type HrmpMaxInboundChannelsBound = frame_support::traits::ConstU32<128>; } impl shared::Config for Test {} diff --git a/runtime/common/src/paras_registrar.rs b/runtime/common/src/paras_registrar.rs index 6e258d68c6ba..bfb0434a03c5 100644 --- a/runtime/common/src/paras_registrar.rs +++ b/runtime/common/src/paras_registrar.rs @@ -683,8 +683,6 @@ mod tests { impl configuration::Config for Test { type WeightInfo = configuration::TestWeightInfo; - type HrmpMaxOutboundChannelsBound = frame_support::traits::ConstU32<128>; - type HrmpMaxInboundChannelsBound = frame_support::traits::ConstU32<128>; } parameter_types! { diff --git a/runtime/kusama/src/lib.rs b/runtime/kusama/src/lib.rs index 1b2339315f9f..02d2d183930d 100644 --- a/runtime/kusama/src/lib.rs +++ b/runtime/kusama/src/lib.rs @@ -1189,8 +1189,6 @@ impl parachains_origin::Config for Runtime {} impl parachains_configuration::Config for Runtime { type WeightInfo = weights::runtime_parachains_configuration::WeightInfo; - type HrmpMaxOutboundChannelsBound = frame_support::traits::ConstU32<128>; - type HrmpMaxInboundChannelsBound = frame_support::traits::ConstU32<128>; } impl parachains_shared::Config for Runtime {} diff --git a/runtime/parachains/src/configuration.rs b/runtime/parachains/src/configuration.rs index 6f384c04e20c..692934bca91b 100644 --- a/runtime/parachains/src/configuration.rs +++ b/runtime/parachains/src/configuration.rs @@ -319,6 +319,10 @@ pub enum InconsistentError { }, /// `validation_upgrade_delay` is less than or equal 1. ValidationUpgradeDelayIsTooLow { validation_upgrade_delay: BlockNumber }, + /// Maximum number of HRMP outbound channels exceeded. + MaxHrmpOutboundChannelsExceeded, + /// Maximum number of HRMP inbound channels exceeded. + MaxHrmpInboundChannelsExceeded, } impl HostConfiguration @@ -381,6 +385,15 @@ where }) } + if self.hrmp_max_parachain_outbound_channels > crate::hrmp::HRMP_MAX_OUTBOUND_CHANNELS_BOUND + { + return Err(MaxHrmpOutboundChannelsExceeded) + } + + if self.hrmp_max_parachain_inbound_channels > crate::hrmp::HRMP_MAX_INBOUND_CHANNELS_BOUND { + return Err(MaxHrmpInboundChannelsExceeded) + } + Ok(()) } @@ -440,18 +453,6 @@ pub mod pallet { pub trait Config: frame_system::Config + shared::Config { /// Weight information for extrinsics in this pallet. type WeightInfo: WeightInfo; - - /// Maximum value that `hrmp_max_parachain_outbound_channels` or - /// `hrmp_max_parathread_outbound_channels` can be set to. - /// - /// This is used for benchmarking sanely bounding relevant storage items. - type HrmpMaxOutboundChannelsBound: Get; - - /// Maximum value that `hrmp_max_parachain_inbound_channels` or - /// `hrmp_max_parathread_inbound_channels` can be set to. - /// - /// This is used for benchmarking sanely bounding relevant storage items. - type HrmpMaxInboundChannelsBound: Get; } #[pallet::error] @@ -960,7 +961,6 @@ pub mod pallet { new: u32, ) -> DispatchResult { ensure_root(origin)?; - ensure!(new <= T::HrmpMaxInboundChannelsBound::get(), Error::::InvalidNewValue); Self::schedule_config_update(|config| { config.hrmp_max_parachain_inbound_channels = new; }) @@ -976,7 +976,6 @@ pub mod pallet { new: u32, ) -> DispatchResult { ensure_root(origin)?; - ensure!(new <= T::HrmpMaxInboundChannelsBound::get(), Error::::InvalidNewValue); Self::schedule_config_update(|config| { config.hrmp_max_parathread_inbound_channels = new; }) @@ -1004,7 +1003,6 @@ pub mod pallet { new: u32, ) -> DispatchResult { ensure_root(origin)?; - ensure!(new <= T::HrmpMaxOutboundChannelsBound::get(), Error::::InvalidNewValue); Self::schedule_config_update(|config| { config.hrmp_max_parachain_outbound_channels = new; }) @@ -1020,7 +1018,6 @@ pub mod pallet { new: u32, ) -> DispatchResult { ensure_root(origin)?; - ensure!(new <= T::HrmpMaxOutboundChannelsBound::get(), Error::::InvalidNewValue); Self::schedule_config_update(|config| { config.hrmp_max_parathread_outbound_channels = new; }) diff --git a/runtime/parachains/src/hrmp.rs b/runtime/parachains/src/hrmp.rs index fd94c4465f24..afdb6aeebc78 100644 --- a/runtime/parachains/src/hrmp.rs +++ b/runtime/parachains/src/hrmp.rs @@ -35,6 +35,14 @@ use sp_std::{ pub use pallet::*; +/// Maximum bound that can be set for inbound channels. +/// +/// If inaccurate, the weighing of this pallet might become inaccurate. It is expected form the +/// `configurations` pallet to check these values before setting +pub const HRMP_MAX_INBOUND_CHANNELS_BOUND: u32 = 128; +/// Same as [`HRMP_MAX_INBOUND_CHANNELS_BOUND`], but for outbound channels. +pub const HRMP_MAX_OUTBOUND_CHANNELS_BOUND: u32 = 128; + #[cfg(feature = "runtime-benchmarks")] mod benchmarking; @@ -312,7 +320,7 @@ pub mod pallet { StorageMap<_, Twox64Concat, HrmpChannelId, HrmpOpenChannelRequest>; // NOTE: could become bounded, but we don't have a global maximum for this. - // `HrmpMaxOutboundChannelsBound` are per parachain/parathread, while this storage tracks the + // `HRMP_MAX_INBOUND_CHANNELS_BOUND` are per parachain/parathread, while this storage tracks the // global state. #[pallet::storage] pub type HrmpOpenChannelRequestsList = diff --git a/runtime/parachains/src/hrmp/benchmarking.rs b/runtime/parachains/src/hrmp/benchmarking.rs index 9f2d01873ac6..6c45449c31ad 100644 --- a/runtime/parachains/src/hrmp/benchmarking.rs +++ b/runtime/parachains/src/hrmp/benchmarking.rs @@ -127,13 +127,13 @@ where /// `PREFIX_2`. /// /// These values are chosen large enough so that the likelihood of any clash is already very low. -/// Nonetheless, the value for `Config::HrmpMaxInboundChannelsBound` and -/// `Config::HrmpMaxOutboundChannelsBound` need to be checked in some places. const PREFIX_0: u32 = 10_000; const PREFIX_1: u32 = PREFIX_0 * 2; const MAX_UNIQUE_CHANNELS: u32 = 128; static_assertions::const_assert!(MAX_UNIQUE_CHANNELS < PREFIX_0); +static_assertions::const_assert!(HRMP_MAX_INBOUND_CHANNELS_BOUND < PREFIX_0); +static_assertions::const_assert!(HRMP_MAX_OUTBOUND_CHANNELS_BOUND < PREFIX_0); frame_benchmarking::benchmarks! { where_clause { where ::Origin: From } @@ -179,14 +179,9 @@ frame_benchmarking::benchmarks! { // channels. force_clean_hrmp { // ingress channels to a single leaving parachain that need to be closed. - let i in 0 .. (::HrmpMaxInboundChannelsBound::get() - 1); + let i in 0 .. (HRMP_MAX_INBOUND_CHANNELS_BOUND - 1); // egress channels to a single leaving parachain that need to be closed. - let e in 0 .. (::HrmpMaxOutboundChannelsBound::get() - 1); - - // we use 10_000 in this benchmark as the prefix of accounts. The components must be greater - // than the configured bounds to keep accounts sane. - assert!(::HrmpMaxInboundChannelsBound::get() < PREFIX_0); - assert!(::HrmpMaxOutboundChannelsBound::get() < PREFIX_0); + let e in 0 .. (HRMP_MAX_OUTBOUND_CHANNELS_BOUND - 1); // first, update the configs to support this many open channels... assert_ok!( diff --git a/runtime/parachains/src/mock.rs b/runtime/parachains/src/mock.rs index d96ecac50c15..05abd0de2757 100644 --- a/runtime/parachains/src/mock.rs +++ b/runtime/parachains/src/mock.rs @@ -25,7 +25,7 @@ use crate::{ use frame_support::{ parameter_types, - traits::{ConstU32, GenesisBuild, KeyOwnerProofSystem}, + traits::{GenesisBuild, KeyOwnerProofSystem}, weights::Weight, }; use frame_support_test::TestRandomness; @@ -184,8 +184,6 @@ impl crate::initializer::Config for Test { impl crate::configuration::Config for Test { type WeightInfo = crate::configuration::TestWeightInfo; - type HrmpMaxOutboundChannelsBound = ConstU32<128>; - type HrmpMaxInboundChannelsBound = ConstU32<128>; } impl crate::shared::Config for Test {} diff --git a/runtime/polkadot/src/lib.rs b/runtime/polkadot/src/lib.rs index 1bee60cf20b3..c49a6d46ce72 100644 --- a/runtime/polkadot/src/lib.rs +++ b/runtime/polkadot/src/lib.rs @@ -1177,8 +1177,6 @@ impl pallet_proxy::Config for Runtime { impl parachains_origin::Config for Runtime {} impl parachains_configuration::Config for Runtime { - type HrmpMaxOutboundChannelsBound = frame_support::traits::ConstU32<128>; - type HrmpMaxInboundChannelsBound = frame_support::traits::ConstU32<128>; type WeightInfo = weights::runtime_parachains_configuration::WeightInfo; } diff --git a/runtime/rococo/src/lib.rs b/runtime/rococo/src/lib.rs index 0596645b2065..1c15d2c93212 100644 --- a/runtime/rococo/src/lib.rs +++ b/runtime/rococo/src/lib.rs @@ -597,8 +597,6 @@ impl parachains_origin::Config for Runtime {} impl parachains_configuration::Config for Runtime { type WeightInfo = parachains_configuration::TestWeightInfo; - type HrmpMaxOutboundChannelsBound = frame_support::traits::ConstU32<128>; - type HrmpMaxInboundChannelsBound = frame_support::traits::ConstU32<128>; } impl parachains_shared::Config for Runtime {} diff --git a/runtime/test-runtime/src/lib.rs b/runtime/test-runtime/src/lib.rs index 0792f3ddbdb3..1e5859cc3f2e 100644 --- a/runtime/test-runtime/src/lib.rs +++ b/runtime/test-runtime/src/lib.rs @@ -465,8 +465,6 @@ impl pallet_sudo::Config for Runtime { impl parachains_configuration::Config for Runtime { type WeightInfo = parachains_configuration::TestWeightInfo; - type HrmpMaxOutboundChannelsBound = frame_support::traits::ConstU32<128>; - type HrmpMaxInboundChannelsBound = frame_support::traits::ConstU32<128>; } impl parachains_shared::Config for Runtime {} diff --git a/runtime/westend/src/lib.rs b/runtime/westend/src/lib.rs index 5956baf59d08..d57e17ebb011 100644 --- a/runtime/westend/src/lib.rs +++ b/runtime/westend/src/lib.rs @@ -817,8 +817,6 @@ impl parachains_origin::Config for Runtime {} impl parachains_configuration::Config for Runtime { type WeightInfo = weights::runtime_parachains_configuration::WeightInfo; - type HrmpMaxOutboundChannelsBound = frame_support::traits::ConstU32<128>; - type HrmpMaxInboundChannelsBound = frame_support::traits::ConstU32<128>; } impl parachains_shared::Config for Runtime {} diff --git a/xcm/xcm-builder/tests/mock/mod.rs b/xcm/xcm-builder/tests/mock/mod.rs index 07dca7c54a75..f11b628f65bc 100644 --- a/xcm/xcm-builder/tests/mock/mod.rs +++ b/xcm/xcm-builder/tests/mock/mod.rs @@ -110,8 +110,6 @@ impl shared::Config for Runtime {} impl configuration::Config for Runtime { type WeightInfo = configuration::TestWeightInfo; - type HrmpMaxOutboundChannelsBound = frame_support::traits::ConstU32<128>; - type HrmpMaxInboundChannelsBound = frame_support::traits::ConstU32<128>; } // aims to closely emulate the Kusama XcmConfig diff --git a/xcm/xcm-simulator/example/src/relay_chain.rs b/xcm/xcm-simulator/example/src/relay_chain.rs index f6baf81ba7a7..792a58d1a8ec 100644 --- a/xcm/xcm-simulator/example/src/relay_chain.rs +++ b/xcm/xcm-simulator/example/src/relay_chain.rs @@ -91,8 +91,6 @@ impl shared::Config for Runtime {} impl configuration::Config for Runtime { type WeightInfo = configuration::TestWeightInfo; - type HrmpMaxOutboundChannelsBound = frame_support::traits::ConstU32<128>; - type HrmpMaxInboundChannelsBound = frame_support::traits::ConstU32<128>; } parameter_types! { diff --git a/xcm/xcm-simulator/fuzzer/src/relay_chain.rs b/xcm/xcm-simulator/fuzzer/src/relay_chain.rs index f6baf81ba7a7..792a58d1a8ec 100644 --- a/xcm/xcm-simulator/fuzzer/src/relay_chain.rs +++ b/xcm/xcm-simulator/fuzzer/src/relay_chain.rs @@ -91,8 +91,6 @@ impl shared::Config for Runtime {} impl configuration::Config for Runtime { type WeightInfo = configuration::TestWeightInfo; - type HrmpMaxOutboundChannelsBound = frame_support::traits::ConstU32<128>; - type HrmpMaxInboundChannelsBound = frame_support::traits::ConstU32<128>; } parameter_types! { From a47ea77b84e8b54727a4b8a05d838f596b1f05df Mon Sep 17 00:00:00 2001 From: kianenigma Date: Fri, 21 Jan 2022 08:02:35 +0000 Subject: [PATCH 34/36] borrow assert_storage_consistency_exhaustive --- runtime/parachains/src/hrmp.rs | 4 ++-- runtime/parachains/src/hrmp/benchmarking.rs | 3 +++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/runtime/parachains/src/hrmp.rs b/runtime/parachains/src/hrmp.rs index 55f399188e41..06611c1a6d71 100644 --- a/runtime/parachains/src/hrmp.rs +++ b/runtime/parachains/src/hrmp.rs @@ -1379,7 +1379,7 @@ impl Pallet { } #[cfg(test)] -mod tests { +pub(crate) mod tests { use super::*; use crate::mock::{ new_test_ext, Configuration, Event as MockEvent, Hrmp, MockGenesisConfig, Paras, @@ -1517,7 +1517,7 @@ mod tests { ::HrmpChannels::get(&HrmpChannelId { sender, recipient }).is_some() } - fn assert_storage_consistency_exhaustive() { + pub(crate) fn assert_storage_consistency_exhaustive() { assert_eq!( ::HrmpOpenChannelRequests::iter() .map(|(k, _)| k) diff --git a/runtime/parachains/src/hrmp/benchmarking.rs b/runtime/parachains/src/hrmp/benchmarking.rs index 6c45449c31ad..c673a4f0cb26 100644 --- a/runtime/parachains/src/hrmp/benchmarking.rs +++ b/runtime/parachains/src/hrmp/benchmarking.rs @@ -224,6 +224,9 @@ frame_benchmarking::benchmarks! { }: _(frame_system::Origin::::Root, para, i, e) verify { // all in all, all of them must be gone by now. assert_eq!(HrmpChannels::::iter().count() as u32, 0); + // borrow this function from the tests to make sure state is clear, given that we do a lot + // of out-of-ordinary ops here. + crate::hrmp::tests::assert_storage_consistency_exhaustive(); } force_process_hrmp_open { From 745e146f7df89ce7f9c738003b71a1c2c531057e Mon Sep 17 00:00:00 2001 From: kianenigma Date: Fri, 21 Jan 2022 09:30:14 +0000 Subject: [PATCH 35/36] move assert_storage_consistency_exhaustive to Pallet, so it can be reused for benchmarks as well. --- runtime/parachains/src/hrmp.rs | 350 ++++++++++---------- runtime/parachains/src/hrmp/benchmarking.rs | 2 +- 2 files changed, 180 insertions(+), 172 deletions(-) diff --git a/runtime/parachains/src/hrmp.rs b/runtime/parachains/src/hrmp.rs index 06611c1a6d71..71a5a8ef9e83 100644 --- a/runtime/parachains/src/hrmp.rs +++ b/runtime/parachains/src/hrmp.rs @@ -1376,6 +1376,171 @@ impl Pallet { }); }); } + + #[cfg(any(feature = "runtime-benchmarks", test))] + fn assert_storage_consistency_exhaustive() { + fn assert_is_sorted(slice: &[T], id: &str) { + assert!(slice.windows(2).all(|xs| xs[0] <= xs[1]), "{} supposed to be sorted", id); + } + + let assert_contains_only_onboarded = |paras: Vec, cause: &str| { + for para in paras { + assert!( + crate::paras::Pallet::::is_valid_para(para), + "{}: {:?} para is offboarded", + cause, + para + ); + } + }; + + assert_eq!( + ::HrmpOpenChannelRequests::iter() + .map(|(k, _)| k) + .collect::>(), + ::HrmpOpenChannelRequestsList::get() + .into_iter() + .collect::>(), + ); + + // verify that the set of keys in `HrmpOpenChannelRequestCount` corresponds to the set + // of _senders_ in `HrmpOpenChannelRequests`. + // + // having ensured that, we can go ahead and go over all counts and verify that they match. + assert_eq!( + ::HrmpOpenChannelRequestCount::iter() + .map(|(k, _)| k) + .collect::>(), + ::HrmpOpenChannelRequests::iter() + .map(|(k, _)| k.sender) + .collect::>(), + ); + for (open_channel_initiator, expected_num) in + ::HrmpOpenChannelRequestCount::iter() + { + let actual_num = ::HrmpOpenChannelRequests::iter() + .filter(|(ch, _)| ch.sender == open_channel_initiator) + .count() as u32; + assert_eq!(expected_num, actual_num); + } + + // The same as above, but for accepted channel request count. Note that we are interested + // only in confirmed open requests. + assert_eq!( + ::HrmpAcceptedChannelRequestCount::iter() + .map(|(k, _)| k) + .collect::>(), + ::HrmpOpenChannelRequests::iter() + .filter(|(_, v)| v.confirmed) + .map(|(k, _)| k.recipient) + .collect::>(), + ); + for (channel_recipient, expected_num) in + ::HrmpAcceptedChannelRequestCount::iter() + { + let actual_num = ::HrmpOpenChannelRequests::iter() + .filter(|(ch, v)| ch.recipient == channel_recipient && v.confirmed) + .count() as u32; + assert_eq!(expected_num, actual_num); + } + + assert_eq!( + ::HrmpCloseChannelRequests::iter() + .map(|(k, _)| k) + .collect::>(), + ::HrmpCloseChannelRequestsList::get() + .into_iter() + .collect::>(), + ); + + // A HRMP watermark can be None for an onboarded parachain. However, an offboarded parachain + // cannot have an HRMP watermark: it should've been cleanup. + assert_contains_only_onboarded( + ::HrmpWatermarks::iter().map(|(k, _)| k).collect::>(), + "HRMP watermarks should contain only onboarded paras", + ); + + // An entry in `HrmpChannels` indicates that the channel is open. Only open channels can + // have contents. + for (non_empty_channel, contents) in ::HrmpChannelContents::iter() { + assert!(::HrmpChannels::contains_key(&non_empty_channel)); + + // pedantic check: there should be no empty vectors in storage, those should be modeled + // by a removed kv pair. + assert!(!contents.is_empty()); + } + + // Senders and recipients must be onboarded. Otherwise, all channels associated with them + // are removed. + assert_contains_only_onboarded( + ::HrmpChannels::iter() + .flat_map(|(k, _)| vec![k.sender, k.recipient]) + .collect::>(), + "senders and recipients in all channels should be onboarded", + ); + + // Check the docs for `HrmpIngressChannelsIndex` and `HrmpEgressChannelsIndex` in decl + // storage to get an index what are the channel mappings indexes. + // + // Here, from indexes. + // + // ingress egress + // + // a -> [x, y] x -> [a, b] + // b -> [x, z] y -> [a] + // z -> [b] + // + // we derive a list of channels they represent. + // + // (a, x) (a, x) + // (a, y) (a, y) + // (b, x) (b, x) + // (b, z) (b, z) + // + // and then that we compare that to the channel list in the `HrmpChannels`. + let channel_set_derived_from_ingress = ::HrmpIngressChannelsIndex::iter() + .flat_map(|(p, v)| v.into_iter().map(|i| (i, p)).collect::>()) + .collect::>(); + let channel_set_derived_from_egress = ::HrmpEgressChannelsIndex::iter() + .flat_map(|(p, v)| v.into_iter().map(|e| (p, e)).collect::>()) + .collect::>(); + let channel_set_ground_truth = ::HrmpChannels::iter() + .map(|(k, _)| (k.sender, k.recipient)) + .collect::>(); + assert_eq!(channel_set_derived_from_ingress, channel_set_derived_from_egress); + assert_eq!(channel_set_derived_from_egress, channel_set_ground_truth); + + ::HrmpIngressChannelsIndex::iter() + .map(|(_, v)| v) + .for_each(|v| assert_is_sorted(&v, "HrmpIngressChannelsIndex")); + ::HrmpEgressChannelsIndex::iter() + .map(|(_, v)| v) + .for_each(|v| assert_is_sorted(&v, "HrmpIngressChannelsIndex")); + + assert_contains_only_onboarded( + ::HrmpChannelDigests::iter().map(|(k, _)| k).collect::>(), + "HRMP channel digests should contain only onboarded paras", + ); + for (_digest_for_para, digest) in ::HrmpChannelDigests::iter() { + // Assert that items are in **strictly** ascending order. The strictness also implies + // there are no duplicates. + assert!(digest.windows(2).all(|xs| xs[0].0 < xs[1].0)); + + for (_, mut senders) in digest { + assert!(!senders.is_empty()); + + // check for duplicates. For that we sort the vector, then perform deduplication. + // if the vector stayed the same, there are no duplicates. + senders.sort(); + let orig_senders = senders.clone(); + senders.dedup(); + assert_eq!( + orig_senders, senders, + "duplicates removed implies existence of duplicates" + ); + } + } + } } #[cfg(test)] @@ -1387,7 +1552,7 @@ pub(crate) mod tests { }; use frame_support::{assert_noop, assert_ok, traits::Currency as _}; use primitives::v1::BlockNumber; - use std::collections::{BTreeMap, HashSet}; + use std::collections::BTreeMap; fn run_to_block(to: BlockNumber, new_session: Option>) { let config = Configuration::config(); @@ -1517,167 +1682,10 @@ pub(crate) mod tests { ::HrmpChannels::get(&HrmpChannelId { sender, recipient }).is_some() } - pub(crate) fn assert_storage_consistency_exhaustive() { - assert_eq!( - ::HrmpOpenChannelRequests::iter() - .map(|(k, _)| k) - .collect::>(), - ::HrmpOpenChannelRequestsList::get() - .into_iter() - .collect::>(), - ); - - // verify that the set of keys in `HrmpOpenChannelRequestCount` corresponds to the set - // of _senders_ in `HrmpOpenChannelRequests`. - // - // having ensured that, we can go ahead and go over all counts and verify that they match. - assert_eq!( - ::HrmpOpenChannelRequestCount::iter() - .map(|(k, _)| k) - .collect::>(), - ::HrmpOpenChannelRequests::iter() - .map(|(k, _)| k.sender) - .collect::>(), - ); - for (open_channel_initiator, expected_num) in - ::HrmpOpenChannelRequestCount::iter() - { - let actual_num = ::HrmpOpenChannelRequests::iter() - .filter(|(ch, _)| ch.sender == open_channel_initiator) - .count() as u32; - assert_eq!(expected_num, actual_num); - } - - // The same as above, but for accepted channel request count. Note that we are interested - // only in confirmed open requests. - assert_eq!( - ::HrmpAcceptedChannelRequestCount::iter() - .map(|(k, _)| k) - .collect::>(), - ::HrmpOpenChannelRequests::iter() - .filter(|(_, v)| v.confirmed) - .map(|(k, _)| k.recipient) - .collect::>(), - ); - for (channel_recipient, expected_num) in - ::HrmpAcceptedChannelRequestCount::iter() - { - let actual_num = ::HrmpOpenChannelRequests::iter() - .filter(|(ch, v)| ch.recipient == channel_recipient && v.confirmed) - .count() as u32; - assert_eq!(expected_num, actual_num); - } - - assert_eq!( - ::HrmpCloseChannelRequests::iter() - .map(|(k, _)| k) - .collect::>(), - ::HrmpCloseChannelRequestsList::get() - .into_iter() - .collect::>(), - ); - - // A HRMP watermark can be None for an onboarded parachain. However, an offboarded parachain - // cannot have an HRMP watermark: it should've been cleanup. - assert_contains_only_onboarded( - ::HrmpWatermarks::iter().map(|(k, _)| k), - "HRMP watermarks should contain only onboarded paras", - ); - - // An entry in `HrmpChannels` indicates that the channel is open. Only open channels can - // have contents. - for (non_empty_channel, contents) in ::HrmpChannelContents::iter() { - assert!(::HrmpChannels::contains_key(&non_empty_channel)); - - // pedantic check: there should be no empty vectors in storage, those should be modeled - // by a removed kv pair. - assert!(!contents.is_empty()); - } - - // Senders and recipients must be onboarded. Otherwise, all channels associated with them - // are removed. - assert_contains_only_onboarded( - ::HrmpChannels::iter().flat_map(|(k, _)| vec![k.sender, k.recipient]), - "senders and recipients in all channels should be onboarded", - ); - - // Check the docs for `HrmpIngressChannelsIndex` and `HrmpEgressChannelsIndex` in decl - // storage to get an index what are the channel mappings indexes. - // - // Here, from indexes. - // - // ingress egress - // - // a -> [x, y] x -> [a, b] - // b -> [x, z] y -> [a] - // z -> [b] - // - // we derive a list of channels they represent. - // - // (a, x) (a, x) - // (a, y) (a, y) - // (b, x) (b, x) - // (b, z) (b, z) - // - // and then that we compare that to the channel list in the `HrmpChannels`. - let channel_set_derived_from_ingress = ::HrmpIngressChannelsIndex::iter() - .flat_map(|(p, v)| v.into_iter().map(|i| (i, p)).collect::>()) - .collect::>(); - let channel_set_derived_from_egress = ::HrmpEgressChannelsIndex::iter() - .flat_map(|(p, v)| v.into_iter().map(|e| (p, e)).collect::>()) - .collect::>(); - let channel_set_ground_truth = ::HrmpChannels::iter() - .map(|(k, _)| (k.sender, k.recipient)) - .collect::>(); - assert_eq!(channel_set_derived_from_ingress, channel_set_derived_from_egress); - assert_eq!(channel_set_derived_from_egress, channel_set_ground_truth); - - ::HrmpIngressChannelsIndex::iter() - .map(|(_, v)| v) - .for_each(|v| assert_is_sorted(&v, "HrmpIngressChannelsIndex")); - ::HrmpEgressChannelsIndex::iter() - .map(|(_, v)| v) - .for_each(|v| assert_is_sorted(&v, "HrmpIngressChannelsIndex")); - - assert_contains_only_onboarded( - ::HrmpChannelDigests::iter().map(|(k, _)| k), - "HRMP channel digests should contain only onboarded paras", - ); - for (_digest_for_para, digest) in ::HrmpChannelDigests::iter() { - // Assert that items are in **strictly** ascending order. The strictness also implies - // there are no duplicates. - assert!(digest.windows(2).all(|xs| xs[0].0 < xs[1].0)); - - for (_, mut senders) in digest { - assert!(!senders.is_empty()); - - // check for duplicates. For that we sort the vector, then perform deduplication. - // if the vector stayed the same, there are no duplicates. - senders.sort(); - let orig_senders = senders.clone(); - senders.dedup(); - assert_eq!( - orig_senders, senders, - "duplicates removed implies existence of duplicates" - ); - } - } - - fn assert_contains_only_onboarded(iter: impl Iterator, cause: &str) { - for para in iter { - assert!(Paras::is_valid_para(para), "{}: {} para is offboarded", cause, para); - } - } - } - - fn assert_is_sorted(slice: &[T], id: &str) { - assert!(slice.windows(2).all(|xs| xs[0] <= xs[1]), "{} supposed to be sorted", id); - } - #[test] fn empty_state_consistent_state() { new_test_ext(GenesisConfigBuilder::default().build()).execute_with(|| { - assert_storage_consistency_exhaustive(); + Hrmp::assert_storage_consistency_exhaustive(); }); } @@ -1695,12 +1703,12 @@ pub(crate) mod tests { run_to_block(5, Some(vec![4, 5])); Hrmp::hrmp_init_open_channel(para_a_origin.into(), para_b, 2, 8).unwrap(); - assert_storage_consistency_exhaustive(); + Hrmp::assert_storage_consistency_exhaustive(); assert!(System::events().iter().any(|record| record.event == MockEvent::Hrmp(Event::OpenChannelRequested(para_a, para_b, 2, 8)))); Hrmp::hrmp_accept_open_channel(para_b_origin.into(), para_a).unwrap(); - assert_storage_consistency_exhaustive(); + Hrmp::assert_storage_consistency_exhaustive(); assert!(System::events().iter().any(|record| record.event == MockEvent::Hrmp(Event::OpenChannelAccepted(para_a, para_b)))); @@ -1708,7 +1716,7 @@ pub(crate) mod tests { // not been created yet. run_to_block(6, None); assert!(!channel_exists(para_a, para_b)); - assert_storage_consistency_exhaustive(); + Hrmp::assert_storage_consistency_exhaustive(); // Now let the session change happen and thus open the channel. run_to_block(8, Some(vec![8])); @@ -1738,12 +1746,12 @@ pub(crate) mod tests { let channel_id = HrmpChannelId { sender: para_a, recipient: para_b }; Hrmp::hrmp_close_channel(para_b_origin.into(), channel_id.clone()).unwrap(); assert!(channel_exists(para_a, para_b)); - assert_storage_consistency_exhaustive(); + Hrmp::assert_storage_consistency_exhaustive(); // After the session change the channel should be closed. run_to_block(8, Some(vec![8])); assert!(!channel_exists(para_a, para_b)); - assert_storage_consistency_exhaustive(); + Hrmp::assert_storage_consistency_exhaustive(); assert!(System::events().iter().any(|record| record.event == MockEvent::Hrmp(Event::ChannelClosed(para_b, channel_id.clone())))); }); @@ -1776,14 +1784,14 @@ pub(crate) mod tests { let config = Configuration::config(); assert!(Hrmp::check_outbound_hrmp(&config, para_a, &msgs).is_ok()); let _ = Hrmp::queue_outbound_hrmp(para_a, msgs); - assert_storage_consistency_exhaustive(); + Hrmp::assert_storage_consistency_exhaustive(); // On Block 7: // B receives the message sent by A. B sets the watermark to 6. run_to_block(7, None); assert!(Hrmp::check_hrmp_watermark(para_b, 7, 6).is_ok()); let _ = Hrmp::prune_hrmp(para_b, 6); - assert_storage_consistency_exhaustive(); + Hrmp::assert_storage_consistency_exhaustive(); }); } @@ -1846,7 +1854,7 @@ pub(crate) mod tests { run_to_block(7, Some(vec![6, 7])); assert!(!Paras::is_valid_para(para_a)); assert!(!channel_exists(para_a, para_b)); - assert_storage_consistency_exhaustive(); + Hrmp::assert_storage_consistency_exhaustive(); }); } @@ -1905,7 +1913,7 @@ pub(crate) mod tests { ], ); - assert_storage_consistency_exhaustive(); + Hrmp::assert_storage_consistency_exhaustive(); }); } @@ -2054,7 +2062,7 @@ pub(crate) mod tests { // The channel should be removed. assert!(!Paras::is_valid_para(para_a)); assert!(!channel_exists(para_a, para_b)); - assert_storage_consistency_exhaustive(); + Hrmp::assert_storage_consistency_exhaustive(); assert_eq!(::Currency::free_balance(¶_a.into_account()), 100); assert_eq!(::Currency::free_balance(¶_b.into_account()), 110); @@ -2092,7 +2100,7 @@ pub(crate) mod tests { // The outcome we expect is `para_b` should receive the refund. assert_eq!(::Currency::free_balance(¶_b.into_account()), 110); assert!(!channel_exists(para_a, para_b)); - assert_storage_consistency_exhaustive(); + Hrmp::assert_storage_consistency_exhaustive(); }); } @@ -2121,7 +2129,7 @@ pub(crate) mod tests { run_to_block(10, Some(vec![10])); assert!(!channel_exists(para_a, para_b)); - assert_storage_consistency_exhaustive(); + Hrmp::assert_storage_consistency_exhaustive(); }); } } diff --git a/runtime/parachains/src/hrmp/benchmarking.rs b/runtime/parachains/src/hrmp/benchmarking.rs index c673a4f0cb26..0ee4509a7a58 100644 --- a/runtime/parachains/src/hrmp/benchmarking.rs +++ b/runtime/parachains/src/hrmp/benchmarking.rs @@ -226,7 +226,7 @@ frame_benchmarking::benchmarks! { assert_eq!(HrmpChannels::::iter().count() as u32, 0); // borrow this function from the tests to make sure state is clear, given that we do a lot // of out-of-ordinary ops here. - crate::hrmp::tests::assert_storage_consistency_exhaustive(); + Hrmp::::assert_storage_consistency_exhaustive(); } force_process_hrmp_open { From 523ff330e0f9ded42f7a1c58cf0bcdaca7a0ed2c Mon Sep 17 00:00:00 2001 From: kianenigma Date: Fri, 21 Jan 2022 12:52:16 +0000 Subject: [PATCH 36/36] fix typo --- runtime/parachains/src/hrmp/benchmarking.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/runtime/parachains/src/hrmp/benchmarking.rs b/runtime/parachains/src/hrmp/benchmarking.rs index 0ee4509a7a58..a9ba7031fe3e 100644 --- a/runtime/parachains/src/hrmp/benchmarking.rs +++ b/runtime/parachains/src/hrmp/benchmarking.rs @@ -118,7 +118,7 @@ where output } -/// Prefix value for account generation. These numbers are used as seeds to crete distinct (para) +/// Prefix value for account generation. These numbers are used as seeds to create distinct (para) /// accounts. /// /// To maintain sensibility created accounts should always be unique and never overlap. For example,