From 4ee6910c75ba6624af2c9c0e63f767f5631959fe Mon Sep 17 00:00:00 2001 From: Andreea Popescu Date: Wed, 15 Jan 2025 14:19:24 +0000 Subject: [PATCH] admin-utils --- hyperparameters.md | 8 +++++--- pallets/admin-utils/src/benchmarking.rs | 8 ++++++++ pallets/admin-utils/src/lib.rs | 25 +++++++++++++++++++++++ pallets/admin-utils/src/tests/mod.rs | 14 ++++++------- pallets/admin-utils/src/weights.rs | 27 +++++++++++++++++++++++++ 5 files changed, 72 insertions(+), 10 deletions(-) diff --git a/hyperparameters.md b/hyperparameters.md index 96f955437..c8d2ce110 100644 --- a/hyperparameters.md +++ b/hyperparameters.md @@ -7,7 +7,7 @@ TxRateLimit: u64 = 1; // [1 @ 64,888] ### netuid 1 (text_prompting) ```rust Rho: u16 = 10; -Kappa: u16 = 32_767; // 0.5 = 65535/2 +Kappa: u16 = 32_767; // 0.5 = 65535/2 MaxAllowedUids: u16 = 1024; Issuance: u64 = 0; MinAllowedWeights: u16 = 8; @@ -32,10 +32,11 @@ ActivityCutoff: u16 = 5000; MaxRegistrationsPerBlock: u16 = 1; PruningScore : u16 = u16::MAX; BondsMovingAverage: u64 = 900_000; +BondsPenalty: u16 = 0; WeightsVersionKey: u64 = 1020; MinDifficulty: u64 = 10_000_000; MaxDifficulty: u64 = u64::MAX / 4; -ServingRateLimit: u64 = 10; +ServingRateLimit: u64 = 10; Burn: u64 = 1_000_000_000; // 1 tao MinBurn: u64 = 1_000_000_000; // 1 tao MaxBurn: u64 = 100_000_000_000; // 100 tao @@ -45,7 +46,7 @@ WeightsSetRateLimit: u64 = 100; ### netuid 3 (causallmnext) ```rust Rho: u16 = 10; -Kappa: u16 = 32_767; // 0.5 = 65535/2 +Kappa: u16 = 32_767; // 0.5 = 65535/2 MaxAllowedUids: u16 = 4096; Issuance: u64 = 0; MinAllowedWeights: u16 = 50; @@ -70,6 +71,7 @@ ActivityCutoff: u16 = 5000; // [5000 @ 7,163] MaxRegistrationsPerBlock: u16 = 1; PruningScore : u16 = u16::MAX; BondsMovingAverage: u64 = 900_000; +BondsPenalty: u16 = 0; WeightsVersionKey: u64 = 400; MinDifficulty: u64 = 10_000_000; MaxDifficulty: u64 = u64::MAX / 4; diff --git a/pallets/admin-utils/src/benchmarking.rs b/pallets/admin-utils/src/benchmarking.rs index abbcd0f16..af9b68051 100644 --- a/pallets/admin-utils/src/benchmarking.rs +++ b/pallets/admin-utils/src/benchmarking.rs @@ -100,6 +100,14 @@ mod benchmarks { _(RawOrigin::Root, 1u16/*netuid*/, 100u64/*bonds_moving_average*/)/*sudo_set_bonds_moving_average*/; } + #[benchmark] + fn sudo_set_bonds_penalty() { + pallet_subtensor::Pallet::::init_new_network(1u16 /*netuid*/, 1u16 /*tempo*/); + + #[extrinsic_call] + _(RawOrigin::Root, 1u16/*netuid*/, 100u16/*bonds_penalty*/)/*sudo_set_bonds_penalty*/; + } + #[benchmark] fn sudo_set_max_allowed_validators() { pallet_subtensor::Pallet::::init_new_network(1u16 /*netuid*/, 1u16 /*tempo*/); diff --git a/pallets/admin-utils/src/lib.rs b/pallets/admin-utils/src/lib.rs index f6b132148..7de39aa38 100644 --- a/pallets/admin-utils/src/lib.rs +++ b/pallets/admin-utils/src/lib.rs @@ -685,6 +685,31 @@ pub mod pallet { Ok(()) } + /// The extrinsic sets the bonds penalty for a subnet. + /// It is only callable by the root account or subnet owner. + /// The extrinsic will call the Subtensor pallet to set the bonds penalty. + #[pallet::call_index(60)] + #[pallet::weight(::WeightInfo::sudo_set_bonds_penalty())] + pub fn sudo_set_bonds_penalty( + origin: OriginFor, + netuid: u16, + bonds_penalty: u16, + ) -> DispatchResult { + pallet_subtensor::Pallet::::ensure_subnet_owner_or_root(origin, netuid)?; + + ensure!( + pallet_subtensor::Pallet::::if_subnet_exist(netuid), + Error::::SubnetDoesNotExist + ); + pallet_subtensor::Pallet::::set_bonds_penalty(netuid, bonds_penalty); + log::debug!( + "BondsPenalty( netuid: {:?} bonds_penalty: {:?} ) ", + netuid, + bonds_penalty + ); + Ok(()) + } + /// The extrinsic sets the maximum registrations per block for a subnet. /// It is only callable by the root account. /// The extrinsic will call the Subtensor pallet to set the maximum registrations per block. diff --git a/pallets/admin-utils/src/tests/mod.rs b/pallets/admin-utils/src/tests/mod.rs index 115683464..f591c3e4e 100644 --- a/pallets/admin-utils/src/tests/mod.rs +++ b/pallets/admin-utils/src/tests/mod.rs @@ -746,26 +746,26 @@ fn test_sudo_set_bonds_penalty() { new_test_ext().execute_with(|| { let netuid: u16 = 1; let to_be_set: u16 = 10; + add_network(netuid, 10); let init_value: u16 = SubtensorModule::get_bonds_penalty(netuid); - add_network(netuid, 10, 0); assert_eq!( - SubtensorModule::sudo_set_bonds_penalty( - <::RuntimeOrigin>::signed(U256::from(0)), + AdminUtils::sudo_set_bonds_penalty( + <::RuntimeOrigin>::signed(U256::from(1)), netuid, to_be_set ), - Err(DispatchError::BadOrigin.into()) + Err(DispatchError::BadOrigin) ); assert_eq!( - SubtensorModule::sudo_set_bonds_penalty( + AdminUtils::sudo_set_bonds_penalty( <::RuntimeOrigin>::root(), netuid + 1, to_be_set ), - Err(Error::::NetworkDoesNotExist.into()) + Err(Error::::SubnetDoesNotExist.into()) ); assert_eq!(SubtensorModule::get_bonds_penalty(netuid), init_value); - assert_ok!(SubtensorModule::sudo_set_bonds_penalty( + assert_ok!(AdminUtils::sudo_set_bonds_penalty( <::RuntimeOrigin>::root(), netuid, to_be_set diff --git a/pallets/admin-utils/src/weights.rs b/pallets/admin-utils/src/weights.rs index cb7017023..6ef952354 100644 --- a/pallets/admin-utils/src/weights.rs +++ b/pallets/admin-utils/src/weights.rs @@ -42,6 +42,7 @@ pub trait WeightInfo { fn sudo_set_weights_set_rate_limit() -> Weight; fn sudo_set_weights_version_key() -> Weight; fn sudo_set_bonds_moving_average() -> Weight; + fn sudo_set_bonds_penalty() -> Weight; fn sudo_set_max_allowed_validators() -> Weight; fn sudo_set_difficulty() -> Weight; fn sudo_set_adjustment_interval() -> Weight; @@ -182,6 +183,19 @@ impl WeightInfo for SubstrateWeight { } /// Storage: SubtensorModule NetworksAdded (r:1 w:0) /// Proof Skipped: SubtensorModule NetworksAdded (max_values: None, max_size: None, mode: Measured) + /// Storage: SubtensorModule BondsPenalty (r:0 w:1) + /// Proof Skipped: SubtensorModule BondsPenalty (max_values: None, max_size: None, mode: Measured) + fn sudo_set_bonds_penalty() -> Weight { + // Proof Size summary in bytes: + // Measured: `1111` + // Estimated: `4697` + // Minimum execution time: 46_099_000 picoseconds. + Weight::from_parts(47_510_000, 4697) + .saturating_add(T::DbWeight::get().reads(1_u64)) + .saturating_add(T::DbWeight::get().writes(1_u64)) + } + /// Storage: SubtensorModule NetworksAdded (r:1 w:0) + /// Proof Skipped: SubtensorModule NetworksAdded (max_values: None, max_size: None, mode: Measured) /// Storage: SubtensorModule MaxAllowedUids (r:1 w:0) /// Proof Skipped: SubtensorModule MaxAllowedUids (max_values: None, max_size: None, mode: Measured) /// Storage: SubtensorModule MaxAllowedValidators (r:0 w:1) @@ -559,6 +573,19 @@ impl WeightInfo for () { } /// Storage: SubtensorModule NetworksAdded (r:1 w:0) /// Proof Skipped: SubtensorModule NetworksAdded (max_values: None, max_size: None, mode: Measured) + /// Storage: SubtensorModule BondsPenalty (r:0 w:1) + /// Proof Skipped: SubtensorModule BondsPenalty (max_values: None, max_size: None, mode: Measured) + fn sudo_set_bonds_penalty() -> Weight { + // Proof Size summary in bytes: + // Measured: `1111` + // Estimated: `4697` + // Minimum execution time: 46_099_000 picoseconds. + Weight::from_parts(47_510_000, 4697) + .saturating_add(RocksDbWeight::get().reads(1_u64)) + .saturating_add(RocksDbWeight::get().writes(1_u64)) + } + /// Storage: SubtensorModule NetworksAdded (r:1 w:0) + /// Proof Skipped: SubtensorModule NetworksAdded (max_values: None, max_size: None, mode: Measured) /// Storage: SubtensorModule MaxAllowedUids (r:1 w:0) /// Proof Skipped: SubtensorModule MaxAllowedUids (max_values: None, max_size: None, mode: Measured) /// Storage: SubtensorModule MaxAllowedValidators (r:0 w:1)