Skip to content

Commit

Permalink
feat: tx-pause and safe-mode pallets integration
Browse files Browse the repository at this point in the history
  • Loading branch information
ipapandinas committed Nov 25, 2024
1 parent d72239b commit ae9ea5d
Show file tree
Hide file tree
Showing 8 changed files with 504 additions and 299 deletions.
612 changes: 326 additions & 286 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,8 @@ pallet-message-queue = { git = "https://github.com/paritytech/polkadot-sdk", bra
pallet-membership = { git = "https://github.com/paritytech/polkadot-sdk", branch = "stable2407", default-features = false }
pallet-collective = { git = "https://github.com/paritytech/polkadot-sdk", branch = "stable2407", default-features = false }
pallet-democracy = { git = "https://github.com/paritytech/polkadot-sdk", branch = "stable2407", default-features = false }
pallet-tx-pause = { git = "https://github.com/paritytech/polkadot-sdk", branch = "stable2407", default-features = false }
pallet-safe-mode = { git = "https://github.com/paritytech/polkadot-sdk", branch = "stable2407", default-features = false }

# EVM & Ethereum
# (wasm)
Expand Down
8 changes: 8 additions & 0 deletions runtime/local/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,13 @@ pallet-insecure-randomness-collective-flip = { workspace = true }
pallet-membership = { workspace = true }
pallet-preimage = { workspace = true }
pallet-proxy = { workspace = true }
pallet-safe-mode = { workspace = true, default-features = false }
pallet-scheduler = { workspace = true }
pallet-sudo = { workspace = true }
pallet-timestamp = { workspace = true }
pallet-transaction-payment = { workspace = true }
pallet-treasury = { workspace = true }
pallet-tx-pause = { workspace = true, default-features = false }
pallet-utility = { workspace = true }
pallet-vesting = { workspace = true }
sp-api = { workspace = true }
Expand Down Expand Up @@ -160,6 +162,8 @@ std = [
"pallet-utility/std",
"pallet-vesting/std",
"pallet-proxy/std",
"pallet-safe-mode/std",
"pallet-tx-pause/std",
"sp-api/std",
"sp-block-builder/std",
"sp-consensus-aura/std",
Expand Down Expand Up @@ -222,9 +226,11 @@ runtime-benchmarks = [
"pallet-evm-precompile-dapp-staking/runtime-benchmarks",
"pallet-grandpa/runtime-benchmarks",
"pallet-proxy/runtime-benchmarks",
"pallet-safe-mode/runtime-benchmarks",
"pallet-scheduler/runtime-benchmarks",
"pallet-static-price-provider/runtime-benchmarks",
"pallet-sudo/runtime-benchmarks",
"pallet-tx-pause/runtime-benchmarks",
"pallet-utility/runtime-benchmarks",
"pallet-vesting/runtime-benchmarks",
]
Expand All @@ -248,11 +254,13 @@ try-runtime = [
"pallet-sudo/try-runtime",
"pallet-timestamp/try-runtime",
"pallet-transaction-payment/try-runtime",
"pallet-tx-pause/try-runtime",
"pallet-utility/try-runtime",
"pallet-vesting/try-runtime",
"pallet-unified-accounts/try-runtime",
"pallet-ethereum/try-runtime",
"pallet-assets/try-runtime",
"pallet-safe-mode/try-runtime",
"pallet-scheduler/try-runtime",
"pallet-proxy/try-runtime",
"pallet-preimage/try-runtime",
Expand Down
2 changes: 2 additions & 0 deletions runtime/local/src/genesis_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,8 @@ pub fn default_config() -> serde_json::Value {
democracy: Default::default(),
treasury: Default::default(),
community_treasury: Default::default(),
safe_mode: Default::default(),
tx_pause: Default::default(),
};

serde_json::to_value(&config).expect("Could not build genesis config.")
Expand Down
88 changes: 79 additions & 9 deletions runtime/local/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,9 @@ use frame_support::{
traits::{
fungible::{Balanced, Credit, HoldConsideration},
tokens::{PayFromAccount, UnityAssetBalanceConversion},
AsEnsureOriginWithArg, ConstU128, ConstU32, ConstU64, EqualPrivilegeOnly, FindAuthor, Get,
InstanceFilter, LinearStoragePrice, Nothing, OnFinalize, WithdrawReasons,
AsEnsureOriginWithArg, ConstU128, ConstU32, ConstU64, Contains, EqualPrivilegeOnly,
FindAuthor, Get, InsideBoth, InstanceFilter, LinearStoragePrice, Nothing, OnFinalize,
WithdrawReasons,
},
weights::{
constants::{ExtrinsicBaseWeight, RocksDbWeight, WEIGHT_REF_TIME_PER_SECOND},
Expand All @@ -41,13 +42,14 @@ use frame_support::{
};
use frame_system::{
limits::{BlockLength, BlockWeights},
EnsureRoot, EnsureSigned,
EnsureRoot, EnsureSigned, EnsureWithSuccess,
};
use pallet_ethereum::PostLogContent;
use pallet_evm::{FeeCalculator, GasWeightMapping, Runner};
use pallet_evm_precompile_assets_erc20::AddressToAssetId;
use pallet_grandpa::{fg_primitives, AuthorityList as GrandpaAuthorityList};
use pallet_transaction_payment::{FungibleAdapter, Multiplier, TargetedFeeAdjustment};
use pallet_tx_pause::RuntimeCallNameOf;
use parity_scale_codec::{Compact, Decode, Encode, MaxEncodedLen};
use sp_api::impl_runtime_apis;
use sp_core::{crypto::KeyTypeId, sr25519, ConstBool, OpaqueMetadata, H160, H256, U256};
Expand All @@ -72,10 +74,10 @@ use astar_primitives::{
governance::{
CommunityCouncilCollectiveInst, CommunityCouncilMembershipInst, CommunityTreasuryInst,
EnsureRootOrAllMainCouncil, EnsureRootOrAllTechnicalCommittee,
EnsureRootOrTwoThirdsCommunityCouncil, EnsureRootOrTwoThirdsMainCouncil,
EnsureRootOrTwoThirdsTechnicalCommittee, MainCouncilCollectiveInst,
MainCouncilMembershipInst, MainTreasuryInst, TechnicalCommitteeCollectiveInst,
TechnicalCommitteeMembershipInst,
EnsureRootOrHalfTechnicalCommittee, EnsureRootOrTwoThirdsCommunityCouncil,
EnsureRootOrTwoThirdsMainCouncil, EnsureRootOrTwoThirdsTechnicalCommittee,
MainCouncilCollectiveInst, MainCouncilMembershipInst, MainTreasuryInst,
TechnicalCommitteeCollectiveInst, TechnicalCommitteeMembershipInst,
},
Address, AssetId, Balance, BlockNumber, Hash, Header, Nonce,
};
Expand Down Expand Up @@ -207,10 +209,9 @@ parameter_types! {
}

// Configure FRAME pallets to include in runtime.

impl frame_system::Config for Runtime {
/// The basic call filter to use in dispatchable.
type BaseCallFilter = frame_support::traits::Everything;
type BaseCallFilter = InsideBoth<SafeMode, TxPause>;
/// Block & extrinsics weights: base values and limits.
type BlockWeights = RuntimeBlockWeights;
/// The maximum length of a block (in bytes).
Expand Down Expand Up @@ -1127,6 +1128,70 @@ impl pallet_collective_proxy::Config for Runtime {
type WeightInfo = pallet_collective_proxy::weights::SubstrateWeight<Runtime>;
}

parameter_types! {
pub const EnterDuration: BlockNumber = 10 * MINUTES;
pub const EnterDepositAmount: Option<Balance> = None;
pub const ExtendDuration: BlockNumber = 5 * MINUTES;
pub const ExtendDepositAmount: Option<Balance> = None;
pub const ReleaseDelay: Option<u32> = None;
}

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

/// Calls that cannot be paused by the tx-pause pallet.
pub struct TxPauseWhitelistedCalls;
/// All calls can be paused, except Sudo calls.
impl Contains<RuntimeCallNameOf<Runtime>> for TxPauseWhitelistedCalls {
fn contains(full_name: &pallet_tx_pause::RuntimeCallNameOf<Runtime>) -> bool {
matches!(full_name.0.as_slice(), b"Sudo")
}
}

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;
// The 'Success' value below represents the number of blocks that the origin may induce safe mode
type ForceEnterOrigin =
EnsureWithSuccess<EnsureRootOrAllTechnicalCommittee, AccountId, EnterDuration>;
type ForceExtendOrigin =
EnsureWithSuccess<EnsureRootOrAllTechnicalCommittee, AccountId, ExtendDuration>;
type ForceExitOrigin = EnsureRootOrAllTechnicalCommittee;
type ForceDepositOrigin = EnsureRootOrAllTechnicalCommittee;
type ReleaseDelay = ReleaseDelay;
type Notify = ();
type WeightInfo = pallet_safe_mode::weights::SubstrateWeight<Runtime>;
}

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

construct_runtime!(
pub struct Runtime {
System: frame_system = 10,
Expand Down Expand Up @@ -1171,6 +1236,9 @@ construct_runtime!(
Treasury: pallet_treasury::<Instance1> = 107,
CommunityTreasury: pallet_treasury::<Instance2> = 108,
CollectiveProxy: pallet_collective_proxy = 109,

SafeMode: pallet_safe_mode = 130,
TxPause: pallet_tx_pause = 131,
}
);

Expand Down Expand Up @@ -1290,6 +1358,8 @@ mod benches {
[pallet_dapp_staking, DappStaking]
[pallet_inflation, Inflation]
[pallet_dynamic_evm_base_fee, DynamicEvmBaseFee]
[pallet_tx_pause, TxPause]
[pallet_safe_mode, SafeMode]
);
}

Expand Down
8 changes: 8 additions & 0 deletions runtime/shibuya/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,15 @@ pallet-migrations = { workspace = true }
pallet-multisig = { workspace = true }
pallet-preimage = { workspace = true }
pallet-proxy = { workspace = true }
pallet-safe-mode = { workspace = true, default-features = false }
pallet-scheduler = { workspace = true }
pallet-session = { workspace = true }
pallet-sudo = { workspace = true }
pallet-timestamp = { workspace = true }
pallet-transaction-payment = { workspace = true }
pallet-transaction-payment-rpc-runtime-api = { workspace = true }
pallet-treasury = { workspace = true }
pallet-tx-pause = { workspace = true, default-features = false }
pallet-utility = { workspace = true }
pallet-vesting = { workspace = true }
vesting-mbm = { workspace = true }
Expand Down Expand Up @@ -223,13 +225,15 @@ std = [
"pallet-preimage/std",
"pallet-price-aggregator/std",
"pallet-proxy/std",
"pallet-safe-mode/std",
"pallet-scheduler/std",
"pallet-session/std",
"pallet-sudo/std",
"pallet-timestamp/std",
"pallet-transaction-payment-rpc-runtime-api/std",
"pallet-transaction-payment/std",
"pallet-treasury/std",
"pallet-tx-pause/std",
"pallet-unified-accounts/std",
"pallet-utility/std",
"pallet-vesting/std",
Expand Down Expand Up @@ -306,10 +310,12 @@ runtime-benchmarks = [
"pallet-preimage/runtime-benchmarks",
"pallet-price-aggregator/runtime-benchmarks",
"pallet-proxy/runtime-benchmarks",
"pallet-safe-mode/runtime-benchmarks",
"pallet-scheduler/runtime-benchmarks",
"pallet-sudo/runtime-benchmarks",
"pallet-timestamp/runtime-benchmarks",
"pallet-treasury/runtime-benchmarks",
"pallet-tx-pause/runtime-benchmarks",
"pallet-unified-accounts/runtime-benchmarks",
"pallet-utility/runtime-benchmarks",
"pallet-vesting/runtime-benchmarks",
Expand Down Expand Up @@ -367,12 +373,14 @@ try-runtime = [
"pallet-preimage/try-runtime",
"pallet-price-aggregator/try-runtime",
"pallet-proxy/try-runtime",
"pallet-safe-mode/try-runtime",
"pallet-scheduler/try-runtime",
"pallet-session/try-runtime",
"pallet-sudo/try-runtime",
"pallet-timestamp/try-runtime",
"pallet-transaction-payment/try-runtime",
"pallet-treasury/try-runtime",
"pallet-tx-pause/try-runtime",
"pallet-unified-accounts/try-runtime",
"pallet-utility/try-runtime",
"pallet-vesting/try-runtime",
Expand Down
2 changes: 2 additions & 0 deletions runtime/shibuya/src/genesis_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,8 @@ pub fn default_config(para_id: u32) -> serde_json::Value {
democracy: Default::default(),
treasury: Default::default(),
community_treasury: Default::default(),
safe_mode: Default::default(),
tx_pause: Default::default(),
};

serde_json::to_value(&config).expect("Could not build genesis config.")
Expand Down
Loading

0 comments on commit ae9ea5d

Please sign in to comment.