From 03934d2af114f8872d8a4a9cce073999d4fbf264 Mon Sep 17 00:00:00 2001 From: Robert Habermeier Date: Thu, 23 Sep 2021 14:29:26 -0500 Subject: [PATCH] Add a `force_unfreeze` extrinsic to the disputes module (#3906) * add a 'force_unfreeze' to the Disputes module * fmt * Benchmark Disputes `force_unfreeze` extrinsic (#3908) * Companion for Generate storage info for pallet babe #9760 (#3831) * Adding MaxSegmentLength and MaxAuthorities to pallet babe * Missed a few to_vec * Removing `MaxSegmentLength` as not needed anymore * Adding `MaxAuthorities` to couple of missing place * Adding missing definition of `MaxAuthorities` * Adding a missing to_vec * update Substrate Co-authored-by: thiolliere Co-authored-by: parity-processbot <> * Benchmark Disputes `force_unfreeze` extrinsic target pr: #3906 target branch: rh-unfreeze * Add benchmark to rococo runtime; run benchmark locally * Revert unintentionally added diff * Some spacing and comments * Bump proc-macro-crate from 1.0.0 to 1.1.0 (#3863) Bumps [proc-macro-crate](https://github.com/bkchr/proc-macro-crate) from 1.0.0 to 1.1.0. - [Release notes](https://github.com/bkchr/proc-macro-crate/releases) - [Commits](https://github.com/bkchr/proc-macro-crate/commits) --- updated-dependencies: - dependency-name: proc-macro-crate dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * Bump parity-scale-codec from 2.2.0 to 2.3.0 (#3833) Bumps [parity-scale-codec](https://github.com/paritytech/parity-scale-codec) from 2.2.0 to 2.3.0. - [Release notes](https://github.com/paritytech/parity-scale-codec/releases) - [Changelog](https://github.com/paritytech/parity-scale-codec/blob/master/CHANGELOG.md) - [Commits](https://github.com/paritytech/parity-scale-codec/compare/v2.2...parity-scale-codec-v2.3.0) --- updated-dependencies: - dependency-name: parity-scale-codec dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * Use super::WeightInfo to try and get CI to compile * cargo run --quiet --release --features runtime-benchmarks -- benchmark --chain=rococo-dev --steps=50 --repeat=20 --pallet=runtime_parachains::disputes --extrinsic=* --execution=wasm --wasm-execution=compiled --heap-pages=4096 --output=./runtime/parachains/src/disputes/weights.rs --header=./file_header.txt * impl TestWeightInfo; remove weights from runtime_parachains dir * fmt * Update test-runtime Co-authored-by: Georges Co-authored-by: thiolliere Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Parity Bot Co-authored-by: Zeke Mostov <32168567+emostov@users.noreply.github.com> Co-authored-by: Georges Co-authored-by: thiolliere Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Parity Bot --- polkadot/Cargo.lock | 2 + polkadot/runtime/parachains/src/disputes.rs | 33 ++++++++++++ .../parachains/src/disputes/benchmarking.rs | 36 +++++++++++++ polkadot/runtime/parachains/src/mock.rs | 1 + polkadot/runtime/rococo/Cargo.toml | 6 +++ polkadot/runtime/rococo/src/lib.rs | 50 ++++++++++++++++++ polkadot/runtime/rococo/src/weights/mod.rs | 1 + .../weights/runtime_parachains_disputes.rs | 52 +++++++++++++++++++ polkadot/runtime/test-runtime/src/lib.rs | 1 + 9 files changed, 182 insertions(+) create mode 100644 polkadot/runtime/parachains/src/disputes/benchmarking.rs create mode 100644 polkadot/runtime/rococo/src/weights/mod.rs create mode 100644 polkadot/runtime/rococo/src/weights/runtime_parachains_disputes.rs diff --git a/polkadot/Cargo.lock b/polkadot/Cargo.lock index c887e6fd17..91213b72d4 100644 --- a/polkadot/Cargo.lock +++ b/polkadot/Cargo.lock @@ -7811,10 +7811,12 @@ dependencies = [ "bp-runtime", "bp-wococo", "bridge-runtime-common", + "frame-benchmarking", "frame-executive", "frame-support", "frame-system", "frame-system-rpc-runtime-api", + "hex-literal", "log", "pallet-authority-discovery", "pallet-authorship", diff --git a/polkadot/runtime/parachains/src/disputes.rs b/polkadot/runtime/parachains/src/disputes.rs index b3bd5a3ed6..09c2d14785 100644 --- a/polkadot/runtime/parachains/src/disputes.rs +++ b/polkadot/runtime/parachains/src/disputes.rs @@ -23,6 +23,7 @@ use crate::{ }; use bitvec::{bitvec, order::Lsb0 as BitOrderLsb0}; use frame_support::{ensure, traits::Get, weights::Weight}; +use frame_system::pallet_prelude::*; use parity_scale_codec::{Decode, Encode}; use primitives::v1::{ byzantine_threshold, supermajority_threshold, ApprovalVote, CandidateHash, CompactStatement, @@ -37,6 +38,11 @@ use sp_runtime::{ }; use sp_std::{collections::btree_set::BTreeSet, prelude::*}; +#[cfg(feature = "runtime-benchmarks")] +mod benchmarking; + +pub use crate::Origin as ParachainOrigin; + /// Whether the dispute is local or remote. #[derive(Encode, Decode, Clone, PartialEq, Eq, RuntimeDebug, TypeInfo)] pub enum DisputeLocation { @@ -212,6 +218,17 @@ impl DisputesHandler for pallet::Pallet { } } +pub trait WeightInfo { + fn force_unfreeze() -> Weight; +} + +pub struct TestWeightInfo; +impl WeightInfo for TestWeightInfo { + fn force_unfreeze() -> Weight { + 0 + } +} + pub use pallet::*; #[frame_support::pallet] pub mod pallet { @@ -223,6 +240,9 @@ pub mod pallet { type Event: From> + IsType<::Event>; type RewardValidators: RewardValidators; type PunishValidators: PunishValidators; + + /// Weight information for extrinsics in this pallet. + type WeightInfo: WeightInfo; } #[pallet::pallet] @@ -305,6 +325,19 @@ pub mod pallet { /// Too many spam slots used by some specific validator. PotentialSpam, } + + #[pallet::origin] + pub type Origin = ParachainOrigin; + + #[pallet::call] + impl Pallet { + #[pallet::weight(::WeightInfo::force_unfreeze())] + pub fn force_unfreeze(origin: OriginFor) -> DispatchResult { + ensure_root(origin)?; + Frozen::::set(None); + Ok(()) + } + } } bitflags::bitflags! { diff --git a/polkadot/runtime/parachains/src/disputes/benchmarking.rs b/polkadot/runtime/parachains/src/disputes/benchmarking.rs new file mode 100644 index 0000000000..b884d1a6e7 --- /dev/null +++ b/polkadot/runtime/parachains/src/disputes/benchmarking.rs @@ -0,0 +1,36 @@ +// 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 super::*; + +use frame_benchmarking::{benchmarks, impl_benchmark_test_suite}; +use frame_system::RawOrigin; +use sp_runtime::traits::One; + +benchmarks! { + force_unfreeze { + Frozen::::set(Some(One::one())); + }: _(RawOrigin::Root) + verify { + assert!(Frozen::::get().is_none()) + } +} + +impl_benchmark_test_suite!( + Pallet, + crate::mock::new_test_ext(Default::default()), + crate::mock::Test +); diff --git a/polkadot/runtime/parachains/src/mock.rs b/polkadot/runtime/parachains/src/mock.rs index 387e0a7bf5..1ccf57ea35 100644 --- a/polkadot/runtime/parachains/src/mock.rs +++ b/polkadot/runtime/parachains/src/mock.rs @@ -149,6 +149,7 @@ impl crate::disputes::Config for Test { type Event = Event; type RewardValidators = Self; type PunishValidators = Self; + type WeightInfo = crate::disputes::TestWeightInfo; } thread_local! { diff --git a/polkadot/runtime/rococo/Cargo.toml b/polkadot/runtime/rococo/Cargo.toml index 527e668908..15b4ed1484 100644 --- a/polkadot/runtime/rococo/Cargo.toml +++ b/polkadot/runtime/rococo/Cargo.toml @@ -78,6 +78,10 @@ pallet-bridge-dispatch = { path = "../../bridges/modules/dispatch", default-feat pallet-bridge-grandpa = { path = "../../bridges/modules/grandpa", default-features = false } pallet-bridge-messages = { path = "../../bridges/modules/messages", default-features = false } +# Benchmarking Dependencies +frame-benchmarking = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false, optional = true } +hex-literal = { version = "0.3.3", optional = true } + [build-dependencies] substrate-wasm-builder = { git = "https://github.com/paritytech/substrate", branch = "master" } @@ -169,6 +173,8 @@ runtime-benchmarks = [ "pallet-timestamp/runtime-benchmarks", "pallet-xcm/runtime-benchmarks", "xcm-builder/runtime-benchmarks", + "frame-benchmarking", + "hex-literal" ] try-runtime = [ "frame-executive/try-runtime", diff --git a/polkadot/runtime/rococo/src/lib.rs b/polkadot/runtime/rococo/src/lib.rs index 9f03cc8253..5323adeefc 100644 --- a/polkadot/runtime/rococo/src/lib.rs +++ b/polkadot/runtime/rococo/src/lib.rs @@ -94,6 +94,7 @@ use xcm_executor::XcmExecutor; /// Constant values used within the runtime. pub mod constants; mod validator_manager; +mod weights; // Make the WASM binary available. #[cfg(feature = "std")] @@ -369,6 +370,7 @@ impl parachains_disputes::Config for Runtime { type Event = Event; type RewardValidators = (); type PunishValidators = (); + type WeightInfo = weights::runtime_parachains_disputes::WeightInfo; } parameter_types! { @@ -1559,4 +1561,52 @@ sp_api::impl_runtime_apis! { TransactionPayment::query_fee_details(uxt, len) } } + + #[cfg(feature = "runtime-benchmarks")] + impl frame_benchmarking::Benchmark for Runtime { + fn benchmark_metadata(extra: bool) -> ( + Vec, + Vec, + ) { + use frame_benchmarking::{list_benchmark, Benchmarking, BenchmarkList}; + use frame_support::traits::StorageInfoTrait; + + let mut list = Vec::::new(); + + list_benchmark!(list, extra, runtime_parachains::disputes, ParasDisputes); + + let storage_info = AllPalletsWithSystem::storage_info(); + + return (list, storage_info) + } + + fn dispatch_benchmark( + config: frame_benchmarking::BenchmarkConfig, + ) -> Result< + Vec, + sp_runtime::RuntimeString, + > { + use frame_benchmarking::{Benchmarking, BenchmarkBatch, add_benchmark, TrackedStorageKey}; + + let mut batches = Vec::::new(); + let whitelist: Vec = vec![ + // Block Number + hex_literal::hex!("26aa394eea5630e07c48ae0c9558cef702a5c1b19ab7a04f536c519aca4983ac").to_vec().into(), + // Total Issuance + hex_literal::hex!("c2261276cc9d1f8598ea4b6a74b15c2f57c875e4cff74148e4628f264b974c80").to_vec().into(), + // Execution Phase + hex_literal::hex!("26aa394eea5630e07c48ae0c9558cef7ff553b5a9862a516939d82b3d3d8661a").to_vec().into(), + // Event Count + hex_literal::hex!("26aa394eea5630e07c48ae0c9558cef70a98fdbe9ce6c55837576c60c7af3850").to_vec().into(), + // System Events + hex_literal::hex!("26aa394eea5630e07c48ae0c9558cef780d41e5e16056765bc8461851072c9d7").to_vec().into(), + ]; + let params = (&config, &whitelist); + + add_benchmark!(params, batches, runtime_parachains::disputes, ParasDisputes); + + if batches.is_empty() { return Err("Benchmark not found for this pallet.".into()) } + Ok(batches) + } + } } diff --git a/polkadot/runtime/rococo/src/weights/mod.rs b/polkadot/runtime/rococo/src/weights/mod.rs new file mode 100644 index 0000000000..bcd0ec248a --- /dev/null +++ b/polkadot/runtime/rococo/src/weights/mod.rs @@ -0,0 +1 @@ +pub mod runtime_parachains_disputes; diff --git a/polkadot/runtime/rococo/src/weights/runtime_parachains_disputes.rs b/polkadot/runtime/rococo/src/weights/runtime_parachains_disputes.rs new file mode 100644 index 0000000000..37c0d4545c --- /dev/null +++ b/polkadot/runtime/rococo/src/weights/runtime_parachains_disputes.rs @@ -0,0 +1,52 @@ +// 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::disputes` +//! +//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev +//! DATE: 2021-09-23, STEPS: `50`, REPEAT: 20, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("rococo-dev"), DB CACHE: 128 + +// Executed Command: +// target/release/polkadot +// benchmark +// --chain=rococo-dev +// --steps=50 +// --repeat=20 +// --pallet=runtime_parachains::disputes +// --extrinsic=* +// --execution=wasm +// --wasm-execution=compiled +// --heap-pages=4096 +// --output=./runtime/parachains/src/disputes/weights.rs +// --header=./file_header.txt + + +#![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::disputes`. +pub struct WeightInfo(PhantomData); +impl runtime_parachains::disputes::WeightInfo for WeightInfo { + // Storage: ParasDisputes Frozen (r:0 w:1) + fn force_unfreeze() -> Weight { + (2_022_000 as Weight) + .saturating_add(T::DbWeight::get().writes(1 as Weight)) + } +} diff --git a/polkadot/runtime/test-runtime/src/lib.rs b/polkadot/runtime/test-runtime/src/lib.rs index 722aab3e16..09da961b21 100644 --- a/polkadot/runtime/test-runtime/src/lib.rs +++ b/polkadot/runtime/test-runtime/src/lib.rs @@ -472,6 +472,7 @@ impl parachains_disputes::Config for Runtime { type Event = Event; type RewardValidators = (); type PunishValidators = (); + type WeightInfo = parachains_disputes::TestWeightInfo; } impl parachains_paras_inherent::Config for Runtime {}