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

[FRAME Core] New pallets: safe-mode and tx-pause #12092

Merged
merged 112 commits into from
Aug 25, 2023
Merged
Show file tree
Hide file tree
Changes from 88 commits
Commits
Show all changes
112 commits
Select commit Hold shift + click to select a range
7faa277
Add safe-mode
ggwpez Aug 22, 2022
e2f3efe
Update pallet
ggwpez Aug 23, 2022
630cf4a
Add to kitchensink-runtime
ggwpez Aug 23, 2022
e29a2ea
Spelling
ggwpez Aug 23, 2022
50a5ddd
Rename to tx-pause
ggwpez Aug 23, 2022
00955c1
Add SafeMode pallet
ggwpez Aug 25, 2022
2b4549b
fmt
ggwpez Aug 29, 2022
59a492a
Automatically disable safe-mode in on_init…
ggwpez Aug 29, 2022
c2140af
Add permissionless enable+extend
ggwpez Aug 29, 2022
b740f4f
Add repay+slash stake methods
ggwpez Aug 29, 2022
13f2ef6
Add docs
ggwpez Sep 6, 2022
8084258
Fix stakes storage
ggwpez Sep 6, 2022
b143cdd
Merge remote-tracking branch 'origin/master' into oty-safe-mode
ggwpez Sep 6, 2022
93acbae
Genesis config for safe-mode pallet
ggwpez Sep 7, 2022
8806aa7
Genesis config for safe-mode pallet
ggwpez Sep 7, 2022
956bb70
Rename ExtrinsicName to FunctionName
ggwpez Sep 7, 2022
e3b388b
Origin variable duration
ggwpez Sep 13, 2022
57219d4
Rename FunctionName -> CallName
ggwpez Sep 15, 2022
3e421f2
Rename and docs
ggwpez Sep 15, 2022
ace1f1c
Merge remote-tracking branch 'origin/master' into oty-safe-mode
ggwpez Sep 15, 2022
379b82f
Pallet safe mode tests (#12148)
nuke-web3 Sep 21, 2022
7f8688e
Tests for `pallet-tx-pause` (#12259)
nuke-web3 Sep 21, 2022
b703957
rename to active/inactive
nuke-web3 Sep 21, 2022
722c4f6
Runtime types, fix tests
nuke-web3 Sep 22, 2022
1983a4d
WIP safe mode and tx pause {continued} (#12371)
nuke-web3 Oct 12, 2022
3a0bec0
Set block number
ggwpez Oct 12, 2022
8902379
dummy weights generated, safe mode
nuke-web3 Oct 12, 2022
3ef4045
add repay_reservation call with RepaymentDelay per #10033 feature req…
nuke-web3 Oct 13, 2022
9c46c46
make call name optional to allow pausing pallets, handle `Contains` c…
nuke-web3 Oct 15, 2022
b8a4fcb
move to full_name notation for all interfaces, last commit introduced…
nuke-web3 Oct 15, 2022
f39cc9d
refactor is_paused
nuke-web3 Oct 15, 2022
9277178
safe math on safe mode
nuke-web3 Oct 31, 2022
46c5f8c
Merge remote-tracking branch 'origin/master' into oty-safe-mode
ggwpez Feb 6, 2023
31167d7
Make stuff compile
ggwpez Feb 6, 2023
ec7aff6
Compile
ggwpez Feb 6, 2023
a53608c
Cleanup & renames
ggwpez Mar 1, 2023
f868b5d
Cleanup TxPause pallet
ggwpez Mar 1, 2023
eb59831
Fix benches
ggwpez Mar 2, 2023
cf3d749
fmt
ggwpez Mar 2, 2023
76e8dc4
Merge remote-tracking branch 'origin/master' into oty-safe-mode
ggwpez Mar 25, 2023
7a5b098
Refactor to fungibles::* and rename stuf
ggwpez Mar 25, 2023
2e535ba
Merge branch 'oty-safe-mode-local' into oty-safe-mode
ggwpez Mar 25, 2023
a8a2948
Make compile
ggwpez Mar 25, 2023
2f551fb
Fix node config
ggwpez Mar 25, 2023
5292a69
Typos
ggwpez Mar 25, 2023
6b5c820
Remove CausalHoldReason
ggwpez Mar 29, 2023
645c2d0
Merge remote-tracking branch 'origin/master' into oty-safe-mode
ggwpez Mar 29, 2023
4aa8f43
Refactor benchmarks and runtime configs
ggwpez Mar 29, 2023
9118a1f
Add traits
ggwpez Mar 29, 2023
ddc94a9
Remove old code
ggwpez Mar 29, 2023
b65d1d5
Cleanup safe-mode benches
ggwpez Mar 29, 2023
3aa32e2
Update frame/safe-mode/Cargo.toml
ggwpez Apr 28, 2023
2c80c63
Update frame/safe-mode/Cargo.toml
ggwpez Apr 28, 2023
b79c9b3
Docs
ggwpez Apr 28, 2023
defb00b
Remove getters
ggwpez Apr 28, 2023
5881f47
Update Cargo.lock
ggwpez Apr 28, 2023
1ab26e4
Remove phantom
ggwpez Apr 28, 2023
53bb17e
Fix test
ggwpez Apr 28, 2023
c2fc849
Remove phantom
ggwpez Apr 28, 2023
273b7ab
Apply suggestions from code review
ggwpez Apr 28, 2023
dda7893
Merge remote-tracking branch 'origin/master' into oty-safe-mode
ggwpez Apr 28, 2023
f237453
Use new as Origin benchmarking syntax
ggwpez Apr 28, 2023
f228a19
Docs
ggwpez Apr 28, 2023
ec3baa5
Fix node
ggwpez Apr 28, 2023
0384516
Fix tx-pause benches
ggwpez Apr 28, 2023
1dc0a1f
Renames
ggwpez Jun 2, 2023
8d978f2
Remove duplicate test
ggwpez Jun 2, 2023
4389622
Add docs
ggwpez Jun 2, 2023
27c803a
docs
ggwpez Jun 2, 2023
0079f87
Apply suggestions from code review
ggwpez Jun 2, 2023
f66cd4a
Cleanup tests
ggwpez Jun 2, 2023
d7d863c
docs
ggwpez Jun 2, 2023
c37e497
Cleanup GenesisConfigs
ggwpez Jun 2, 2023
82a8a06
Doc traits
ggwpez Jun 2, 2023
ba81f08
Remove PauseTooLongNames
ggwpez Jun 2, 2023
1542959
docs
ggwpez Jun 2, 2023
0e4c0c1
Merge remote-tracking branch 'origin/oty-safe-mode' into oty-safe-mode
ggwpez Jun 2, 2023
16b46d6
Use V2 benchmarking
ggwpez Jun 2, 2023
1f4e223
Merge remote-tracking branch 'origin/master' into oty-safe-mode
ggwpez Jun 2, 2023
8915860
Use RuntimeHoldReason
ggwpez Jun 2, 2023
d0967a8
Fix kitchensink runtime
ggwpez Jun 2, 2023
c56f1f9
Fix CI
ggwpez Jun 5, 2023
055d465
Fix CI
ggwpez Jun 5, 2023
7fbd556
Review
ggwpez Jun 5, 2023
c86894b
Rename Stake to Deposit
ggwpez Jun 5, 2023
77456ad
Add docs
ggwpez Jun 5, 2023
b80ff71
Add Notify and test it
ggwpez Jun 5, 2023
5ece51a
Fix kitchensink
ggwpez Jun 5, 2023
57dea70
Update frame/safe-mode/src/tests.rs
ggwpez Jun 5, 2023
533bdc9
Update frame/safe-mode/src/tests.rs
ggwpez Jun 5, 2023
2abedb4
Update frame/support/src/traits/safe_mode.rs
ggwpez Jun 5, 2023
bbde914
Update frame/support/src/traits/safe_mode.rs
ggwpez Jun 5, 2023
e6a8646
Update frame/support/src/traits/safe_mode.rs
ggwpez Jun 5, 2023
05917be
Update frame/support/src/traits/tx_pause.rs
ggwpez Jun 5, 2023
3de3041
Update frame/tx-pause/src/lib.rs
ggwpez Jun 5, 2023
b024c1a
Update frame/tx-pause/src/lib.rs
ggwpez Jun 5, 2023
bee80ed
Update frame/tx-pause/src/mock.rs
ggwpez Jun 5, 2023
55406a7
Update frame/support/src/traits/safe_mode.rs
ggwpez Jun 5, 2023
78f541e
Simplify code
ggwpez Jun 5, 2023
4643c38
Update frame/support/src/traits/safe_mode.rs
ggwpez Jun 5, 2023
f652595
Update frame/support/src/traits/safe_mode.rs
ggwpez Jun 5, 2023
48481d9
Update frame/support/src/traits/safe_mode.rs
ggwpez Jun 5, 2023
f1b4f0c
Merge remote-tracking branch 'origin/master' into oty-safe-mode
ggwpez Jun 5, 2023
de0c81c
Merge remote-tracking branch 'origin/master' into oty-safe-mode
ggwpez Aug 24, 2023
a287d99
Fixup merge
ggwpez Aug 24, 2023
80cf834
Make stuff compile
ggwpez Aug 24, 2023
f39ca0a
Make tx-pause compile again
ggwpez Aug 24, 2023
9259c64
Fix features
ggwpez Aug 24, 2023
3ed9996
Fix more features
ggwpez Aug 24, 2023
37d9c4d
Merge branch 'master' of https://github.com/paritytech/substrate into…
Aug 24, 2023
022f9da
".git/.scripts/commands/bench/bench.sh" --subcommand=pallet --runtime…
Aug 24, 2023
93d9e44
Update weights
ggwpez Aug 24, 2023
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
39 changes: 39 additions & 0 deletions Cargo.lock

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

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,8 @@ members = [
"frame/recovery",
"frame/referenda",
"frame/remark",
"frame/tx-pause",
"frame/safe-mode",
"frame/salary",
"frame/scheduler",
"frame/scored-pool",
Expand Down
2 changes: 2 additions & 0 deletions bin/node/cli/src/chain_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,8 @@ pub fn testnet_genesis(
transaction_storage: Default::default(),
transaction_payment: Default::default(),
alliance: Default::default(),
safe_mode: Default::default(),
tx_pause: Default::default(),
alliance_motion: Default::default(),
nomination_pools: NominationPoolsConfig {
min_create_bond: 10 * DOLLARS,
Expand Down
8 changes: 8 additions & 0 deletions bin/node/runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,8 @@ pallet-transaction-storage = { version = "4.0.0-dev", default-features = false,
pallet-uniques = { version = "4.0.0-dev", default-features = false, path = "../../../frame/uniques" }
pallet-vesting = { version = "4.0.0-dev", default-features = false, path = "../../../frame/vesting" }
pallet-whitelist = { version = "4.0.0-dev", default-features = false, path = "../../../frame/whitelist" }
pallet-tx-pause = { version = "4.0.0-dev", default-features = false, path = "../../../frame/tx-pause" }
pallet-safe-mode = { version = "4.0.0-dev", default-features = false, path = "../../../frame/safe-mode" }

[build-dependencies]
substrate-wasm-builder = { version = "5.0.0-dev", path = "../../../utils/wasm-builder", optional = true }
Expand Down Expand Up @@ -177,6 +179,8 @@ std = [
"pallet-nomination-pools-runtime-api/std",
"pallet-nomination-pools-benchmarking?/std",
"pallet-identity/std",
"pallet-tx-pause/std",
"pallet-safe-mode/std",
"pallet-scheduler/std",
"node-primitives/std",
"sp-offchain/std",
Expand Down Expand Up @@ -277,6 +281,8 @@ runtime-benchmarks = [
"pallet-referenda/runtime-benchmarks",
"pallet-recovery/runtime-benchmarks",
"pallet-remark/runtime-benchmarks",
"pallet-tx-pause/runtime-benchmarks",
"pallet-safe-mode/runtime-benchmarks",
"pallet-salary/runtime-benchmarks",
"pallet-session-benchmarking/runtime-benchmarks",
"pallet-society/runtime-benchmarks",
Expand Down Expand Up @@ -341,6 +347,7 @@ try-runtime = [
"pallet-referenda/try-runtime",
"pallet-remark/try-runtime",
"pallet-root-testing/try-runtime",
"pallet-safe-mode/try-runtime",
"pallet-salary/try-runtime",
"pallet-session/try-runtime",
"pallet-staking/try-runtime",
Expand All @@ -352,6 +359,7 @@ try-runtime = [
"pallet-timestamp/try-runtime",
"pallet-tips/try-runtime",
"pallet-treasury/try-runtime",
"pallet-tx-pause/try-runtime",
"pallet-asset-rate/try-runtime",
"pallet-utility/try-runtime",
"pallet-transaction-payment/try-runtime",
Expand Down
79 changes: 73 additions & 6 deletions bin/node/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,10 @@ use frame_support::{
traits::{
fungible::ItemOf,
tokens::{nonfungibles_v2::Inspect, GetSalary, PayFromAccount},
AsEnsureOriginWithArg, ConstBool, ConstU128, ConstU16, ConstU32, Currency, EitherOfDiverse,
EqualPrivilegeOnly, Everything, Imbalance, InstanceFilter, KeyOwnerProofSystem,
LockIdentifier, Nothing, OnUnbalanced, U128CurrencyToVote, WithdrawReasons,
AsEnsureOriginWithArg, ConstBool, ConstU128, ConstU16, ConstU32, Contains, Currency,
EitherOfDiverse, EqualPrivilegeOnly, Imbalance, InsideBoth, InstanceFilter,
KeyOwnerProofSystem, LockIdentifier, Nothing, OnUnbalanced, U128CurrencyToVote,
WithdrawReasons,
},
weights::{
constants::{
Expand All @@ -62,6 +63,7 @@ use pallet_nis::WithMaximumOf;
use pallet_session::historical as pallet_session_historical;
pub use pallet_transaction_payment::{CurrencyAdapter, Multiplier, TargetedFeeAdjustment};
use pallet_transaction_payment::{FeeDetails, RuntimeDispatchInfo};
use pallet_tx_pause::RuntimeCallNameOf;
use sp_api::impl_runtime_apis;
use sp_authority_discovery::AuthorityId as AuthorityDiscoveryId;
use sp_consensus_grandpa::AuthorityId as GrandpaId;
Expand Down Expand Up @@ -217,8 +219,69 @@ parameter_types! {

const_assert!(NORMAL_DISPATCH_RATIO.deconstruct() >= AVERAGE_ON_INITIALIZE_RATIO.deconstruct());

/// Calls that can bypass the safe-mode pallet.
pub struct SafeModeWhitelistedCalls;
impl Contains<RuntimeCall> for SafeModeWhitelistedCalls {
fn contains(call: &RuntimeCall) -> bool {
match call {
RuntimeCall::System(_) | RuntimeCall::SafeMode(_) | RuntimeCall::TxPause(_) => true,
_ => false,
}
}
}

/// Calls that cannot be paused by the tx-pause pallet.
pub struct TxPauseWhitelistedCalls;
/// Whitelist `Balances::transfer_keep_alive`, all others are pauseable.
impl Contains<RuntimeCallNameOf<Runtime>> for TxPauseWhitelistedCalls {
fn contains(full_name: &RuntimeCallNameOf<Runtime>) -> bool {
let unpausables: Vec<RuntimeCallNameOf<Runtime>> = vec![(
b"Balances".to_vec().try_into().unwrap(),
b"transfer_keep_alive".to_vec().try_into().unwrap(),
)];
ggwpez marked this conversation as resolved.
Show resolved Hide resolved

unpausables.contains(full_name)
}
}

impl pallet_tx_pause::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type RuntimeCall = RuntimeCall;
type PauseOrigin = EnsureRoot<AccountId>;
type UnpauseOrigin = EnsureRoot<AccountId>;
type WhitelistedCalls = TxPauseWhitelistedCalls;
type MaxNameLen = ConstU32<256>;
type WeightInfo = pallet_tx_pause::weights::SubstrateWeight<Runtime>;
}

parameter_types! {
pub const EnterDuration: BlockNumber = 4 * HOURS;
pub const EnterDepositAmount: Balance = 2_000_000 * DOLLARS;
pub const ExtendDuration: BlockNumber = 2 * HOURS;
pub const ExtendDepositAmount: Balance = 1_000_000 * DOLLARS;
pub const ReleaseDelay: u32 = 2 * DAYS;
}

impl pallet_safe_mode::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type Currency = Balances;
type RuntimeHoldReason = RuntimeHoldReason;
type WhitelistedCalls = SafeModeWhitelistedCalls;
type EnterDuration = EnterDuration;
type EnterDepositAmount = EnterDepositAmount;
type ExtendDuration = ExtendDuration;
type ExtendDepositAmount = ExtendDepositAmount;
type ForceEnterOrigin = EnsureRootWithSuccess<AccountId, ConstU32<9>>;
type ForceExtendOrigin = EnsureRootWithSuccess<AccountId, ConstU32<11>>;
type ForceExitOrigin = EnsureRoot<AccountId>;
type ForceDepositOrigin = EnsureRoot<AccountId>;
type ReleaseDelay = ReleaseDelay;
type Notify = ();
type WeightInfo = pallet_safe_mode::weights::SubstrateWeight<Runtime>;
}

impl frame_system::Config for Runtime {
type BaseCallFilter = Everything;
type BaseCallFilter = InsideBoth<SafeMode, TxPause>;
ggwpez marked this conversation as resolved.
Show resolved Hide resolved
type BlockWeights = RuntimeBlockWeights;
type BlockLength = RuntimeBlockLength;
type DbWeight = RocksDbWeight;
Expand Down Expand Up @@ -1659,8 +1722,8 @@ impl pallet_core_fellowship::Config for Runtime {
type Balance = Balance;
type ParamsOrigin = frame_system::EnsureRoot<AccountId>;
type InductOrigin = pallet_core_fellowship::EnsureInducted<Runtime, (), 1>;
type ApproveOrigin = frame_system::EnsureRootWithSuccess<AccountId, ConstU16<9>>;
type PromoteOrigin = frame_system::EnsureRootWithSuccess<AccountId, ConstU16<9>>;
type ApproveOrigin = EnsureRootWithSuccess<AccountId, ConstU16<9>>;
type PromoteOrigin = EnsureRootWithSuccess<AccountId, ConstU16<9>>;
type EvidenceSize = ConstU32<16_384>;
}

Expand Down Expand Up @@ -1929,6 +1992,8 @@ construct_runtime!(
FastUnstake: pallet_fast_unstake,
MessageQueue: pallet_message_queue,
Pov: frame_benchmarking_pallet_pov,
TxPause: pallet_tx_pause,
SafeMode: pallet_safe_mode,
Statement: pallet_statement,
}
);
Expand Down Expand Up @@ -2058,6 +2123,8 @@ mod benches {
[pallet_utility, Utility]
[pallet_vesting, Vesting]
[pallet_whitelist, Whitelist]
[pallet_tx_pause, TxPause]
[pallet_safe_mode, SafeMode]
);
}

Expand Down
2 changes: 2 additions & 0 deletions bin/node/testing/src/genesis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ pub fn config_endowed(code: Option<&[u8]>, extra_endowed: Vec<AccountId>) -> Run
alliance: Default::default(),
alliance_motion: Default::default(),
nomination_pools: Default::default(),
safe_mode: Default::default(),
tx_pause: Default::default(),
glutton: GluttonConfig {
compute: Default::default(),
storage: Default::default(),
Expand Down
60 changes: 60 additions & 0 deletions frame/safe-mode/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
[package]
name = "pallet-safe-mode"
version = "4.0.0-dev"
authors = ["Parity Technologies <admin@parity.io>"]
edition = "2021"
license = "Apache-2.0"
homepage = "https://substrate.io"
repository = "https://github.com/paritytech/substrate/"
description = "FRAME safe-mode pallet"

[package.metadata.docs.rs]
targets = ["x86_64-unknown-linux-gnu"]

[dependencies]
codec = { package = "parity-scale-codec", version = "3.2.2", default-features = false, features = ["derive"] }
frame-benchmarking = { version = "4.0.0-dev", default-features = false, optional = true, path = "../benchmarking" }
frame-support = { version = "4.0.0-dev", default-features = false, path = "../support" }
frame-system = { version = "4.0.0-dev", default-features = false, path = "../system" }
scale-info = { version = "2.5.0", default-features = false, features = ["derive"] }
sp-arithmetic = { version = "16.0.0", default-features = false, path = "../../primitives/arithmetic" }
sp-runtime = { version = "24.0.0", default-features = false, path = "../../primitives/runtime" }
sp-std = { version = "8.0.0", default-features = false, path = "../../primitives/std" }
pallet-balances = { version = "4.0.0-dev", path = "../balances", default-features = false, optional = true }
pallet-utility = { version = "4.0.0-dev", path = "../utility", default-features = false, optional = true }
pallet-proxy = { version = "4.0.0-dev", path = "../proxy", default-features = false, optional = true }

[dev-dependencies]
sp-core = { version = "21.0.0", path = "../../primitives/core" }
sp-io = { version = "23.0.0", path = "../../primitives/io" }
pallet-balances = { version = "4.0.0-dev", path = "../balances" }
pallet-utility = { version = "4.0.0-dev", path = "../utility" }
pallet-proxy = { version = "4.0.0-dev", path = "../proxy" }

[features]
default = ["std"]
std = [
"codec/std",
"scale-info/std",
"frame-benchmarking/std",
"frame-system/std",
"frame-support/std",
"pallet-balances?/std",
"pallet-utility?/std",
"pallet-proxy?/std",
"sp-arithmetic/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-utility/runtime-benchmarks",
"pallet-proxy/runtime-benchmarks",
]
try-runtime = [
"frame-support/try-runtime",
"frame-system/try-runtime",
]
Loading