@@ -37,9 +37,9 @@ use frame_support::{
3737 traits:: {
3838 fungible:: { Balanced , Credit , ItemOf } ,
3939 tokens:: { nonfungibles_v2:: Inspect , GetSalary , PayFromAccount } ,
40- AsEnsureOriginWithArg , ConstBool , ConstU128 , ConstU16 , ConstU32 , Currency , EitherOfDiverse ,
41- EqualPrivilegeOnly , Everything , Imbalance , InstanceFilter , KeyOwnerProofSystem ,
42- LockIdentifier , Nothing , OnUnbalanced , WithdrawReasons ,
40+ AsEnsureOriginWithArg , ConstBool , ConstU128 , ConstU16 , ConstU32 , Contains , Currency ,
41+ EitherOfDiverse , EqualPrivilegeOnly , Imbalance , InsideBoth , InstanceFilter ,
42+ KeyOwnerProofSystem , LockIdentifier , Nothing , OnUnbalanced , WithdrawReasons ,
4343 } ,
4444 weights:: {
4545 constants:: {
@@ -64,6 +64,7 @@ use pallet_nis::WithMaximumOf;
6464use pallet_session:: historical as pallet_session_historical;
6565pub use pallet_transaction_payment:: { CurrencyAdapter , Multiplier , TargetedFeeAdjustment } ;
6666use pallet_transaction_payment:: { FeeDetails , RuntimeDispatchInfo } ;
67+ use pallet_tx_pause:: RuntimeCallNameOf ;
6768use sp_api:: impl_runtime_apis;
6869use sp_authority_discovery:: AuthorityId as AuthorityDiscoveryId ;
6970use sp_consensus_grandpa:: AuthorityId as GrandpaId ;
@@ -220,8 +221,67 @@ parameter_types! {
220221
221222const_assert ! ( NORMAL_DISPATCH_RATIO . deconstruct( ) >= AVERAGE_ON_INITIALIZE_RATIO . deconstruct( ) ) ;
222223
224+ /// Calls that can bypass the safe-mode pallet.
225+ pub struct SafeModeWhitelistedCalls ;
226+ impl Contains < RuntimeCall > for SafeModeWhitelistedCalls {
227+ fn contains ( call : & RuntimeCall ) -> bool {
228+ match call {
229+ RuntimeCall :: System ( _) | RuntimeCall :: SafeMode ( _) | RuntimeCall :: TxPause ( _) => true ,
230+ _ => false ,
231+ }
232+ }
233+ }
234+
235+ /// Calls that cannot be paused by the tx-pause pallet.
236+ pub struct TxPauseWhitelistedCalls ;
237+ /// Whitelist `Balances::transfer_keep_alive`, all others are pauseable.
238+ impl Contains < RuntimeCallNameOf < Runtime > > for TxPauseWhitelistedCalls {
239+ fn contains ( full_name : & RuntimeCallNameOf < Runtime > ) -> bool {
240+ match ( full_name. 0 . as_slice ( ) , full_name. 1 . as_slice ( ) ) {
241+ ( b"Balances" , b"transfer_keep_alive" ) => true ,
242+ _ => false ,
243+ }
244+ }
245+ }
246+
247+ impl pallet_tx_pause:: Config for Runtime {
248+ type RuntimeEvent = RuntimeEvent ;
249+ type RuntimeCall = RuntimeCall ;
250+ type PauseOrigin = EnsureRoot < AccountId > ;
251+ type UnpauseOrigin = EnsureRoot < AccountId > ;
252+ type WhitelistedCalls = TxPauseWhitelistedCalls ;
253+ type MaxNameLen = ConstU32 < 256 > ;
254+ type WeightInfo = pallet_tx_pause:: weights:: SubstrateWeight < Runtime > ;
255+ }
256+
257+ parameter_types ! {
258+ pub const EnterDuration : BlockNumber = 4 * HOURS ;
259+ pub const EnterDepositAmount : Balance = 2_000_000 * DOLLARS ;
260+ pub const ExtendDuration : BlockNumber = 2 * HOURS ;
261+ pub const ExtendDepositAmount : Balance = 1_000_000 * DOLLARS ;
262+ pub const ReleaseDelay : u32 = 2 * DAYS ;
263+ }
264+
265+ impl pallet_safe_mode:: Config for Runtime {
266+ type RuntimeEvent = RuntimeEvent ;
267+ type Currency = Balances ;
268+ type RuntimeHoldReason = RuntimeHoldReason ;
269+ type WhitelistedCalls = SafeModeWhitelistedCalls ;
270+ type EnterDuration = EnterDuration ;
271+ type EnterDepositAmount = EnterDepositAmount ;
272+ type ExtendDuration = ExtendDuration ;
273+ type ExtendDepositAmount = ExtendDepositAmount ;
274+ type ForceEnterOrigin = EnsureRootWithSuccess < AccountId , ConstU32 < 9 > > ;
275+ type ForceExtendOrigin = EnsureRootWithSuccess < AccountId , ConstU32 < 11 > > ;
276+ type ForceExitOrigin = EnsureRoot < AccountId > ;
277+ type ForceDepositOrigin = EnsureRoot < AccountId > ;
278+ type ReleaseDelay = ReleaseDelay ;
279+ type Notify = ( ) ;
280+ type WeightInfo = pallet_safe_mode:: weights:: SubstrateWeight < Runtime > ;
281+ }
282+
223283impl frame_system:: Config for Runtime {
224- type BaseCallFilter = Everything ;
284+ type BaseCallFilter = InsideBoth < SafeMode , TxPause > ;
225285 type BlockWeights = RuntimeBlockWeights ;
226286 type BlockLength = RuntimeBlockLength ;
227287 type DbWeight = RocksDbWeight ;
@@ -1682,8 +1742,8 @@ impl pallet_core_fellowship::Config for Runtime {
16821742 type Balance = Balance ;
16831743 type ParamsOrigin = frame_system:: EnsureRoot < AccountId > ;
16841744 type InductOrigin = pallet_core_fellowship:: EnsureInducted < Runtime , ( ) , 1 > ;
1685- type ApproveOrigin = frame_system :: EnsureRootWithSuccess < AccountId , ConstU16 < 9 > > ;
1686- type PromoteOrigin = frame_system :: EnsureRootWithSuccess < AccountId , ConstU16 < 9 > > ;
1745+ type ApproveOrigin = EnsureRootWithSuccess < AccountId , ConstU16 < 9 > > ;
1746+ type PromoteOrigin = EnsureRootWithSuccess < AccountId , ConstU16 < 9 > > ;
16871747 type EvidenceSize = ConstU32 < 16_384 > ;
16881748}
16891749
@@ -2021,6 +2081,8 @@ construct_runtime!(
20212081 FastUnstake : pallet_fast_unstake,
20222082 MessageQueue : pallet_message_queue,
20232083 Pov : frame_benchmarking_pallet_pov,
2084+ TxPause : pallet_tx_pause,
2085+ SafeMode : pallet_safe_mode,
20242086 Statement : pallet_statement,
20252087 Broker : pallet_broker,
20262088 }
@@ -2153,6 +2215,8 @@ mod benches {
21532215 [ pallet_utility, Utility ]
21542216 [ pallet_vesting, Vesting ]
21552217 [ pallet_whitelist, Whitelist ]
2218+ [ pallet_tx_pause, TxPause ]
2219+ [ pallet_safe_mode, SafeMode ]
21562220 ) ;
21572221}
21582222
0 commit comments