From 6e698891d8e105052925eac1f33b3f372aa22095 Mon Sep 17 00:00:00 2001 From: Nisheeth Barthwal Date: Thu, 22 Dec 2022 09:03:08 +0100 Subject: [PATCH 1/4] benchmark parachain-system --- Cargo.lock | 1 + pallets/parachain-system/Cargo.toml | 5 ++++- pallets/parachain-system/src/lib.rs | 14 +++++++++++--- parachain-template/runtime/Cargo.toml | 1 + parachain-template/runtime/src/lib.rs | 2 ++ parachains/runtimes/assets/statemine/Cargo.toml | 1 + parachains/runtimes/assets/statemine/src/lib.rs | 2 ++ parachains/runtimes/assets/statemint/Cargo.toml | 1 + parachains/runtimes/assets/statemint/src/lib.rs | 2 ++ parachains/runtimes/assets/westmint/Cargo.toml | 1 + parachains/runtimes/assets/westmint/src/lib.rs | 2 ++ .../runtimes/contracts/contracts-rococo/Cargo.toml | 1 + .../runtimes/contracts/contracts-rococo/src/lib.rs | 2 ++ parachains/runtimes/starters/seedling/src/lib.rs | 1 + parachains/runtimes/starters/shell/src/lib.rs | 1 + .../runtimes/testing/rococo-parachain/src/lib.rs | 1 + test/runtime/src/lib.rs | 1 + 17 files changed, 35 insertions(+), 4 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index f5238838f98..9f29592d763 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1824,6 +1824,7 @@ dependencies = [ "cumulus-test-client", "cumulus-test-relay-sproof-builder", "environmental", + "frame-benchmarking", "frame-support", "frame-system", "hex-literal", diff --git a/pallets/parachain-system/Cargo.toml b/pallets/parachain-system/Cargo.toml index 5aab22fce31..01c9cf8bc8b 100644 --- a/pallets/parachain-system/Cargo.toml +++ b/pallets/parachain-system/Cargo.toml @@ -26,6 +26,7 @@ sp-state-machine = { git = "https://github.com/paritytech/substrate", default-fe sp-std = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" } sp-trie = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" } sp-version = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" } +frame-benchmarking = { git = "https://github.com/paritytech/substrate", default-features = false, optional = true, branch = "master" } # Polkadot polkadot-parachain = { git = "https://github.com/paritytech/polkadot", default-features = false, features = [ "wasm-api" ], branch = "master" } @@ -75,5 +76,7 @@ std = [ ] runtime-benchmarks = [ - "sp-runtime/runtime-benchmarks" + "frame-benchmarking/runtime-benchmarks", + "frame-support/runtime-benchmarks", + "frame-system/runtime-benchmarks", ] diff --git a/pallets/parachain-system/src/lib.rs b/pallets/parachain-system/src/lib.rs index b42453401a0..2d3847c103d 100644 --- a/pallets/parachain-system/src/lib.rs +++ b/pallets/parachain-system/src/lib.rs @@ -54,6 +54,7 @@ use sp_runtime::{ }; use sp_std::{cmp, collections::btree_map::BTreeMap, prelude::*}; +pub mod weights; mod migration; mod relay_state_snapshot; #[macro_use] @@ -61,6 +62,11 @@ pub mod validate_block; #[cfg(test)] mod tests; +#[cfg(feature = "runtime-benchmarks")] +mod benchmarking; +#[cfg(test)] +mod mock; + /// Register the `validate_block` function that is used by parachains to validate blocks on a /// validator. /// @@ -136,6 +142,7 @@ impl CheckAssociatedRelayNumber for AnyRelayNumber { #[frame_support::pallet] pub mod pallet { use super::*; + pub use crate::weights::WeightInfo; use frame_support::pallet_prelude::*; use frame_system::pallet_prelude::*; @@ -176,6 +183,9 @@ pub mod pallet { /// Something that can check the associated relay parent block number. type CheckAssociatedRelayNumber: CheckAssociatedRelayNumber; + + /// The weight information of this pallet. + type WeightInfo: WeightInfo; } #[pallet::hooks] @@ -334,8 +344,7 @@ pub mod pallet { /// /// As a side effect, this function upgrades the current validation function /// if the appropriate time has come. - #[pallet::weight((0, DispatchClass::Mandatory))] - // TODO: This weight should be corrected. + #[pallet::weight((T::WeightInfo::set_validation_data_no_messages(), DispatchClass::Mandatory))] pub fn set_validation_data( origin: OriginFor, data: ParachainInherentData, @@ -426,7 +435,6 @@ pub mod pallet { horizontal_messages, vfp.relay_parent_number, ); - Ok(PostDispatchInfo { actual_weight: Some(total_weight), pays_fee: Pays::No }) } diff --git a/parachain-template/runtime/Cargo.toml b/parachain-template/runtime/Cargo.toml index 77c8c12e123..c10b353a2e3 100644 --- a/parachain-template/runtime/Cargo.toml +++ b/parachain-template/runtime/Cargo.toml @@ -142,6 +142,7 @@ runtime-benchmarks = [ "xcm-builder/runtime-benchmarks", "cumulus-pallet-session-benchmarking/runtime-benchmarks", "cumulus-pallet-xcmp-queue/runtime-benchmarks", + "cumulus-pallet-parachain-system/runtime-benchmarks", ] try-runtime = [ diff --git a/parachain-template/runtime/src/lib.rs b/parachain-template/runtime/src/lib.rs index a4aecb880cc..a1f99342ce6 100644 --- a/parachain-template/runtime/src/lib.rs +++ b/parachain-template/runtime/src/lib.rs @@ -377,6 +377,7 @@ impl cumulus_pallet_parachain_system::Config for Runtime { type XcmpMessageHandler = XcmpQueue; type ReservedXcmpWeight = ReservedXcmpWeight; type CheckAssociatedRelayNumber = RelayNumberStrictlyIncreases; + type WeightInfo = cumulus_pallet_parachain_system::weights::SubstrateWeight; } impl parachain_info::Config for Runtime {} @@ -508,6 +509,7 @@ mod benches { [pallet_session, SessionBench::] [pallet_timestamp, Timestamp] [pallet_collator_selection, CollatorSelection] + [cumulus_pallet_parachain_system, ParachainSystem] [cumulus_pallet_xcmp_queue, XcmpQueue] ); } diff --git a/parachains/runtimes/assets/statemine/Cargo.toml b/parachains/runtimes/assets/statemine/Cargo.toml index 7fdcbbe90c2..2eb690cde7c 100644 --- a/parachains/runtimes/assets/statemine/Cargo.toml +++ b/parachains/runtimes/assets/statemine/Cargo.toml @@ -100,6 +100,7 @@ runtime-benchmarks = [ "cumulus-pallet-session-benchmarking/runtime-benchmarks", "pallet-collator-selection/runtime-benchmarks", "cumulus-pallet-xcmp-queue/runtime-benchmarks", + "cumulus-pallet-parachain-system/runtime-benchmarks", ] try-runtime = [ "frame-executive/try-runtime", diff --git a/parachains/runtimes/assets/statemine/src/lib.rs b/parachains/runtimes/assets/statemine/src/lib.rs index 4bdb45601cf..a9b39d65ebb 100644 --- a/parachains/runtimes/assets/statemine/src/lib.rs +++ b/parachains/runtimes/assets/statemine/src/lib.rs @@ -419,6 +419,7 @@ impl cumulus_pallet_parachain_system::Config for Runtime { type XcmpMessageHandler = XcmpQueue; type ReservedXcmpWeight = ReservedXcmpWeight; type CheckAssociatedRelayNumber = RelayNumberStrictlyIncreases; + type WeightInfo = cumulus_pallet_parachain_system::weights::SubstrateWeight; } impl parachain_info::Config for Runtime {} @@ -634,6 +635,7 @@ mod benches { [pallet_utility, Utility] [pallet_timestamp, Timestamp] [pallet_collator_selection, CollatorSelection] + [cumulus_pallet_parachain_system, ParachainSystem] [cumulus_pallet_xcmp_queue, XcmpQueue] ); } diff --git a/parachains/runtimes/assets/statemint/Cargo.toml b/parachains/runtimes/assets/statemint/Cargo.toml index 9e549bc20e1..bc8438069da 100644 --- a/parachains/runtimes/assets/statemint/Cargo.toml +++ b/parachains/runtimes/assets/statemint/Cargo.toml @@ -99,6 +99,7 @@ runtime-benchmarks = [ "cumulus-pallet-session-benchmarking/runtime-benchmarks", "pallet-collator-selection/runtime-benchmarks", "cumulus-pallet-xcmp-queue/runtime-benchmarks", + "cumulus-pallet-parachain-system/runtime-benchmarks", ] try-runtime = [ "frame-executive/try-runtime", diff --git a/parachains/runtimes/assets/statemint/src/lib.rs b/parachains/runtimes/assets/statemint/src/lib.rs index f58a6821cf5..dc1aa47cc88 100644 --- a/parachains/runtimes/assets/statemint/src/lib.rs +++ b/parachains/runtimes/assets/statemint/src/lib.rs @@ -449,6 +449,7 @@ impl cumulus_pallet_parachain_system::Config for Runtime { type XcmpMessageHandler = XcmpQueue; type ReservedXcmpWeight = ReservedXcmpWeight; type CheckAssociatedRelayNumber = RelayNumberStrictlyIncreases; + type WeightInfo = cumulus_pallet_parachain_system::weights::SubstrateWeight; } impl parachain_info::Config for Runtime {} @@ -663,6 +664,7 @@ mod benches { [pallet_utility, Utility] [pallet_timestamp, Timestamp] [pallet_collator_selection, CollatorSelection] + [cumulus_pallet_parachain_system, ParachainSystem] [cumulus_pallet_xcmp_queue, XcmpQueue] ); } diff --git a/parachains/runtimes/assets/westmint/Cargo.toml b/parachains/runtimes/assets/westmint/Cargo.toml index 3fc7d857acc..97154dc40d4 100644 --- a/parachains/runtimes/assets/westmint/Cargo.toml +++ b/parachains/runtimes/assets/westmint/Cargo.toml @@ -99,6 +99,7 @@ runtime-benchmarks = [ "cumulus-pallet-session-benchmarking/runtime-benchmarks", "pallet-collator-selection/runtime-benchmarks", "cumulus-pallet-xcmp-queue/runtime-benchmarks", + "cumulus-pallet-parachain-system/runtime-benchmarks", ] try-runtime = [ "frame-executive/try-runtime", diff --git a/parachains/runtimes/assets/westmint/src/lib.rs b/parachains/runtimes/assets/westmint/src/lib.rs index 234357c6348..f19995ecdc2 100644 --- a/parachains/runtimes/assets/westmint/src/lib.rs +++ b/parachains/runtimes/assets/westmint/src/lib.rs @@ -414,6 +414,7 @@ impl cumulus_pallet_parachain_system::Config for Runtime { type XcmpMessageHandler = XcmpQueue; type ReservedXcmpWeight = ReservedXcmpWeight; type CheckAssociatedRelayNumber = RelayNumberStrictlyIncreases; + type WeightInfo = cumulus_pallet_parachain_system::weights::SubstrateWeight; } impl parachain_info::Config for Runtime {} @@ -624,6 +625,7 @@ mod benches { [pallet_utility, Utility] [pallet_timestamp, Timestamp] [pallet_collator_selection, CollatorSelection] + [pallet_parachain_system, ParachainSystem] [cumulus_pallet_xcmp_queue, XcmpQueue] ); } diff --git a/parachains/runtimes/contracts/contracts-rococo/Cargo.toml b/parachains/runtimes/contracts/contracts-rococo/Cargo.toml index 998da496480..70c935354e4 100644 --- a/parachains/runtimes/contracts/contracts-rococo/Cargo.toml +++ b/parachains/runtimes/contracts/contracts-rococo/Cargo.toml @@ -159,6 +159,7 @@ runtime-benchmarks = [ "sp-runtime/runtime-benchmarks", "xcm-builder/runtime-benchmarks", "cumulus-pallet-session-benchmarking/runtime-benchmarks", + "cumulus-pallet-parachain-system/runtime-benchmarks", ] try-runtime = [ diff --git a/parachains/runtimes/contracts/contracts-rococo/src/lib.rs b/parachains/runtimes/contracts/contracts-rococo/src/lib.rs index e8639269fe9..b91b8fa4e70 100644 --- a/parachains/runtimes/contracts/contracts-rococo/src/lib.rs +++ b/parachains/runtimes/contracts/contracts-rococo/src/lib.rs @@ -255,6 +255,7 @@ impl cumulus_pallet_parachain_system::Config for Runtime { type XcmpMessageHandler = XcmpQueue; type ReservedXcmpWeight = ConstU64<{ MAXIMUM_BLOCK_WEIGHT / 4 }>; type CheckAssociatedRelayNumber = RelayNumberStrictlyIncreases; + type WeightInfo = cumulus_pallet_parachain_system::weights::SubstrateWeight; } impl pallet_randomness_collective_flip::Config for Runtime {} @@ -372,6 +373,7 @@ mod benches { [pallet_utility, Utility] [pallet_timestamp, Timestamp] [pallet_collator_selection, CollatorSelection] + [cumulus_pallet_parachain_system, ParachainSystem] [pallet_contracts, Contracts] ); } diff --git a/parachains/runtimes/starters/seedling/src/lib.rs b/parachains/runtimes/starters/seedling/src/lib.rs index 146a769fd5a..11fd6a694fa 100644 --- a/parachains/runtimes/starters/seedling/src/lib.rs +++ b/parachains/runtimes/starters/seedling/src/lib.rs @@ -168,6 +168,7 @@ impl cumulus_pallet_parachain_system::Config for Runtime { type XcmpMessageHandler = (); type ReservedXcmpWeight = (); type CheckAssociatedRelayNumber = RelayNumberStrictlyIncreases; + type WeightInfo = cumulus_pallet_parachain_system::weights::SubstrateWeight; } impl parachain_info::Config for Runtime {} diff --git a/parachains/runtimes/starters/shell/src/lib.rs b/parachains/runtimes/starters/shell/src/lib.rs index d08cebe47e0..73fe309ae09 100644 --- a/parachains/runtimes/starters/shell/src/lib.rs +++ b/parachains/runtimes/starters/shell/src/lib.rs @@ -172,6 +172,7 @@ impl cumulus_pallet_parachain_system::Config for Runtime { type XcmpMessageHandler = (); type ReservedXcmpWeight = (); type CheckAssociatedRelayNumber = RelayNumberStrictlyIncreases; + type WeightInfo = cumulus_pallet_parachain_system::weights::SubstrateWeight; } impl parachain_info::Config for Runtime {} diff --git a/parachains/runtimes/testing/rococo-parachain/src/lib.rs b/parachains/runtimes/testing/rococo-parachain/src/lib.rs index ec86567217d..0b05bcf158a 100644 --- a/parachains/runtimes/testing/rococo-parachain/src/lib.rs +++ b/parachains/runtimes/testing/rococo-parachain/src/lib.rs @@ -268,6 +268,7 @@ impl cumulus_pallet_parachain_system::Config for Runtime { type XcmpMessageHandler = XcmpQueue; type ReservedXcmpWeight = ReservedXcmpWeight; type CheckAssociatedRelayNumber = RelayNumberStrictlyIncreases; + type WeightInfo = cumulus_pallet_parachain_system::weights::SubstrateWeight; } impl parachain_info::Config for Runtime {} diff --git a/test/runtime/src/lib.rs b/test/runtime/src/lib.rs index 73246dd3171..4c4a5e8bbac 100644 --- a/test/runtime/src/lib.rs +++ b/test/runtime/src/lib.rs @@ -267,6 +267,7 @@ impl cumulus_pallet_parachain_system::Config for Runtime { type XcmpMessageHandler = (); type ReservedXcmpWeight = (); type CheckAssociatedRelayNumber = cumulus_pallet_parachain_system::AnyRelayNumber; + type WeightInfo = cumulus_pallet_parachain_system::weights::SubstrateWeight; } parameter_types! { From 6b85bfa21a04fa931128b1f7fd41bcd40f03eaf0 Mon Sep 17 00:00:00 2001 From: Nisheeth Barthwal Date: Thu, 22 Dec 2022 09:04:07 +0100 Subject: [PATCH 2/4] add weights --- pallets/parachain-system/src/benchmarking.rs | 69 +++++++++++++++ pallets/parachain-system/src/mock.rs | 92 ++++++++++++++++++++ pallets/parachain-system/src/weights.rs | 87 ++++++++++++++++++ 3 files changed, 248 insertions(+) create mode 100644 pallets/parachain-system/src/benchmarking.rs create mode 100644 pallets/parachain-system/src/mock.rs create mode 100644 pallets/parachain-system/src/weights.rs diff --git a/pallets/parachain-system/src/benchmarking.rs b/pallets/parachain-system/src/benchmarking.rs new file mode 100644 index 00000000000..36ed00b4b14 --- /dev/null +++ b/pallets/parachain-system/src/benchmarking.rs @@ -0,0 +1,69 @@ +// Copyright (C) 2021 Parity Technologies (UK) Ltd. +// SPDX-License-Identifier: Apache-2.0 + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +//! Benchmarking setup for pallet-collator-selection + +#![allow(unused)] + +use super::*; + +use crate::{Pallet, ValidationData}; +use cumulus_primitives_core::relay_chain::v2::HeadData; +use frame_benchmarking::{account, benchmarks, impl_benchmark_test_suite, whitelisted_caller}; +use frame_support::{ + assert_ok, + codec::Decode, + traits::{Currency, EnsureOrigin, Get}, +}; +use frame_system::{EnsureNone, EnsureSigned, EventRecord, RawOrigin}; +use sp_core::H256; +use sp_std::{collections::btree_set::BTreeSet, prelude::*}; +use sp_trie::StorageProof; + +const SEED: u32 = 0; + +benchmarks! { + set_validation_data_no_messages { + // root and proof are obtained via `RelayStateSproofBuilder::default().into_state_root_and_proof()` + let root = [87, 247, 132, 202, 60, 197, 129, 248, 29, 30, 75, 209, 87, 82, 217, 27, 193, 91, 133, 158, 57, 219, 5, 125, 31, 120, 73, 108, 83, 161, 122, 141]; + let proof = vec![ + vec![0, 0, 32, 0, 0, 0, 16, 0, 8, 0, 0, 0, 0, 4, 0, 0, 0, 1, 0, 0, 5, 0, 0, 0, 5, 0, 0, 0, 6, 0, 0, 0, 6, 0, 0, 0], + vec![63, 32, 6, 222, 61, 138, 84, 210, 126, 68, 169, 213, 206, 24, 150, 24, 242, 45, 180, 180, 157, 149, 50, 13, 144, 33, 153, 76, 133, 15, 37, 184, 227, 133, 122, 95, 83, 148, 165, 203, 236, 87, 253, 11, 60, 82, 36, 95, 199, 120, 54, 22, 228, 227, 110, 231, 204, 83, 94, 179, 154, 8, 200, 180, 89, 235], + vec![127, 0, 12, 182, 243, 110, 2, 122, 187, 32, 145, 207, 181, 17, 10, 181, 8, 127, 6, 21, 91, 60, 217, 168, 201, 229, 233, 162, 63, 213, 220, 19, 165, 237, 32, 0, 0, 0, 0, 0, 0, 0, 0], + vec![128, 3, 0, 128, 242, 238, 200, 199, 170, 3, 233, 7, 253, 11, 161, 204, 28, 109, 207, 110, 116, 240, 105, 181, 38, 64, 118, 111, 3, 222, 55, 184, 183, 81, 181, 61, 128, 30, 47, 17, 234, 172, 118, 214, 115, 102, 113, 126, 126, 111, 149, 151, 252, 216, 113, 234, 7, 17, 48, 53, 220, 0, 90, 170, 247, 242, 1, 69, 8], + ]; + + let data = ParachainInherentData { + validation_data: PersistedValidationData { + parent_head: vec![].into(), + relay_parent_number: 1, + relay_parent_storage_root: H256::from_slice(&root), + max_pov_size: Default::default(), + }, + relay_chain_state: StorageProof::new(proof), + downward_messages: vec![], + horizontal_messages: BTreeMap::new(), + }; + }: { + assert_ok!( + >::set_validation_data(EnsureNone::successful_origin(), data) + ); + } + verify { + assert_eq!(>::get().unwrap().relay_parent_number, 1); + } +} + +impl_benchmark_test_suite!(Pallet, crate::mock::new_test_ext(), crate::mock::Test,); diff --git a/pallets/parachain-system/src/mock.rs b/pallets/parachain-system/src/mock.rs new file mode 100644 index 00000000000..e04451e81c8 --- /dev/null +++ b/pallets/parachain-system/src/mock.rs @@ -0,0 +1,92 @@ +#![allow(unused)] + +use super::*; + +use codec::Encode; +use cumulus_primitives_core::{ + relay_chain::BlockNumber as RelayBlockNumber, AbridgedHrmpChannel, InboundDownwardMessage, + InboundHrmpMessage, PersistedValidationData, +}; +use frame_support::{ + assert_ok, + dispatch::UnfilteredDispatchable, + inherent::{InherentData, ProvideInherent}, + parameter_types, + traits::{OnFinalize, OnInitialize}, + weights::Weight, +}; +use frame_system::RawOrigin; +use relay_chain::v2::HrmpChannelId; +use sp_core::H256; +use sp_runtime::traits::{BlakeTwo256, IdentityLookup}; +use sp_version::RuntimeVersion; + +use crate as parachain_system; + +type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic; +type Block = frame_system::mocking::MockBlock; + +frame_support::construct_runtime!( + pub enum Test where + Block = Block, + NodeBlock = Block, + UncheckedExtrinsic = UncheckedExtrinsic, + { + System: frame_system::{Pallet, Call, Config, Storage, Event}, + ParachainSystem: parachain_system::{Pallet, Call, Config, Storage, Inherent, Event, ValidateUnsigned}, + } +); + +parameter_types! { + pub const BlockHashCount: u64 = 250; + pub Version: RuntimeVersion = RuntimeVersion { + spec_name: sp_version::create_runtime_str!("test"), + impl_name: sp_version::create_runtime_str!("system-test"), + authoring_version: 1, + spec_version: 1, + impl_version: 1, + apis: sp_version::create_apis_vec!([]), + transaction_version: 1, + state_version: 1, + }; + pub const ParachainId: ParaId = ParaId::new(200); + pub const ReservedXcmpWeight: Weight = 0; + pub const ReservedDmpWeight: Weight = 0; +} +impl frame_system::Config for Test { + type Origin = Origin; + type Call = Call; + type Index = u64; + type BlockNumber = u64; + type Hash = H256; + type Hashing = BlakeTwo256; + type AccountId = u64; + type Lookup = IdentityLookup; + type Header = sp_runtime::generic::Header; + type Event = Event; + type BlockHashCount = BlockHashCount; + type BlockLength = (); + type BlockWeights = (); + type Version = Version; + type PalletInfo = PalletInfo; + type AccountData = (); + type OnNewAccount = (); + type OnKilledAccount = (); + type DbWeight = (); + type BaseCallFilter = frame_support::traits::Everything; + type SystemWeightInfo = (); + type SS58Prefix = (); + type OnSetCode = ParachainSetCode; + type MaxConsumers = frame_support::traits::ConstU32<16>; +} +impl Config for Test { + type Event = Event; + type OnSystemEvent = (); + type SelfParaId = ParachainId; + type OutboundXcmpMessageSource = (); + type DmpMessageHandler = (); + type ReservedDmpWeight = ReservedDmpWeight; + type XcmpMessageHandler = (); + type ReservedXcmpWeight = ReservedXcmpWeight; + type CheckAssociatedRelayNumber = RelayNumberStrictlyIncreases; +} diff --git a/pallets/parachain-system/src/weights.rs b/pallets/parachain-system/src/weights.rs new file mode 100644 index 00000000000..db900f29b3b --- /dev/null +++ b/pallets/parachain-system/src/weights.rs @@ -0,0 +1,87 @@ +// Copyright 2020 Parity Technologies (UK) Ltd. +// This file is part of Cumulus. + +// Cumulus 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. + +// Cumulus 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 Cumulus. If not, see . + +//! Autogenerated weights for pallet_parachain_system +//! +//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev +//! DATE: 2022-12-21, STEPS: `50`, REPEAT: 20, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("westmint-dev"), DB CACHE: 1024 + +#![allow(unused_parens)] +#![allow(unused_imports)] + +use frame_support::{ + traits::Get, + weights::{constants::RocksDbWeight, Weight}, +}; +use sp_std::marker::PhantomData; + +/// Weight functions needed for pallet_parachain_system. +pub trait WeightInfo { + #[rustfmt::skip] + fn set_validation_data_no_messages() -> Weight; +} + +/// Weights for pallet_parachain_system using the Substrate node and recommended hardware. +pub struct SubstrateWeight(PhantomData); +impl WeightInfo for SubstrateWeight { + // Storage: ParachainSystem ValidationData (r:1 w:1) + // Storage: ParachainSystem LastRelayChainBlockNumber (r:1 w:1) + // Storage: ParachainInfo ParachainId (r:1 w:0) + // Storage: ParachainSystem LastDmqMqcHead (r:1 w:0) + // Storage: ParachainSystem LastHrmpMqcHeads (r:1 w:1) + // Storage: ParachainSystem ReservedXcmpWeightOverride (r:1 w:0) + // Storage: XcmpQueue InboundXcmpStatus (r:1 w:1) + // Storage: XcmpQueue QueueConfig (r:1 w:0) + // Storage: XcmpQueue QueueSuspended (r:1 w:0) + // Storage: ParachainSystem RelevantMessagingState (r:0 w:1) + // Storage: ParachainSystem HrmpWatermark (r:0 w:1) + // Storage: ParachainSystem RelayStateProof (r:0 w:1) + // Storage: ParachainSystem HostConfiguration (r:0 w:1) + // Storage: ParachainSystem ProcessedDownwardMessages (r:0 w:1) + // Storage: ParachainSystem UpgradeRestrictionSignal (r:0 w:1) + #[rustfmt::skip] + fn set_validation_data_no_messages() -> Weight { + (45_216_000 as Weight) + .saturating_add(T::DbWeight::get().reads(9 as u64)) + .saturating_add(T::DbWeight::get().writes(10 as u64)) + } +} + +// For backwards compatibility and tests +impl WeightInfo for () { + // Storage: ParachainSystem ValidationData (r:1 w:1) + // Storage: ParachainSystem LastRelayChainBlockNumber (r:1 w:1) + // Storage: ParachainInfo ParachainId (r:1 w:0) + // Storage: ParachainSystem LastDmqMqcHead (r:1 w:0) + // Storage: ParachainSystem LastHrmpMqcHeads (r:1 w:1) + // Storage: ParachainSystem ReservedXcmpWeightOverride (r:1 w:0) + // Storage: XcmpQueue InboundXcmpStatus (r:1 w:1) + // Storage: XcmpQueue QueueConfig (r:1 w:0) + // Storage: XcmpQueue QueueSuspended (r:1 w:0) + // Storage: ParachainSystem RelevantMessagingState (r:0 w:1) + // Storage: ParachainSystem HrmpWatermark (r:0 w:1) + // Storage: ParachainSystem RelayStateProof (r:0 w:1) + // Storage: ParachainSystem HostConfiguration (r:0 w:1) + // Storage: ParachainSystem ProcessedDownwardMessages (r:0 w:1) + // Storage: ParachainSystem UpgradeRestrictionSignal (r:0 w:1) + #[rustfmt::skip] + fn set_validation_data_no_messages() -> Weight { + (45_216_000 as Weight) + .saturating_add(RocksDbWeight::get().reads(9 as u64)) + .saturating_add(RocksDbWeight::get().writes(10 as u64)) + } +} From e3ed0fd28459e43d4567abda9a23d5169a9d5a1d Mon Sep 17 00:00:00 2001 From: Nisheeth Barthwal Date: Thu, 22 Dec 2022 09:50:26 +0100 Subject: [PATCH 3/4] update weights for all extrinsics --- pallets/parachain-system/src/benchmarking.rs | 79 +++++++++++++++++--- pallets/parachain-system/src/lib.rs | 8 +- pallets/parachain-system/src/weights.rs | 60 +++++++++++++++ 3 files changed, 131 insertions(+), 16 deletions(-) diff --git a/pallets/parachain-system/src/benchmarking.rs b/pallets/parachain-system/src/benchmarking.rs index 36ed00b4b14..f66f60a42c9 100644 --- a/pallets/parachain-system/src/benchmarking.rs +++ b/pallets/parachain-system/src/benchmarking.rs @@ -19,7 +19,7 @@ use super::*; -use crate::{Pallet, ValidationData}; +use crate::{Pallet, PendingUpwardMessages, PendingValidationCode, ValidationData}; use cumulus_primitives_core::relay_chain::v2::HeadData; use frame_benchmarking::{account, benchmarks, impl_benchmark_test_suite, whitelisted_caller}; use frame_support::{ @@ -27,7 +27,7 @@ use frame_support::{ codec::Decode, traits::{Currency, EnsureOrigin, Get}, }; -use frame_system::{EnsureNone, EnsureSigned, EventRecord, RawOrigin}; +use frame_system::{EnsureNone, EnsureRoot, EnsureSigned, EventRecord, RawOrigin}; use sp_core::H256; use sp_std::{collections::btree_set::BTreeSet, prelude::*}; use sp_trie::StorageProof; @@ -37,12 +37,31 @@ const SEED: u32 = 0; benchmarks! { set_validation_data_no_messages { // root and proof are obtained via `RelayStateSproofBuilder::default().into_state_root_and_proof()` - let root = [87, 247, 132, 202, 60, 197, 129, 248, 29, 30, 75, 209, 87, 82, 217, 27, 193, 91, 133, 158, 57, 219, 5, 125, 31, 120, 73, 108, 83, 161, 122, 141]; + let root = [ + 87, 247, 132, 202, 60, 197, 129, 248, 29, 30, 75, 209, 87, 82, 217, 27, 193, 91, 133, 158, 57, + 219, 5, 125, 31, 120, 73, 108, 83, 161, 122, 141, + ]; let proof = vec![ - vec![0, 0, 32, 0, 0, 0, 16, 0, 8, 0, 0, 0, 0, 4, 0, 0, 0, 1, 0, 0, 5, 0, 0, 0, 5, 0, 0, 0, 6, 0, 0, 0, 6, 0, 0, 0], - vec![63, 32, 6, 222, 61, 138, 84, 210, 126, 68, 169, 213, 206, 24, 150, 24, 242, 45, 180, 180, 157, 149, 50, 13, 144, 33, 153, 76, 133, 15, 37, 184, 227, 133, 122, 95, 83, 148, 165, 203, 236, 87, 253, 11, 60, 82, 36, 95, 199, 120, 54, 22, 228, 227, 110, 231, 204, 83, 94, 179, 154, 8, 200, 180, 89, 235], - vec![127, 0, 12, 182, 243, 110, 2, 122, 187, 32, 145, 207, 181, 17, 10, 181, 8, 127, 6, 21, 91, 60, 217, 168, 201, 229, 233, 162, 63, 213, 220, 19, 165, 237, 32, 0, 0, 0, 0, 0, 0, 0, 0], - vec![128, 3, 0, 128, 242, 238, 200, 199, 170, 3, 233, 7, 253, 11, 161, 204, 28, 109, 207, 110, 116, 240, 105, 181, 38, 64, 118, 111, 3, 222, 55, 184, 183, 81, 181, 61, 128, 30, 47, 17, 234, 172, 118, 214, 115, 102, 113, 126, 126, 111, 149, 151, 252, 216, 113, 234, 7, 17, 48, 53, 220, 0, 90, 170, 247, 242, 1, 69, 8], + vec![ + 0, 0, 32, 0, 0, 0, 16, 0, 8, 0, 0, 0, 0, 4, 0, 0, 0, 1, 0, 0, 5, 0, 0, 0, 5, 0, 0, 0, 6, 0, + 0, 0, 6, 0, 0, 0 + ], + vec![ + 63, 32, 6, 222, 61, 138, 84, 210, 126, 68, 169, 213, 206, 24, 150, 24, 242, 45, 180, 180, 157, + 149, 50, 13, 144, 33, 153, 76, 133, 15, 37, 184, 227, 133, 122, 95, 83, 148, 165, 203, 236, 87, + 253, 11, 60, 82, 36, 95, 199, 120, 54, 22, 228, 227, 110, 231, 204, 83, 94, 179, 154, 8, 200, + 180, 89, 235, + ], + vec![ + 127, 0, 12, 182, 243, 110, 2, 122, 187, 32, 145, 207, 181, 17, 10, 181, 8, 127, 6, 21, 91, 60, 217, + 168, 201, 229, 233, 162, 63, 213, 220, 19, 165, 237, 32, 0, 0, 0, 0, 0, 0, 0, 0, + ], + vec![ + 128, 3, 0, 128, 242, 238, 200, 199, 170, 3, 233, 7, 253, 11, 161, 204, 28, 109, 207, 110, 116, 240, + 105, 181, 38, 64, 118, 111, 3, 222, 55, 184, 183, 81, 181, 61, 128, 30, 47, 17, 234, 172, 118, 214, + 115, 102, 113, 126, 126, 111, 149, 151, 252, 216, 113, 234, 7, 17, 48, 53, 220, 0, 90, 170, 247, 242, + 1, 69, 8, + ], ]; let data = ParachainInherentData { @@ -56,13 +75,49 @@ benchmarks! { downward_messages: vec![], horizontal_messages: BTreeMap::new(), }; - }: { - assert_ok!( - >::set_validation_data(EnsureNone::successful_origin(), data) - ); + }: { assert_ok!(>::set_validation_data(EnsureNone::successful_origin(), data)); } + verify { + assert_eq!(>::get().expect("validation data must exist").relay_parent_number, 1); + } + + sudo_send_upward_message { + }: { assert_ok!(>::sudo_send_upward_message(EnsureRoot::successful_origin(), vec![])); } + verify { + assert_eq!(>::get().len(), 1); } + + authorize_upgrade { + let hash = T::Hashing::hash(vec![0u8; 32].as_slice()); + }: { assert_ok!(>::authorize_upgrade(EnsureRoot::successful_origin(), hash.clone())); } + verify { + assert_eq!(>::get(), Some(hash)); + } + + enact_authorized_upgrade { + let code = vec![0u8; 32]; + let hash = T::Hashing::hash(code.as_slice()); + >::put(PersistedValidationData { + parent_head: vec![].into(), + relay_parent_number: Default::default(), + max_pov_size: Default::default(), + relay_parent_storage_root: Default::default(), + }); + >::put(AbridgedHostConfiguration { + max_code_size: 2 * 1024 * 1024, + max_head_data_size: 1024 * 1024, + max_upward_queue_count: 8, + max_upward_queue_size: 1024, + max_upward_message_size: 256, + max_upward_message_num_per_candidate: 5, + hrmp_max_message_num_per_candidate: 5, + validation_upgrade_cooldown: 6, + validation_upgrade_delay: 6, + }); + assert_ok!(>::authorize_upgrade(EnsureRoot::successful_origin(), hash)); + }: { assert_ok!(>::enact_authorized_upgrade(EnsureRoot::successful_origin(), code.clone())); } verify { - assert_eq!(>::get().unwrap().relay_parent_number, 1); + assert_eq!(>::get(), None); + assert_eq!(>::get(), code); } } diff --git a/pallets/parachain-system/src/lib.rs b/pallets/parachain-system/src/lib.rs index 2d3847c103d..f059e2a3fc2 100644 --- a/pallets/parachain-system/src/lib.rs +++ b/pallets/parachain-system/src/lib.rs @@ -54,9 +54,9 @@ use sp_runtime::{ }; use sp_std::{cmp, collections::btree_map::BTreeMap, prelude::*}; -pub mod weights; mod migration; mod relay_state_snapshot; +pub mod weights; #[macro_use] pub mod validate_block; #[cfg(test)] @@ -438,7 +438,7 @@ pub mod pallet { Ok(PostDispatchInfo { actual_weight: Some(total_weight), pays_fee: Pays::No }) } - #[pallet::weight((1_000, DispatchClass::Operational))] + #[pallet::weight((T::WeightInfo::sudo_send_upward_message(), DispatchClass::Operational))] pub fn sudo_send_upward_message( origin: OriginFor, message: UpwardMessage, @@ -448,7 +448,7 @@ pub mod pallet { Ok(()) } - #[pallet::weight((1_000_000, DispatchClass::Operational))] + #[pallet::weight((T::WeightInfo::authorize_upgrade(), DispatchClass::Operational))] pub fn authorize_upgrade(origin: OriginFor, code_hash: T::Hash) -> DispatchResult { ensure_root(origin)?; @@ -458,7 +458,7 @@ pub mod pallet { Ok(()) } - #[pallet::weight(1_000_000)] + #[pallet::weight(T::WeightInfo::enact_authorized_upgrade())] pub fn enact_authorized_upgrade( _: OriginFor, code: Vec, diff --git a/pallets/parachain-system/src/weights.rs b/pallets/parachain-system/src/weights.rs index db900f29b3b..c3d9592adf5 100644 --- a/pallets/parachain-system/src/weights.rs +++ b/pallets/parachain-system/src/weights.rs @@ -33,6 +33,12 @@ use sp_std::marker::PhantomData; pub trait WeightInfo { #[rustfmt::skip] fn set_validation_data_no_messages() -> Weight; + #[rustfmt::skip] + fn sudo_send_upward_message() -> Weight; + #[rustfmt::skip] + fn authorize_upgrade() -> Weight; + #[rustfmt::skip] + fn enact_authorized_upgrade() -> Weight; } /// Weights for pallet_parachain_system using the Substrate node and recommended hardware. @@ -59,6 +65,33 @@ impl WeightInfo for SubstrateWeight { .saturating_add(T::DbWeight::get().reads(9 as u64)) .saturating_add(T::DbWeight::get().writes(10 as u64)) } + // Storage: ParachainSystem HostConfiguration (r:1 w:0) + // Storage: ParachainSystem PendingUpwardMessages (r:1 w:1) + #[rustfmt::skip] + fn sudo_send_upward_message() -> Weight { + (3_647_000 as Weight) + .saturating_add(T::DbWeight::get().reads(2 as u64)) + .saturating_add(T::DbWeight::get().writes(1 as u64)) + } + // Storage: ParachainSystem AuthorizedUpgrade (r:0 w:1) + #[rustfmt::skip] + fn authorize_upgrade() -> Weight { + (9_779_000 as Weight) + .saturating_add(T::DbWeight::get().writes(1 as u64)) + } + // Storage: ParachainSystem AuthorizedUpgrade (r:1 w:1) + // Storage: ParachainSystem ValidationData (r:1 w:0) + // Storage: ParachainSystem UpgradeRestrictionSignal (r:1 w:0) + // Storage: ParachainSystem PendingValidationCode (r:1 w:1) + // Storage: ParachainSystem HostConfiguration (r:1 w:0) + // Storage: ParachainSystem NewValidationCode (r:0 w:1) + // Storage: ParachainSystem DidSetValidationCode (r:0 w:1) + #[rustfmt::skip] + fn enact_authorized_upgrade() -> Weight { + (25_628_000 as Weight) + .saturating_add(T::DbWeight::get().reads(5 as u64)) + .saturating_add(T::DbWeight::get().writes(4 as u64)) + } } // For backwards compatibility and tests @@ -84,4 +117,31 @@ impl WeightInfo for () { .saturating_add(RocksDbWeight::get().reads(9 as u64)) .saturating_add(RocksDbWeight::get().writes(10 as u64)) } + // Storage: ParachainSystem HostConfiguration (r:1 w:0) + // Storage: ParachainSystem PendingUpwardMessages (r:1 w:1) + #[rustfmt::skip] + fn sudo_send_upward_message() -> Weight { + (3_647_000 as Weight) + .saturating_add(RocksDbWeight::get().reads(2 as u64)) + .saturating_add(RocksDbWeight::get().writes(1 as u64)) + } + // Storage: ParachainSystem AuthorizedUpgrade (r:0 w:1) + #[rustfmt::skip] + fn authorize_upgrade() -> Weight { + (9_779_000 as Weight) + .saturating_add(RocksDbWeight::get().writes(1 as u64)) + } + // Storage: ParachainSystem AuthorizedUpgrade (r:1 w:1) + // Storage: ParachainSystem ValidationData (r:1 w:0) + // Storage: ParachainSystem UpgradeRestrictionSignal (r:1 w:0) + // Storage: ParachainSystem PendingValidationCode (r:1 w:1) + // Storage: ParachainSystem HostConfiguration (r:1 w:0) + // Storage: ParachainSystem NewValidationCode (r:0 w:1) + // Storage: ParachainSystem DidSetValidationCode (r:0 w:1) + #[rustfmt::skip] + fn enact_authorized_upgrade() -> Weight { + (25_628_000 as Weight) + .saturating_add(RocksDbWeight::get().reads(5 as u64)) + .saturating_add(RocksDbWeight::get().writes(4 as u64)) + } } From 82b44f84341b296c07102242e1111b627800c71b Mon Sep 17 00:00:00 2001 From: Nisheeth Barthwal Date: Thu, 22 Dec 2022 13:03:28 +0100 Subject: [PATCH 4/4] update weights from benchmarking system --- pallets/parachain-system/src/weights.rs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/pallets/parachain-system/src/weights.rs b/pallets/parachain-system/src/weights.rs index c3d9592adf5..cb46c8556c6 100644 --- a/pallets/parachain-system/src/weights.rs +++ b/pallets/parachain-system/src/weights.rs @@ -61,7 +61,7 @@ impl WeightInfo for SubstrateWeight { // Storage: ParachainSystem UpgradeRestrictionSignal (r:0 w:1) #[rustfmt::skip] fn set_validation_data_no_messages() -> Weight { - (45_216_000 as Weight) + (42_259_000 as Weight) .saturating_add(T::DbWeight::get().reads(9 as u64)) .saturating_add(T::DbWeight::get().writes(10 as u64)) } @@ -69,14 +69,14 @@ impl WeightInfo for SubstrateWeight { // Storage: ParachainSystem PendingUpwardMessages (r:1 w:1) #[rustfmt::skip] fn sudo_send_upward_message() -> Weight { - (3_647_000 as Weight) + (4_669_000 as Weight) .saturating_add(T::DbWeight::get().reads(2 as u64)) .saturating_add(T::DbWeight::get().writes(1 as u64)) } // Storage: ParachainSystem AuthorizedUpgrade (r:0 w:1) #[rustfmt::skip] fn authorize_upgrade() -> Weight { - (9_779_000 as Weight) + (12_872_000 as Weight) .saturating_add(T::DbWeight::get().writes(1 as u64)) } // Storage: ParachainSystem AuthorizedUpgrade (r:1 w:1) @@ -88,7 +88,7 @@ impl WeightInfo for SubstrateWeight { // Storage: ParachainSystem DidSetValidationCode (r:0 w:1) #[rustfmt::skip] fn enact_authorized_upgrade() -> Weight { - (25_628_000 as Weight) + (25_830_000 as Weight) .saturating_add(T::DbWeight::get().reads(5 as u64)) .saturating_add(T::DbWeight::get().writes(4 as u64)) } @@ -113,7 +113,7 @@ impl WeightInfo for () { // Storage: ParachainSystem UpgradeRestrictionSignal (r:0 w:1) #[rustfmt::skip] fn set_validation_data_no_messages() -> Weight { - (45_216_000 as Weight) + (42_259_000 as Weight) .saturating_add(RocksDbWeight::get().reads(9 as u64)) .saturating_add(RocksDbWeight::get().writes(10 as u64)) } @@ -121,14 +121,14 @@ impl WeightInfo for () { // Storage: ParachainSystem PendingUpwardMessages (r:1 w:1) #[rustfmt::skip] fn sudo_send_upward_message() -> Weight { - (3_647_000 as Weight) + (4_669_000 as Weight) .saturating_add(RocksDbWeight::get().reads(2 as u64)) .saturating_add(RocksDbWeight::get().writes(1 as u64)) } // Storage: ParachainSystem AuthorizedUpgrade (r:0 w:1) #[rustfmt::skip] fn authorize_upgrade() -> Weight { - (9_779_000 as Weight) + (12_872_000 as Weight) .saturating_add(RocksDbWeight::get().writes(1 as u64)) } // Storage: ParachainSystem AuthorizedUpgrade (r:1 w:1) @@ -140,7 +140,7 @@ impl WeightInfo for () { // Storage: ParachainSystem DidSetValidationCode (r:0 w:1) #[rustfmt::skip] fn enact_authorized_upgrade() -> Weight { - (25_628_000 as Weight) + (25_830_000 as Weight) .saturating_add(RocksDbWeight::get().reads(5 as u64)) .saturating_add(RocksDbWeight::get().writes(4 as u64)) }