Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove call_switchgear and add tx_pause #1308

Merged
merged 2 commits into from
Jul 15, 2024
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
25 changes: 22 additions & 3 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down Expand Up @@ -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 }
Expand Down
6 changes: 2 additions & 4 deletions runtime/bifrost-kusama/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down Expand Up @@ -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 }
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down
155 changes: 30 additions & 125 deletions runtime/bifrost-kusama/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -194,118 +194,6 @@ parameter_types! {
pub const SS58Prefix: u8 = 6;
}

pub struct CallFilter;
impl Contains<RuntimeCall> 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::<Runtime>::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::<Runtime>::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::<Runtime>::contains(
&currency_id,
),
RuntimeCall::Currencies(bifrost_currencies::Call::transfer_native_currency {
dest: _,
amount: _,
}) => bifrost_call_switchgear::DisableTransfersFilter::<Runtime>::contains(
&NativeCurrencyId::get(),
),
// orml-tokens module
RuntimeCall::Tokens(orml_tokens::Call::transfer {
dest: _,
currency_id,
amount: _,
}) => bifrost_call_switchgear::DisableTransfersFilter::<Runtime>::contains(
&currency_id,
),
RuntimeCall::Tokens(orml_tokens::Call::transfer_all {
dest: _,
currency_id,
keep_alive: _,
}) => bifrost_call_switchgear::DisableTransfersFilter::<Runtime>::contains(
&currency_id,
),
RuntimeCall::Tokens(orml_tokens::Call::transfer_keep_alive {
dest: _,
currency_id,
amount: _,
}) => bifrost_call_switchgear::DisableTransfersFilter::<Runtime>::contains(
&currency_id,
),
// Balances module
RuntimeCall::Balances(pallet_balances::Call::transfer_allow_death {
dest: _,
value: _,
}) => bifrost_call_switchgear::DisableTransfersFilter::<Runtime>::contains(
&NativeCurrencyId::get(),
),
RuntimeCall::Balances(pallet_balances::Call::transfer_keep_alive {
dest: _,
value: _,
}) => bifrost_call_switchgear::DisableTransfersFilter::<Runtime>::contains(
&NativeCurrencyId::get(),
),
RuntimeCall::Balances(pallet_balances::Call::transfer_all {
dest: _,
keep_alive: _,
}) => bifrost_call_switchgear::DisableTransfersFilter::<Runtime>::contains(
&NativeCurrencyId::get(),
),
_ => false,
};

if is_disabled {
// no switched off call
return false;
}
}

true
}
}

pub struct BaseFilter;
impl Contains<RuntimeCall> 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);
Expand Down Expand Up @@ -348,7 +236,7 @@ impl frame_system::Config for Runtime {
type AccountData = pallet_balances::AccountData<Balance>;
/// The identifier used to distinguish between accounts.
type AccountId = AccountId;
type BaseCallFilter = CallFilter;
type BaseCallFilter = InsideBoth<Everything, TxPause>;
/// Maximum number of block number to block hash mappings to keep (oldest pruned first).
type BlockHashCount = BlockHashCount;
type BlockLength = RuntimeBlockLength;
Expand Down Expand Up @@ -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<pallet_tx_pause::RuntimeCallNameOf<Runtime>> for TxPauseWhitelistedCalls {
fn contains(full_name: &pallet_tx_pause::RuntimeCallNameOf<Runtime>) -> 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<Runtime>;
}

impl<LocalCall> frame_system::offchain::CreateSignedTransaction<LocalCall> for Runtime
where
RuntimeCall: From<LocalCall>,
Expand Down Expand Up @@ -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<Runtime>;
}

impl bifrost_asset_registry::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type Currency = Balances;
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -2032,7 +1933,7 @@ pub type CheckedExtrinsic = generic::CheckedExtrinsic<AccountId, RuntimeCall, Si
pub type SignedPayload = generic::SignedPayload<RuntimeCall, SignedExtra>;

parameter_types! {
pub const DmpQueuePalletName: &'static str = "DmpQueue";
pub const CallSwitchgearPalletName: &'static str = "CallSwitchgear";
}

/// All migrations that will run on the next runtime upgrade.
Expand All @@ -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,
<Runtime as frame_system::Config>::DbWeight,
>,
);
}

/// Executive: handles dispatch to the various modules.
Expand All @@ -2068,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]
Expand Down
Loading