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

Add pallet-proxy to runtimes #1322

Open
wants to merge 3 commits into
base: manta
Choose a base branch
from
Open
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
2 changes: 2 additions & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ pallet-membership = { git = "https://github.com/paritytech/polkadot-sdk", branch
pallet-message-queue = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.6.0", default-features = false }
pallet-multisig = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.6.0", default-features = false }
pallet-preimage = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.6.0", default-features = false }
pallet-proxy = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.6.0", default-features = false }
pallet-ranked-collective = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.6.0", default-features = false }
pallet-referenda = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.6.0", default-features = false }
pallet-scheduler = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.6.0", default-features = false }
Expand Down
4 changes: 4 additions & 0 deletions runtime/calamari/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ pallet-membership = { workspace = true }
pallet-message-queue = { 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 }
Expand Down Expand Up @@ -174,6 +175,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',
Expand Down Expand Up @@ -201,6 +203,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',
Expand Down Expand Up @@ -273,6 +276,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',
Expand Down
104 changes: 97 additions & 7 deletions runtime/calamari/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,11 @@ use sp_runtime::{
create_runtime_str, generic, impl_opaque_keys,
traits::{AccountIdConversion, AccountIdLookup, BlakeTwo256, Block as BlockT, IdentityLookup},
transaction_validity::{TransactionSource, TransactionValidity},
ApplyExtrinsicResult, Perbill, Percent, Permill,
ApplyExtrinsicResult, Perbill, Percent, Permill, RuntimeDebug,
};
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,
Expand All @@ -47,8 +44,8 @@ use frame_support::{
traits::{
fungible::HoldConsideration,
tokens::{PayFromAccount, UnityAssetBalanceConversion},
ConstBool, ConstU128, ConstU32, ConstU8, Contains, Currency, EitherOfDiverse, IsInVec,
LinearStoragePrice, PrivilegeCmp,
ConstBool, ConstU128, ConstU32, ConstU8, Contains, Currency, EitherOfDiverse,
InstanceFilter, IsInVec, LinearStoragePrice, PrivilegeCmp,
},
weights::{ConstantMultiplier, Weight},
PalletId,
Expand All @@ -75,6 +72,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};

use xcm::latest::prelude::*;
Expand Down Expand Up @@ -277,6 +277,7 @@ impl Contains<RuntimeCall> for BaseFilter {

// Explicitly ALLOWED calls
| RuntimeCall::Multisig(_)
| RuntimeCall::Proxy(_)
| RuntimeCall::Democracy(pallet_democracy::Call::vote {..}
| pallet_democracy::Call::emergency_cancel {..}
| pallet_democracy::Call::external_propose {..}
Expand Down Expand Up @@ -375,6 +376,93 @@ 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,
TransferNotDie,
Governance,
Delegation,
}

impl Default for ProxyType {
fn default() -> Self {
Self::Any
}
}

impl InstanceFilter<RuntimeCall> for ProxyType {
fn filter(&self, c: &RuntimeCall) -> bool {
match self {
ProxyType::Any => true,
ProxyType::TransferNotDie => !matches!(
c,
RuntimeCall::Balances(pallet_balances::Call::transfer_allow_death { .. })
), // proxy account cannot transfer all
Comment on lines +419 to +422
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this will allow all calls that are not pallet_balances::Call::transfer_allow_death { .. }, I don't think you can use the !matches pattern for that reason

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unless I'm mistaken but I think we would want a sanity integration test

Copy link
Contributor Author

@Dengjianping Dengjianping Jun 19, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fasle means the call will be filtered, so if it's the transfer_allow_death, !matches will be false. I guess it should be right. I will add a test case for it.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah but any other call will be true, this means that TransferNotDie will allow you to act as a proxy for every other extrinsic except transfer_allow_death

ProxyType::Governance => !matches!(
c,
RuntimeCall::Democracy(..)
| RuntimeCall::TechnicalCommittee(..)
| RuntimeCall::Council(..)
), // we don't allow proxy call in governance
ProxyType::Delegation => matches!(
c,
RuntimeCall::ParachainStaking(pallet_parachain_staking::Call::delegate { .. })
| RuntimeCall::ParachainStaking(
pallet_parachain_staking::Call::schedule_revoke_delegation { .. }
)
| RuntimeCall::ParachainStaking(
pallet_parachain_staking::Call::execute_delegation_request { .. }
)
), // only allow delegation & undelegation in staking
}
}
fn is_superset(&self, o: &Self) -> bool {
match (self, o) {
(x, y) if x == y => true,
(ProxyType::Any, _) => true,
(_, ProxyType::Any) => false,
_ => 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 = weights::pallet_proxy::SubstrateWeight<Runtime>;
type MaxPending = ConstU32<32>;
type CallHasher = BlakeTwo256;
type AnnouncementDepositBase = AnnouncementDepositBase;
type AnnouncementDepositFactor = AnnouncementDepositFactor;
}

parameter_types! {
pub const MinimumPeriod: u64 = SLOT_DURATION / 2;
}
Expand Down Expand Up @@ -1065,6 +1153,7 @@ construct_runtime!(
Utility: pallet_utility::{Pallet, Call, Event} = 40,
Multisig: pallet_multisig::{Pallet, Call, Storage, Event<T>} = 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<T>} = 43,

// Assets management
Assets: pallet_assets::{Pallet, Call, Storage, Event<T>} = 45,
Expand Down Expand Up @@ -1139,6 +1228,7 @@ mod benches {
[pallet_membership, CouncilMembership]
[pallet_treasury, Treasury]
[pallet_preimage, Preimage]
[pallet_proxy, Proxy]
[pallet_scheduler, Scheduler]
[pallet_session, SessionBench::<Runtime>]
[pallet_assets, Assets]
Expand Down
1 change: 1 addition & 0 deletions runtime/calamari/src/weights/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Loading
Loading