From a9b4141fec807d63706e79044152d7dbda48f3ac Mon Sep 17 00:00:00 2001 From: Francisco Valentim Castilho Date: Mon, 26 Aug 2024 15:37:33 -0300 Subject: [PATCH] Delete: local pallet-tx-pause --- invarch/pallet-tx-pause/Cargo.toml | 67 ------- invarch/pallet-tx-pause/src/lib.rs | 241 ------------------------- invarch/pallet-tx-pause/src/weights.rs | 107 ----------- 3 files changed, 415 deletions(-) delete mode 100644 invarch/pallet-tx-pause/Cargo.toml delete mode 100644 invarch/pallet-tx-pause/src/lib.rs delete mode 100644 invarch/pallet-tx-pause/src/weights.rs diff --git a/invarch/pallet-tx-pause/Cargo.toml b/invarch/pallet-tx-pause/Cargo.toml deleted file mode 100644 index 6c8a588b..00000000 --- a/invarch/pallet-tx-pause/Cargo.toml +++ /dev/null @@ -1,67 +0,0 @@ -[package] -name = "pallet-tx-pause" -version = "4.0.0-dev" -authors = ["Parity Technologies "] -edition = "2021" -license = "Apache-2.0" -homepage = "https://substrate.io" -repository = "https://github.com/paritytech/substrate/" -description = "FRAME transaction pause pallet" -readme = "README.md" - -[package.metadata.docs.rs] -targets = ["x86_64-unknown-linux-gnu"] - -[dependencies] -codec = { package = "parity-scale-codec", version = "3.6.5", default-features = false, features = ["derive"] } -scale-info = { version = "2.10.0", default-features = false, features = ["derive"] } - -frame-benchmarking = { git = "https://github.com/paritytech/polkadot-sdk.git", branch = "release-polkadot-v1.6.0", default-features = false, optional = true} -frame-support = { git = "https://github.com/paritytech/polkadot-sdk.git", branch = "release-polkadot-v1.6.0", default-features = false } -frame-system = { git = "https://github.com/paritytech/polkadot-sdk.git", branch = "release-polkadot-v1.6.0", default-features = false } -sp-runtime = { git = "https://github.com/paritytech/polkadot-sdk.git", branch = "release-polkadot-v1.6.0", default-features = false } -sp-std = { git = "https://github.com/paritytech/polkadot-sdk.git", branch = "release-polkadot-v1.6.0", default-features = false } -pallet-balances = { git = "https://github.com/paritytech/polkadot-sdk.git", branch = "release-polkadot-v1.6.0", default-features = false, optional = true} -pallet-utility = { git = "https://github.com/paritytech/polkadot-sdk.git", branch = "release-polkadot-v1.6.0", default-features = false, optional = true} -pallet-proxy = { git = "https://github.com/paritytech/polkadot-sdk.git", branch = "release-polkadot-v1.6.0", default-features = false, optional = true} - -[dev-dependencies] -sp-core = { git = "https://github.com/paritytech/polkadot-sdk.git", branch = "release-polkadot-v1.6.0", default-features = false } -sp-io = { git = "https://github.com/paritytech/polkadot-sdk.git", branch = "release-polkadot-v1.6.0", default-features = false } -pallet-balances = { git = "https://github.com/paritytech/polkadot-sdk.git", branch = "release-polkadot-v1.6.0", default-features = false } -pallet-utility = { git = "https://github.com/paritytech/polkadot-sdk.git", branch = "release-polkadot-v1.6.0", default-features = false } -pallet-proxy = { git = "https://github.com/paritytech/polkadot-sdk.git", branch = "release-polkadot-v1.6.0", default-features = false } - -[features] -default = [ "std" ] -std = [ - "codec/std", - "frame-benchmarking/std", - "frame-support/std", - "frame-system/std", - "pallet-balances?/std", - "pallet-proxy?/std", - "pallet-utility?/std", - "scale-info/std", - "sp-core/std", - "sp-io/std", - "sp-runtime/std", - "sp-std/std", -] -runtime-benchmarks = [ - "frame-benchmarking/runtime-benchmarks", - "frame-support/runtime-benchmarks", - "frame-system/runtime-benchmarks", - "pallet-balances/runtime-benchmarks", - "pallet-proxy/runtime-benchmarks", - "pallet-utility/runtime-benchmarks", - "sp-runtime/runtime-benchmarks", -] -try-runtime = [ - "frame-support/try-runtime", - "frame-system/try-runtime", - "pallet-balances?/try-runtime", - "pallet-proxy?/try-runtime", - "pallet-utility?/try-runtime", - "sp-runtime/try-runtime", -] diff --git a/invarch/pallet-tx-pause/src/lib.rs b/invarch/pallet-tx-pause/src/lib.rs deleted file mode 100644 index 4a130a2e..00000000 --- a/invarch/pallet-tx-pause/src/lib.rs +++ /dev/null @@ -1,241 +0,0 @@ -// This file is part of Substrate. - -// Copyright (C) 2022 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. - -#![cfg_attr(not(feature = "std"), no_std)] -#![deny(rustdoc::broken_intra_doc_links)] - -pub mod weights; - -use frame_support::{ - dispatch::GetDispatchInfo, - pallet_prelude::*, - traits::{CallMetadata, Contains, GenesisBuild, GetCallMetadata, IsSubType, IsType}, - DefaultNoBound, -}; -use frame_system::pallet_prelude::*; -use sp_runtime::{traits::Dispatchable, DispatchResult}; -use sp_std::{convert::TryInto, prelude::*}; - -pub use pallet::*; -pub use weights::*; - -/// The stringy name of a pallet from [`GetCallMetadata`] for [`Config::RuntimeCall`] variants. -pub type PalletNameOf = BoundedVec::MaxNameLen>; - -/// The stringy name of a call (within a pallet) from [`GetCallMetadata`] for -/// [`Config::RuntimeCall`] variants. -pub type PalletCallNameOf = BoundedVec::MaxNameLen>; - -/// A fully specified pallet ([`PalletNameOf`]) and optional call ([`PalletCallNameOf`]) -/// to partially or fully specify an item a variant of a [`Config::RuntimeCall`]. -pub type RuntimeCallNameOf = (PalletNameOf, PalletCallNameOf); - -#[frame_support::pallet] -pub mod pallet { - use super::*; - - #[pallet::pallet] - pub struct Pallet(PhantomData); - - #[pallet::config] - pub trait Config: frame_system::Config { - /// The overarching event type. - type RuntimeEvent: From> + IsType<::RuntimeEvent>; - - /// The overarching call type. - type RuntimeCall: Parameter - + Dispatchable - + GetDispatchInfo - + GetCallMetadata - + From> - + IsSubType> - + IsType<::RuntimeCall>; - - /// The only origin that can pause calls. - type PauseOrigin: EnsureOrigin; - - /// The only origin that can un-pause calls. - type UnpauseOrigin: EnsureOrigin; - - /// Contains all calls that cannot be paused. - /// - /// The `TxMode` pallet cannot pause its own calls, and does not need to be explicitly - /// added here. - type WhitelistedCalls: Contains>; - - /// Maximum length for pallet name and call name SCALE encoded string names. - /// - /// TOO LONG NAMES WILL BE TREATED AS PAUSED. - #[pallet::constant] - type MaxNameLen: Get; - - // Weight information for extrinsics in this pallet. - type WeightInfo: WeightInfo; - } - - /// The set of calls that are explicitly paused. - #[pallet::storage] - pub type PausedCalls = - StorageMap<_, Blake2_128Concat, RuntimeCallNameOf, (), OptionQuery>; - - #[pallet::error] - pub enum Error { - /// The call is paused. - IsPaused, - - /// The call is unpaused. - IsUnpaused, - - /// The call is whitelisted and cannot be paused. - Unpausable, - - // The pallet or call does not exist in the runtime. - NotFound, - } - - #[pallet::event] - #[pallet::generate_deposit(pub(super) fn deposit_event)] - pub enum Event { - /// This pallet, or a specific call is now paused. - CallPaused { full_name: RuntimeCallNameOf }, - /// This pallet, or a specific call is now unpaused. - CallUnpaused { full_name: RuntimeCallNameOf }, - } - - /// Configure the initial state of this pallet in the genesis block. - #[pallet::genesis_config] - #[derive(DefaultNoBound)] - pub struct GenesisConfig { - /// Initially paused calls. - pub paused: Vec>, - } - - #[pallet::genesis_build] - impl GenesisBuild for GenesisConfig { - fn build(&self) { - for call in &self.paused { - Pallet::::ensure_can_pause(call).expect("Genesis data is known good; qed"); - PausedCalls::::insert(call, ()); - } - } - } - - #[pallet::call] - impl Pallet { - /// Pause a call. - /// - /// Can only be called by [`Config::PauseOrigin`]. - /// Emits an [`Event::CallPaused`] event on success. - #[pallet::call_index(0)] - #[pallet::weight(T::WeightInfo::pause())] - pub fn pause(origin: OriginFor, full_name: RuntimeCallNameOf) -> DispatchResult { - T::PauseOrigin::ensure_origin(origin)?; - - Self::do_pause(full_name).map_err(Into::into) - } - - /// Un-pause a call. - /// - /// Can only be called by [`Config::UnpauseOrigin`]. - /// Emits an [`Event::CallUnpaused`] event on success. - #[pallet::call_index(1)] - #[pallet::weight(T::WeightInfo::unpause())] - pub fn unpause(origin: OriginFor, ident: RuntimeCallNameOf) -> DispatchResult { - T::UnpauseOrigin::ensure_origin(origin)?; - - Self::do_unpause(ident).map_err(Into::into) - } - } -} - -impl Pallet { - pub(crate) fn do_pause(ident: RuntimeCallNameOf) -> Result<(), Error> { - Self::ensure_can_pause(&ident)?; - PausedCalls::::insert(&ident, ()); - Self::deposit_event(Event::CallPaused { full_name: ident }); - - Ok(()) - } - - pub(crate) fn do_unpause(ident: RuntimeCallNameOf) -> Result<(), Error> { - Self::ensure_can_unpause(&ident)?; - PausedCalls::::remove(&ident); - Self::deposit_event(Event::CallUnpaused { full_name: ident }); - - Ok(()) - } - - /// Return whether this call is paused. - pub fn is_paused(full_name: &RuntimeCallNameOf) -> bool { - if T::WhitelistedCalls::contains(full_name) { - return false; - } - - >::contains_key(full_name) - } - - /// Same as [`Self::is_paused`] but for inputs unbound by max-encoded-len. - pub fn is_paused_unbound(pallet: Vec, call: Vec) -> bool { - let pallet = PalletNameOf::::try_from(pallet); - let call = PalletCallNameOf::::try_from(call); - - match (pallet, call) { - (Ok(pallet), Ok(call)) => Self::is_paused(&(pallet, call)), - _ => true, - } - } - - /// Ensure that this call can be paused. - pub fn ensure_can_pause(full_name: &RuntimeCallNameOf) -> Result<(), Error> { - // SAFETY: The `TxPause` pallet can never pause itself. - if full_name.0.as_ref() == ::name().as_bytes().to_vec() { - return Err(Error::::Unpausable); - } - - if T::WhitelistedCalls::contains(full_name) { - return Err(Error::::Unpausable); - } - if Self::is_paused(full_name) { - return Err(Error::::IsPaused); - } - Ok(()) - } - - /// Ensure that this call can be un-paused. - pub fn ensure_can_unpause(full_name: &RuntimeCallNameOf) -> Result<(), Error> { - if Self::is_paused(full_name) { - // SAFETY: Everything that is paused, can be un-paused. - Ok(()) - } else { - Err(Error::IsUnpaused) - } - } -} - -impl Contains<::RuntimeCall> for Pallet -where - ::RuntimeCall: GetCallMetadata, -{ - /// Return whether the call is allowed to be dispatched. - fn contains(call: &::RuntimeCall) -> bool { - let CallMetadata { - pallet_name, - function_name, - } = call.get_call_metadata(); - !Pallet::::is_paused_unbound(pallet_name.into(), function_name.into()) - } -} diff --git a/invarch/pallet-tx-pause/src/weights.rs b/invarch/pallet-tx-pause/src/weights.rs deleted file mode 100644 index b733e64b..00000000 --- a/invarch/pallet-tx-pause/src/weights.rs +++ /dev/null @@ -1,107 +0,0 @@ -// This file is part of Substrate. - -// Copyright (C) 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. - -//! Autogenerated weights for `pallet_tx_pause` -//! -//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev -//! DATE: 2023-08-24, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` -//! WORST CASE MAP SIZE: `1000000` -//! HOSTNAME: `runner-aahe6cbd-project-145-concurrent-0`, CPU: `Intel(R) Xeon(R) CPU @ 2.60GHz` -//! WASM-EXECUTION: `Compiled`, CHAIN: `Some("dev")`, DB CACHE: `1024` - -// Executed Command: -// target/production/substrate-node -// benchmark -// pallet -// --steps=50 -// --repeat=20 -// --extrinsic=* -// --wasm-execution=compiled -// --heap-pages=4096 -// --json-file=/builds/parity/mirrors/substrate/.git/.artifacts/bench.json -// --pallet=pallet_tx_pause -// --chain=dev -// --header=./HEADER-APACHE2 -// --output=./frame/tx-pause/src/weights.rs -// --template=./.maintain/frame-weight-template.hbs - -#![cfg_attr(rustfmt, rustfmt_skip)] -#![allow(unused_parens)] -#![allow(unused_imports)] -#![allow(missing_docs)] - -use frame_support::{traits::Get, weights::{Weight, constants::RocksDbWeight}}; -use core::marker::PhantomData; - -/// Weight functions needed for `pallet_tx_pause`. -pub trait WeightInfo { - fn pause() -> Weight; - fn unpause() -> Weight; -} - -/// Weights for `pallet_tx_pause` using the Substrate node and recommended hardware. -pub struct SubstrateWeight(PhantomData); -impl WeightInfo for SubstrateWeight { - /// Storage: `TxPause::PausedCalls` (r:1 w:1) - /// Proof: `TxPause::PausedCalls` (`max_values`: None, `max_size`: Some(532), added: 3007, mode: `MaxEncodedLen`) - fn pause() -> Weight { - // Proof Size summary in bytes: - // Measured: `3` - // Estimated: `3997` - // Minimum execution time: 15_096_000 picoseconds. - Weight::from_parts(15_437_000, 3997) - .saturating_add(T::DbWeight::get().reads(1_u64)) - .saturating_add(T::DbWeight::get().writes(1_u64)) - } - /// Storage: `TxPause::PausedCalls` (r:1 w:1) - /// Proof: `TxPause::PausedCalls` (`max_values`: None, `max_size`: Some(532), added: 3007, mode: `MaxEncodedLen`) - fn unpause() -> Weight { - // Proof Size summary in bytes: - // Measured: `565` - // Estimated: `3997` - // Minimum execution time: 21_546_000 picoseconds. - Weight::from_parts(22_178_000, 3997) - .saturating_add(T::DbWeight::get().reads(1_u64)) - .saturating_add(T::DbWeight::get().writes(1_u64)) - } -} - -// For backwards compatibility and tests. -impl WeightInfo for () { - /// Storage: `TxPause::PausedCalls` (r:1 w:1) - /// Proof: `TxPause::PausedCalls` (`max_values`: None, `max_size`: Some(532), added: 3007, mode: `MaxEncodedLen`) - fn pause() -> Weight { - // Proof Size summary in bytes: - // Measured: `3` - // Estimated: `3997` - // Minimum execution time: 15_096_000 picoseconds. - Weight::from_parts(15_437_000, 3997) - .saturating_add(RocksDbWeight::get().reads(1_u64)) - .saturating_add(RocksDbWeight::get().writes(1_u64)) - } - /// Storage: `TxPause::PausedCalls` (r:1 w:1) - /// Proof: `TxPause::PausedCalls` (`max_values`: None, `max_size`: Some(532), added: 3007, mode: `MaxEncodedLen`) - fn unpause() -> Weight { - // Proof Size summary in bytes: - // Measured: `565` - // Estimated: `3997` - // Minimum execution time: 21_546_000 picoseconds. - Weight::from_parts(22_178_000, 3997) - .saturating_add(RocksDbWeight::get().reads(1_u64)) - .saturating_add(RocksDbWeight::get().writes(1_u64)) - } -}