Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Add a force_unfreeze extrinsic to the disputes module #3906

Merged
4 commits merged into from
Sep 23, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

33 changes: 33 additions & 0 deletions runtime/parachains/src/disputes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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 {
Expand Down Expand Up @@ -212,6 +218,17 @@ impl<T: Config> DisputesHandler<T::BlockNumber> for pallet::Pallet<T> {
}
}

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 {
Expand All @@ -223,6 +240,9 @@ pub mod pallet {
type Event: From<Event<Self>> + IsType<<Self as frame_system::Config>::Event>;
type RewardValidators: RewardValidators;
type PunishValidators: PunishValidators;

/// Weight information for extrinsics in this pallet.
type WeightInfo: WeightInfo;
}

#[pallet::pallet]
Expand Down Expand Up @@ -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<T: Config> Pallet<T> {
#[pallet::weight(<T as Config>::WeightInfo::force_unfreeze())]
pub fn force_unfreeze(origin: OriginFor<T>) -> DispatchResult {
ensure_root(origin)?;
Frozen::<T>::set(None);
Ok(())
}
}
}

bitflags::bitflags! {
Expand Down
36 changes: 36 additions & 0 deletions runtime/parachains/src/disputes/benchmarking.rs
Original file line number Diff line number Diff line change
@@ -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 <http://www.gnu.org/licenses/>.

use super::*;

use frame_benchmarking::{benchmarks, impl_benchmark_test_suite};
use frame_system::RawOrigin;
use sp_runtime::traits::One;

benchmarks! {
force_unfreeze {
Frozen::<T>::set(Some(One::one()));
}: _(RawOrigin::Root)
verify {
assert!(Frozen::<T>::get().is_none())
}
}

impl_benchmark_test_suite!(
Pallet,
crate::mock::new_test_ext(Default::default()),
crate::mock::Test
);
1 change: 1 addition & 0 deletions runtime/parachains/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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! {
Expand Down
6 changes: 6 additions & 0 deletions runtime/rococo/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" }

Expand Down Expand Up @@ -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",
Expand Down
50 changes: 50 additions & 0 deletions runtime/rococo/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
Expand Down Expand Up @@ -369,6 +370,7 @@ impl parachains_disputes::Config for Runtime {
type Event = Event;
type RewardValidators = ();
type PunishValidators = ();
type WeightInfo = weights::runtime_parachains_disputes::WeightInfo<Runtime>;
}

parameter_types! {
Expand Down Expand Up @@ -1559,4 +1561,52 @@ sp_api::impl_runtime_apis! {
TransactionPayment::query_fee_details(uxt, len)
}
}

#[cfg(feature = "runtime-benchmarks")]
impl frame_benchmarking::Benchmark<Block> for Runtime {
fn benchmark_metadata(extra: bool) -> (
Vec<frame_benchmarking::BenchmarkList>,
Vec<frame_support::traits::StorageInfo>,
) {
use frame_benchmarking::{list_benchmark, Benchmarking, BenchmarkList};
use frame_support::traits::StorageInfoTrait;

let mut list = Vec::<BenchmarkList>::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<frame_benchmarking::BenchmarkBatch>,
sp_runtime::RuntimeString,
> {
use frame_benchmarking::{Benchmarking, BenchmarkBatch, add_benchmark, TrackedStorageKey};

let mut batches = Vec::<BenchmarkBatch>::new();
let whitelist: Vec<TrackedStorageKey> = 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)
}
}
}
1 change: 1 addition & 0 deletions runtime/rococo/src/weights/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pub mod runtime_parachains_disputes;
52 changes: 52 additions & 0 deletions runtime/rococo/src/weights/runtime_parachains_disputes.rs
Original file line number Diff line number Diff line change
@@ -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 <http://www.gnu.org/licenses/>.
//! 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<T>(PhantomData<T>);
impl<T: frame_system::Config> runtime_parachains::disputes::WeightInfo for WeightInfo<T> {
// 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))
}
}
1 change: 1 addition & 0 deletions runtime/test-runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {}
Expand Down