diff --git a/.github/workflows/build_docker.yml b/.github/workflows/build_docker.yml index eb61aadb..84183103 100644 --- a/.github/workflows/build_docker.yml +++ b/.github/workflows/build_docker.yml @@ -14,7 +14,7 @@ jobs: - name: Extract metadata (tags, labels) for Docker id: meta - uses: docker/metadata-action@96383f45573cb7f253c731d3b3ab81c87ef81934 # v5.0.0 + uses: docker/metadata-action@e6428a5c4e294a61438ed7f43155db912025b6b3 # v5.2.0 with: images: paritytech/trappist diff --git a/.github/workflows/publish-docker.yml b/.github/workflows/publish-docker.yml index 18f08f51..e4ad76fd 100644 --- a/.github/workflows/publish-docker.yml +++ b/.github/workflows/publish-docker.yml @@ -20,7 +20,7 @@ jobs: - name: Extract metadata (tags, labels) for Docker id: meta - uses: docker/metadata-action@96383f45573cb7f253c731d3b3ab81c87ef81934 # v5.0.0 + uses: docker/metadata-action@e6428a5c4e294a61438ed7f43155db912025b6b3 # v5.2.0 with: images: paritytech/trappist diff --git a/Cargo.lock b/Cargo.lock index 12293c9a..75f13bf2 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -6814,39 +6814,6 @@ dependencies = [ "sp-std", ] -[[package]] -name = "pallet-lockdown-mode" -version = "0.1.0" -dependencies = [ - "cumulus-pallet-dmp-queue", - "cumulus-pallet-xcmp-queue", - "cumulus-primitives-core", - "frame-benchmarking", - "frame-support", - "frame-system", - "log", - "pallet-assets", - "pallet-balances", - "pallet-remark", - "pallet-xcm", - "parachain-info", - "parachains-common", - "parity-scale-codec", - "polkadot-core-primitives", - "polkadot-parachain-primitives", - "polkadot-runtime-parachains", - "scale-info", - "sp-core", - "sp-io", - "sp-runtime", - "sp-std", - "staging-xcm", - "staging-xcm-builder", - "staging-xcm-executor", - "xcm-primitives", - "xcm-simulator", -] - [[package]] name = "pallet-membership" version = "4.0.0-dev" @@ -7109,16 +7076,19 @@ dependencies = [ ] [[package]] -name = "pallet-remark" +name = "pallet-safe-mode" version = "4.0.0-dev" source = "git+https://github.com/paritytech/polkadot-sdk.git?branch=release-polkadot-v1.1.0#f60318f68687e601c47de5ad5ca88e2c3f8139a7" dependencies = [ + "frame-benchmarking", "frame-support", "frame-system", + "pallet-balances", + "pallet-proxy", + "pallet-utility", "parity-scale-codec", "scale-info", - "sp-core", - "sp-io", + "sp-arithmetic", "sp-runtime", "sp-std", ] @@ -7381,6 +7351,23 @@ dependencies = [ "sp-std", ] +[[package]] +name = "pallet-tx-pause" +version = "4.0.0-dev" +source = "git+https://github.com/paritytech/polkadot-sdk.git?branch=release-polkadot-v1.1.0#f60318f68687e601c47de5ad5ca88e2c3f8139a7" +dependencies = [ + "frame-benchmarking", + "frame-support", + "frame-system", + "pallet-balances", + "pallet-proxy", + "pallet-utility", + "parity-scale-codec", + "scale-info", + "sp-runtime", + "sp-std", +] + [[package]] name = "pallet-uniques" version = "4.0.0-dev" @@ -13821,9 +13808,9 @@ dependencies = [ "pallet-democracy", "pallet-identity", "pallet-insecure-randomness-collective-flip", - "pallet-lockdown-mode", "pallet-multisig", "pallet-preimage", + "pallet-safe-mode", "pallet-scheduler", "pallet-session", "pallet-sudo", @@ -13831,6 +13818,7 @@ dependencies = [ "pallet-transaction-payment", "pallet-transaction-payment-rpc-runtime-api", "pallet-treasury", + "pallet-tx-pause", "pallet-uniques", "pallet-utility", "pallet-withdraw-teleport", diff --git a/Cargo.toml b/Cargo.toml index 1a64e818..e8c7099d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -51,7 +51,6 @@ jsonrpsee = { version = "0.16.2" } # Trappist Pallets pallet-asset-registry = { default-features = false, path = "pallets/asset-registry" } trappist-runtime-benchmarks = { default-features = false, path = "pallets/benchmarks" } -pallet-lockdown-mode = { version = "0.1.0", default-features = false, path = "pallets/lockdown-mode" } pallet-withdraw-teleport = { version = "0.1.0", default-features = false, path = "pallets/withdraw-teleport" } # Substrate std @@ -138,6 +137,8 @@ pallet-transaction-payment-rpc-runtime-api = { git = "https://github.com/parityt pallet-uniques = { git = "https://github.com/paritytech/polkadot-sdk", default-features = false, branch = "release-polkadot-v1.1.0" } pallet-utility = { git = "https://github.com/paritytech/polkadot-sdk", default-features = false, branch = "release-polkadot-v1.1.0" } pallet-treasury = { git = "https://github.com/paritytech/polkadot-sdk", default-features = false, branch = "release-polkadot-v1.1.0" } +pallet-safe-mode = { git = "https://github.com/paritytech/polkadot-sdk", default-features = false, branch = "release-polkadot-v1.1.0" } +pallet-tx-pause = { git = "https://github.com/paritytech/polkadot-sdk", default-features = false, branch = "release-polkadot-v1.1.0" } # Cumulus client dependencies cumulus-client-cli = { git = "https://github.com/paritytech/polkadot-sdk.git", branch = "release-polkadot-v1.1.0" } diff --git a/node/src/chain_spec/trappist.rs b/node/src/chain_spec/trappist.rs index ea32af61..eb6fafe7 100644 --- a/node/src/chain_spec/trappist.rs +++ b/node/src/chain_spec/trappist.rs @@ -24,7 +24,7 @@ use sc_service::ChainType; use sp_core::{crypto::UncheckedInto, sr25519}; use trappist_runtime::{ constants::currency::EXISTENTIAL_DEPOSIT, AccountId, AssetsConfig, AuraId, BalancesConfig, - CouncilConfig, ForeignAssetsConfig, LockdownModeConfig, PoolAssetsConfig, RuntimeGenesisConfig, + CouncilConfig, ForeignAssetsConfig, PoolAssetsConfig, RuntimeGenesisConfig, SessionConfig, SessionKeys, SudoConfig, SystemConfig, }; @@ -212,8 +212,9 @@ pub fn testnet_genesis( members: invulnerables.into_iter().map(|x| x.0).collect::>(), phantom: Default::default(), }, - treasury: Default::default(), - lockdown_mode: LockdownModeConfig { initial_status: false, ..Default::default() }, + treasury: Default::default(), + safe_mode: Default::default(), + tx_pause: Default::default(), foreign_assets: ForeignAssetsConfig { assets: vec![], accounts: vec![], metadata: vec![] }, pool_assets: PoolAssetsConfig { assets: vec![], accounts: vec![], metadata: vec![] }, transaction_payment: Default::default(), @@ -331,7 +332,8 @@ fn trappist_live_genesis( phantom: Default::default(), }, treasury: Default::default(), - lockdown_mode: Default::default(), + safe_mode: Default::default(), + tx_pause: Default::default(), foreign_assets: ForeignAssetsConfig { assets: vec![], accounts: vec![], metadata: vec![] }, pool_assets: PoolAssetsConfig { assets: vec![], accounts: vec![], metadata: vec![] }, transaction_payment: Default::default(), diff --git a/pallets/lockdown-mode/Cargo.toml b/pallets/lockdown-mode/Cargo.toml deleted file mode 100644 index 57a49fd5..00000000 --- a/pallets/lockdown-mode/Cargo.toml +++ /dev/null @@ -1,80 +0,0 @@ -[package] -name = "pallet-lockdown-mode" -version = "0.1.0" -description = "Trappist pallet for setting lockdown mode." -authors = { workspace = true } -license = { workspace = true } -homepage = { workspace = true } -repository = { workspace = true } -edition = { workspace = true } - -[package.metadata.docs.rs] -targets = ["x86_64-unknown-linux-gnu"] - -[dependencies] -parity-scale-codec = { workspace = true, features = [ "derive" ] } -scale-info = { workspace = true } -sp-runtime = { workspace = true } -sp-std = { workspace = true } -frame-benchmarking = { workspace = true } -frame-support = { workspace = true } -frame-system = { workspace = true } - -cumulus-primitives-core = { workspace = true } -pallet-assets = { workspace = true } -pallet-balances = { workspace = true } -log = { workspace = true } -xcm = { workspace = true } - -xcm-primitives = { workspace = true } - -[dev-dependencies] -sp-core = { workspace = true } -sp-io = { workspace = true } -sp-runtime = { workspace = true } -pallet-remark = { workspace = true } - - -xcm = { workspace = true } -xcm-simulator = { workspace = true } -xcm-executor = { workspace = true } -xcm-builder = { workspace = true } -pallet-xcm = { workspace = true } -polkadot-core-primitives = { workspace = true } -polkadot-runtime-parachains = { workspace = true } -polkadot-parachain-primitives = { workspace = true } - -parachain-info = { workspace = true } -parachains-common = { workspace = true } -cumulus-pallet-dmp-queue = { workspace = true } -cumulus-pallet-xcmp-queue = { workspace = true } -cumulus-primitives-core = { workspace = true } - -[features] -default = ["std"] -std = [ - "parity-scale-codec/std", - "sp-runtime/std", - "sp-std/std", - "pallet-assets/std", - "pallet-balances/std", - "frame-benchmarking/std", - "frame-support/std", - "frame-system/std", - "scale-info/std", - "xcm-primitives/std", - "xcm/std", - "xcm-executor/std", - "xcm-builder/std", - "pallet-xcm/std", - "polkadot-core-primitives/std", - "polkadot-runtime-parachains/std", - "polkadot-parachain-primitives/std", - "parachain-info/std", - "parachains-common/std", - "cumulus-pallet-dmp-queue/std", - "cumulus-pallet-xcmp-queue/std", - "cumulus-primitives-core/std", -] -runtime-benchmarks = ["frame-benchmarking/runtime-benchmarks"] -try-runtime = ["frame-support/try-runtime"] diff --git a/pallets/lockdown-mode/README.md b/pallets/lockdown-mode/README.md deleted file mode 100644 index c5d6a5ad..00000000 --- a/pallets/lockdown-mode/README.md +++ /dev/null @@ -1,41 +0,0 @@ -# Lockdown Mode Pallet - -The Lockdown Mode Pallet is a Substrate module that provides functionality to lock down the runtime execution in a Substrate-based blockchain system. When the lockdown mode is activated, it filters out incoming calls and messages to ensure that only authorized actions are allowed. - -## Overview - -This pallet the governance of the chain to activate or deactivate a lockdown mode. When the lockdown mode is activated, incoming runtime calls and downward messages are filtered based on a preconfigured filter. Additionally, it suspends the execution of XCM (Cross-Consensus Message) messages in the `on_idle` hook. - -The lockdown mode status is stored in the `LockdownModeStatus` storage item. When the lockdown mode is deactivated, the system resumes normal operations, including the execution of XCM messages in the `on_idle` hook. - -## Configuration - -This pallet supports configurable traits that allow customization according to specific needs. - -### Types - -- `RuntimeEvent`: Specifies the runtime event type. -- `LockdownModeOrigin`: Specifies the origin that is allowed to activate and deactivate the lockdown mode. -- `BlackListedCalls`: Specifies the filter used to filter incoming runtime calls in lockdown mode. -- `LockdownDmpHandler`: Specifies the handler for downward messages in lockdown mode. -- `XcmExecutorManager`: Interface to control the execution of XCMP Queue messages. - - -## Extrinsics - -The pallet provides the following extrinsics: - -- `activate_lockdown_mode`: Activates the lockdown mode. Only the specified `LockdownModeOrigin` can call this extrinsic. It updates the `LockdownModeStatus` storage item to `ACTIVATED` (true) and attempts to suspend the execution of XCM messages in the `on_idle` hook. -- `deactivate_lockdown_mode`: Deactivates the lockdown mode. Only the specified `LockdownModeOrigin` can call this extrinsic. It updates the `LockdownModeStatus` storage item to `DEACTIVATED` (false) and attempts to resume the execution of XCM messages in the `on_idle` hook. - - -#### Errors - -Possible errors returned by the dispatchable calls are: - -- `LockdownModeAlreadyActivated`: The lockdown mode is already activated. -- `LockdownModeAlreadyDeactivated`: The lockdown mode is already deactivated. - -Please note that any failure to suspend or resume XCM execution in the `on_idle` hook is not treated as a fatal error that stops the function execution. Instead, it is recorded as an event `FailedToSuspendIdleXcmExecution` or `FailedToResumeIdleXcmExecution`, respectively, and the function continues its execution. - -The lockdown mode can serve as a crucial tool in system maintenance or in case of emergency, when it's necessary to restrict system operation and ensure the system's security and stability. diff --git a/pallets/lockdown-mode/src/benchmarking.rs b/pallets/lockdown-mode/src/benchmarking.rs deleted file mode 100644 index f5196adb..00000000 --- a/pallets/lockdown-mode/src/benchmarking.rs +++ /dev/null @@ -1,42 +0,0 @@ -// This file is part of Trappist. - -// 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. - -use super::*; - -#[allow(unused)] -use crate::Pallet as LockdownMode; -use crate::{ACTIVATED, DEACTIVATED}; -use frame_benchmarking::benchmarks; -use frame_system::RawOrigin; - -benchmarks! { - activate_lockdown_mode { - LockdownModeStatus::::put(DEACTIVATED); - }: activate_lockdown_mode(RawOrigin::Root) - verify { - assert_eq!(LockdownModeStatus::::get(), ACTIVATED); - } - - deactivate_lockdown_mode { - LockdownModeStatus::::put(ACTIVATED); - }: deactivate_lockdown_mode(RawOrigin::Root) - verify { - assert_eq!(LockdownModeStatus::::get(), DEACTIVATED); - } - - impl_benchmark_test_suite!(LockdownMode, crate::mock::new_test_ext(true), crate::mock::Test); -} diff --git a/pallets/lockdown-mode/src/lib.rs b/pallets/lockdown-mode/src/lib.rs deleted file mode 100644 index 0a462a1e..00000000 --- a/pallets/lockdown-mode/src/lib.rs +++ /dev/null @@ -1,169 +0,0 @@ -// This file is part of Trappist. - -// 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. - -#![cfg_attr(not(feature = "std"), no_std)] - -/// Edit this file to define custom logic or remove it if it is not needed. -/// Learn more about FRAME and the core library of Substrate FRAME pallets: -/// -pub use pallet::*; - -#[cfg(test)] -mod mock; -#[cfg(test)] -mod tests; - -#[cfg(feature = "runtime-benchmarks")] -mod benchmarking; -pub mod weights; -pub use weights::*; - -pub const ACTIVATED: bool = true; -pub const DEACTIVATED: bool = false; - -#[frame_support::pallet] -pub mod pallet { - use super::*; - use cumulus_primitives_core::{ - relay_chain::BlockNumber as RelayBlockNumber, DmpMessageHandler, - }; - use frame_support::{ - pallet_prelude::{ValueQuery, *}, - traits::Contains, - }; - use frame_system::pallet_prelude::*; - use sp_std::vec::Vec; - use xcm_primitives::PauseXcmExecution; - #[pallet::pallet] - pub struct Pallet(_); - - #[pallet::genesis_config] - pub struct GenesisConfig { - pub initial_status: bool, - #[serde(skip)] - pub _config: PhantomData, - } - - impl Default for GenesisConfig { - fn default() -> Self { - Self { initial_status: ACTIVATED, _config: Default::default() } - } - } - - #[pallet::genesis_build] - impl BuildGenesisConfig for GenesisConfig { - fn build(&self) { - LockdownModeStatus::::put(self.initial_status); - } - } - - #[pallet::config] - pub trait Config: frame_system::Config { - type RuntimeEvent: From> + IsType<::RuntimeEvent>; - type LockdownModeOrigin: EnsureOrigin; - type BlackListedCalls: Contains; - type LockdownDmpHandler: DmpMessageHandler; - type XcmExecutorManager: PauseXcmExecution; - type WeightInfo: WeightInfo; - } - - #[pallet::storage] - pub type LockdownModeStatus = StorageValue<_, bool, ValueQuery>; - - #[pallet::event] - #[pallet::generate_deposit(pub(super) fn deposit_event)] - pub enum Event { - LockdownModeActivated, - LockdownModeDeactivated, - /// The call to suspend on_idle XCM execution failed with inner error - FailedToSuspendIdleXcmExecution { - error: DispatchError, - }, - /// The call to resume on_idle XCM execution failed with inner error - FailedToResumeIdleXcmExecution { - error: DispatchError, - }, - } - - #[pallet::error] - pub enum Error { - /// Lockdown mode was already activated - LockdownModeAlreadyActivated, - /// Lockdown mode was already deactivated - LockdownModeAlreadyDeactivated, - } - - #[pallet::call] - impl Pallet { - #[pallet::call_index(0)] - #[pallet::weight(::WeightInfo::activate_lockdown_mode())] - pub fn activate_lockdown_mode(origin: OriginFor) -> DispatchResult { - T::LockdownModeOrigin::ensure_origin(origin)?; - - ensure!(!LockdownModeStatus::::get(), Error::::LockdownModeAlreadyActivated); - - LockdownModeStatus::::put(ACTIVATED); - - if let Err(error) = T::XcmExecutorManager::suspend_xcm_execution() { - log::error!("Failed to suspend idle XCM execution {:?}", error); - Self::deposit_event(Event::FailedToSuspendIdleXcmExecution { error }); - } - - Self::deposit_event(Event::LockdownModeActivated); - - Ok(()) - } - - #[pallet::call_index(1)] - #[pallet::weight(::WeightInfo::deactivate_lockdown_mode())] - pub fn deactivate_lockdown_mode(origin: OriginFor) -> DispatchResult { - T::LockdownModeOrigin::ensure_origin(origin)?; - ensure!(LockdownModeStatus::::get(), Error::::LockdownModeAlreadyDeactivated); - - LockdownModeStatus::::put(DEACTIVATED); - - if let Err(error) = T::XcmExecutorManager::resume_xcm_execution() { - log::error!("Failed to resume idle XCM execution {:?}", error); - Self::deposit_event(Event::FailedToResumeIdleXcmExecution { error }); - } - - Self::deposit_event(Event::LockdownModeDeactivated); - - Ok(()) - } - } - - impl Contains for Pallet { - fn contains(call: &T::RuntimeCall) -> bool { - !LockdownModeStatus::::get() || T::BlackListedCalls::contains(call) - } - } - - impl DmpMessageHandler for Pallet { - fn handle_dmp_messages( - iter: impl Iterator)>, - limit: Weight, - ) -> Weight { - if LockdownModeStatus::::get() { - T::LockdownDmpHandler::handle_dmp_messages(iter, Weight::zero()) - } else { - // Normal path, everything should pass through - T::LockdownDmpHandler::handle_dmp_messages(iter, limit) - } - } - } -} diff --git a/pallets/lockdown-mode/src/mock.rs b/pallets/lockdown-mode/src/mock.rs deleted file mode 100644 index 3de6e708..00000000 --- a/pallets/lockdown-mode/src/mock.rs +++ /dev/null @@ -1,142 +0,0 @@ -// This file is part of Trappist. - -// 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. - -use crate as pallet_lockdown_mode; -use cumulus_primitives_core::{relay_chain::BlockNumber as RelayBlockNumber, DmpMessageHandler}; -use frame_support::{ - traits::{ConstU16, ConstU64, Contains}, - weights::Weight, -}; -use frame_system as system; -use sp_core::H256; -use sp_runtime::{ - traits::{BlakeTwo256, ConstU32, IdentityLookup}, - BuildStorage, DispatchResult, -}; - -type Block = frame_system::mocking::MockBlock; - -frame_support::parameter_types! { - pub const StatemineParaIdInfo: u32 = 1000u32; - pub const StatemineAssetsInstanceInfo: u8 = 50u8; - pub const StatemineAssetIdInfo: u128 = 1u128; -} - -// Configure a mock runtime to test the pallet. -frame_support::construct_runtime!( - pub struct Test { - System: frame_system, - LockdownMode: pallet_lockdown_mode::{Pallet, Call, Storage, Event}, - Balance: pallet_balances::{Pallet, Call, Storage, Event}, - Remark: pallet_remark::{Pallet, Call, Storage, Event}, - } -); - -impl system::Config for Test { - type RuntimeEvent = RuntimeEvent; - type BaseCallFilter = frame_support::traits::Everything; - type BlockWeights = (); - type BlockLength = (); - type RuntimeOrigin = RuntimeOrigin; - type RuntimeCall = RuntimeCall; - type Nonce = u64; - type Hash = H256; - type Hashing = BlakeTwo256; - type AccountId = u64; - type Lookup = IdentityLookup; - type Block = Block; - type BlockHashCount = ConstU64<250>; - type DbWeight = (); - type Version = (); - type PalletInfo = PalletInfo; - type AccountData = pallet_balances::AccountData; - type OnNewAccount = (); - type OnKilledAccount = (); - type SystemWeightInfo = (); - type SS58Prefix = ConstU16<42>; - type OnSetCode = (); - type MaxConsumers = ConstU32<16>; -} - -impl pallet_balances::Config for Test { - type RuntimeEvent = RuntimeEvent; - type WeightInfo = (); - type Balance = u64; - type DustRemoval = (); - type ExistentialDeposit = ConstU64<1>; - type AccountStore = System; - type ReserveIdentifier = [u8; 8]; - type RuntimeHoldReason = (); - type FreezeIdentifier = (); - type MaxLocks = (); - type MaxReserves = (); - type MaxHolds = ConstU32<0>; - type MaxFreezes = ConstU32<0>; -} - -pub struct RuntimeBlackListedCalls; -impl Contains for RuntimeBlackListedCalls { - fn contains(call: &RuntimeCall) -> bool { - match call { - RuntimeCall::Balance(_) => false, - _ => true, - } - } -} - -pub struct LockdownDmpHandler; -impl DmpMessageHandler for LockdownDmpHandler { - fn handle_dmp_messages( - _iter: impl Iterator)>, - limit: Weight, - ) -> Weight { - limit - } -} - -pub struct XcmExecutionManager {} - -impl xcm_primitives::PauseXcmExecution for XcmExecutionManager { - fn suspend_xcm_execution() -> DispatchResult { - Ok(()) - } - fn resume_xcm_execution() -> DispatchResult { - Ok(()) - } -} - -impl pallet_remark::Config for Test { - type RuntimeEvent = RuntimeEvent; - type WeightInfo = (); -} - -impl pallet_lockdown_mode::Config for Test { - type RuntimeEvent = RuntimeEvent; - type LockdownModeOrigin = frame_system::EnsureRoot; - type BlackListedCalls = RuntimeBlackListedCalls; - type LockdownDmpHandler = LockdownDmpHandler; - type XcmExecutorManager = XcmExecutionManager; - type WeightInfo = pallet_lockdown_mode::weights::SubstrateWeight; -} - -pub fn new_test_ext(initial_status: bool) -> sp_io::TestExternalities { - let mut storage = system::GenesisConfig::::default().build_storage().unwrap(); - pallet_lockdown_mode::GenesisConfig:: { initial_status, ..Default::default() } - .assimilate_storage(&mut storage) - .unwrap(); - storage.into() -} diff --git a/pallets/lockdown-mode/src/tests.rs b/pallets/lockdown-mode/src/tests.rs deleted file mode 100644 index fdf9bb95..00000000 --- a/pallets/lockdown-mode/src/tests.rs +++ /dev/null @@ -1,100 +0,0 @@ -// This file is part of Trappist. - -// 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. - -use super::{GenesisConfig, *}; -use crate::{mock::*, Error, ACTIVATED, DEACTIVATED}; -use frame_support::{assert_noop, assert_ok, traits::Contains}; -use pallet_balances::{self, Call as BalancesCall}; -use pallet_remark::{self, Call as RemarkCall}; - -#[test] -fn genesis_config_default() { - let default_genesis = GenesisConfig::::default(); - assert_eq!(default_genesis.initial_status, ACTIVATED); -} - -#[test] -fn genesis_config_initialized() { - [true, false].into_iter().for_each(|expected| { - new_test_ext(expected).execute_with(|| { - let lockdown_mode = LockdownModeStatus::::get(); - assert_eq!(lockdown_mode, expected); - }); - }); -} - -#[test] -fn activate_lockdown_mode_works() { - new_test_ext(false).execute_with(|| { - assert_ok!(LockdownMode::activate_lockdown_mode(RuntimeOrigin::root())); - - let lockdown_mode = LockdownModeStatus::::get(); - assert_eq!(lockdown_mode, ACTIVATED); - - assert_noop!( - LockdownMode::activate_lockdown_mode(RuntimeOrigin::root(),), - Error::::LockdownModeAlreadyActivated - ); - }); -} - -#[test] -fn deactivate_lockdown_mode_works() { - new_test_ext(true).execute_with(|| { - assert_ok!(LockdownMode::deactivate_lockdown_mode(RuntimeOrigin::root())); - - let lockdown_mode = LockdownModeStatus::::get(); - assert_eq!(lockdown_mode, DEACTIVATED); - - assert_noop!( - LockdownMode::deactivate_lockdown_mode(RuntimeOrigin::root(),), - Error::::LockdownModeAlreadyDeactivated - ); - }); -} - -#[test] -fn call_not_filtered_in_lockdown_mode() { - new_test_ext(false).execute_with(|| { - assert_ok!(LockdownMode::activate_lockdown_mode(RuntimeOrigin::root())); - let remark_call = RuntimeCall::Remark(RemarkCall::store { remark: vec![1, 2, 3] }); - let result: bool = LockdownMode::contains(&remark_call); - assert!(result); - }); -} - -#[test] -fn call_filtered_in_lockdown_mode() { - new_test_ext(false).execute_with(|| { - assert_ok!(LockdownMode::activate_lockdown_mode(RuntimeOrigin::root())); - let balance_call = RuntimeCall::Balance(BalancesCall::transfer { dest: 1, value: 2 }); - - let result: bool = LockdownMode::contains(&balance_call); - assert!(!result); - }); -} - -#[test] -fn call_not_filtered_in_normal_mode() { - new_test_ext(false).execute_with(|| { - let lockdown_mode = LockdownModeStatus::::get(); - assert_eq!(lockdown_mode, DEACTIVATED); - let balance_call = RuntimeCall::Balance(BalancesCall::transfer { dest: 1, value: 2 }); - let result: bool = LockdownMode::contains(&balance_call); - assert!(result); - }); -} diff --git a/pallets/lockdown-mode/src/weights.rs b/pallets/lockdown-mode/src/weights.rs deleted file mode 100644 index 7a1a66d8..00000000 --- a/pallets/lockdown-mode/src/weights.rs +++ /dev/null @@ -1,87 +0,0 @@ -// This file is part of Trappist. - -// 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_lockdown_mode` -//! -//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev -//! DATE: 2023-05-11, STEPS: `50`, REPEAT: 20, LOW RANGE: `[]`, HIGH RANGE: `[]` -//! HOSTNAME: `Hectors-MBP-14.fritz.box`, CPU: `` -//! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("trappist-rococo"), DB CACHE: 1024 - -// Executed Command: -// ./target/release/trappist-collator -// benchmark -// pallet -// --chain -// trappist-rococo -// --execution=wasm -// --wasm-execution=compiled -// --pallet -// pallet_lockdown_mode -// --extrinsic -// * -// --steps -// 50 -// --repeat -// 20 -// --output -// weight.rs - -#![cfg_attr(rustfmt, rustfmt_skip)] -#![allow(unused_parens)] -#![allow(unused_imports)] - -use frame_support::{traits::Get, weights::{Weight, constants::RocksDbWeight}}; -use sp_std::marker::PhantomData; - -pub trait WeightInfo { - fn activate_lockdown_mode() -> Weight; - fn deactivate_lockdown_mode() -> Weight; -} - -/// Weight functions for `pallet_lockdown_mode`. -pub struct SubstrateWeight(PhantomData); -impl WeightInfo for SubstrateWeight { - /// Storage: LockdownMode LockdownModeStatus (r:1 w:1) - /// Proof: LockdownMode LockdownModeStatus (max_values: Some(1), max_size: Some(1), added: 496, mode: MaxEncodedLen) - /// Storage: XcmpQueue QueueSuspended (r:0 w:1) - /// Proof Skipped: XcmpQueue QueueSuspended (max_values: Some(1), max_size: None, mode: Measured) - fn activate_lockdown_mode() -> Weight { - // Proof Size summary in bytes: - // Measured: `100` - // Estimated: `1586` - // Minimum execution time: 69_552_000 picoseconds. - Weight::from_parts(75_364_000, 0) - .saturating_add(Weight::from_parts(0, 1586)) - .saturating_add(T::DbWeight::get().reads(1)) - .saturating_add(T::DbWeight::get().writes(2)) - } - /// Storage: LockdownMode LockdownModeStatus (r:1 w:1) - /// Proof: LockdownMode LockdownModeStatus (max_values: Some(1), max_size: Some(1), added: 496, mode: MaxEncodedLen) - /// Storage: XcmpQueue QueueSuspended (r:0 w:1) - /// Proof Skipped: XcmpQueue QueueSuspended (max_values: Some(1), max_size: None, mode: Measured) - fn deactivate_lockdown_mode() -> Weight { - // Proof Size summary in bytes: - // Measured: `100` - // Estimated: `1586` - // Minimum execution time: 42_162_000 picoseconds. - Weight::from_parts(43_321_000, 0) - .saturating_add(Weight::from_parts(0, 1586)) - .saturating_add(T::DbWeight::get().reads(1)) - .saturating_add(T::DbWeight::get().writes(2)) - } -} diff --git a/runtime/trappist/Cargo.toml b/runtime/trappist/Cargo.toml index 880095cf..e7ecb49a 100644 --- a/runtime/trappist/Cargo.toml +++ b/runtime/trappist/Cargo.toml @@ -103,8 +103,9 @@ pallet-xcm-benchmarks = { workspace = true, optional = true } # Trappist Pallets pallet-asset-registry = { workspace = true } trappist-runtime-benchmarks = { workspace = true } -pallet-lockdown-mode = { workspace = true } pallet-withdraw-teleport = { workspace = true } +pallet-safe-mode = { workspace = true } +pallet-tx-pause = { workspace = true } [features] default = ["std"] @@ -143,7 +144,8 @@ std = [ "pallet-contracts-primitives/std", "pallet-democracy/std", "pallet-identity/std", - "pallet-lockdown-mode/std", + "pallet-safe-mode/std", + "pallet-tx-pause/std", "pallet-preimage/std", "pallet-withdraw-teleport/std", "pallet-multisig/std", @@ -195,7 +197,8 @@ runtime-benchmarks = [ "pallet-contracts/runtime-benchmarks", "pallet-democracy/runtime-benchmarks", "pallet-identity/runtime-benchmarks", - "pallet-lockdown-mode/runtime-benchmarks", + "pallet-safe-mode/runtime-benchmarks", + "pallet-tx-pause/runtime-benchmarks", "pallet-preimage/runtime-benchmarks", "pallet-multisig/runtime-benchmarks", "pallet-scheduler/runtime-benchmarks", @@ -225,7 +228,8 @@ try-runtime = [ "pallet-contracts/try-runtime", "pallet-democracy/try-runtime", "pallet-identity/try-runtime", - "pallet-lockdown-mode/try-runtime", + "pallet-safe-mode/try-runtime", + "pallet-tx-pause/try-runtime", "pallet-multisig/try-runtime", "pallet-scheduler/try-runtime", "pallet-timestamp/try-runtime", diff --git a/runtime/trappist/src/impls.rs b/runtime/trappist/src/impls.rs index 384f29c0..fa8b604e 100644 --- a/runtime/trappist/src/impls.rs +++ b/runtime/trappist/src/impls.rs @@ -76,43 +76,6 @@ where } } -pub struct RuntimeBlackListedCalls; -impl Contains for RuntimeBlackListedCalls { - fn contains(call: &RuntimeCall) -> bool { - !matches!( - call, - RuntimeCall::Balances(_) - | RuntimeCall::Assets(_) - | RuntimeCall::AssetConversion(_) - | RuntimeCall::PolkadotXcm(_) - | RuntimeCall::Treasury(_) - | RuntimeCall::Contracts(_) - | RuntimeCall::Uniques(_) - | RuntimeCall::AssetRegistry(_) - ) - } -} - -pub struct LockdownDmpHandler; -impl DmpMessageHandler for LockdownDmpHandler { - fn handle_dmp_messages( - _iter: impl Iterator)>, - limit: Weight, - ) -> Weight { - DmpQueue::handle_dmp_messages(_iter, limit) - } -} - -pub struct XcmExecutionManager {} -impl xcm_primitives::PauseXcmExecution for XcmExecutionManager { - fn suspend_xcm_execution() -> DispatchResult { - XcmpQueue::suspend_xcm_execution(RuntimeOrigin::root()) - } - fn resume_xcm_execution() -> DispatchResult { - XcmpQueue::resume_xcm_execution(RuntimeOrigin::root()) - } -} - #[cfg(test)] mod tests { use frame_support::{ diff --git a/runtime/trappist/src/lib.rs b/runtime/trappist/src/lib.rs index 51e1c1f5..cb5f8e66 100644 --- a/runtime/trappist/src/lib.rs +++ b/runtime/trappist/src/lib.rs @@ -27,6 +27,7 @@ use assets_common::local_and_foreign_assets::{LocalAndForeignAssets, MultiLocati use assets_common::matching::FromSiblingParachain; use assets_common::{AssetIdForTrustBackedAssetsConvert, MultiLocationForAssetId}; use cumulus_pallet_parachain_system::RelayNumberStrictlyIncreases; +use frame_support::traits::InsideBoth; use frame_support::{ construct_runtime, dispatch::DispatchClass, @@ -41,8 +42,9 @@ use frame_support::{ pub use frame_system::Call as SystemCall; use frame_system::{ limits::{BlockLength, BlockWeights}, - EnsureRoot, EnsureSigned, EnsureSignedBy, + EnsureRoot, EnsureRootWithSuccess, EnsureSigned, EnsureSignedBy }; +use pallet_tx_pause::RuntimeCallNameOf; use pallet_xcm::{EnsureXcm, IsMajorityOfBody}; pub use parachains_common as common; pub use parachains_common::{ @@ -70,7 +72,7 @@ use xcm::latest::prelude::BodyId; use xcm::latest::MultiLocation; use constants::{currency::*, fee::WeightToFee}; -use impls::{DealWithFees, LockdownDmpHandler, RuntimeBlackListedCalls, XcmExecutionManager}; +use impls::DealWithFees; use weights::{block_weights::BlockExecutionWeight, extrinsic_weights::ExtrinsicBaseWeight}; use xcm_config::{ CollatorSelectionUpdateOrigin, ForeignCreatorsSovereignAccountOf, @@ -185,7 +187,7 @@ parameter_types! { // Configure FRAME pallets to include in runtime. impl frame_system::Config for Runtime { type RuntimeEvent = RuntimeEvent; - type BaseCallFilter = LockdownMode; + type BaseCallFilter = InsideBoth; type BlockWeights = RuntimeBlockWeights; type BlockLength = RuntimeBlockLength; type RuntimeOrigin = RuntimeOrigin; @@ -299,7 +301,7 @@ impl cumulus_pallet_parachain_system::Config for Runtime { type OnSystemEvent = (); type SelfParaId = parachain_info::Pallet; type OutboundXcmpMessageSource = XcmpQueue; - type DmpMessageHandler = LockdownMode; + type DmpMessageHandler = DmpQueue; type ReservedDmpWeight = ReservedDmpWeight; type XcmpMessageHandler = XcmpQueue; type ReservedXcmpWeight = ReservedXcmpWeight; @@ -761,13 +763,66 @@ impl pallet_withdraw_teleport::Config for Runtime { type WeightInfo = weights::pallet_withdraw_teleport::WeightInfo; } -impl pallet_lockdown_mode::Config for Runtime { +/// Calls that can bypass the safe-mode pallet. +pub struct SafeModeWhitelistedCalls; +impl Contains for SafeModeWhitelistedCalls { + fn contains(call: &RuntimeCall) -> bool { + match call { + RuntimeCall::System(_) + | RuntimeCall::SafeMode(_) + | RuntimeCall::TxPause(_) + | RuntimeCall::Balances(_) => true, + _ => false, + } + } +} + +parameter_types! { + pub const EnterDuration: BlockNumber = 4 * HOURS; + pub const EnterDepositAmount: Option = None; + pub const ExtendDuration: BlockNumber = 2 * HOURS; + pub const ExtendDepositAmount: Option = None; + pub const ReleaseDelay: u32 = 2 * DAYS; +} + +impl pallet_safe_mode::Config for Runtime { type RuntimeEvent = RuntimeEvent; - type LockdownModeOrigin = frame_system::EnsureRoot; - type BlackListedCalls = RuntimeBlackListedCalls; - type LockdownDmpHandler = LockdownDmpHandler; - type XcmExecutorManager = XcmExecutionManager; - type WeightInfo = weights::pallet_lockdown_mode::WeightInfo; + type Currency = Balances; + type RuntimeHoldReason = RuntimeHoldReason; + type WhitelistedCalls = SafeModeWhitelistedCalls; + type EnterDuration = EnterDuration; + type ExtendDuration = ExtendDuration; + type EnterDepositAmount = EnterDepositAmount; + type ExtendDepositAmount = ExtendDepositAmount; + type ForceEnterOrigin = EnsureRootWithSuccess>; + type ForceExtendOrigin = EnsureRootWithSuccess>; + type ForceExitOrigin = EnsureRoot; + type ForceDepositOrigin = EnsureRoot; + type Notify = (); + type ReleaseDelay = ReleaseDelay; + type WeightInfo = pallet_safe_mode::weights::SubstrateWeight; +} + +/// Calls that cannot be paused by the tx-pause pallet. +pub struct TxPauseWhitelistedCalls; +/// Whitelist `Balances::transfer_keep_alive`, all others are pauseable. +impl Contains> for TxPauseWhitelistedCalls { + fn contains(full_name: &RuntimeCallNameOf) -> bool { + match (full_name.0.as_slice(), full_name.1.as_slice()) { + (b"Balances", b"transfer_keep_alive") => true, + _ => false, + } + } +} + +impl pallet_tx_pause::Config for Runtime { + type RuntimeEvent = RuntimeEvent; + type RuntimeCall = RuntimeCall; + type PauseOrigin = EnsureRoot; + type UnpauseOrigin = EnsureRoot; + type WhitelistedCalls = TxPauseWhitelistedCalls; + type MaxNameLen = ConstU32<256>; + type WeightInfo = weights::pallet_tx_pause::WeightInfo; } // Create the runtime by composing the FRAME pallets that were previously configured. @@ -805,7 +860,8 @@ construct_runtime!( Uniques: pallet_uniques = 43, Scheduler: pallet_scheduler = 44, Preimage: pallet_preimage = 45, - LockdownMode: pallet_lockdown_mode = 46, + SafeMode: pallet_safe_mode = 47, // 46 used to be the old LockdownMode pallet + TxPause: pallet_tx_pause = 48, // Handy utilities. Utility: pallet_utility = 50, @@ -841,7 +897,8 @@ mod benches { [pallet_contracts, Contracts] [pallet_collective, Council] [pallet_democracy, Democracy] - [pallet_lockdown_mode, LockdownMode] + [pallet_safe_mode, SafeMode] + [pallet_tx_pause, TxPause] [pallet_preimage, Preimage] [pallet_treasury, Treasury] [pallet_assets, Assets] diff --git a/runtime/trappist/src/weights/mod.rs b/runtime/trappist/src/weights/mod.rs index 764fc05f..0675c304 100644 --- a/runtime/trappist/src/weights/mod.rs +++ b/runtime/trappist/src/weights/mod.rs @@ -33,13 +33,13 @@ pub mod pallet_collective; pub mod pallet_contracts; pub mod pallet_democracy; pub mod pallet_identity; -pub mod pallet_lockdown_mode; pub mod pallet_multisig; pub mod pallet_preimage; pub mod pallet_scheduler; pub mod pallet_session; pub mod pallet_timestamp; pub mod pallet_treasury; +pub mod pallet_tx_pause; pub mod pallet_uniques; pub mod pallet_utility; pub mod pallet_withdraw_teleport; diff --git a/runtime/trappist/src/weights/pallet_lockdown_mode.rs b/runtime/trappist/src/weights/pallet_tx_pause.rs similarity index 50% rename from runtime/trappist/src/weights/pallet_lockdown_mode.rs rename to runtime/trappist/src/weights/pallet_tx_pause.rs index 9dda707b..045c3de6 100644 --- a/runtime/trappist/src/weights/pallet_lockdown_mode.rs +++ b/runtime/trappist/src/weights/pallet_tx_pause.rs @@ -15,12 +15,12 @@ // See the License for the specific language governing permissions and // limitations under the License. -//! Autogenerated weights for `pallet_lockdown_mode` +//! Autogenerated weights for `pallet_tx_pause` //! //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev -//! DATE: 2023-11-23, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! DATE: 2023-10-23, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` //! WORST CASE MAP SIZE: `1000000` -//! HOSTNAME: `runner-yprdrvc7-project-647-concurrent-0`, CPU: `Intel(R) Xeon(R) CPU @ 2.60GHz` +//! HOSTNAME: `PAR03651`, CPU: `` //! WASM-EXECUTION: `Compiled`, CHAIN: `Some("trappist-dev")`, DB CACHE: 1024 // Executed Command: @@ -33,7 +33,7 @@ // --no-storage-info // --no-median-slopes // --no-min-squares -// --pallet=pallet_lockdown_mode +// --pallet=pallet_tx_pause // --extrinsic=* // --wasm-execution=compiled // --header=./templates/file_header.txt @@ -47,35 +47,31 @@ use frame_support::{traits::Get, weights::Weight}; use core::marker::PhantomData; -/// Weight functions for `pallet_lockdown_mode`. +/// Weight functions for `pallet_tx_pause`. pub struct WeightInfo(PhantomData); -impl pallet_lockdown_mode::WeightInfo for WeightInfo { - /// Storage: `LockdownMode::LockdownModeStatus` (r:1 w:1) - /// Proof: `LockdownMode::LockdownModeStatus` (`max_values`: Some(1), `max_size`: Some(1), added: 496, mode: `MaxEncodedLen`) - /// Storage: `XcmpQueue::QueueSuspended` (r:0 w:1) - /// Proof: `XcmpQueue::QueueSuspended` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) - fn activate_lockdown_mode() -> Weight { +impl pallet_tx_pause::WeightInfo for WeightInfo { + /// 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: `100` - // Estimated: `1486` - // Minimum execution time: 13_278_000 picoseconds. - Weight::from_parts(13_751_000, 0) - .saturating_add(Weight::from_parts(0, 1486)) + // Measured: `4` + // Estimated: `3997` + // Minimum execution time: 9_000_000 picoseconds. + Weight::from_parts(10_000_000, 0) + .saturating_add(Weight::from_parts(0, 3997)) .saturating_add(T::DbWeight::get().reads(1)) - .saturating_add(T::DbWeight::get().writes(2)) + .saturating_add(T::DbWeight::get().writes(1)) } - /// Storage: `LockdownMode::LockdownModeStatus` (r:1 w:1) - /// Proof: `LockdownMode::LockdownModeStatus` (`max_values`: Some(1), `max_size`: Some(1), added: 496, mode: `MaxEncodedLen`) - /// Storage: `XcmpQueue::QueueSuspended` (r:0 w:1) - /// Proof: `XcmpQueue::QueueSuspended` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) - fn deactivate_lockdown_mode() -> Weight { + /// 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: `100` - // Estimated: `1486` - // Minimum execution time: 13_302_000 picoseconds. - Weight::from_parts(13_714_000, 0) - .saturating_add(Weight::from_parts(0, 1486)) + // Measured: `566` + // Estimated: `3997` + // Minimum execution time: 13_000_000 picoseconds. + Weight::from_parts(14_000_000, 0) + .saturating_add(Weight::from_parts(0, 3997)) .saturating_add(T::DbWeight::get().reads(1)) - .saturating_add(T::DbWeight::get().writes(2)) + .saturating_add(T::DbWeight::get().writes(1)) } }