From d2775580583040be3398d9fbfe60c43c09d39ea6 Mon Sep 17 00:00:00 2001 From: hqwangningbo <2536935847@qq.com> Date: Mon, 15 Jul 2024 16:14:15 +0800 Subject: [PATCH 1/2] Remove call_switchgear and add tx_pause --- Cargo.lock | 25 ++- Cargo.toml | 2 +- runtime/bifrost-kusama/Cargo.toml | 6 +- runtime/bifrost-kusama/src/lib.rs | 154 ++++-------------- .../src/weights/bifrost_call_switchgear.rs | 101 ------------ runtime/bifrost-kusama/src/weights/mod.rs | 1 - runtime/bifrost-polkadot/Cargo.toml | 5 +- runtime/bifrost-polkadot/src/lib.rs | 145 ++++------------- .../src/weights/bifrost_call_switchgear.rs | 101 ------------ runtime/bifrost-polkadot/src/weights/mod.rs | 1 - 10 files changed, 86 insertions(+), 455 deletions(-) delete mode 100644 runtime/bifrost-kusama/src/weights/bifrost_call_switchgear.rs delete mode 100644 runtime/bifrost-polkadot/src/weights/bifrost_call_switchgear.rs diff --git a/Cargo.lock b/Cargo.lock index 0257b1ddf..bf9e6a75e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1073,7 +1073,6 @@ name = "bifrost-kusama-runtime" version = "0.8.0" dependencies = [ "bifrost-asset-registry", - "bifrost-call-switchgear", "bifrost-channel-commission", "bifrost-cross-in-out", "bifrost-currencies", @@ -1156,6 +1155,7 @@ dependencies = [ "pallet-transaction-payment", "pallet-transaction-payment-rpc-runtime-api", "pallet-treasury", + "pallet-tx-pause", "pallet-utility", "pallet-whitelist", "pallet-xcm", @@ -1227,7 +1227,6 @@ version = "0.8.0" dependencies = [ "bifrost-asset-registry", "bifrost-buy-back", - "bifrost-call-switchgear", "bifrost-channel-commission", "bifrost-clouds-convert", "bifrost-cross-in-out", @@ -1311,6 +1310,7 @@ dependencies = [ "pallet-transaction-payment", "pallet-transaction-payment-rpc-runtime-api", "pallet-treasury", + "pallet-tx-pause", "pallet-utility", "pallet-whitelist", "pallet-xcm", @@ -8691,6 +8691,25 @@ dependencies = [ "sp-std", ] +[[package]] +name = "pallet-tx-pause" +version = "10.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "26ee3c04e718d399c43effb666c82ced0fc0303f3c57e930571035b59722021e" +dependencies = [ + "docify", + "frame-benchmarking", + "frame-support", + "frame-system", + "pallet-balances", + "pallet-proxy", + "pallet-utility", + "parity-scale-codec", + "scale-info", + "sp-runtime", + "sp-std", +] + [[package]] name = "pallet-utility" version = "29.0.0" @@ -16434,4 +16453,4 @@ checksum = "c253a4914af5bafc8fa8c86ee400827e83cf6ec01195ec1f1ed8441bf00d65aa" dependencies = [ "cc", "pkg-config", -] \ No newline at end of file +] diff --git a/Cargo.toml b/Cargo.toml index 7f9b60fe8..90fdcc80a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -61,7 +61,6 @@ bifrost-polkadot-runtime = { path = "runtime/bifrost-polkadot" } # Bifrost Wasm bifrost-asset-registry = { path = "pallets/asset-registry", default-features = false } bifrost-buy-back = { path = "pallets/buy-back", default-features = false } -bifrost-call-switchgear = { path = "pallets/call-switchgear", default-features = false } bifrost-cross-in-out = { path = "pallets/cross-in-out", default-features = false } bifrost-currencies = { path = "pallets/currencies", default-features = false } bifrost-farming = { path = "pallets/farming", default-features = false } @@ -169,6 +168,7 @@ pallet-staking = { version = "29.0.0", default-featu pallet-sudo = { version = "29.0.0", default-features = false } pallet-timestamp = { version = "28.0.0", default-features = false } pallet-tips = { version = "28.0.0", default-features = false } +pallet-tx-pause = { version = "10.0.0", default-features = false } pallet-transaction-payment = { version = "29.0.0", default-features = false } pallet-transaction-payment-rpc-runtime-api = { version = "29.0.0", default-features = false } pallet-treasury = { version = "28.0.0", default-features = false } diff --git a/runtime/bifrost-kusama/Cargo.toml b/runtime/bifrost-kusama/Cargo.toml index a07343319..66fd6df29 100644 --- a/runtime/bifrost-kusama/Cargo.toml +++ b/runtime/bifrost-kusama/Cargo.toml @@ -49,6 +49,7 @@ pallet-scheduler = { workspace = true } pallet-session = { workspace = true } pallet-timestamp = { workspace = true } pallet-tips = { workspace = true } +pallet-tx-pause = { workspace = true } pallet-transaction-payment = { workspace = true } pallet-transaction-payment-rpc-runtime-api = { workspace = true } pallet-treasury = { workspace = true } @@ -113,7 +114,6 @@ bifrost-stable-asset = { workspace = true } # Bifrost bifrost-asset-registry = { workspace = true } -bifrost-call-switchgear = { workspace = true } bifrost-cross-in-out = { workspace = true } bifrost-currencies = { workspace = true } bifrost-farming = { workspace = true } @@ -185,6 +185,7 @@ std = [ "pallet-session/std", "pallet-timestamp/std", "pallet-tips/std", + "pallet-tx-pause/std", "pallet-transaction-payment-rpc-runtime-api/std", "pallet-transaction-payment/std", "pallet-treasury/std", @@ -239,7 +240,6 @@ std = [ "bifrost-primitives/std", "bifrost-asset-registry/std", - "bifrost-call-switchgear/std", "bifrost-cross-in-out/std", "bifrost-currencies/std", "bifrost-farming-rpc-runtime-api/std", @@ -304,7 +304,6 @@ runtime-benchmarks = [ "bifrost-salp/runtime-benchmarks", "bifrost-vsbond-auction/runtime-benchmarks", "bifrost-token-issuer/runtime-benchmarks", - "bifrost-call-switchgear/runtime-benchmarks", "bifrost-vtoken-minting/runtime-benchmarks", "bifrost-farming/runtime-benchmarks", "bifrost-system-staking/runtime-benchmarks", @@ -374,7 +373,6 @@ try-runtime = [ "bifrost-flexible-fee/try-runtime", "bifrost-salp/try-runtime", "bifrost-token-issuer/try-runtime", - "bifrost-call-switchgear/try-runtime", "bifrost-vsbond-auction/try-runtime", "bifrost-asset-registry/try-runtime", "bifrost-vtoken-minting/try-runtime", diff --git a/runtime/bifrost-kusama/src/lib.rs b/runtime/bifrost-kusama/src/lib.rs index 2dadb3a48..6f719b912 100644 --- a/runtime/bifrost-kusama/src/lib.rs +++ b/runtime/bifrost-kusama/src/lib.rs @@ -94,8 +94,8 @@ use frame_support::{ traits::{ fungible::HoldConsideration, tokens::{PayFromAccount, UnityAssetBalanceConversion}, - Currency, EitherOf, EitherOfDiverse, Get, Imbalance, LinearStoragePrice, LockIdentifier, - OnUnbalanced, + Currency, EitherOf, EitherOfDiverse, Get, Imbalance, InsideBoth, LinearStoragePrice, + LockIdentifier, OnUnbalanced, }, }; use frame_system::{EnsureRoot, EnsureRootWithSuccess, EnsureSigned}; @@ -194,118 +194,6 @@ parameter_types! { pub const SS58Prefix: u8 = 6; } -pub struct CallFilter; -impl Contains for CallFilter { - fn contains(call: &RuntimeCall) -> bool { - let is_core_call = matches!( - call, - RuntimeCall::System(_) | RuntimeCall::Timestamp(_) | RuntimeCall::ParachainSystem(_) - ); - if is_core_call { - // always allow core call - return true; - } - - if bifrost_call_switchgear::OverallToggleFilter::::get_overall_toggle_status() { - return false; - } - - // temporarily ban PhragmenElection - let is_temporarily_banned = matches!(call, RuntimeCall::PhragmenElection(_)); - - if is_temporarily_banned { - return false; - } - - let is_switched_off = - bifrost_call_switchgear::SwitchOffTransactionFilter::::contains(call); - if is_switched_off { - // no switched off call - return false; - } - - // disable transfer - let is_transfer = matches!( - call, - RuntimeCall::Currencies(_) | RuntimeCall::Tokens(_) | RuntimeCall::Balances(_) - ); - if is_transfer { - let is_disabled = match *call { - // bifrost-currencies module - RuntimeCall::Currencies(bifrost_currencies::Call::transfer { - dest: _, - currency_id, - amount: _, - }) => bifrost_call_switchgear::DisableTransfersFilter::::contains( - ¤cy_id, - ), - RuntimeCall::Currencies(bifrost_currencies::Call::transfer_native_currency { - dest: _, - amount: _, - }) => bifrost_call_switchgear::DisableTransfersFilter::::contains( - &NativeCurrencyId::get(), - ), - // orml-tokens module - RuntimeCall::Tokens(orml_tokens::Call::transfer { - dest: _, - currency_id, - amount: _, - }) => bifrost_call_switchgear::DisableTransfersFilter::::contains( - ¤cy_id, - ), - RuntimeCall::Tokens(orml_tokens::Call::transfer_all { - dest: _, - currency_id, - keep_alive: _, - }) => bifrost_call_switchgear::DisableTransfersFilter::::contains( - ¤cy_id, - ), - RuntimeCall::Tokens(orml_tokens::Call::transfer_keep_alive { - dest: _, - currency_id, - amount: _, - }) => bifrost_call_switchgear::DisableTransfersFilter::::contains( - ¤cy_id, - ), - // Balances module - RuntimeCall::Balances(pallet_balances::Call::transfer_allow_death { - dest: _, - value: _, - }) => bifrost_call_switchgear::DisableTransfersFilter::::contains( - &NativeCurrencyId::get(), - ), - RuntimeCall::Balances(pallet_balances::Call::transfer_keep_alive { - dest: _, - value: _, - }) => bifrost_call_switchgear::DisableTransfersFilter::::contains( - &NativeCurrencyId::get(), - ), - RuntimeCall::Balances(pallet_balances::Call::transfer_all { - dest: _, - keep_alive: _, - }) => bifrost_call_switchgear::DisableTransfersFilter::::contains( - &NativeCurrencyId::get(), - ), - _ => false, - }; - - if is_disabled { - // no switched off call - return false; - } - } - - true - } -} - -pub struct BaseFilter; -impl Contains for BaseFilter { - fn contains(_c: &RuntimeCall) -> bool { - true - } -} - parameter_types! { pub const NativeCurrencyId: CurrencyId = CurrencyId::Native(TokenSymbol::BNC); pub const RelayCurrencyId: CurrencyId = CurrencyId::Token(TokenSymbol::KSM); @@ -348,7 +236,7 @@ impl frame_system::Config for Runtime { type AccountData = pallet_balances::AccountData; /// The identifier used to distinguish between accounts. type AccountId = AccountId; - type BaseCallFilter = CallFilter; + type BaseCallFilter = InsideBoth; /// Maximum number of block number to block hash mappings to keep (oldest pruned first). type BlockHashCount = BlockHashCount; type BlockLength = RuntimeBlockLength; @@ -892,6 +780,25 @@ impl pallet_transaction_payment::Config for Runtime { type RuntimeEvent = RuntimeEvent; } +/// Calls that can bypass the tx-pause pallet. +/// We always allow system calls and timestamp since it is required for block production +pub struct TxPauseWhitelistedCalls; +impl Contains> for TxPauseWhitelistedCalls { + fn contains(full_name: &pallet_tx_pause::RuntimeCallNameOf) -> bool { + matches!(full_name.0.as_slice(), b"System" | b"Timestamp" | b"TxPause") + } +} + +impl pallet_tx_pause::Config for Runtime { + type RuntimeEvent = RuntimeEvent; + type RuntimeCall = RuntimeCall; + type PauseOrigin = TechAdminOrCouncil; + type UnpauseOrigin = TechAdminOrCouncil; + type WhitelistedCalls = TxPauseWhitelistedCalls; + type MaxNameLen = ConstU32<256>; + type WeightInfo = pallet_tx_pause::weights::SubstrateWeight; +} + impl frame_system::offchain::CreateSignedTransaction for Runtime where RuntimeCall: From, @@ -1312,12 +1219,6 @@ impl bifrost_token_issuer::Config for Runtime { type MaxLengthLimit = MaxLengthLimit; } -impl bifrost_call_switchgear::Config for Runtime { - type RuntimeEvent = RuntimeEvent; - type UpdateOrigin = CoreAdminOrCouncil; - type WeightInfo = weights::bifrost_call_switchgear::BifrostWeight; -} - impl bifrost_asset_registry::Config for Runtime { type RuntimeEvent = RuntimeEvent; type Currency = Balances; @@ -1907,6 +1808,7 @@ construct_runtime! { Indices: pallet_indices = 2, ParachainSystem: cumulus_pallet_parachain_system = 5, ParachainInfo: parachain_info = 6, + TxPause: pallet_tx_pause = 7, // Monetary stuff Balances: pallet_balances = 10, @@ -1966,7 +1868,6 @@ construct_runtime! { FlexibleFee: bifrost_flexible_fee = 100, Salp: bifrost_salp = 105, TokenIssuer: bifrost_token_issuer = 109, - CallSwitchgear: bifrost_call_switchgear = 112, VSBondAuction: bifrost_vsbond_auction = 113, AssetRegistry: bifrost_asset_registry = 114, VtokenMinting: bifrost_vtoken_minting = 115, @@ -2032,7 +1933,7 @@ pub type CheckedExtrinsic = generic::CheckedExtrinsic; parameter_types! { - pub const DmpQueuePalletName: &'static str = "DmpQueue"; + pub const CallSwitchgearPalletName: &'static str = "CallSwitchgear"; } /// All migrations that will run on the next runtime upgrade. @@ -2047,7 +1948,12 @@ pub mod migrations { use super::*; /// Unreleased migrations. Add new ones here: - pub type Unreleased = (); + pub type Unreleased = ( + frame_support::migrations::RemovePallet< + CallSwitchgearPalletName, + ::DbWeight, + >, + ); } /// Executive: handles dispatch to the various modules. diff --git a/runtime/bifrost-kusama/src/weights/bifrost_call_switchgear.rs b/runtime/bifrost-kusama/src/weights/bifrost_call_switchgear.rs deleted file mode 100644 index 439245f52..000000000 --- a/runtime/bifrost-kusama/src/weights/bifrost_call_switchgear.rs +++ /dev/null @@ -1,101 +0,0 @@ -// This file is part of Bifrost. - -// Copyright (C) Liebi Technologies PTE. LTD. -// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0 - -// This program 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. - -// This program 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 this program. If not, see . -// -// 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 bifrost_call_switchgear -//! -//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev -//! DATE: 2023-09-14, STEPS: `50`, REPEAT: 20, LOW RANGE: `[]`, HIGH RANGE: `[]` -//! HOSTNAME: `bifrost-jenkins`, CPU: `Intel(R) Xeon(R) CPU E5-26xx v4` -//! WASM-EXECUTION: Compiled, CHAIN: Some("bifrost-kusama-local"), DB CACHE: 1024 - -// Executed Command: -// target/release/bifrost -// benchmark -// pallet -// --chain=bifrost-kusama-local -// --steps=50 -// --repeat=20 -// --pallet=bifrost_call_switchgear -// --extrinsic=* -// --execution=wasm -// --wasm-execution=compiled -// --heap-pages=4096 -// --output=./runtime/bifrost-kusama/src/weights/bifrost_call_switchgear.rs -// --template=./weight-template/runtime-weight-template.hbs - -#![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; - -/// Weight functions for bifrost_call_switchgear. -pub struct BifrostWeight(PhantomData); -impl bifrost_call_switchgear::WeightInfo for BifrostWeight { - // Storage: CallSwitchgear SwitchedOffTransactions (r:1 w:1) - // Proof Skipped: CallSwitchgear SwitchedOffTransactions (max_values: None, max_size: None, mode: Measured) - fn switchoff_transaction() -> Weight { - // Proof Size summary in bytes: - // Measured: `4` - // Estimated: `3469` - // Minimum execution time: 29_214 nanoseconds. - Weight::from_parts(30_398_000, 3469) - .saturating_add(T::DbWeight::get().reads(1)) - .saturating_add(T::DbWeight::get().writes(1)) - } - // Storage: CallSwitchgear SwitchedOffTransactions (r:1 w:1) - // Proof Skipped: CallSwitchgear SwitchedOffTransactions (max_values: None, max_size: None, mode: Measured) - fn switchon_transaction() -> Weight { - // Proof Size summary in bytes: - // Measured: `55` - // Estimated: `3520` - // Minimum execution time: 31_720 nanoseconds. - Weight::from_parts(32_717_000, 3520) - .saturating_add(T::DbWeight::get().reads(1)) - .saturating_add(T::DbWeight::get().writes(1)) - } - // Storage: CallSwitchgear DisabledTransfers (r:1 w:1) - // Proof Skipped: CallSwitchgear DisabledTransfers (max_values: None, max_size: None, mode: Measured) - fn disable_transfers() -> Weight { - // Proof Size summary in bytes: - // Measured: `4` - // Estimated: `3469` - // Minimum execution time: 26_079 nanoseconds. - Weight::from_parts(26_977_000, 3469) - .saturating_add(T::DbWeight::get().reads(1)) - .saturating_add(T::DbWeight::get().writes(1)) - } - // Storage: CallSwitchgear DisabledTransfers (r:1 w:1) - // Proof Skipped: CallSwitchgear DisabledTransfers (max_values: None, max_size: None, mode: Measured) - fn enable_transfers() -> Weight { - // Proof Size summary in bytes: - // Measured: `38` - // Estimated: `3503` - // Minimum execution time: 27_719 nanoseconds. - Weight::from_parts(28_319_000, 3503) - .saturating_add(T::DbWeight::get().reads(1)) - .saturating_add(T::DbWeight::get().writes(1)) - } -} diff --git a/runtime/bifrost-kusama/src/weights/mod.rs b/runtime/bifrost-kusama/src/weights/mod.rs index b5ccb51c5..9782e1bcc 100644 --- a/runtime/bifrost-kusama/src/weights/mod.rs +++ b/runtime/bifrost-kusama/src/weights/mod.rs @@ -21,7 +21,6 @@ //! A list of the different weight modules for our runtime. pub mod bifrost_asset_registry; -pub mod bifrost_call_switchgear; pub mod bifrost_channel_commission; pub mod bifrost_cross_in_out; pub mod bifrost_currencies; diff --git a/runtime/bifrost-polkadot/Cargo.toml b/runtime/bifrost-polkadot/Cargo.toml index f8f4715a3..07ccf634c 100644 --- a/runtime/bifrost-polkadot/Cargo.toml +++ b/runtime/bifrost-polkadot/Cargo.toml @@ -49,6 +49,7 @@ pallet-scheduler = { workspace = true } pallet-session = { workspace = true } pallet-timestamp = { workspace = true } pallet-tips = { workspace = true } +pallet-tx-pause = { workspace = true } pallet-transaction-payment = { workspace = true } pallet-transaction-payment-rpc-runtime-api = { workspace = true } pallet-treasury = { workspace = true } @@ -111,7 +112,6 @@ bifrost-stable-asset = { workspace = true } # Bifrost bifrost-asset-registry = { workspace = true } bifrost-buy-back = { workspace = true } -bifrost-call-switchgear = { workspace = true } bifrost-cross-in-out = { workspace = true } bifrost-currencies = { workspace = true } bifrost-farming = { workspace = true } @@ -181,6 +181,7 @@ std = [ "pallet-session/std", "pallet-timestamp/std", "pallet-tips/std", + "pallet-tx-pause/std", "pallet-transaction-payment-rpc-runtime-api/std", "pallet-transaction-payment/std", "pallet-treasury/std", @@ -284,7 +285,6 @@ runtime-benchmarks = [ "pallet-xcm/runtime-benchmarks", "sp-runtime/runtime-benchmarks", "xcm-builder/runtime-benchmarks", - "bifrost-call-switchgear/runtime-benchmarks", "bifrost-slp/runtime-benchmarks", "bifrost-salp/runtime-benchmarks", "bifrost-vtoken-minting/runtime-benchmarks", @@ -303,7 +303,6 @@ runtime-benchmarks = [ try-runtime = [ "bifrost-asset-registry/try-runtime", "bifrost-buy-back/try-runtime", - "bifrost-call-switchgear/try-runtime", "bifrost-channel-commission/try-runtime", "bifrost-clouds-convert/try-runtime", "bifrost-cross-in-out/try-runtime", diff --git a/runtime/bifrost-polkadot/src/lib.rs b/runtime/bifrost-polkadot/src/lib.rs index add1e7f42..8801aa644 100644 --- a/runtime/bifrost-polkadot/src/lib.rs +++ b/runtime/bifrost-polkadot/src/lib.rs @@ -94,7 +94,7 @@ use frame_support::{ traits::{ fungible::HoldConsideration, tokens::{PayFromAccount, UnityAssetBalanceConversion}, - Currency, EitherOf, EitherOfDiverse, Get, LinearStoragePrice, + Currency, EitherOf, EitherOfDiverse, Get, InsideBoth, LinearStoragePrice, }, }; use frame_system::{EnsureRoot, EnsureRootWithSuccess, EnsureSigned}; @@ -192,111 +192,6 @@ parameter_types! { pub const SS58Prefix: u8 = 6; } -pub struct CallFilter; -impl Contains for CallFilter { - fn contains(call: &RuntimeCall) -> bool { - let is_core_call = matches!( - call, - RuntimeCall::System(_) | RuntimeCall::Timestamp(_) | RuntimeCall::ParachainSystem(_) - ); - if is_core_call { - // always allow core call - return true; - } - - if bifrost_call_switchgear::OverallToggleFilter::::get_overall_toggle_status() { - return false; - } - - // temporarily ban PhragmenElection - let is_temporarily_banned = matches!(call, RuntimeCall::PhragmenElection(_)); - - if is_temporarily_banned { - return false; - } - - let is_switched_off = - bifrost_call_switchgear::SwitchOffTransactionFilter::::contains(call); - if is_switched_off { - // no switched off call - return false; - } - - // disable transfer - let is_transfer = matches!( - call, - RuntimeCall::Currencies(_) | RuntimeCall::Tokens(_) | RuntimeCall::Balances(_) - ); - if is_transfer { - let is_disabled = match *call { - // bifrost-currencies module - RuntimeCall::Currencies(bifrost_currencies::Call::transfer { - dest: _, - currency_id, - amount: _, - }) => bifrost_call_switchgear::DisableTransfersFilter::::contains( - ¤cy_id, - ), - RuntimeCall::Currencies(bifrost_currencies::Call::transfer_native_currency { - dest: _, - amount: _, - }) => bifrost_call_switchgear::DisableTransfersFilter::::contains( - &NativeCurrencyId::get(), - ), - // orml-tokens module - RuntimeCall::Tokens(orml_tokens::Call::transfer { - dest: _, - currency_id, - amount: _, - }) => bifrost_call_switchgear::DisableTransfersFilter::::contains( - ¤cy_id, - ), - RuntimeCall::Tokens(orml_tokens::Call::transfer_all { - dest: _, - currency_id, - keep_alive: _, - }) => bifrost_call_switchgear::DisableTransfersFilter::::contains( - ¤cy_id, - ), - RuntimeCall::Tokens(orml_tokens::Call::transfer_keep_alive { - dest: _, - currency_id, - amount: _, - }) => bifrost_call_switchgear::DisableTransfersFilter::::contains( - ¤cy_id, - ), - // Balances module - RuntimeCall::Balances(pallet_balances::Call::transfer_allow_death { - dest: _, - value: _, - }) => bifrost_call_switchgear::DisableTransfersFilter::::contains( - &NativeCurrencyId::get(), - ), - RuntimeCall::Balances(pallet_balances::Call::transfer_keep_alive { - dest: _, - value: _, - }) => bifrost_call_switchgear::DisableTransfersFilter::::contains( - &NativeCurrencyId::get(), - ), - RuntimeCall::Balances(pallet_balances::Call::transfer_all { - dest: _, - keep_alive: _, - }) => bifrost_call_switchgear::DisableTransfersFilter::::contains( - &NativeCurrencyId::get(), - ), - _ => false, - }; - - if is_disabled { - // no switched off call - return false; - } - } - - true - } -} - parameter_types! { pub const NativeCurrencyId: CurrencyId = CurrencyId::Native(TokenSymbol::BNC); pub const RelayCurrencyId: CurrencyId = CurrencyId::Token2(DOT_TOKEN_ID); @@ -335,7 +230,7 @@ impl frame_system::Config for Runtime { type AccountData = pallet_balances::AccountData; /// The identifier used to distinguish between accounts. type AccountId = AccountId; - type BaseCallFilter = CallFilter; + type BaseCallFilter = InsideBoth; /// Maximum number of block number to block hash mappings to keep (oldest pruned first). type BlockHashCount = BlockHashCount; type BlockLength = RuntimeBlockLength; @@ -861,6 +756,25 @@ impl pallet_transaction_payment::Config for Runtime { type WeightToFee = WeightToFee; } +/// Calls that can bypass the tx-pause pallet. +/// We always allow system calls and timestamp since it is required for block production +pub struct TxPauseWhitelistedCalls; +impl Contains> for TxPauseWhitelistedCalls { + fn contains(full_name: &pallet_tx_pause::RuntimeCallNameOf) -> bool { + matches!(full_name.0.as_slice(), b"System" | b"Timestamp" | b"TxPause") + } +} + +impl pallet_tx_pause::Config for Runtime { + type RuntimeEvent = RuntimeEvent; + type RuntimeCall = RuntimeCall; + type PauseOrigin = TechAdminOrCouncil; + type UnpauseOrigin = TechAdminOrCouncil; + type WhitelistedCalls = TxPauseWhitelistedCalls; + type MaxNameLen = ConstU32<256>; + type WeightInfo = pallet_tx_pause::weights::SubstrateWeight; +} + // culumus runtime start parameter_types! { pub const ReservedXcmpWeight: Weight = MAXIMUM_BLOCK_WEIGHT.saturating_div(4); @@ -1139,12 +1053,6 @@ impl bifrost_salp::Config for Runtime { type BatchLimit = BatchLimit; } -impl bifrost_call_switchgear::Config for Runtime { - type RuntimeEvent = RuntimeEvent; - type UpdateOrigin = CoreAdminOrCouncil; - type WeightInfo = weights::bifrost_call_switchgear::BifrostWeight; -} - impl bifrost_asset_registry::Config for Runtime { type RuntimeEvent = RuntimeEvent; type Currency = Balances; @@ -1741,6 +1649,7 @@ construct_runtime! { Indices: pallet_indices = 2, ParachainSystem: cumulus_pallet_parachain_system = 5, ParachainInfo: parachain_info = 6, + TxPause: pallet_tx_pause = 7, // Monetary stuff Balances: pallet_balances = 10, @@ -1797,7 +1706,6 @@ construct_runtime! { // Bifrost modules FlexibleFee: bifrost_flexible_fee = 100, Salp: bifrost_salp = 105, - CallSwitchgear: bifrost_call_switchgear = 112, AssetRegistry: bifrost_asset_registry = 114, VtokenMinting: bifrost_vtoken_minting = 115, Slp: bifrost_slp = 116, @@ -1865,7 +1773,7 @@ pub type CheckedExtrinsic = generic::CheckedExtrinsic; parameter_types! { - pub const DmpQueuePalletName: &'static str = "DmpQueue"; + pub const CallSwitchgearPalletName: &'static str = "CallSwitchgear"; } /// All migrations that will run on the next runtime upgrade. @@ -1880,7 +1788,12 @@ pub mod migrations { use super::*; /// Unreleased migrations. Add new ones here: - pub type Unreleased = (); + pub type Unreleased = ( + frame_support::migrations::RemovePallet< + CallSwitchgearPalletName, + ::DbWeight, + >, + ); } /// Executive: handles dispatch to the various modules. diff --git a/runtime/bifrost-polkadot/src/weights/bifrost_call_switchgear.rs b/runtime/bifrost-polkadot/src/weights/bifrost_call_switchgear.rs deleted file mode 100644 index 439245f52..000000000 --- a/runtime/bifrost-polkadot/src/weights/bifrost_call_switchgear.rs +++ /dev/null @@ -1,101 +0,0 @@ -// This file is part of Bifrost. - -// Copyright (C) Liebi Technologies PTE. LTD. -// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0 - -// This program 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. - -// This program 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 this program. If not, see . -// -// 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 bifrost_call_switchgear -//! -//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev -//! DATE: 2023-09-14, STEPS: `50`, REPEAT: 20, LOW RANGE: `[]`, HIGH RANGE: `[]` -//! HOSTNAME: `bifrost-jenkins`, CPU: `Intel(R) Xeon(R) CPU E5-26xx v4` -//! WASM-EXECUTION: Compiled, CHAIN: Some("bifrost-kusama-local"), DB CACHE: 1024 - -// Executed Command: -// target/release/bifrost -// benchmark -// pallet -// --chain=bifrost-kusama-local -// --steps=50 -// --repeat=20 -// --pallet=bifrost_call_switchgear -// --extrinsic=* -// --execution=wasm -// --wasm-execution=compiled -// --heap-pages=4096 -// --output=./runtime/bifrost-kusama/src/weights/bifrost_call_switchgear.rs -// --template=./weight-template/runtime-weight-template.hbs - -#![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; - -/// Weight functions for bifrost_call_switchgear. -pub struct BifrostWeight(PhantomData); -impl bifrost_call_switchgear::WeightInfo for BifrostWeight { - // Storage: CallSwitchgear SwitchedOffTransactions (r:1 w:1) - // Proof Skipped: CallSwitchgear SwitchedOffTransactions (max_values: None, max_size: None, mode: Measured) - fn switchoff_transaction() -> Weight { - // Proof Size summary in bytes: - // Measured: `4` - // Estimated: `3469` - // Minimum execution time: 29_214 nanoseconds. - Weight::from_parts(30_398_000, 3469) - .saturating_add(T::DbWeight::get().reads(1)) - .saturating_add(T::DbWeight::get().writes(1)) - } - // Storage: CallSwitchgear SwitchedOffTransactions (r:1 w:1) - // Proof Skipped: CallSwitchgear SwitchedOffTransactions (max_values: None, max_size: None, mode: Measured) - fn switchon_transaction() -> Weight { - // Proof Size summary in bytes: - // Measured: `55` - // Estimated: `3520` - // Minimum execution time: 31_720 nanoseconds. - Weight::from_parts(32_717_000, 3520) - .saturating_add(T::DbWeight::get().reads(1)) - .saturating_add(T::DbWeight::get().writes(1)) - } - // Storage: CallSwitchgear DisabledTransfers (r:1 w:1) - // Proof Skipped: CallSwitchgear DisabledTransfers (max_values: None, max_size: None, mode: Measured) - fn disable_transfers() -> Weight { - // Proof Size summary in bytes: - // Measured: `4` - // Estimated: `3469` - // Minimum execution time: 26_079 nanoseconds. - Weight::from_parts(26_977_000, 3469) - .saturating_add(T::DbWeight::get().reads(1)) - .saturating_add(T::DbWeight::get().writes(1)) - } - // Storage: CallSwitchgear DisabledTransfers (r:1 w:1) - // Proof Skipped: CallSwitchgear DisabledTransfers (max_values: None, max_size: None, mode: Measured) - fn enable_transfers() -> Weight { - // Proof Size summary in bytes: - // Measured: `38` - // Estimated: `3503` - // Minimum execution time: 27_719 nanoseconds. - Weight::from_parts(28_319_000, 3503) - .saturating_add(T::DbWeight::get().reads(1)) - .saturating_add(T::DbWeight::get().writes(1)) - } -} diff --git a/runtime/bifrost-polkadot/src/weights/mod.rs b/runtime/bifrost-polkadot/src/weights/mod.rs index 6ea6b29d5..2dfce402e 100644 --- a/runtime/bifrost-polkadot/src/weights/mod.rs +++ b/runtime/bifrost-polkadot/src/weights/mod.rs @@ -22,7 +22,6 @@ pub mod bifrost_asset_registry; pub mod bifrost_buy_back; -pub mod bifrost_call_switchgear; pub mod bifrost_channel_commission; pub mod bifrost_clouds_convert; pub mod bifrost_cross_in_out; From 35717b4cb29e655ab94d8396218df80ff1846cea Mon Sep 17 00:00:00 2001 From: hqwangningbo <2536935847@qq.com> Date: Mon, 15 Jul 2024 17:12:04 +0800 Subject: [PATCH 2/2] Fix clippy --- runtime/bifrost-kusama/src/lib.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/runtime/bifrost-kusama/src/lib.rs b/runtime/bifrost-kusama/src/lib.rs index 6f719b912..d7699ce22 100644 --- a/runtime/bifrost-kusama/src/lib.rs +++ b/runtime/bifrost-kusama/src/lib.rs @@ -1974,7 +1974,6 @@ extern crate frame_benchmarking; mod benches { define_benchmarks!( [bifrost_asset_registry, AssetRegistry] - [bifrost_call_switchgear, CallSwitchgear] [bifrost_cross_in_out, CrossInOut] [bifrost_farming, Farming] [bifrost_fee_share, FeeShare]