From 2655ac600140a372c08c5ef56b1b2a2cf4037c92 Mon Sep 17 00:00:00 2001 From: Deepanshu Hooda <43631678+gitofdeepanshu@users.noreply.github.com> Date: Fri, 2 Jun 2023 13:16:38 +0530 Subject: [PATCH] feat: add pallet proxy to astar (#926) * feat: add pallet proxy to astar * fix merge conflicts * chore: fmt * chore: fmt .toml * add stakerRewardClaim proxy type * fmt * update spec_version and semver * update .toml files * taplo fix * add proxy test * typo fix * fix format * add astar-proxy-tests to integration tests * remove proxy-tests from astar-runtime file * fmt --- Cargo.lock | 9 +- bin/collator/Cargo.toml | 2 +- runtime/astar/Cargo.toml | 6 +- runtime/astar/src/lib.rs | 147 ++++++++++++++++++++++++++++++++- runtime/local/Cargo.toml | 2 +- runtime/shibuya/Cargo.toml | 2 +- tests/integration/src/lib.rs | 2 +- tests/integration/src/proxy.rs | 2 +- tests/integration/src/setup.rs | 2 +- 9 files changed, 161 insertions(+), 13 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 8bf0ea5be..e2a2232c4 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -405,7 +405,7 @@ dependencies = [ [[package]] name = "astar-collator" -version = "5.9.0" +version = "5.10.0" dependencies = [ "astar-runtime", "async-trait", @@ -506,7 +506,7 @@ dependencies = [ [[package]] name = "astar-runtime" -version = "5.9.0" +version = "5.10.0" dependencies = [ "array-bytes 6.1.0", "cumulus-pallet-aura-ext", @@ -559,6 +559,7 @@ dependencies = [ "pallet-identity", "pallet-multisig", "pallet-precompile-dapps-staking", + "pallet-proxy", "pallet-session", "pallet-state-trie-migration", "pallet-sudo", @@ -5270,7 +5271,7 @@ checksum = "ece97ea872ece730aed82664c424eb4c8291e1ff2480247ccf7409044bc6479f" [[package]] name = "local-runtime" -version = "5.9.0" +version = "5.10.0" dependencies = [ "array-bytes 6.1.0", "fp-rpc", @@ -11807,7 +11808,7 @@ dependencies = [ [[package]] name = "shibuya-runtime" -version = "5.9.0" +version = "5.10.0" dependencies = [ "array-bytes 6.1.0", "cumulus-pallet-aura-ext", diff --git a/bin/collator/Cargo.toml b/bin/collator/Cargo.toml index 6c796a93f..dc5e4bf86 100644 --- a/bin/collator/Cargo.toml +++ b/bin/collator/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "astar-collator" -version = "5.9.0" +version = "5.10.0" description = "Astar collator implementation in Rust." build = "build.rs" default-run = "astar-collator" diff --git a/runtime/astar/Cargo.toml b/runtime/astar/Cargo.toml index 0a1f88dc2..18e9f8a23 100644 --- a/runtime/astar/Cargo.toml +++ b/runtime/astar/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "astar-runtime" -version = "5.9.0" +version = "5.10.0" build = "build.rs" authors.workspace = true edition.workspace = true @@ -55,6 +55,7 @@ pallet-evm-precompile-sha3fips = { workspace = true } pallet-evm-precompile-simple = { workspace = true } pallet-identity = { workspace = true } pallet-multisig = { workspace = true } +pallet-proxy = { workspace = true } pallet-session = { workspace = true, features = ["historical"] } pallet-state-trie-migration = { workspace = true } pallet-sudo = { workspace = true } @@ -142,6 +143,7 @@ std = [ "pallet-authorship/std", "pallet-aura/std", "pallet-balances/std", + "pallet-proxy/std", "pallet-block-reward/std", "pallet-custom-signatures/std", "pallet-dapps-staking/std", @@ -206,6 +208,7 @@ runtime-benchmarks = [ 'frame-system/runtime-benchmarks', 'sp-runtime/runtime-benchmarks', 'pallet-balances/runtime-benchmarks', + "pallet-proxy/runtime-benchmarks", 'pallet-timestamp/runtime-benchmarks', 'pallet-collective/runtime-benchmarks', "pallet-ethereum/runtime-benchmarks", @@ -226,6 +229,7 @@ try-runtime = [ "frame-system/try-runtime", "pallet-aura/try-runtime", "pallet-balances/try-runtime", + "pallet-proxy/try-runtime", "pallet-block-reward/try-runtime", "pallet-custom-signatures/try-runtime", "pallet-dapps-staking/try-runtime", diff --git a/runtime/astar/src/lib.rs b/runtime/astar/src/lib.rs index a459faa45..921f804f5 100644 --- a/runtime/astar/src/lib.rs +++ b/runtime/astar/src/lib.rs @@ -28,7 +28,7 @@ use frame_support::{ parameter_types, traits::{ AsEnsureOriginWithArg, ConstBool, ConstU32, Contains, Currency, FindAuthor, Get, Imbalance, - Nothing, OnUnbalanced, Randomness, WithdrawReasons, + InstanceFilter, Nothing, OnUnbalanced, Randomness, WithdrawReasons, }, weights::{ constants::{ @@ -139,7 +139,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion { spec_name: create_runtime_str!("astar"), impl_name: create_runtime_str!("astar"), authoring_version: 1, - spec_version: 59, + spec_version: 60, impl_version: 0, apis: RUNTIME_API_VERSIONS, transaction_version: 2, @@ -869,6 +869,148 @@ impl pallet_state_trie_migration::Config for Runtime { type WeightInfo = pallet_state_trie_migration::weights::SubstrateWeight; type MaxKeyLen = ConstU32<512>; } +/// 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 { + /// Allows all runtime calls for proxy account + Any, + /// Allows only NonTransfer runtime calls for proxy account + /// To know exact calls check InstanceFilter inmplementation for ProxyTypes + NonTransfer, + /// All Runtime calls from Pallet Balances allowed for proxy account + Balances, + /// All Runtime calls from Pallet Assets allowed for proxy account + Assets, + /// Only provide_judgement call from pallet identity allowed for proxy account + IdentityJudgement, + /// Only reject_announcement call from pallet proxy allowed for proxy account + CancelProxy, + /// All runtime calls from pallet DappStaking allowed for proxy account + DappsStaking, + /// Only claim_staker call from pallet DappStaking allowed for proxy account + StakerRewardClaim, +} + +impl Default for ProxyType { + fn default() -> Self { + Self::Any + } +} + +impl InstanceFilter for ProxyType { + fn filter(&self, c: &RuntimeCall) -> bool { + match self { + // Always allowed RuntimeCall::Utility no matter type. + // Only transactions allowed by Proxy.filter can be executed + _ if matches!(c, RuntimeCall::Utility(..)) => true, + ProxyType::Any => true, + ProxyType::NonTransfer => { + matches!( + c, + RuntimeCall::System(..) + | RuntimeCall::Identity(..) + | RuntimeCall::Timestamp(..) + | RuntimeCall::Multisig(..) + | RuntimeCall::Proxy(..) + | RuntimeCall::ParachainSystem(..) + | RuntimeCall::ParachainInfo(..) + // Skip entire Balances pallet + | RuntimeCall::Vesting(pallet_vesting::Call::vest{..}) + | RuntimeCall::Vesting(pallet_vesting::Call::vest_other{..}) + // Specifically omitting Vesting `vested_transfer`, and `force_vested_transfer` + | RuntimeCall::DappsStaking(..) + // Skip entire Assets pallet + | RuntimeCall::CollatorSelection(..) + | RuntimeCall::Session(..) + | RuntimeCall::XcmpQueue(..) + | RuntimeCall::PolkadotXcm(..) + | RuntimeCall::CumulusXcm(..) + | RuntimeCall::DmpQueue(..) + | RuntimeCall::XcAssetConfig(..) + // Skip entire EVM pallet + // Skip entire Ethereum pallet + // Skip entire EthCall pallet + | RuntimeCall::BaseFee(..) // Skip entire Contracts pallet + ) + } + ProxyType::Balances => { + matches!(c, RuntimeCall::Balances(..)) + } + ProxyType::Assets => { + matches!(c, RuntimeCall::Assets(..)) + } + ProxyType::IdentityJudgement => { + matches!( + c, + RuntimeCall::Identity(pallet_identity::Call::provide_judgement { .. }) + ) + } + ProxyType::CancelProxy => { + matches!( + c, + RuntimeCall::Proxy(pallet_proxy::Call::reject_announcement { .. }) + ) + } + ProxyType::DappsStaking => { + matches!(c, RuntimeCall::DappsStaking(..)) + } + ProxyType::StakerRewardClaim => { + matches!( + c, + RuntimeCall::DappsStaking(pallet_dapps_staking::Call::claim_staker { .. }) + ) + } + } + } + + fn is_superset(&self, o: &Self) -> bool { + match (self, o) { + (x, y) if x == y => true, + (ProxyType::Any, _) => true, + (_, ProxyType::Any) => false, + (ProxyType::DappsStaking, ProxyType::StakerRewardClaim) => true, + _ => false, + } + } +} + +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 MaxProxies: u16 = 32; + pub const MaxPending: u16 = 32; + pub const AnnouncementDepositBase: Balance = deposit(1, 8); + pub const AnnouncementDepositFactor: Balance = deposit(0, 66); +} + +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 = MaxProxies; + type WeightInfo = pallet_proxy::weights::SubstrateWeight; + type MaxPending = MaxPending; + type CallHasher = BlakeTwo256; + type AnnouncementDepositBase = AnnouncementDepositBase; + type AnnouncementDepositFactor = AnnouncementDepositFactor; +} construct_runtime!( pub struct Runtime where @@ -881,6 +1023,7 @@ construct_runtime!( Identity: pallet_identity = 12, Timestamp: pallet_timestamp = 13, Multisig: pallet_multisig = 14, + Proxy: pallet_proxy = 15, ParachainSystem: cumulus_pallet_parachain_system = 20, ParachainInfo: parachain_info = 21, diff --git a/runtime/local/Cargo.toml b/runtime/local/Cargo.toml index 286273822..36addaecc 100644 --- a/runtime/local/Cargo.toml +++ b/runtime/local/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "local-runtime" -version = "5.9.0" +version = "5.10.0" build = "build.rs" authors.workspace = true edition.workspace = true diff --git a/runtime/shibuya/Cargo.toml b/runtime/shibuya/Cargo.toml index a1639e94e..6186dd086 100644 --- a/runtime/shibuya/Cargo.toml +++ b/runtime/shibuya/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "shibuya-runtime" -version = "5.9.0" +version = "5.10.0" build = "build.rs" authors.workspace = true edition.workspace = true diff --git a/tests/integration/src/lib.rs b/tests/integration/src/lib.rs index e2c677cd3..875704333 100644 --- a/tests/integration/src/lib.rs +++ b/tests/integration/src/lib.rs @@ -23,5 +23,5 @@ #[cfg(any(feature = "shibuya", feature = "shiden", feature = "astar"))] mod setup; -#[cfg(any(feature = "shibuya", feature = "shiden"))] +#[cfg(any(feature = "shibuya", feature = "shiden", feature = "astar"))] mod proxy; diff --git a/tests/integration/src/proxy.rs b/tests/integration/src/proxy.rs index a59289593..41fc24737 100644 --- a/tests/integration/src/proxy.rs +++ b/tests/integration/src/proxy.rs @@ -196,7 +196,7 @@ fn test_staker_reward_claim_proxy_works() { assert_ok!(DappsStaking::bond_and_stake( RuntimeOrigin::signed(BOB), contract.clone(), - 100 * UNIT + 600 * UNIT )); run_to_block(10); diff --git a/tests/integration/src/setup.rs b/tests/integration/src/setup.rs index 8510d70cf..4ec548885 100644 --- a/tests/integration/src/setup.rs +++ b/tests/integration/src/setup.rs @@ -135,7 +135,7 @@ pub fn run_to_block(n: u32) { AuraExt::on_initialize(block_number); Ethereum::on_initialize(block_number); BaseFee::on_initialize(block_number); - #[cfg(any(feature = "shibuya", feature = "shiden"))] + #[cfg(any(feature = "shibuya", feature = "shiden", features = "astar"))] RandomnessCollectiveFlip::on_initialize(block_number); StateTrieMigration::on_initialize(block_number);