From 3eafed42a08cf33346e16fc64b8be4dd9d4bd4c4 Mon Sep 17 00:00:00 2001 From: YourUsername Date: Sat, 10 Aug 2024 14:38:15 +0000 Subject: [PATCH 1/5] chore: bump versions --- pallets/subspace/Cargo.toml | 2 +- runtime/Cargo.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/pallets/subspace/Cargo.toml b/pallets/subspace/Cargo.toml index bc33166b7..b612240f4 100644 --- a/pallets/subspace/Cargo.toml +++ b/pallets/subspace/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "pallet-subspace" -version = "1.8.1" +version = "1.8.2" description = "FRAME pallet for runtime logic of Subspace Blockchain." authors = ["Commune Community"] homepage = "https://commune.com" diff --git a/runtime/Cargo.toml b/runtime/Cargo.toml index e62b21455..6cf0fdf11 100644 --- a/runtime/Cargo.toml +++ b/runtime/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "node-subspace-runtime" -version = "1.8.1" +version = "1.8.2" description = "A Substrate node for commune-ai" authors = ["Commune Community"] homepage = "https://substrate.io/" From 93c50e282875f7a8952e083416258e297f4d8d02 Mon Sep 17 00:00:00 2001 From: YourUsername Date: Sat, 10 Aug 2024 17:30:55 +0000 Subject: [PATCH 2/5] feat: adding missing subnet parameter --- Cargo.lock | 4 ++-- pallets/governance/src/lib.rs | 2 ++ pallets/subspace/src/lib.rs | 4 ++++ pallets/subspace/src/subnet.rs | 1 + tests/src/governance.rs | 2 ++ tests/src/subspace/subnet.rs | 3 +++ 6 files changed, 14 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index dbf52a9e7..a9752383b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4804,7 +4804,7 @@ dependencies = [ [[package]] name = "node-subspace-runtime" -version = "1.8.1" +version = "1.8.2" dependencies = [ "fp-account", "fp-rpc", @@ -5279,7 +5279,7 @@ dependencies = [ [[package]] name = "pallet-subspace" -version = "1.8.1" +version = "1.8.2" dependencies = [ "bty", "frame-benchmarking", diff --git a/pallets/governance/src/lib.rs b/pallets/governance/src/lib.rs index f905f99b2..1128067e2 100644 --- a/pallets/governance/src/lib.rs +++ b/pallets/governance/src/lib.rs @@ -243,6 +243,7 @@ pub mod pallet { max_registrations_per_interval: u16, adjustment_alpha: u64, min_validator_stake: u64, + max_allowed_validators: Option, ) -> DispatchResult { let mut params = pallet_subspace::Pallet::subnet_params(netuid); params.founder = founder; @@ -267,6 +268,7 @@ pub mod pallet { params.max_registrations_per_interval = max_registrations_per_interval; params.adjustment_alpha = adjustment_alpha; params.min_validator_stake = min_validator_stake; + params.max_allowed_validators = max_allowed_validators; Self::do_add_subnet_params_proposal(origin, netuid, data, params) } diff --git a/pallets/subspace/src/lib.rs b/pallets/subspace/src/lib.rs index d881904bd..b48c731c3 100644 --- a/pallets/subspace/src/lib.rs +++ b/pallets/subspace/src/lib.rs @@ -366,6 +366,7 @@ pub mod pallet { adjustment_alpha: module_burn_defaults.adjustment_alpha, min_validator_stake: DefaultMinValidatorStake::::get(), + max_allowed_validators: None, governance_config: GovernanceConfiguration { vote_mode: VoteMode::Authority, ..Default::default() @@ -406,6 +407,7 @@ pub mod pallet { pub max_registrations_per_interval: u16, pub adjustment_alpha: u64, pub min_validator_stake: u64, + pub max_allowed_validators: Option, pub governance_config: GovernanceConfiguration, } @@ -1016,6 +1018,7 @@ pub mod pallet { max_registrations_per_interval: u16, adjustment_alpha: u64, min_validator_stake: u64, + max_allowed_validators: Option, ) -> DispatchResult { let params = SubnetParams { founder, @@ -1038,6 +1041,7 @@ pub mod pallet { max_registrations_per_interval, adjustment_alpha, min_validator_stake, + max_allowed_validators, governance_config: GovernanceConfiguration { vote_mode, ..T::get_subnet_governance_configuration(netuid) diff --git a/pallets/subspace/src/subnet.rs b/pallets/subspace/src/subnet.rs index d3731367b..3ea3dfc1d 100644 --- a/pallets/subspace/src/subnet.rs +++ b/pallets/subspace/src/subnet.rs @@ -188,6 +188,7 @@ impl Pallet { adjustment_alpha: module_burn_config.adjustment_alpha, min_validator_stake: MinValidatorStake::::get(netuid), + max_allowed_validators: MaxAllowedValidators::::get(netuid), governance_config: T::get_subnet_governance_configuration(netuid), metadata: SubnetMetadata::::get(netuid), } diff --git a/tests/src/governance.rs b/tests/src/governance.rs index 5d62e1d43..d889c74a0 100644 --- a/tests/src/governance.rs +++ b/tests/src/governance.rs @@ -332,6 +332,7 @@ fn subnet_params_proposal_accepted() { max_registrations_per_interval, adjustment_alpha, min_validator_stake, + max_allowed_validators, mut governance_config, .. } = SubspaceMod::subnet_params(0); @@ -364,6 +365,7 @@ fn subnet_params_proposal_accepted() { max_registrations_per_interval, adjustment_alpha, min_validator_stake, + max_allowed_validators, ) .unwrap(); diff --git a/tests/src/subspace/subnet.rs b/tests/src/subspace/subnet.rs index d3b1c183a..a416b4da3 100644 --- a/tests/src/subspace/subnet.rs +++ b/tests/src/subspace/subnet.rs @@ -64,6 +64,7 @@ fn subnet_update_changes_all_parameter_values() { max_registrations_per_interval: 16, adjustment_alpha: 17, min_validator_stake: to_nano(50_000), + max_allowed_validators: Some(18), governance_config: GovernanceConfiguration { proposal_cost: 18, proposal_expiration: 19, @@ -98,6 +99,7 @@ fn subnet_update_changes_all_parameter_values() { max_registrations_per_interval, adjustment_alpha, min_validator_stake, + max_allowed_validators, governance_config, } = params.clone(); @@ -257,6 +259,7 @@ fn update_subnet_verifies_names_uniquiness_integrity() { params.max_registrations_per_interval, params.adjustment_alpha, params.min_validator_stake, + params.max_allowed_validators, ) }; From e7d64327501c6e70410f7949b80e27414497fd39 Mon Sep 17 00:00:00 2001 From: YourUsername Date: Sat, 10 Aug 2024 19:47:47 +0000 Subject: [PATCH 3/5] feat: updating max allowed validators --- pallets/subspace/src/subnet.rs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/pallets/subspace/src/subnet.rs b/pallets/subspace/src/subnet.rs index 3ea3dfc1d..9a4dc222f 100644 --- a/pallets/subspace/src/subnet.rs +++ b/pallets/subspace/src/subnet.rs @@ -69,6 +69,7 @@ impl SubnetChangeset { Pallet::::deposit_event(Event::SubnetParamsUpdated(netuid)); SubnetMetadata::::set(netuid, self.params.metadata); + MaxAllowedValidators::::insert(netuid, self.params.max_allowed_validators); Ok(()) } @@ -141,6 +142,13 @@ impl SubnetChangeset { Error::::InvalidMinValidatorStake ); + if let Some(max_allowed_validators) = params.max_allowed_validators { + ensure!( + max_allowed_validators >= 10, + Error::::InvalidMaxAllowedValidators + ); + } + match Pallet::::get_netuid_for_name(¶ms.name) { Some(id) if netuid.is_some_and(|netuid| netuid == id) => { /* subnet kept same name */ } Some(_) => return Err(Error::::SubnetNameAlreadyExists.into()), From 0a14f7bb5192c0ac0a3720543886d09589b3ebbe Mon Sep 17 00:00:00 2001 From: YourUsername Date: Sat, 10 Aug 2024 19:52:48 +0000 Subject: [PATCH 4/5] feat: adding missing error --- pallets/subspace/src/lib.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pallets/subspace/src/lib.rs b/pallets/subspace/src/lib.rs index b48c731c3..f4b4623e8 100644 --- a/pallets/subspace/src/lib.rs +++ b/pallets/subspace/src/lib.rs @@ -733,6 +733,8 @@ pub mod pallet { RootnetSubnetNotFound, /// MinValidatorStake must be lower than 250k InvalidMinValidatorStake, + /// The maximum allowed validators value is invalid, minimum is 10. + InvalidMaxAllowedValidators, } // --------------------------------- From 808a323ba7c5d9c386713f522515d215afc1d608 Mon Sep 17 00:00:00 2001 From: YourUsername Date: Sat, 10 Aug 2024 21:59:42 +0000 Subject: [PATCH 5/5] refac: simplifying extrinsics --- pallets/governance/src/lib.rs | 16 ++-------- pallets/subspace/src/lib.rs | 33 +++------------------ pallets/subspace/src/subnet.rs | 21 ++------------ tests/src/governance.rs | 14 ++------- tests/src/subspace/subnet.rs | 53 +++++++++------------------------- 5 files changed, 25 insertions(+), 112 deletions(-) diff --git a/pallets/governance/src/lib.rs b/pallets/governance/src/lib.rs index 1128067e2..13c715719 100644 --- a/pallets/governance/src/lib.rs +++ b/pallets/governance/src/lib.rs @@ -37,7 +37,7 @@ pub mod pallet { PalletId, }; use frame_system::pallet_prelude::{ensure_signed, BlockNumberFor}; - use pallet_subspace::DefaultKey; + use pallet_subspace::{global::GeneralBurnConfiguration, DefaultKey}; use sp_runtime::traits::AccountIdConversion; const STORAGE_VERSION: StorageVersion = StorageVersion::new(1); @@ -236,12 +236,7 @@ pub mod pallet { maximum_set_weight_calls_per_epoch: u16, vote_mode: VoteMode, bonds_ma: u64, - min_burn: u64, - max_burn: u64, - target_registrations_interval: u16, - target_registrations_per_interval: u16, - max_registrations_per_interval: u16, - adjustment_alpha: u64, + module_burn_config: GeneralBurnConfiguration, min_validator_stake: u64, max_allowed_validators: Option, ) -> DispatchResult { @@ -261,12 +256,7 @@ pub mod pallet { params.maximum_set_weight_calls_per_epoch = maximum_set_weight_calls_per_epoch; params.governance_config.vote_mode = vote_mode; params.bonds_ma = bonds_ma; - params.min_burn = min_burn; - params.max_burn = max_burn; - params.target_registrations_interval = target_registrations_interval; - params.target_registrations_per_interval = target_registrations_per_interval; - params.max_registrations_per_interval = max_registrations_per_interval; - params.adjustment_alpha = adjustment_alpha; + params.module_burn_config = module_burn_config; params.min_validator_stake = min_validator_stake; params.max_allowed_validators = max_allowed_validators; Self::do_add_subnet_params_proposal(origin, netuid, data, params) diff --git a/pallets/subspace/src/lib.rs b/pallets/subspace/src/lib.rs index f4b4623e8..c44a67dad 100644 --- a/pallets/subspace/src/lib.rs +++ b/pallets/subspace/src/lib.rs @@ -339,8 +339,6 @@ pub mod pallet { // TODO: not hardcode values here, get them from the storages instead, // if they implement default already. pub fn get() -> SubnetParams { - let module_burn_defaults = GeneralBurnConfiguration::::default_for(BurnType::Module); - SubnetParams { name: BoundedVec::default(), tempo: 100, @@ -357,14 +355,7 @@ pub mod pallet { bonds_ma: 900_000, // registrations - min_burn: module_burn_defaults.min_burn, - max_burn: module_burn_defaults.max_burn, - target_registrations_interval: module_burn_defaults.target_registrations_interval, - target_registrations_per_interval: module_burn_defaults - .target_registrations_per_interval, - max_registrations_per_interval: module_burn_defaults.max_registrations_per_interval, - adjustment_alpha: module_burn_defaults.adjustment_alpha, - + module_burn_config: GeneralBurnConfiguration::::default_for(BurnType::Module), min_validator_stake: DefaultMinValidatorStake::::get(), max_allowed_validators: None, governance_config: GovernanceConfiguration { @@ -399,13 +390,7 @@ pub mod pallet { pub maximum_set_weight_calls_per_epoch: u16, // consensus pub bonds_ma: u64, - // registrations - pub min_burn: u64, - pub max_burn: u64, - pub target_registrations_interval: u16, - pub target_registrations_per_interval: u16, - pub max_registrations_per_interval: u16, - pub adjustment_alpha: u64, + pub module_burn_config: GeneralBurnConfiguration, pub min_validator_stake: u64, pub max_allowed_validators: Option, pub governance_config: GovernanceConfiguration, @@ -1013,12 +998,7 @@ pub mod pallet { maximum_set_weight_calls_per_epoch: u16, vote_mode: VoteMode, bonds_ma: u64, - min_burn: u64, - max_burn: u64, - target_registrations_interval: u16, - target_registrations_per_interval: u16, - max_registrations_per_interval: u16, - adjustment_alpha: u64, + module_burn_config: GeneralBurnConfiguration, min_validator_stake: u64, max_allowed_validators: Option, ) -> DispatchResult { @@ -1036,12 +1016,7 @@ pub mod pallet { trust_ratio, maximum_set_weight_calls_per_epoch, bonds_ma, - min_burn, - max_burn, - target_registrations_interval, - target_registrations_per_interval, - max_registrations_per_interval, - adjustment_alpha, + module_burn_config, min_validator_stake, max_allowed_validators, governance_config: GovernanceConfiguration { diff --git a/pallets/subspace/src/subnet.rs b/pallets/subspace/src/subnet.rs index 9a4dc222f..5e9c8cdcb 100644 --- a/pallets/subspace/src/subnet.rs +++ b/pallets/subspace/src/subnet.rs @@ -44,16 +44,7 @@ impl SubnetChangeset { TrustRatio::::insert(netuid, self.params.trust_ratio); IncentiveRatio::::insert(netuid, self.params.incentive_ratio); BondsMovingAverage::::insert(netuid, self.params.bonds_ma); - let burn_config: GeneralBurnConfiguration = GeneralBurnConfiguration { - min_burn: self.params.min_burn, - max_burn: self.params.max_burn, - adjustment_alpha: self.params.adjustment_alpha, - target_registrations_interval: self.params.target_registrations_interval, - target_registrations_per_interval: self.params.target_registrations_per_interval, - max_registrations_per_interval: self.params.max_registrations_per_interval, - _pd: PhantomData, - }; - burn_config.apply_module_burn(netuid)?; + self.params.module_burn_config.apply_module_burn(netuid)?; MinValidatorStake::::insert(netuid, self.params.min_validator_stake); if self.params.maximum_set_weight_calls_per_epoch == 0 { MaximumSetWeightCallsPerEpoch::::remove(netuid); @@ -169,8 +160,6 @@ impl SubnetChangeset { impl Pallet { pub fn subnet_params(netuid: u16) -> SubnetParams { - let module_burn_config = ModuleBurnConfig::::get(netuid); - SubnetParams { founder: Founder::::get(netuid), founder_share: FounderShare::::get(netuid), @@ -188,13 +177,7 @@ impl Pallet { bonds_ma: BondsMovingAverage::::get(netuid), // Registrations - min_burn: module_burn_config.min_burn, - max_burn: module_burn_config.max_burn, - target_registrations_interval: module_burn_config.target_registrations_interval, - target_registrations_per_interval: module_burn_config.target_registrations_per_interval, - max_registrations_per_interval: module_burn_config.max_registrations_per_interval, - adjustment_alpha: module_burn_config.adjustment_alpha, - + module_burn_config: ModuleBurnConfig::::get(netuid), min_validator_stake: MinValidatorStake::::get(netuid), max_allowed_validators: MaxAllowedValidators::::get(netuid), governance_config: T::get_subnet_governance_configuration(netuid), diff --git a/tests/src/governance.rs b/tests/src/governance.rs index d889c74a0..7de08e353 100644 --- a/tests/src/governance.rs +++ b/tests/src/governance.rs @@ -325,12 +325,7 @@ fn subnet_params_proposal_accepted() { trust_ratio, maximum_set_weight_calls_per_epoch, bonds_ma, - min_burn, - max_burn, - target_registrations_interval, - target_registrations_per_interval, - max_registrations_per_interval, - adjustment_alpha, + module_burn_config, min_validator_stake, max_allowed_validators, mut governance_config, @@ -358,12 +353,7 @@ fn subnet_params_proposal_accepted() { maximum_set_weight_calls_per_epoch, governance_config.vote_mode, bonds_ma, - min_burn, - max_burn, - target_registrations_interval, - target_registrations_per_interval, - max_registrations_per_interval, - adjustment_alpha, + module_burn_config, min_validator_stake, max_allowed_validators, ) diff --git a/tests/src/subspace/subnet.rs b/tests/src/subspace/subnet.rs index a416b4da3..d46dc9214 100644 --- a/tests/src/subspace/subnet.rs +++ b/tests/src/subspace/subnet.rs @@ -1,5 +1,6 @@ use crate::mock::*; use frame_support::assert_err; +use global::GeneralBurnConfiguration; use pallet_governance::{GovernanceConfiguration, SubnetGovernanceConfig, VoteMode}; use pallet_subspace::*; use sp_runtime::Percent; @@ -59,10 +60,6 @@ fn subnet_update_changes_all_parameter_values() { trust_ratio: 11, maximum_set_weight_calls_per_epoch: 12, bonds_ma: 13, - target_registrations_interval: 14, - target_registrations_per_interval: 15, - max_registrations_per_interval: 16, - adjustment_alpha: 17, min_validator_stake: to_nano(50_000), max_allowed_validators: Some(18), governance_config: GovernanceConfiguration { @@ -73,8 +70,15 @@ fn subnet_update_changes_all_parameter_values() { max_proposal_reward_treasury_allocation: 21, proposal_reward_interval: 22, }, - min_burn: 20000000000, - max_burn: 21000000000, + module_burn_config: GeneralBurnConfiguration { + min_burn: to_nano(15), + max_burn: to_nano(24), + target_registrations_interval: 25, + target_registrations_per_interval: 26, + max_registrations_per_interval: 27, + adjustment_alpha: 28, + ..Default::default() + }, }; let SubnetParams { @@ -92,19 +96,13 @@ fn subnet_update_changes_all_parameter_values() { trust_ratio, maximum_set_weight_calls_per_epoch, bonds_ma, - min_burn, - max_burn, - target_registrations_interval, - target_registrations_per_interval, - max_registrations_per_interval, - adjustment_alpha, + module_burn_config, min_validator_stake, max_allowed_validators, governance_config, } = params.clone(); SubnetChangeset::::update(netuid, params).unwrap().apply(netuid).unwrap(); - assert_eq!(Founder::::get(netuid), founder); assert_eq!(FounderShare::::get(netuid), founder_share); assert_eq!(ImmunityPeriod::::get(netuid), immunity_period); @@ -121,31 +119,13 @@ fn subnet_update_changes_all_parameter_values() { Some(maximum_set_weight_calls_per_epoch) ); assert_eq!(BondsMovingAverage::::get(netuid), bonds_ma); - assert_eq!(ModuleBurnConfig::::get(netuid).min_burn, min_burn); - assert_eq!(ModuleBurnConfig::::get(netuid).max_burn, max_burn); - assert_eq!( - ModuleBurnConfig::::get(netuid).target_registrations_interval, - target_registrations_interval - ); - assert_eq!( - ModuleBurnConfig::::get(netuid).target_registrations_per_interval, - target_registrations_per_interval - ); - assert_eq!( - ModuleBurnConfig::::get(netuid).max_registrations_per_interval, - max_registrations_per_interval - ); - assert_eq!( - ModuleBurnConfig::::get(netuid).adjustment_alpha, - adjustment_alpha - ); + assert_eq!(ModuleBurnConfig::::get(netuid), module_burn_config); + assert_eq!(MinValidatorStake::::get(netuid), min_validator_stake); assert_eq!(MinValidatorStake::::get(netuid), min_validator_stake); - assert_eq!( SubnetGovernanceConfig::::get(netuid), governance_config ); - assert_eq!(SubspaceMod::get_total_subnets(), 1); assert_eq!(N::::get(netuid), 1); assert_eq!(SubnetMetadata::::get(netuid), metadata); @@ -252,12 +232,7 @@ fn update_subnet_verifies_names_uniquiness_integrity() { params.maximum_set_weight_calls_per_epoch, params.governance_config.vote_mode, params.bonds_ma, - params.min_burn, - params.max_burn, - params.target_registrations_interval, - params.target_registrations_per_interval, - params.max_registrations_per_interval, - params.adjustment_alpha, + params.module_burn_config, params.min_validator_stake, params.max_allowed_validators, )