From d74773cee0a8c66bdfdb2c386c880dedcd5e8938 Mon Sep 17 00:00:00 2001 From: Dengjianping Date: Wed, 6 Mar 2024 00:35:59 +0800 Subject: [PATCH 1/2] Add pallet-proxy to runtimes Signed-off-by: Dengjianping --- Cargo.lock | 2 + Cargo.toml | 1 + runtime/calamari/Cargo.toml | 4 ++ runtime/calamari/src/lib.rs | 90 ++++++++++++++++++++++++++++++++--- runtime/manta/Cargo.toml | 4 ++ runtime/manta/src/lib.rs | 94 +++++++++++++++++++++++++++++++++---- 6 files changed, 181 insertions(+), 14 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index ff32278b7..e043d9ba3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1040,6 +1040,7 @@ dependencies = [ "pallet-name-service", "pallet-parachain-staking", "pallet-preimage", + "pallet-proxy", "pallet-randomness", "pallet-ranked-collective", "pallet-referenda", @@ -5554,6 +5555,7 @@ dependencies = [ "pallet-name-service", "pallet-parachain-staking", "pallet-preimage", + "pallet-proxy", "pallet-randomness", "pallet-scheduler", "pallet-session", diff --git a/Cargo.toml b/Cargo.toml index ee910a11e..1a9672dbe 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -93,6 +93,7 @@ pallet-membership = { git = "https://github.com/paritytech/substrate.git", branc pallet-message-queue = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.43", default-features = false } pallet-multisig = { git = 'https://github.com/paritytech/substrate.git', branch = "polkadot-v0.9.43", default-features = false } pallet-preimage = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.43", default-features = false } +pallet-proxy = { git = 'https://github.com/paritytech/substrate.git', branch = "polkadot-v0.9.43", default-features = false } pallet-ranked-collective = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.43", default-features = false } pallet-referenda = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.43", default-features = false } pallet-scheduler = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.43", default-features = false } diff --git a/runtime/calamari/Cargo.toml b/runtime/calamari/Cargo.toml index fb053d59a..5cccfb53b 100644 --- a/runtime/calamari/Cargo.toml +++ b/runtime/calamari/Cargo.toml @@ -51,6 +51,7 @@ pallet-democracy = { workspace = true } pallet-membership = { workspace = true } pallet-multisig = { workspace = true } pallet-preimage = { workspace = true } +pallet-proxy = { workspace = true } pallet-scheduler = { workspace = true } pallet-session = { workspace = true } pallet-timestamp = { workspace = true } @@ -169,6 +170,7 @@ runtime-benchmarks = [ 'pallet-treasury/runtime-benchmarks', 'pallet-parachain-staking/runtime-benchmarks', 'pallet-preimage/runtime-benchmarks', + "pallet-proxy/runtime-benchmarks", 'pallet-assets/runtime-benchmarks', 'pallet-asset-manager/runtime-benchmarks', 'cumulus-pallet-xcmp-queue/runtime-benchmarks', @@ -195,6 +197,7 @@ try-runtime = [ 'pallet-balances/try-runtime', 'pallet-parachain-staking/try-runtime', 'pallet-preimage/try-runtime', + "pallet-proxy/try-runtime", 'pallet-scheduler/try-runtime', 'pallet-multisig/try-runtime', 'pallet-session/try-runtime', @@ -263,6 +266,7 @@ std = [ 'pallet-parachain-staking/std', 'substrate-fixed/std', 'pallet-preimage/std', + "pallet-proxy/std", 'pallet-utility/std', 'pallet-transaction-payment-rpc-runtime-api/std', 'pallet-timestamp/std', diff --git a/runtime/calamari/src/lib.rs b/runtime/calamari/src/lib.rs index cc259c65d..bee098416 100644 --- a/runtime/calamari/src/lib.rs +++ b/runtime/calamari/src/lib.rs @@ -35,21 +35,18 @@ use sp_runtime::{ }; use sp_std::{cmp::Ordering, prelude::*}; -#[cfg(feature = "std")] -use sp_version::NativeVersion; -use sp_version::RuntimeVersion; - +use codec::{Decode, Encode, MaxEncodedLen}; use cumulus_primitives_core::relay_chain::MAX_POV_SIZE; use frame_support::{ construct_runtime, dispatch::DispatchClass, parameter_types, traits::{ - ConstU128, ConstU32, ConstU8, Contains, Currency, EitherOfDiverse, IsInVec, + ConstU128, ConstU32, ConstU8, Contains, Currency, EitherOfDiverse, InstanceFilter, IsInVec, NeverEnsureOrigin, PrivilegeCmp, }, weights::{ConstantMultiplier, Weight}, - PalletId, + PalletId, RuntimeDebug, }; use frame_system::{ limits::{BlockLength, BlockWeights}, @@ -73,6 +70,9 @@ use runtime_common::{ ExtrinsicBaseWeight, }; use session_key_primitives::{AuraId, NimbusId, VrfId}; +#[cfg(feature = "std")] +use sp_version::NativeVersion; +use sp_version::RuntimeVersion; use zenlink_protocol::{AssetBalance, AssetId as ZenlinkAssetId, MultiAssetsHandler, PairInfo}; #[cfg(any(feature = "std", test))] @@ -376,6 +376,82 @@ impl frame_system::Config for Runtime { type MaxConsumers = ConstU32<16>; } +parameter_types! { + // One storage item; key size 32, value size 8; . + pub const ProxyDepositBase: Balance = deposit(1, 8); + // Additional storage item size of 33 bytes. + pub const ProxyDepositFactor: Balance = deposit(0, 33); + pub const AnnouncementDepositBase: Balance = deposit(1, 8); + pub const AnnouncementDepositFactor: Balance = deposit(0, 66); +} + +/// The type used to represent the kinds of proxying allowed. +#[derive( + Copy, + Clone, + Eq, + PartialEq, + Ord, + PartialOrd, + Encode, + Decode, + RuntimeDebug, + MaxEncodedLen, + scale_info::TypeInfo, +)] +pub enum ProxyType { + Any, + NonTransfer, + Governance, + Staking, +} + +impl Default for ProxyType { + fn default() -> Self { + Self::Any + } +} + +impl InstanceFilter for ProxyType { + fn filter(&self, c: &RuntimeCall) -> bool { + match self { + ProxyType::Any => true, + ProxyType::NonTransfer => !matches!(c, RuntimeCall::Balances(..)), + ProxyType::Governance => matches!( + c, + RuntimeCall::Democracy(..) + | RuntimeCall::Council(..) + | RuntimeCall::TechnicalCommittee(..) + ), + ProxyType::Staking => matches!(c, RuntimeCall::ParachainStaking(..)), + } + } + fn is_superset(&self, o: &Self) -> bool { + match (self, o) { + (x, y) if x == y => true, + (ProxyType::Any, _) => true, + (_, ProxyType::Any) => false, + (ProxyType::NonTransfer, _) => true, + _ => false, + } + } +} + +impl pallet_proxy::Config for Runtime { + type RuntimeEvent = RuntimeEvent; + type RuntimeCall = RuntimeCall; + type Currency = Balances; + type ProxyType = ProxyType; + type ProxyDepositBase = ProxyDepositBase; + type ProxyDepositFactor = ProxyDepositFactor; + type MaxProxies = ConstU32<32>; + type WeightInfo = (); + type MaxPending = ConstU32<32>; + type CallHasher = BlakeTwo256; + type AnnouncementDepositBase = AnnouncementDepositBase; + type AnnouncementDepositFactor = AnnouncementDepositFactor; +} + parameter_types! { pub const MinimumPeriod: u64 = SLOT_DURATION / 2; } @@ -1030,6 +1106,7 @@ construct_runtime!( Utility: pallet_utility::{Pallet, Call, Event} = 40, Multisig: pallet_multisig::{Pallet, Call, Storage, Event} = 41, // 42 was occupied by pallet-sudo, we should discuss it if another pallet takes 42 in the future. + Proxy: pallet_proxy::{Pallet, Call, Storage, Event} = 43, // Assets management Assets: pallet_assets::{Pallet, Call, Storage, Event} = 45, @@ -1108,6 +1185,7 @@ mod benches { [pallet_membership, CouncilMembership] [pallet_treasury, Treasury] [pallet_preimage, Preimage] + [pallet_proxy, Proxy] [pallet_scheduler, Scheduler] [pallet_session, SessionBench::] [pallet_assets, Assets] diff --git a/runtime/manta/Cargo.toml b/runtime/manta/Cargo.toml index 0bea1e8c5..7d3bc4865 100644 --- a/runtime/manta/Cargo.toml +++ b/runtime/manta/Cargo.toml @@ -50,6 +50,7 @@ pallet-democracy = { workspace = true } pallet-membership = { workspace = true } pallet-multisig = { workspace = true } pallet-preimage = { workspace = true } +pallet-proxy = { workspace = true } pallet-scheduler = { workspace = true } pallet-session = { workspace = true } pallet-sudo = { workspace = true } @@ -150,6 +151,7 @@ runtime-benchmarks = [ 'pallet-treasury/runtime-benchmarks', 'pallet-parachain-staking/runtime-benchmarks', 'pallet-preimage/runtime-benchmarks', + "pallet-proxy/runtime-benchmarks", 'pallet-assets/runtime-benchmarks', 'pallet-asset-manager/runtime-benchmarks', 'cumulus-pallet-xcmp-queue/runtime-benchmarks', @@ -175,6 +177,7 @@ try-runtime = [ 'pallet-balances/try-runtime', 'pallet-parachain-staking/try-runtime', 'pallet-preimage/try-runtime', + "pallet-proxy/try-runtime", 'pallet-multisig/try-runtime', 'pallet-session/try-runtime', 'pallet-scheduler/try-runtime', @@ -244,6 +247,7 @@ std = [ 'pallet-randomness/std', 'pallet-lottery/std', 'pallet-preimage/std', + "pallet-proxy/std", 'pallet-utility/std', 'pallet-transaction-payment-rpc-runtime-api/std', 'pallet-timestamp/std', diff --git a/runtime/manta/src/lib.rs b/runtime/manta/src/lib.rs index 22d15a012..194ecffa7 100644 --- a/runtime/manta/src/lib.rs +++ b/runtime/manta/src/lib.rs @@ -35,11 +35,7 @@ use sp_runtime::{ ApplyExtrinsicResult, Perbill, Percent, Permill, }; -use sp_std::{cmp::Ordering, prelude::*}; -#[cfg(feature = "std")] -use sp_version::NativeVersion; -use sp_version::RuntimeVersion; - +use codec::{Decode, Encode, MaxEncodedLen}; use cumulus_pallet_parachain_system::{ register_validate_block, CheckInherents, ParachainSetCode, RelayChainStateProof, RelaychainDataProvider, @@ -49,12 +45,16 @@ use frame_support::{ dispatch::DispatchClass, parameter_types, traits::{ - ConstU128, ConstU32, ConstU8, Contains, Currency, EitherOfDiverse, NeverEnsureOrigin, - PrivilegeCmp, + ConstU128, ConstU32, ConstU8, Contains, Currency, EitherOfDiverse, InstanceFilter, + NeverEnsureOrigin, PrivilegeCmp, }, weights::{ConstantMultiplier, Weight}, - PalletId, + PalletId, RuntimeDebug, }; +use sp_std::{cmp::Ordering, prelude::*}; +#[cfg(feature = "std")] +use sp_version::NativeVersion; +use sp_version::RuntimeVersion; use frame_system::{ limits::{BlockLength, BlockWeights}, @@ -319,6 +319,82 @@ impl frame_system::Config for Runtime { type MaxConsumers = ConstU32<16>; } +parameter_types! { + // One storage item; key size 32, value size 8; . + pub const ProxyDepositBase: Balance = deposit(1, 8); + // Additional storage item size of 33 bytes. + pub const ProxyDepositFactor: Balance = deposit(0, 33); + pub const AnnouncementDepositBase: Balance = deposit(1, 8); + pub const AnnouncementDepositFactor: Balance = deposit(0, 66); +} + +/// The type used to represent the kinds of proxying allowed. +#[derive( + Copy, + Clone, + Eq, + PartialEq, + Ord, + PartialOrd, + Encode, + Decode, + RuntimeDebug, + MaxEncodedLen, + scale_info::TypeInfo, +)] +pub enum ProxyType { + Any, + NonTransfer, + Governance, + Staking, +} + +impl Default for ProxyType { + fn default() -> Self { + Self::Any + } +} + +impl InstanceFilter for ProxyType { + fn filter(&self, c: &RuntimeCall) -> bool { + match self { + ProxyType::Any => true, + ProxyType::NonTransfer => !matches!(c, RuntimeCall::Balances(..)), + ProxyType::Governance => matches!( + c, + RuntimeCall::Democracy(..) + | RuntimeCall::Council(..) + | RuntimeCall::TechnicalCommittee(..) + ), + ProxyType::Staking => matches!(c, RuntimeCall::ParachainStaking(..)), + } + } + fn is_superset(&self, o: &Self) -> bool { + match (self, o) { + (x, y) if x == y => true, + (ProxyType::Any, _) => true, + (_, ProxyType::Any) => false, + (ProxyType::NonTransfer, _) => true, + _ => false, + } + } +} + +impl pallet_proxy::Config for Runtime { + type RuntimeEvent = RuntimeEvent; + type RuntimeCall = RuntimeCall; + type Currency = Balances; + type ProxyType = ProxyType; + type ProxyDepositBase = ProxyDepositBase; + type ProxyDepositFactor = ProxyDepositFactor; + type MaxProxies = ConstU32<32>; + type WeightInfo = (); + type MaxPending = ConstU32<32>; + type CallHasher = BlakeTwo256; + type AnnouncementDepositBase = AnnouncementDepositBase; + type AnnouncementDepositFactor = AnnouncementDepositFactor; +} + parameter_types! { pub NonPausablePallets: Vec> = vec![b"Democracy".to_vec(), b"Balances".to_vec(), b"Council".to_vec(), b"CouncilMembership".to_vec(), b"TechnicalCommittee".to_vec(), b"TechnicalMembership".to_vec()]; } @@ -978,6 +1054,7 @@ construct_runtime!( Multisig: pallet_multisig::{Pallet, Call, Storage, Event} = 41, // Temporary Sudo: pallet_sudo::{Pallet, Call, Config, Storage, Event} = 42, + Proxy: pallet_proxy::{Pallet, Call, Storage, Event} = 43, // Assets management Assets: pallet_assets::{Pallet, Call, Storage, Event} = 45, @@ -1052,6 +1129,7 @@ mod benches { [pallet_timestamp, Timestamp] [pallet_utility, Utility] [pallet_preimage, Preimage] + [pallet_proxy, Proxy] [pallet_treasury, Treasury] [pallet_assets, Assets] [pallet_asset_manager, AssetManager] From 433f681f8d7dc5ee364d29e1b42c8e6e4daeefc7 Mon Sep 17 00:00:00 2001 From: Jamie Date: Fri, 14 Jun 2024 20:20:41 +0800 Subject: [PATCH 2/2] Fix compilation Signed-off-by: Jamie --- runtime/calamari/src/weights/mod.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/runtime/calamari/src/weights/mod.rs b/runtime/calamari/src/weights/mod.rs index ae4b42684..7a16950b2 100644 --- a/runtime/calamari/src/weights/mod.rs +++ b/runtime/calamari/src/weights/mod.rs @@ -35,6 +35,7 @@ pub mod pallet_multisig; pub mod pallet_name_service; pub mod pallet_parachain_staking; pub mod pallet_preimage; +pub mod pallet_proxy; pub mod pallet_randomness; pub mod pallet_scheduler; pub mod pallet_session;