From 563908ac21b37794ed65dec4c7b65ecbaa567a3b Mon Sep 17 00:00:00 2001 From: Cameron Fairchild Date: Fri, 22 Mar 2024 23:37:44 -0400 Subject: [PATCH 01/14] add proxy pallet --- Cargo.lock | 16 ++++++++++++++++ pallets/subtensor/Cargo.toml | 2 ++ runtime/Cargo.toml | 3 +++ 3 files changed, 21 insertions(+) diff --git a/Cargo.lock b/Cargo.lock index 77ba885b1..7065359ba 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4231,6 +4231,7 @@ dependencies = [ "pallet-membership", "pallet-multisig", "pallet-preimage", + "pallet-proxy", "pallet-registry", "pallet-scheduler", "pallet-subtensor", @@ -4637,6 +4638,20 @@ dependencies = [ "sp-std", ] +[[package]] +name = "pallet-proxy" +version = "4.0.0-dev" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.39#8c4b84520cee2d7de53cc33cb67605ce4efefba8" +dependencies = [ + "frame-support", + "frame-system", + "parity-scale-codec", + "scale-info", + "sp-io", + "sp-runtime", + "sp-std", +] + [[package]] name = "pallet-registry" version = "4.0.0-dev" @@ -4705,6 +4720,7 @@ dependencies = [ "pallet-balances", "pallet-collective", "pallet-membership", + "pallet-proxy", "pallet-transaction-payment", "pallet-utility", "parity-scale-codec", diff --git a/pallets/subtensor/Cargo.toml b/pallets/subtensor/Cargo.toml index 536db9ed5..328229753 100644 --- a/pallets/subtensor/Cargo.toml +++ b/pallets/subtensor/Cargo.toml @@ -47,6 +47,8 @@ pallet-collective = { version = "4.0.0-dev", default-features = false, path = ". pallet-membership = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.39" } hex-literal = "0.4.1" +pallet-proxy = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.39" } + [dev-dependencies] pallet-balances = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.39", features = [ "std", diff --git a/runtime/Cargo.toml b/runtime/Cargo.toml index 919e64fb2..01928d4d8 100644 --- a/runtime/Cargo.toml +++ b/runtime/Cargo.toml @@ -60,6 +60,9 @@ pallet-membership = { version = "4.0.0-dev", default-features = false, git = "ht # Multisig pallet-multisig = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.39" } +# Proxy Pallet +pallet-proxy = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.39" } + # Scheduler pallet pallet-scheduler = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.39" } pallet-preimage = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.39" } From 71dae03d5fd717dc5b309123d31d1bbd5bf32ee6 Mon Sep 17 00:00:00 2001 From: Cameron Fairchild Date: Sat, 23 Mar 2024 00:37:27 -0400 Subject: [PATCH 02/14] add pallet imports and config --- Cargo.lock | 1 + runtime/Cargo.toml | 2 + runtime/src/lib.rs | 112 ++++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 114 insertions(+), 1 deletion(-) diff --git a/Cargo.lock b/Cargo.lock index 7065359ba..e73e2bd68 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4643,6 +4643,7 @@ name = "pallet-proxy" version = "4.0.0-dev" source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.39#8c4b84520cee2d7de53cc33cb67605ce4efefba8" dependencies = [ + "frame-benchmarking", "frame-support", "frame-system", "parity-scale-codec", diff --git a/runtime/Cargo.toml b/runtime/Cargo.toml index 01928d4d8..1bd12c1ba 100644 --- a/runtime/Cargo.toml +++ b/runtime/Cargo.toml @@ -109,6 +109,7 @@ std = [ "pallet-utility/std", "pallet-sudo/std", "pallet-multisig/std", + "pallet-proxy/std", "pallet-scheduler/std", "pallet-preimage/std", "pallet-commitments/std", @@ -162,6 +163,7 @@ try-runtime = [ "pallet-subtensor/try-runtime", "pallet-collective/try-runtime", "pallet-membership/try-runtime", + "pallet-proxy/std", "pallet-multisig/try-runtime", "pallet-scheduler/try-runtime", "pallet-preimage/try-runtime", diff --git a/runtime/src/lib.rs b/runtime/src/lib.rs index 26d71cd0c..136670543 100644 --- a/runtime/src/lib.rs +++ b/runtime/src/lib.rs @@ -40,7 +40,9 @@ use sp_version::RuntimeVersion; pub use frame_support::{ construct_runtime, parameter_types, traits::{ - ConstU128, ConstU32, ConstU64, ConstU8, KeyOwnerProofSystem, PrivilegeCmp, Randomness, + ConstU128, ConstU32, ConstU64, ConstU8, KeyOwnerProofSystem, + InstanceFilter, + PrivilegeCmp, Randomness, StorageInfo, }, weights::{ @@ -491,6 +493,113 @@ impl pallet_multisig::Config for Runtime { type WeightInfo = pallet_multisig::weights::SubstrateWeight; } +///f Proxy Pallet config +parameter_types! { + // One storage item; key size sizeof(AccountId) = 32, value sizeof(Balance) = 8; 40 total + pub const ProxyDepositBase = (1) as Balance * 2_000 * 10_000 + (40 as Balance) * 100 * 10_000; + // Adding 32 bytes + sizeof(ProxyType) = 32 + 1 + pub const ProxyDepositFactor = (0) as Balance * 2_000 * 10_000 + (33 as Balance) * 100 * 10_000; + pub const MaxProxies: u32 = 20; // max num proxies per acct + pub const MaxPending: u32 = 15 * 5; // max blocks pending ~15min + // 16 bytes + pub const AnnouncementDepositBase = (1) as Balance * 2_000 * 10_000 + (16 as Balance) * 100 * 10_000; + // 68 bytes per announcement + pub const AnnouncementDepositFactor = (0) as Balance * 2_000 * 10_000 + (68 as Balance) * 100 * 10_000; +} + +#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Encode, Decode, RuntimeDebug)] +pub enum ProxyType { + Any, + Owner, // Subnet owner Calls + NonCritical, + NonTransfer, + Senate, + NonFungibile, // Nothing involving moving TAO + Triumvirate, + Governance, // Both above governance + Staking, + Registration, +} +impl Default for ProxyType { fn default() -> Self { Self::Any } } // allow all Calls; required to be most permissive +impl InstanceFilter for ProxyType { + fn filter(&self, c: &Call) -> bool { + match self { + ProxyType::Any => true, + ProxyType::NonTransfer => !matches!( + c, + Call::Balances(..) + ), + ProxyType::NonFungibile => !matches!( + c, + Call::Balances(..) | + Call::SubtensorModule(pallet_subtensor::Call::add_stake(..)) | + Call::SubtensorModule(pallet_subtensor::Call::remove_stake(..)) | + Call::SubtensorModule(pallet_subtensor::Call::burned_register(..)) | + Call::SubtensorModule(pallet_subtensor::Call::root_register(..)) + ), + ProxyType::Owner => matches!( + c, + Call::AdminUtils(..) + ), + ProxyType::NonCritical => !matches!( + c, + Call::SubtensorModule(pallet_subtensor::Call::dissolve_network(..)) | + Call::SubtensorModule(pallet_subtensor::Call::root_register(..)) | + Call::SubtensorModule(pallet_subtensor::Call::burned_register(..)) | + Call::Collective(..) + ), + ProxyType::Triumvirate => matches!( + c, + Call::Collective(..) + ), + ProxyType::Senate => matches!( + c, + Call::Democracy(..) + ), + ProxyType::Governance => matches!( + c, + Call::Democracy(..) | + Call::Collective(..) + ), + ProxyType::Staking => matches!( + c, + Call::SubtensorModule(pallet_subtensor::Call::add_stake(..)) | + Call::SubtensorModule(pallet_subtensor::Call::remove_stake(..)) + ), + ProxyType::Registration => matches!( + c, + Call::SubtensorModule(pallet_subtensor::Call::burned_register(..)) | + Call::SubtensorModule(pallet_subtensor::Call::register(..)) + ), + } + } + 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 = MaxProxies; + type WeightInfo = pallet_proxy::weights::SubstrateWeight; + type MaxPending = MaxPending; + type CallHasher = Hash; + type AnnouncementDepositBase = AnnouncementDepositBase; + type AnnouncementDepositFactor = AnnouncementDepositFactor; +} + + parameter_types! { pub MaximumSchedulerWeight: Weight = Perbill::from_percent(80) * BlockWeights::get().max_block; @@ -993,6 +1102,7 @@ construct_runtime!( Utility: pallet_utility, Sudo: pallet_sudo, Multisig: pallet_multisig, + Proxy: pallet_proxy::{Pallet, Call, Storage, Event}, Preimage: pallet_preimage, Scheduler: pallet_scheduler, Registry: pallet_registry, From bbbede67775c97701402f64f539f1cb575a17260 Mon Sep 17 00:00:00 2001 From: Cameron Fairchild Date: Sat, 23 Mar 2024 01:20:28 -0400 Subject: [PATCH 03/14] fix types --- runtime/src/lib.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/runtime/src/lib.rs b/runtime/src/lib.rs index 136670543..b4d47563d 100644 --- a/runtime/src/lib.rs +++ b/runtime/src/lib.rs @@ -496,15 +496,15 @@ impl pallet_multisig::Config for Runtime { ///f Proxy Pallet config parameter_types! { // One storage item; key size sizeof(AccountId) = 32, value sizeof(Balance) = 8; 40 total - pub const ProxyDepositBase = (1) as Balance * 2_000 * 10_000 + (40 as Balance) * 100 * 10_000; + pub const ProxyDepositBase: Balance = (1) as Balance * 2_000 * 10_000 + (40 as Balance) * 100 * 10_000; // Adding 32 bytes + sizeof(ProxyType) = 32 + 1 - pub const ProxyDepositFactor = (0) as Balance * 2_000 * 10_000 + (33 as Balance) * 100 * 10_000; + pub const ProxyDepositFactor: Balance = (0) as Balance * 2_000 * 10_000 + (33 as Balance) * 100 * 10_000; pub const MaxProxies: u32 = 20; // max num proxies per acct pub const MaxPending: u32 = 15 * 5; // max blocks pending ~15min // 16 bytes - pub const AnnouncementDepositBase = (1) as Balance * 2_000 * 10_000 + (16 as Balance) * 100 * 10_000; + pub const AnnouncementDepositBase: Balance = (1) as Balance * 2_000 * 10_000 + (16 as Balance) * 100 * 10_000; // 68 bytes per announcement - pub const AnnouncementDepositFactor = (0) as Balance * 2_000 * 10_000 + (68 as Balance) * 100 * 10_000; + pub const AnnouncementDepositFactor: Balance = (0) as Balance * 2_000 * 10_000 + (68 as Balance) * 100 * 10_000; } #[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Encode, Decode, RuntimeDebug)] From 43bff65ac14ca50406dab6dd65ec05e6c67a0557 Mon Sep 17 00:00:00 2001 From: Cameron Fairchild Date: Sat, 23 Mar 2024 01:34:35 -0400 Subject: [PATCH 04/14] fix feature flag --- runtime/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/runtime/Cargo.toml b/runtime/Cargo.toml index 1bd12c1ba..57ca0789a 100644 --- a/runtime/Cargo.toml +++ b/runtime/Cargo.toml @@ -163,7 +163,7 @@ try-runtime = [ "pallet-subtensor/try-runtime", "pallet-collective/try-runtime", "pallet-membership/try-runtime", - "pallet-proxy/std", + "pallet-proxy/try-runtime", "pallet-multisig/try-runtime", "pallet-scheduler/try-runtime", "pallet-preimage/try-runtime", From 3c00ccc8c2b1c74558b20dfd0800f6796c9f6e6a Mon Sep 17 00:00:00 2001 From: Cameron Fairchild Date: Sat, 23 Mar 2024 01:34:50 -0400 Subject: [PATCH 05/14] fix imports --- runtime/src/lib.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/runtime/src/lib.rs b/runtime/src/lib.rs index b4d47563d..07b0a0b6d 100644 --- a/runtime/src/lib.rs +++ b/runtime/src/lib.rs @@ -6,7 +6,7 @@ #[cfg(feature = "std")] include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs")); -use codec::Encode; +use codec::{Encode, Decode}; use pallet_commitments::CanCommit; use pallet_grandpa::{ @@ -39,6 +39,7 @@ use sp_version::RuntimeVersion; // A few exports that help ease life for downstream crates. pub use frame_support::{ construct_runtime, parameter_types, + RuntimeDebug, traits::{ ConstU128, ConstU32, ConstU64, ConstU8, KeyOwnerProofSystem, InstanceFilter, @@ -493,7 +494,7 @@ impl pallet_multisig::Config for Runtime { type WeightInfo = pallet_multisig::weights::SubstrateWeight; } -///f Proxy Pallet config +// Proxy Pallet config parameter_types! { // One storage item; key size sizeof(AccountId) = 32, value sizeof(Balance) = 8; 40 total pub const ProxyDepositBase: Balance = (1) as Balance * 2_000 * 10_000 + (40 as Balance) * 100 * 10_000; From 305f31a8761a5826be7df2811e59abddcb9de873 Mon Sep 17 00:00:00 2001 From: Cameron Fairchild Date: Sat, 23 Mar 2024 01:51:03 -0400 Subject: [PATCH 06/14] update toml --- Cargo.lock | 1 - pallets/subtensor/Cargo.toml | 2 -- runtime/Cargo.toml | 1 + 3 files changed, 1 insertion(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index e73e2bd68..34aa5a7f3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4721,7 +4721,6 @@ dependencies = [ "pallet-balances", "pallet-collective", "pallet-membership", - "pallet-proxy", "pallet-transaction-payment", "pallet-utility", "parity-scale-codec", diff --git a/pallets/subtensor/Cargo.toml b/pallets/subtensor/Cargo.toml index 328229753..536db9ed5 100644 --- a/pallets/subtensor/Cargo.toml +++ b/pallets/subtensor/Cargo.toml @@ -47,8 +47,6 @@ pallet-collective = { version = "4.0.0-dev", default-features = false, path = ". pallet-membership = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.39" } hex-literal = "0.4.1" -pallet-proxy = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.39" } - [dev-dependencies] pallet-balances = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.39", features = [ "std", diff --git a/runtime/Cargo.toml b/runtime/Cargo.toml index 57ca0789a..922274610 100644 --- a/runtime/Cargo.toml +++ b/runtime/Cargo.toml @@ -143,6 +143,7 @@ runtime-benchmarks = [ "pallet-subtensor/runtime-benchmarks", "pallet-collective/runtime-benchmarks", "pallet-membership/runtime-benchmarks", + "pallet-proxy/runtime-benchmarks", "pallet-registry/runtime-benchmarks", "pallet-commitments/runtime-benchmarks", "pallet-admin-utils/runtime-benchmarks", From 23707290076c2edcecbc31ac90a68543a665c8ee Mon Sep 17 00:00:00 2001 From: Cameron Fairchild Date: Sat, 23 Mar 2024 03:23:19 -0400 Subject: [PATCH 07/14] fix impl generation --- runtime/src/lib.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/runtime/src/lib.rs b/runtime/src/lib.rs index 07b0a0b6d..7a7f0d0d1 100644 --- a/runtime/src/lib.rs +++ b/runtime/src/lib.rs @@ -6,7 +6,7 @@ #[cfg(feature = "std")] include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs")); -use codec::{Encode, Decode}; +use codec::{Decode, Encode, MaxEncodedLen}; use pallet_commitments::CanCommit; use pallet_grandpa::{ @@ -17,6 +17,7 @@ use frame_support::pallet_prelude::{DispatchError, DispatchResult, Get}; use frame_system::{EnsureNever, EnsureRoot, RawOrigin}; use pallet_registry::CanRegisterIdentity; +use scale_info::TypeInfo; use smallvec::smallvec; use sp_api::impl_runtime_apis; use sp_consensus_aura::sr25519::AuthorityId as AuraId; @@ -508,7 +509,7 @@ parameter_types! { pub const AnnouncementDepositFactor: Balance = (0) as Balance * 2_000 * 10_000 + (68 as Balance) * 100 * 10_000; } -#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Encode, Decode, RuntimeDebug)] +#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Encode, Decode, RuntimeDebug, MaxEncodedLen, TypeInfo)] pub enum ProxyType { Any, Owner, // Subnet owner Calls From 377da13d8bb57ec7a7c3f6e7d9a65d349b1ad371 Mon Sep 17 00:00:00 2001 From: Cameron Fairchild Date: Sat, 23 Mar 2024 03:24:31 -0400 Subject: [PATCH 08/14] change import --- runtime/src/lib.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/runtime/src/lib.rs b/runtime/src/lib.rs index 7a7f0d0d1..a0f3c09e7 100644 --- a/runtime/src/lib.rs +++ b/runtime/src/lib.rs @@ -1107,6 +1107,7 @@ construct_runtime!( Proxy: pallet_proxy::{Pallet, Call, Storage, Event}, Preimage: pallet_preimage, Scheduler: pallet_scheduler, + Proxy: pallet_proxy, Registry: pallet_registry, Commitments: pallet_commitments, AdminUtils: pallet_admin_utils From 60377402e1f921472b249e1816703101641dfa33 Mon Sep 17 00:00:00 2001 From: Cameron Fairchild Date: Sat, 23 Mar 2024 03:24:45 -0400 Subject: [PATCH 09/14] fix matching --- runtime/src/lib.rs | 47 +++++++++++++++++++++++----------------------- 1 file changed, 24 insertions(+), 23 deletions(-) diff --git a/runtime/src/lib.rs b/runtime/src/lib.rs index a0f3c09e7..e314f708a 100644 --- a/runtime/src/lib.rs +++ b/runtime/src/lib.rs @@ -523,55 +523,57 @@ pub enum ProxyType { Registration, } impl Default for ProxyType { fn default() -> Self { Self::Any } } // allow all Calls; required to be most permissive -impl InstanceFilter for ProxyType { - fn filter(&self, c: &Call) -> bool { +impl InstanceFilter for ProxyType { + fn filter(&self, c: &RuntimeCall) -> bool { match self { ProxyType::Any => true, ProxyType::NonTransfer => !matches!( c, - Call::Balances(..) + RuntimeCall::Balances(..) ), ProxyType::NonFungibile => !matches!( c, - Call::Balances(..) | - Call::SubtensorModule(pallet_subtensor::Call::add_stake(..)) | - Call::SubtensorModule(pallet_subtensor::Call::remove_stake(..)) | - Call::SubtensorModule(pallet_subtensor::Call::burned_register(..)) | - Call::SubtensorModule(pallet_subtensor::Call::root_register(..)) + RuntimeCall::Balances(..) | + RuntimeCall::SubtensorModule(pallet_subtensor::Call::add_stake {..}) | + RuntimeCall::SubtensorModule(pallet_subtensor::Call::remove_stake {..}) | + RuntimeCall::SubtensorModule(pallet_subtensor::Call::burned_register {..}) | + RuntimeCall::SubtensorModule(pallet_subtensor::Call::root_register {..}) ), ProxyType::Owner => matches!( c, - Call::AdminUtils(..) + RuntimeCall::AdminUtils(..) ), ProxyType::NonCritical => !matches!( c, - Call::SubtensorModule(pallet_subtensor::Call::dissolve_network(..)) | - Call::SubtensorModule(pallet_subtensor::Call::root_register(..)) | - Call::SubtensorModule(pallet_subtensor::Call::burned_register(..)) | - Call::Collective(..) + RuntimeCall::SubtensorModule(pallet_subtensor::Call::dissolve_network {..}) | + RuntimeCall::SubtensorModule(pallet_subtensor::Call::root_register {..}) | + RuntimeCall::SubtensorModule(pallet_subtensor::Call::burned_register {..}) | + RuntimeCall::Triumvirate(..) ), ProxyType::Triumvirate => matches!( c, - Call::Collective(..) + RuntimeCall::Triumvirate(..) | + RuntimeCall::TriumvirateMembers(..) ), ProxyType::Senate => matches!( c, - Call::Democracy(..) + RuntimeCall::SenateMembers(..) ), ProxyType::Governance => matches!( c, - Call::Democracy(..) | - Call::Collective(..) + RuntimeCall::SenateMembers(..) | + RuntimeCall::Triumvirate(..) | + RuntimeCall::TriumvirateMembers(..) ), ProxyType::Staking => matches!( c, - Call::SubtensorModule(pallet_subtensor::Call::add_stake(..)) | - Call::SubtensorModule(pallet_subtensor::Call::remove_stake(..)) + RuntimeCall::SubtensorModule(pallet_subtensor::Call::add_stake {..}) | + RuntimeCall::SubtensorModule(pallet_subtensor::Call::remove_stake {..}) ), ProxyType::Registration => matches!( c, - Call::SubtensorModule(pallet_subtensor::Call::burned_register(..)) | - Call::SubtensorModule(pallet_subtensor::Call::register(..)) + RuntimeCall::SubtensorModule(pallet_subtensor::Call::burned_register {..}) | + RuntimeCall::SubtensorModule(pallet_subtensor::Call::register {..}) ), } } @@ -596,7 +598,7 @@ impl pallet_proxy::Config for Runtime { type MaxProxies = MaxProxies; type WeightInfo = pallet_proxy::weights::SubstrateWeight; type MaxPending = MaxPending; - type CallHasher = Hash; + type CallHasher = BlakeTwo256; type AnnouncementDepositBase = AnnouncementDepositBase; type AnnouncementDepositFactor = AnnouncementDepositFactor; } @@ -1104,7 +1106,6 @@ construct_runtime!( Utility: pallet_utility, Sudo: pallet_sudo, Multisig: pallet_multisig, - Proxy: pallet_proxy::{Pallet, Call, Storage, Event}, Preimage: pallet_preimage, Scheduler: pallet_scheduler, Proxy: pallet_proxy, From ddae821e0e0d4a92c05abc5386fd3096e4238dd2 Mon Sep 17 00:00:00 2001 From: Cameron Fairchild Date: Mon, 25 Mar 2024 20:01:17 -0400 Subject: [PATCH 10/14] fmt --- runtime/src/lib.rs | 210 +++++++++++++++++++++++---------------------- 1 file changed, 106 insertions(+), 104 deletions(-) diff --git a/runtime/src/lib.rs b/runtime/src/lib.rs index e314f708a..e57ce1161 100644 --- a/runtime/src/lib.rs +++ b/runtime/src/lib.rs @@ -40,12 +40,9 @@ use sp_version::RuntimeVersion; // A few exports that help ease life for downstream crates. pub use frame_support::{ construct_runtime, parameter_types, - RuntimeDebug, traits::{ - ConstU128, ConstU32, ConstU64, ConstU8, KeyOwnerProofSystem, - InstanceFilter, - PrivilegeCmp, Randomness, - StorageInfo, + ConstU128, ConstU32, ConstU64, ConstU8, InstanceFilter, KeyOwnerProofSystem, PrivilegeCmp, + Randomness, StorageInfo, }, weights::{ constants::{ @@ -54,7 +51,7 @@ pub use frame_support::{ IdentityFee, Weight, WeightToFeeCoefficient, WeightToFeeCoefficients, WeightToFeePolynomial, }, - StorageValue, + RuntimeDebug, StorageValue, }; pub use frame_system::Call as SystemCall; pub use pallet_balances::Call as BalancesCall; @@ -497,113 +494,118 @@ impl pallet_multisig::Config for Runtime { // Proxy Pallet config parameter_types! { - // One storage item; key size sizeof(AccountId) = 32, value sizeof(Balance) = 8; 40 total - pub const ProxyDepositBase: Balance = (1) as Balance * 2_000 * 10_000 + (40 as Balance) * 100 * 10_000; - // Adding 32 bytes + sizeof(ProxyType) = 32 + 1 - pub const ProxyDepositFactor: Balance = (0) as Balance * 2_000 * 10_000 + (33 as Balance) * 100 * 10_000; - pub const MaxProxies: u32 = 20; // max num proxies per acct - pub const MaxPending: u32 = 15 * 5; // max blocks pending ~15min - // 16 bytes - pub const AnnouncementDepositBase: Balance = (1) as Balance * 2_000 * 10_000 + (16 as Balance) * 100 * 10_000; - // 68 bytes per announcement - pub const AnnouncementDepositFactor: Balance = (0) as Balance * 2_000 * 10_000 + (68 as Balance) * 100 * 10_000; + // One storage item; key size sizeof(AccountId) = 32, value sizeof(Balance) = 8; 40 total + pub const ProxyDepositBase: Balance = (1) as Balance * 2_000 * 10_000 + (40 as Balance) * 100 * 10_000; + // Adding 32 bytes + sizeof(ProxyType) = 32 + 1 + pub const ProxyDepositFactor: Balance = (0) as Balance * 2_000 * 10_000 + (33 as Balance) * 100 * 10_000; + pub const MaxProxies: u32 = 20; // max num proxies per acct + pub const MaxPending: u32 = 15 * 5; // max blocks pending ~15min + // 16 bytes + pub const AnnouncementDepositBase: Balance = (1) as Balance * 2_000 * 10_000 + (16 as Balance) * 100 * 10_000; + // 68 bytes per announcement + pub const AnnouncementDepositFactor: Balance = (0) as Balance * 2_000 * 10_000 + (68 as Balance) * 100 * 10_000; } -#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Encode, Decode, RuntimeDebug, MaxEncodedLen, TypeInfo)] +#[derive( + Copy, + Clone, + Eq, + PartialEq, + Ord, + PartialOrd, + Encode, + Decode, + RuntimeDebug, + MaxEncodedLen, + TypeInfo, +)] pub enum ProxyType { - Any, - Owner, // Subnet owner Calls - NonCritical, - NonTransfer, - Senate, - NonFungibile, // Nothing involving moving TAO - Triumvirate, - Governance, // Both above governance - Staking, - Registration, + Any, + Owner, // Subnet owner Calls + NonCritical, + NonTransfer, + Senate, + NonFungibile, // Nothing involving moving TAO + Triumvirate, + Governance, // Both above governance + Staking, + Registration, } -impl Default for ProxyType { fn default() -> Self { Self::Any } } // allow all Calls; required to be most permissive +impl Default for ProxyType { + fn default() -> Self { + Self::Any + } +} // allow all Calls; required to be most permissive impl InstanceFilter for ProxyType { - fn filter(&self, c: &RuntimeCall) -> bool { - match self { - ProxyType::Any => true, - ProxyType::NonTransfer => !matches!( - c, - RuntimeCall::Balances(..) - ), - ProxyType::NonFungibile => !matches!( - c, - RuntimeCall::Balances(..) | - RuntimeCall::SubtensorModule(pallet_subtensor::Call::add_stake {..}) | - RuntimeCall::SubtensorModule(pallet_subtensor::Call::remove_stake {..}) | - RuntimeCall::SubtensorModule(pallet_subtensor::Call::burned_register {..}) | - RuntimeCall::SubtensorModule(pallet_subtensor::Call::root_register {..}) - ), - ProxyType::Owner => matches!( - c, - RuntimeCall::AdminUtils(..) - ), - ProxyType::NonCritical => !matches!( - c, - RuntimeCall::SubtensorModule(pallet_subtensor::Call::dissolve_network {..}) | - RuntimeCall::SubtensorModule(pallet_subtensor::Call::root_register {..}) | - RuntimeCall::SubtensorModule(pallet_subtensor::Call::burned_register {..}) | - RuntimeCall::Triumvirate(..) - ), - ProxyType::Triumvirate => matches!( - c, - RuntimeCall::Triumvirate(..) | - RuntimeCall::TriumvirateMembers(..) - ), - ProxyType::Senate => matches!( - c, - RuntimeCall::SenateMembers(..) - ), - ProxyType::Governance => matches!( - c, - RuntimeCall::SenateMembers(..) | - RuntimeCall::Triumvirate(..) | - RuntimeCall::TriumvirateMembers(..) - ), - ProxyType::Staking => matches!( - c, - RuntimeCall::SubtensorModule(pallet_subtensor::Call::add_stake {..}) | - RuntimeCall::SubtensorModule(pallet_subtensor::Call::remove_stake {..}) - ), - ProxyType::Registration => matches!( - c, - RuntimeCall::SubtensorModule(pallet_subtensor::Call::burned_register {..}) | - RuntimeCall::SubtensorModule(pallet_subtensor::Call::register {..}) - ), - } - } - 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, - } - } + fn filter(&self, c: &RuntimeCall) -> bool { + match self { + ProxyType::Any => true, + ProxyType::NonTransfer => !matches!(c, RuntimeCall::Balances(..)), + ProxyType::NonFungibile => !matches!( + c, + RuntimeCall::Balances(..) + | RuntimeCall::SubtensorModule(pallet_subtensor::Call::add_stake { .. }) + | RuntimeCall::SubtensorModule(pallet_subtensor::Call::remove_stake { .. }) + | RuntimeCall::SubtensorModule(pallet_subtensor::Call::burned_register { .. }) + | RuntimeCall::SubtensorModule(pallet_subtensor::Call::root_register { .. }) + ), + ProxyType::Owner => matches!(c, RuntimeCall::AdminUtils(..)), + ProxyType::NonCritical => !matches!( + c, + RuntimeCall::SubtensorModule(pallet_subtensor::Call::dissolve_network { .. }) + | RuntimeCall::SubtensorModule(pallet_subtensor::Call::root_register { .. }) + | RuntimeCall::SubtensorModule(pallet_subtensor::Call::burned_register { .. }) + | RuntimeCall::Triumvirate(..) + ), + ProxyType::Triumvirate => matches!( + c, + RuntimeCall::Triumvirate(..) | RuntimeCall::TriumvirateMembers(..) + ), + ProxyType::Senate => matches!(c, RuntimeCall::SenateMembers(..)), + ProxyType::Governance => matches!( + c, + RuntimeCall::SenateMembers(..) + | RuntimeCall::Triumvirate(..) + | RuntimeCall::TriumvirateMembers(..) + ), + ProxyType::Staking => matches!( + c, + RuntimeCall::SubtensorModule(pallet_subtensor::Call::add_stake { .. }) + | RuntimeCall::SubtensorModule(pallet_subtensor::Call::remove_stake { .. }) + ), + ProxyType::Registration => matches!( + c, + RuntimeCall::SubtensorModule(pallet_subtensor::Call::burned_register { .. }) + | RuntimeCall::SubtensorModule(pallet_subtensor::Call::register { .. }) + ), + } + } + 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 = MaxProxies; - type WeightInfo = pallet_proxy::weights::SubstrateWeight; - type MaxPending = MaxPending; - type CallHasher = BlakeTwo256; - type AnnouncementDepositBase = AnnouncementDepositBase; - type AnnouncementDepositFactor = AnnouncementDepositFactor; + 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; } - parameter_types! { pub MaximumSchedulerWeight: Weight = Perbill::from_percent(80) * BlockWeights::get().max_block; @@ -1108,7 +1110,7 @@ construct_runtime!( Multisig: pallet_multisig, Preimage: pallet_preimage, Scheduler: pallet_scheduler, - Proxy: pallet_proxy, + Proxy: pallet_proxy, Registry: pallet_registry, Commitments: pallet_commitments, AdminUtils: pallet_admin_utils From 55f5a022ef04c228d29f07c25d77a4d8292d433f Mon Sep 17 00:00:00 2001 From: open-junius Date: Fri, 12 Apr 2024 00:19:47 +0800 Subject: [PATCH 11/14] fix clippy --- runtime/src/lib.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/runtime/src/lib.rs b/runtime/src/lib.rs index a3dde6d96..b19cefd3b 100644 --- a/runtime/src/lib.rs +++ b/runtime/src/lib.rs @@ -41,8 +41,8 @@ use sp_version::RuntimeVersion; pub use frame_support::{ construct_runtime, parameter_types, traits::{ - ConstBool, ConstU128, ConstU32, ConstU64, ConstU8, KeyOwnerProofSystem, PrivilegeCmp, - Randomness, StorageInfo, InstanceFilter + ConstBool, ConstU128, ConstU32, ConstU64, ConstU8, InstanceFilter, KeyOwnerProofSystem, + PrivilegeCmp, Randomness, StorageInfo, }, weights::{ constants::{ From ad43983647ec830f44c0f2140f40bfbaf0463c88 Mon Sep 17 00:00:00 2001 From: open-junius Date: Fri, 12 Apr 2024 14:20:35 +0800 Subject: [PATCH 12/14] add deposit method --- runtime/src/lib.rs | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/runtime/src/lib.rs b/runtime/src/lib.rs index b19cefd3b..2846126fe 100644 --- a/runtime/src/lib.rs +++ b/runtime/src/lib.rs @@ -88,6 +88,13 @@ type MemberCount = u32; pub type Nonce = u32; +// Method used to calculate the fee of an extrinsic +pub const fn deposit(items: u32, bytes: u32) -> Balance { + pub const ITEMS_FEE: Balance = 2_000 * 10_000; + pub const BYTES_FEE: Balance = 100 * 10_000; + items as Balance * ITEMS_FEE + bytes as Balance * BYTES_FEE +} + // Opaque types. These are used by the CLI to instantiate machinery that don't need to know // the specifics of the runtime. They can then be made to be agnostic over specific formats // of data like extrinsics, allowing for them to continue syncing the network through upgrades @@ -474,9 +481,9 @@ impl pallet_sudo::Config for Runtime { parameter_types! { // One storage item; key size is 32; value is size 4+4+16+32 bytes = 56 bytes. - pub const DepositBase: Balance = (1) as Balance * 2_000 * 10_000 + (88 as Balance) * 100 * 10_000; + pub const DepositBase: Balance = deposit(1, 88); // Additional storage item size of 32 bytes. - pub const DepositFactor: Balance = (0) as Balance * 2_000 * 10_000 + (32 as Balance) * 100 * 10_000; + pub const DepositFactor: Balance = deposit(0, 32); pub const MaxSignatories: u32 = 100; } @@ -493,15 +500,15 @@ impl pallet_multisig::Config for Runtime { // Proxy Pallet config parameter_types! { // One storage item; key size sizeof(AccountId) = 32, value sizeof(Balance) = 8; 40 total - pub const ProxyDepositBase: Balance = (1) as Balance * 2_000 * 10_000 + (40 as Balance) * 100 * 10_000; + pub const ProxyDepositBase: Balance = deposit(1, 40);; // Adding 32 bytes + sizeof(ProxyType) = 32 + 1 - pub const ProxyDepositFactor: Balance = (0) as Balance * 2_000 * 10_000 + (33 as Balance) * 100 * 10_000; + pub const ProxyDepositFactor: Balance = deposit(0, 33); pub const MaxProxies: u32 = 20; // max num proxies per acct pub const MaxPending: u32 = 15 * 5; // max blocks pending ~15min // 16 bytes - pub const AnnouncementDepositBase: Balance = (1) as Balance * 2_000 * 10_000 + (16 as Balance) * 100 * 10_000; + pub const AnnouncementDepositBase: Balance = deposit(1, 16); // 68 bytes per announcement - pub const AnnouncementDepositFactor: Balance = (0) as Balance * 2_000 * 10_000 + (68 as Balance) * 100 * 10_000; + pub const AnnouncementDepositFactor: Balance = deposit(0, 68); } #[derive( @@ -584,6 +591,7 @@ impl InstanceFilter for ProxyType { (ProxyType::Any, _) => true, (_, ProxyType::Any) => false, (ProxyType::NonTransfer, _) => true, + (ProxyType::Governance, ProxyType::Triumvirate | ProxyType::Senate) => true, _ => false, } } From 622b5b33603c4380d33f79f93bbc8b0ab1f47bec Mon Sep 17 00:00:00 2001 From: open-junius Date: Fri, 12 Apr 2024 16:49:31 +0800 Subject: [PATCH 13/14] sort dep in cargo --- Cargo.toml | 2 +- runtime/src/lib.rs | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index d559d12b2..e7917c27b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,8 +2,8 @@ members = [ "integration-tests", "node", - "pallets/subtensor", "pallets/commitments", + "pallets/subtensor", "runtime", ] resolver = "2" diff --git a/runtime/src/lib.rs b/runtime/src/lib.rs index 2846126fe..36f9504f1 100644 --- a/runtime/src/lib.rs +++ b/runtime/src/lib.rs @@ -500,7 +500,7 @@ impl pallet_multisig::Config for Runtime { // Proxy Pallet config parameter_types! { // One storage item; key size sizeof(AccountId) = 32, value sizeof(Balance) = 8; 40 total - pub const ProxyDepositBase: Balance = deposit(1, 40);; + pub const ProxyDepositBase: Balance = deposit(1, 40); // Adding 32 bytes + sizeof(ProxyType) = 32 + 1 pub const ProxyDepositFactor: Balance = deposit(0, 33); pub const MaxProxies: u32 = 20; // max num proxies per acct @@ -663,8 +663,8 @@ impl pallet_scheduler::Config for Runtime { parameter_types! { pub const PreimageMaxSize: u32 = 4096 * 1024; - pub const PreimageBaseDeposit: Balance = (2) as Balance * 2_000 * 10_000_000 + (64 as Balance) * 100 * 1_000_000; - pub const PreimageByteDeposit: Balance = (0) as Balance * 2_000 * 10_000_000 + (1 as Balance) * 100 * 1_000_000; + pub const PreimageBaseDeposit: Balance = deposit(2, 64); + pub const PreimageByteDeposit: Balance = deposit(0, 1); } impl pallet_preimage::Config for Runtime { From efc4cb11578b8e22b80fce29edd434dfe72efa96 Mon Sep 17 00:00:00 2001 From: open-junius Date: Tue, 16 Apr 2024 16:02:55 +0800 Subject: [PATCH 14/14] update storage weights --- runtime/src/lib.rs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/runtime/src/lib.rs b/runtime/src/lib.rs index 36f9504f1..9987688a5 100644 --- a/runtime/src/lib.rs +++ b/runtime/src/lib.rs @@ -480,8 +480,11 @@ impl pallet_sudo::Config for Runtime { } parameter_types! { - // One storage item; key size is 32; value is size 4+4+16+32 bytes = 56 bytes. - pub const DepositBase: Balance = deposit(1, 88); + // According to multisig pallet, key and value size be computed as follows: + // value size is `4 + sizeof((BlockNumber, Balance, AccountId))` bytes + // key size is `32 + sizeof(AccountId)` bytes. + // For our case, One storage item; key size is 32+32=64 bytes; value is size 4+4+8+32 bytes = 48 bytes. + pub const DepositBase: Balance = deposit(1, 112); // Additional storage item size of 32 bytes. pub const DepositFactor: Balance = deposit(0, 32); pub const MaxSignatories: u32 = 100;