diff --git a/pallets/paratensor/src/lib.rs b/pallets/paratensor/src/lib.rs index df0400c..7f21cf8 100644 --- a/pallets/paratensor/src/lib.rs +++ b/pallets/paratensor/src/lib.rs @@ -95,6 +95,12 @@ pub mod pallet { type InitialValidatorEpochLen: Get; #[pallet::constant] /// Default Reset length. type InitialValidatorEpochsPerReset: Get; + #[pallet::constant] /// Initial validator exclude quantile. + type InitialValidatorExcludeQuantile: Get; + #[pallet::constant] /// Initial scaling law power. + type InitialScalingLawPower: Get; + #[pallet::constant] /// Initial synergy scaling law power. + type InitialSynergyScalingLawPower: Get; #[pallet::constant] /// Immunity Period Constant. type InitialImmunityPeriod: Get; #[pallet::constant] /// Activity constant @@ -103,8 +109,6 @@ pub mod pallet { type InitialMaxRegistrationsPerBlock: Get; #[pallet::constant] /// Initial pruning score for each neuron type InitialPruningScore: Get; - #[pallet::constant] /// Initial validator exclude quantile. - type InitialValidatorExcludeQuantile: Get; #[pallet::constant] /// Initial allowed validators per network. type InitialMaxAllowedValidators: Get; #[pallet::constant] /// Initial default delegation take. @@ -325,6 +329,10 @@ pub mod pallet { pub fn DefaultValidatorEpochsPerReset() -> u16 { T::InitialValidatorEpochsPerReset::get() } #[pallet::type_value] pub fn DefaultValidatorExcludeQuantile() -> u16 {T::InitialValidatorExcludeQuantile::get()} + #[pallet::type_value] + pub fn DefaultScalingLawPower() -> u16 {T::InitialScalingLawPower::get()} + #[pallet::type_value] + pub fn DefaultSynergyScalingLawPower() -> u16 {T::InitialSynergyScalingLawPower::get()} #[pallet::type_value] pub fn DefaultTargetRegistrationsPerInterval() -> u16 { T::InitialTargetRegistrationsPerInterval::get() } @@ -367,6 +375,10 @@ pub mod pallet { pub type ValidatorEpochsPerReset = StorageMap<_, Identity, u16, u16, ValueQuery, DefaultValidatorEpochsPerReset >; #[pallet::storage] /// --- MAP ( netuid ) --> validator_exclude_quantile pub type ValidatorExcludeQuantile = StorageMap<_, Identity, u16, u16, ValueQuery, DefaultValidatorExcludeQuantile >; + #[pallet::storage] /// --- MAP ( netuid ) --> scaling_law_power + pub type ScalingLawPower = StorageMap<_, Identity, u16, u16, ValueQuery, DefaultScalingLawPower >; + #[pallet::storage] /// --- MAP ( netuid ) --> synergy_scaling_law_power + pub type SynergyScalingLawPower = StorageMap<_, Identity, u16, u16, ValueQuery, DefaultSynergyScalingLawPower >; #[pallet::storage] /// --- MAP ( netuid ) --> target_registrations_this_interval pub type TargetRegistrationsPerInterval = StorageMap<_, Identity, u16, u16, ValueQuery, DefaultTargetRegistrationsPerInterval >; #[pallet::storage] /// --- DMAP ( netuid, uid ) --> block_at_registration @@ -459,11 +471,13 @@ pub mod pallet { ValidatorBatchSizeSet( u16, u16 ), // --- Event created when validator batch size is set for a subnet. ValidatorSequenceLengthSet( u16, u16 ), // --- Event created when validator sequence length i set for a subnet. ValidatorEpochPerResetSet( u16, u16 ), // --- Event created when validator epoch per reset is set for a subnet. + ValidatorExcludeQuantileSet( u16, u16 ), // --- Event created when the validator exclude quantile has been set for a subnet. + ScalingLawPowerSet( u16, u16 ), // --- Event created when the scaling law power has been set for a subnet. + SynergyScalingLawPowerSet( u16, u16 ), // --- Event created when the synergy scaling law has been set for a subnet. WeightsSetRateLimitSet( u16, u64 ), // --- Event create when weights set rate limit has been set for a subnet. ImmunityPeriodSet( u16, u16), // --- Event created when immunity period is set for a subnet. BondsMovingAverageSet( u16, u64), // --- Event created when bonds moving average is set for a subnet. MaxAllowedValidatorsSet( u16, u16), // --- Event created when setting the max number of allowed validators on a subnet. - ValidatorExcludeQuantileSet( u16, u16 ), // --- Event created when the validator exclude quantile has been set for a subnet. AxonServed( T::AccountId ), // --- Event created when the axon server information is added to the network. PrometheusServed( T::AccountId ), // --- Event created when the axon server information is added to the network. EmissionValuesSet(), // --- Event created when emission ratios fr all networks is set. @@ -1112,6 +1126,18 @@ pub mod pallet { Self::do_sudo_set_validator_epochs_per_reset( origin, netuid, validator_epochs_per_reset ) } #[pallet::weight((0, DispatchClass::Operational, Pays::No))] + pub fn sudo_set_validator_exclude_quantile( origin:OriginFor, netuid: u16, validator_exclude_quantile: u16 ) -> DispatchResult { + Self::do_sudo_set_validator_exclude_quantile( origin, netuid, validator_exclude_quantile ) + } + #[pallet::weight((0, DispatchClass::Operational, Pays::No))] + pub fn sudo_set_scaling_law_power( origin:OriginFor, netuid: u16, scaling_law_power: u16 ) -> DispatchResult { + Self::do_sudo_set_scaling_law_power( origin, netuid, scaling_law_power ) + } + #[pallet::weight((0, DispatchClass::Operational, Pays::No))] + pub fn sudo_set_synergy_scaling_law_power( origin:OriginFor, netuid: u16, synergy_scaling_law_power: u16 ) -> DispatchResult { + Self::do_sudo_set_synergy_scaling_law_power( origin, netuid, synergy_scaling_law_power ) + } + #[pallet::weight((0, DispatchClass::Operational, Pays::No))] pub fn sudo_set_immunity_period( origin:OriginFor, netuid: u16, immunity_period: u16 ) -> DispatchResult { Self::do_sudo_set_immunity_period( origin, netuid, immunity_period ) } @@ -1119,10 +1145,6 @@ pub mod pallet { pub fn sudo_set_max_weight_limit( origin:OriginFor, netuid: u16, max_weight_limit: u16 ) -> DispatchResult { Self::do_sudo_set_max_weight_limit( origin, netuid, max_weight_limit ) } - #[pallet::weight((0, DispatchClass::Operational, Pays::No))] - pub fn sudo_set_validator_exclude_quantile( origin:OriginFor, netuid: u16, validator_exclude_quantile: u16 ) -> DispatchResult { - Self::do_sudo_set_validator_exclude_quantile( origin, netuid, validator_exclude_quantile ) - } } } diff --git a/pallets/paratensor/src/registration.rs b/pallets/paratensor/src/registration.rs index e2d700e..6fdb3a2 100644 --- a/pallets/paratensor/src/registration.rs +++ b/pallets/paratensor/src/registration.rs @@ -83,7 +83,7 @@ impl Pallet { ensure!( Self::if_subnet_exist( netuid ), Error::::NetworkDoesNotExist ); // --- 3. Ensure we are not exceeding the max allowed registrations per block. - ensure!( Self::get_registrations_this_block( netuid ) < Self::get_max_registratations_per_block( netuid ), Error::::TooManyRegistrationsThisBlock ); + ensure!( Self::get_registrations_this_block( netuid ) < Self::get_max_registrations_per_block( netuid ), Error::::TooManyRegistrationsThisBlock ); // --- 4. Ensure that the key is not already registered. ensure!( !Uids::::contains_key( netuid, &hotkey ), Error::::AlreadyRegistered ); diff --git a/pallets/paratensor/src/utils.rs b/pallets/paratensor/src/utils.rs index fc28b15..a83a7d3 100644 --- a/pallets/paratensor/src/utils.rs +++ b/pallets/paratensor/src/utils.rs @@ -36,7 +36,7 @@ impl Pallet { pub fn get_registrations_this_block( netuid:u16 ) -> u16 { RegistrationsThisBlock::::get( netuid ) } pub fn get_last_mechanism_step_block( netuid: u16 ) -> u64 { LastMechansimStepBlock::::get( netuid ) } pub fn get_registrations_this_interval( netuid: u16 ) -> u16 { RegistrationsThisInterval::::get( netuid ) } - pub fn get_max_registratations_per_block( netuid: u16 ) -> u16 { MaxRegistrationsPerBlock::::get( netuid ) } + pub fn get_max_registrations_per_block( netuid: u16 ) -> u16 { MaxRegistrationsPerBlock::::get( netuid ) } pub fn get_neuron_block_at_registration( netuid: u16, neuron_uid: u16 ) -> u64 { BlockAtRegistration::::get( netuid, neuron_uid )} /// ======================== @@ -129,6 +129,30 @@ impl Pallet { Ok(()) } + pub fn get_scaling_law_power( netuid: u16 ) -> u16 { ScalingLawPower::::get( netuid ) } + pub fn set_scaling_law_power( netuid: u16, scaling_law_power: u16 ) { ScalingLawPower::::insert( netuid, scaling_law_power ); } + pub fn do_sudo_set_scaling_law_power( origin:T::Origin, netuid: u16, scaling_law_power: u16 ) -> DispatchResult { + ensure_root( origin )?; + ensure!( Self::if_subnet_exist(netuid), Error::::NetworkDoesNotExist ); + ensure!( scaling_law_power <= 100, Error::::StorageValueOutOfRange ); // The scaling law power must be between 0 and 100 => 0% and 100% + Self::set_scaling_law_power( netuid, scaling_law_power ); + log::info!("ScalingLawPowerSet( netuid: {:?} scaling_law_power: {:?} ) ", netuid, scaling_law_power); + Self::deposit_event( Event::ScalingLawPowerSet( netuid, scaling_law_power )); + Ok(()) + } + + pub fn get_synergy_scaling_law_power( netuid: u16 ) -> u16 { SynergyScalingLawPower::::get( netuid ) } + pub fn set_synergy_scaling_law_power( netuid: u16, synergy_scaling_law_power: u16 ) { SynergyScalingLawPower::::insert( netuid, synergy_scaling_law_power ); } + pub fn do_sudo_set_synergy_scaling_law_power( origin:T::Origin, netuid: u16, synergy_scaling_law_power: u16 ) -> DispatchResult { + ensure_root( origin )?; + ensure!( Self::if_subnet_exist(netuid), Error::::NetworkDoesNotExist ); + ensure!( synergy_scaling_law_power <= 100, Error::::StorageValueOutOfRange ); // The synergy scaling law power must be between 0 and 100 => 0% and 100% + Self::set_synergy_scaling_law_power( netuid, synergy_scaling_law_power ); + log::info!("SynergyScalingLawPowerSet( netuid: {:?} synergy_scaling_law_power: {:?} ) ", netuid, synergy_scaling_law_power); + Self::deposit_event( Event::SynergyScalingLawPowerSet( netuid, synergy_scaling_law_power )); + Ok(()) + } + pub fn get_max_weight_limit( netuid: u16) -> u16 { MaxWeightsLimit::::get( netuid ) } pub fn set_max_weight_limit( netuid: u16, max_weight_limit: u16 ) { MaxWeightsLimit::::insert( netuid, max_weight_limit ); } pub fn do_sudo_set_max_weight_limit( origin:T::Origin, netuid: u16, max_weight_limit: u16 ) -> DispatchResult { diff --git a/pallets/paratensor/tests/difficulty.rs b/pallets/paratensor/tests/difficulty.rs index 3046c7a..fae5445 100644 --- a/pallets/paratensor/tests/difficulty.rs +++ b/pallets/paratensor/tests/difficulty.rs @@ -25,7 +25,7 @@ fn test_registration_difficulty_adjustment() { assert_eq!( ParatensorModule::get_difficulty_as_u64( netuid ), 20000 ); // Check set difficutly. assert_eq!( ParatensorModule::get_adjustment_interval( netuid ), 1 ); // Check set adjustment interval. assert_eq!( ParatensorModule::get_target_registrations_per_interval( netuid ), 1 ); // Check set adjustment interval. - assert_eq!( ParatensorModule::get_max_registratations_per_block( netuid ), 3 ); // Check set registrations per block. + assert_eq!( ParatensorModule::get_max_registrations_per_block( netuid ), 3 ); // Check set registrations per block. assert_eq!( ParatensorModule::get_max_allowed_uids( netuid ), 3 ); // Check set registrations per block. // Lets register 3 neurons... diff --git a/pallets/paratensor/tests/mock.rs b/pallets/paratensor/tests/mock.rs index 3756df8..d864c5e 100644 --- a/pallets/paratensor/tests/mock.rs +++ b/pallets/paratensor/tests/mock.rs @@ -120,6 +120,8 @@ parameter_types! { pub const InitialValidatorEpochLen: u16 = 10; pub const InitialValidatorEpochsPerReset: u16 = 10; pub const InitialValidatorExcludeQuantile: u16 = 10; + pub const InitialScalingLawPower: u16 = 50; + pub const InitialSynergyScalingLawPower: u16 = 50; pub const InitialMaxAllowedValidators: u16 = 100; pub const InitialIssuance: u64 = 548833985028256; @@ -155,12 +157,14 @@ impl pallet_paratensor::Config for Test { type InitialValidatorSequenceLen = InitialValidatorSequenceLen; type InitialValidatorEpochLen = InitialValidatorEpochLen; type InitialValidatorEpochsPerReset = InitialValidatorEpochsPerReset; + type InitialValidatorExcludeQuantile = InitialValidatorExcludeQuantile; + type InitialScalingLawPower = InitialScalingLawPower; + type InitialSynergyScalingLawPower = InitialSynergyScalingLawPower; type InitialImmunityPeriod = InitialImmunityPeriod; type InitialActivityCutoff = InitialActivityCutoff; type InitialMaxRegistrationsPerBlock = InitialMaxRegistrationsPerBlock; type InitialPruningScore = InitialPruningScore; type InitialBondsMovingAverage = InitialBondsMovingAverage; - type InitialValidatorExcludeQuantile = InitialValidatorExcludeQuantile; type InitialMaxAllowedValidators = InitialMaxAllowedValidators; type InitialDefaultTake = InitialDefaultTake; type InitialWeightsVersionKey = InitialWeightsVersionKey; diff --git a/pallets/paratensor/tests/registration.rs b/pallets/paratensor/tests/registration.rs index 30c946d..6b44786 100644 --- a/pallets/paratensor/tests/registration.rs +++ b/pallets/paratensor/tests/registration.rs @@ -101,7 +101,7 @@ fn test_registration_too_many_registrations_per_block() { let netuid: u16 = 1; let tempo: u16 = 13; ParatensorModule::set_max_registrations_per_block( netuid, 10 ); - assert_eq!( ParatensorModule::get_max_registratations_per_block(netuid), 10 ); + assert_eq!( ParatensorModule::get_max_registrations_per_block(netuid), 10 ); let block_number: u64 = 0; let (nonce0, work0): (u64, Vec) = ParatensorModule::create_work_for_block_number( netuid, block_number, 3942084); @@ -306,7 +306,7 @@ fn test_registration_get_neuron_metadata() { assert_ok!(ParatensorModule::register(<::Origin>::signed(hotkey_account_id), netuid, block_number, nonce0, work0, hotkey_account_id, coldkey_account_id)); // //let neuron_id = ParatensorModule::get_uid_for_net_and_hotkey(netuid, &hotkey_account_id); - let neuron_uid = ParatensorModule::get_uid_for_net_and_hotkey( netuid, &hotkey_account_id ).unwrap(); + // let neuron_uid = ParatensorModule::get_uid_for_net_and_hotkey( netuid, &hotkey_account_id ).unwrap(); let neuron: AxonInfoOf = ParatensorModule::get_axon_info( &hotkey_account_id ); assert_eq!(neuron.ip, 0); assert_eq!(neuron.version, 0); @@ -398,9 +398,9 @@ fn test_full_pass_through() { ParatensorModule::set_max_registrations_per_block( netuid0, 3 ); ParatensorModule::set_max_registrations_per_block( netuid1, 3 ); ParatensorModule::set_max_registrations_per_block( netuid2, 3 ); - assert_eq!( ParatensorModule::get_max_registratations_per_block(netuid0), 3 ); - assert_eq!( ParatensorModule::get_max_registratations_per_block(netuid1), 3 ); - assert_eq!( ParatensorModule::get_max_registratations_per_block(netuid2), 3 ); + assert_eq!( ParatensorModule::get_max_registrations_per_block(netuid0), 3 ); + assert_eq!( ParatensorModule::get_max_registrations_per_block(netuid1), 3 ); + assert_eq!( ParatensorModule::get_max_registrations_per_block(netuid2), 3 ); // Check that no one has registered yet. assert_eq!(ParatensorModule::get_subnetwork_n(netuid0), 0); diff --git a/pallets/paratensor/tests/sudo.rs b/pallets/paratensor/tests/sudo.rs index 5046e36..de19759 100644 --- a/pallets/paratensor/tests/sudo.rs +++ b/pallets/paratensor/tests/sudo.rs @@ -36,8 +36,10 @@ fn test_defaults() { assert_eq!( ParatensorModule::get_validator_epochs_per_reset( netuid ), 10 ); assert_eq!( ParatensorModule::get_validator_sequence_length( netuid ), 10 ); assert_eq!( ParatensorModule::get_validator_exclude_quantile( netuid ), 10 ); + assert_eq!( ParatensorModule::get_scaling_law_power( netuid ), 50 ); + assert_eq!( ParatensorModule::get_synergy_scaling_law_power( netuid ), 50 ); assert_eq!( ParatensorModule::get_registrations_this_interval( netuid ), 0 ); - assert_eq!( ParatensorModule::get_max_registratations_per_block( netuid ), 3 ); + assert_eq!( ParatensorModule::get_max_registrations_per_block( netuid ), 3 ); assert_eq!( ParatensorModule::get_target_registrations_per_interval( netuid ), 2 ); }); } @@ -159,6 +161,36 @@ fn test_sudo_set_validator_exclude_quantile() { }); } +#[test] +fn test_sudo_set_scaling_law_power() { + new_test_ext().execute_with(|| { + let netuid: u16 = 1; + let to_be_set: u16 = 50; + let init_value: u16 = ParatensorModule::get_scaling_law_power( netuid ); + add_network(netuid, 10, 0); + assert_eq!( ParatensorModule::sudo_set_scaling_law_power(<::Origin>::signed(0), netuid, to_be_set), Err(DispatchError::BadOrigin.into()) ); + assert_eq!( ParatensorModule::sudo_set_scaling_law_power(<::Origin>::root(), netuid + 1, to_be_set), Err(Error::::NetworkDoesNotExist.into()) ); + assert_eq!( ParatensorModule::get_scaling_law_power(netuid), init_value); + assert_ok!( ParatensorModule::sudo_set_scaling_law_power(<::Origin>::root(), netuid, to_be_set) ); + assert_eq!( ParatensorModule::get_scaling_law_power(netuid), to_be_set); + }); +} + +#[test] +fn test_sudo_set_synergy_scaling_law_power() { + new_test_ext().execute_with(|| { + let netuid: u16 = 1; + let to_be_set: u16 = 50; + let init_value: u16 = ParatensorModule::get_synergy_scaling_law_power( netuid ); + add_network(netuid, 10, 0); + assert_eq!( ParatensorModule::sudo_set_synergy_scaling_law_power(<::Origin>::signed(0), netuid, to_be_set), Err(DispatchError::BadOrigin.into()) ); + assert_eq!( ParatensorModule::sudo_set_synergy_scaling_law_power(<::Origin>::root(), netuid + 1, to_be_set), Err(Error::::NetworkDoesNotExist.into()) ); + assert_eq!( ParatensorModule::get_synergy_scaling_law_power(netuid), init_value); + assert_ok!( ParatensorModule::sudo_set_synergy_scaling_law_power(<::Origin>::root(), netuid, to_be_set) ); + assert_eq!( ParatensorModule::get_synergy_scaling_law_power(netuid), to_be_set); + }); +} + #[test] fn test_sudo_set_max_weight_limit() { new_test_ext().execute_with(|| { diff --git a/runtime/src/lib.rs b/runtime/src/lib.rs index 49aa58c..41bfb20 100644 --- a/runtime/src/lib.rs +++ b/runtime/src/lib.rs @@ -473,6 +473,9 @@ parameter_types! { pub const ParatensorInitialValidatorSequenceLen: u16 = 10; pub const ParatensorInitialValidatorEpochLen: u16 = 1000; pub const ParatensorInitialValidatorEpochsPerReset: u16 = 60; + pub const ParatensorInitialValidatorExcludeQuantile: u16 = 10; // 0.1 + pub const ParatensorInitialScalingLawPower: u16 = 50; // 0.5 + pub const ParatensorInitialSynergyScalingLawPower: u16 = 50; // 0.5 pub const ParatensorInitialMaxAllowedValidators: u16 = 100; pub const ParatensorInitialTempo: u16 = 0; pub const ParatensorInitialDifficulty: u64 = 10000000; @@ -483,7 +486,6 @@ parameter_types! { pub const ParatensorInitialMaxRegistrationsPerBlock: u16 = 2; pub const ParatensorInitialPruningScore : u16 = u16::MAX; pub const ParatensorInitialBondsMovingAverage: u64 = 900000; - pub const ParatensorInitialValidatorExcludeQuantile: u8 = 10; // 0.1 pub const ParatensorInitialDefaultTake: u16 = 11_796; // 18% honest number. pub const ParatensorInitialWeightsVersionKey: u64 = 0; pub const ParatensorInitialMinDifficulty: u64 = 1; @@ -506,6 +508,9 @@ impl pallet_paratensor::Config for Runtime { type InitialValidatorSequenceLen = ParatensorInitialValidatorSequenceLen; type InitialValidatorEpochLen = ParatensorInitialValidatorEpochLen; type InitialValidatorEpochsPerReset = ParatensorInitialValidatorEpochsPerReset; + type InitialValidatorExcludeQuantile = ParatensorInitialValidatorExcludeQuantile; + type InitialScalingLawPower = ParatensorInitialScalingLawPower; + type InitialSynergyScalingLawPower = ParatensorInitialSynergyScalingLawPower; type InitialTempo = ParatensorInitialTempo; type InitialDifficulty = ParatensorInitialDifficulty; type InitialAdjustmentInterval = ParatensorInitialAdjustmentInterval; @@ -514,7 +519,6 @@ impl pallet_paratensor::Config for Runtime { type InitialActivityCutoff = ParatensorInitialActivityCutoff; type InitialMaxRegistrationsPerBlock = ParatensorInitialMaxRegistrationsPerBlock; type InitialPruningScore = ParatensorInitialPruningScore; - type InitialValidatorExcludeQuantile = ParatensorInitialValidatorExcludeQuantile; type InitialMaxAllowedValidators = ParatensorInitialMaxAllowedValidators; type InitialDefaultTake = ParatensorInitialDefaultTake; type InitialWeightsVersionKey = ParatensorInitialWeightsVersionKey;