Skip to content

Commit 4a1340c

Browse files
add bonds_penalty admin-utils
1 parent 4d91ec4 commit 4a1340c

File tree

6 files changed

+74
-12
lines changed

6 files changed

+74
-12
lines changed

hyperparameters.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ TxRateLimit: u64 = 1; // [1 @ 64,888]
77
### netuid 1 (text_prompting)
88
```rust
99
Rho: u16 = 10;
10-
Kappa: u16 = 32_767; // 0.5 = 65535/2
10+
Kappa: u16 = 32_767; // 0.5 = 65535/2
1111
MaxAllowedUids: u16 = 1024;
1212
Issuance: u64 = 0;
1313
MinAllowedWeights: u16 = 8;
@@ -32,10 +32,11 @@ ActivityCutoff: u16 = 5000;
3232
MaxRegistrationsPerBlock: u16 = 1;
3333
PruningScore : u16 = u16::MAX;
3434
BondsMovingAverage: u64 = 900_000;
35+
BondsPenalty: u16 = 0;
3536
WeightsVersionKey: u64 = 1020;
3637
MinDifficulty: u64 = 10_000_000;
3738
MaxDifficulty: u64 = u64::MAX / 4;
38-
ServingRateLimit: u64 = 10;
39+
ServingRateLimit: u64 = 10;
3940
Burn: u64 = 1_000_000_000; // 1 tao
4041
MinBurn: u64 = 1_000_000_000; // 1 tao
4142
MaxBurn: u64 = 100_000_000_000; // 100 tao
@@ -45,7 +46,7 @@ WeightsSetRateLimit: u64 = 100;
4546
### netuid 3 (causallmnext)
4647
```rust
4748
Rho: u16 = 10;
48-
Kappa: u16 = 32_767; // 0.5 = 65535/2
49+
Kappa: u16 = 32_767; // 0.5 = 65535/2
4950
MaxAllowedUids: u16 = 4096;
5051
Issuance: u64 = 0;
5152
MinAllowedWeights: u16 = 50;
@@ -70,6 +71,7 @@ ActivityCutoff: u16 = 5000; // [5000 @ 7,163]
7071
MaxRegistrationsPerBlock: u16 = 1;
7172
PruningScore : u16 = u16::MAX;
7273
BondsMovingAverage: u64 = 900_000;
74+
BondsPenalty: u16 = 0;
7375
WeightsVersionKey: u64 = 400;
7476
MinDifficulty: u64 = 10_000_000;
7577
MaxDifficulty: u64 = u64::MAX / 4;

pallets/admin-utils/src/benchmarking.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,14 @@ mod benchmarks {
100100
_(RawOrigin::Root, 1u16/*netuid*/, 100u64/*bonds_moving_average*/)/*sudo_set_bonds_moving_average*/;
101101
}
102102

103+
#[benchmark]
104+
fn sudo_set_bonds_penalty() {
105+
pallet_subtensor::Pallet::<T>::init_new_network(1u16 /*netuid*/, 1u16 /*tempo*/);
106+
107+
#[extrinsic_call]
108+
_(RawOrigin::Root, 1u16/*netuid*/, 100u16/*bonds_penalty*/)/*sudo_set_bonds_penalty*/;
109+
}
110+
103111
#[benchmark]
104112
fn sudo_set_max_allowed_validators() {
105113
pallet_subtensor::Pallet::<T>::init_new_network(1u16 /*netuid*/, 1u16 /*tempo*/);

pallets/admin-utils/src/lib.rs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -685,6 +685,31 @@ pub mod pallet {
685685
Ok(())
686686
}
687687

688+
/// The extrinsic sets the bonds penalty for a subnet.
689+
/// It is only callable by the root account or subnet owner.
690+
/// The extrinsic will call the Subtensor pallet to set the bonds penalty.
691+
#[pallet::call_index(60)]
692+
#[pallet::weight(<T as Config>::WeightInfo::sudo_set_bonds_penalty())]
693+
pub fn sudo_set_bonds_penalty(
694+
origin: OriginFor<T>,
695+
netuid: u16,
696+
bonds_penalty: u16,
697+
) -> DispatchResult {
698+
pallet_subtensor::Pallet::<T>::ensure_subnet_owner_or_root(origin, netuid)?;
699+
700+
ensure!(
701+
pallet_subtensor::Pallet::<T>::if_subnet_exist(netuid),
702+
Error::<T>::SubnetDoesNotExist
703+
);
704+
pallet_subtensor::Pallet::<T>::set_bonds_penalty(netuid, bonds_penalty);
705+
log::debug!(
706+
"BondsPenalty( netuid: {:?} bonds_penalty: {:?} ) ",
707+
netuid,
708+
bonds_penalty
709+
);
710+
Ok(())
711+
}
712+
688713
/// The extrinsic sets the maximum registrations per block for a subnet.
689714
/// It is only callable by the root account.
690715
/// The extrinsic will call the Subtensor pallet to set the maximum registrations per block.

pallets/admin-utils/src/tests/mod.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -746,26 +746,26 @@ fn test_sudo_set_bonds_penalty() {
746746
new_test_ext().execute_with(|| {
747747
let netuid: u16 = 1;
748748
let to_be_set: u16 = 10;
749+
add_network(netuid, 10);
749750
let init_value: u16 = SubtensorModule::get_bonds_penalty(netuid);
750-
add_network(netuid, 10, 0);
751751
assert_eq!(
752-
SubtensorModule::sudo_set_bonds_penalty(
753-
<<Test as Config>::RuntimeOrigin>::signed(U256::from(0)),
752+
AdminUtils::sudo_set_bonds_penalty(
753+
<<Test as Config>::RuntimeOrigin>::signed(U256::from(1)),
754754
netuid,
755755
to_be_set
756756
),
757-
Err(DispatchError::BadOrigin.into())
757+
Err(DispatchError::BadOrigin)
758758
);
759759
assert_eq!(
760-
SubtensorModule::sudo_set_bonds_penalty(
760+
AdminUtils::sudo_set_bonds_penalty(
761761
<<Test as Config>::RuntimeOrigin>::root(),
762762
netuid + 1,
763763
to_be_set
764764
),
765-
Err(Error::<Test>::NetworkDoesNotExist.into())
765+
Err(Error::<Test>::SubnetDoesNotExist.into())
766766
);
767767
assert_eq!(SubtensorModule::get_bonds_penalty(netuid), init_value);
768-
assert_ok!(SubtensorModule::sudo_set_bonds_penalty(
768+
assert_ok!(AdminUtils::sudo_set_bonds_penalty(
769769
<<Test as Config>::RuntimeOrigin>::root(),
770770
netuid,
771771
to_be_set

pallets/admin-utils/src/weights.rs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ pub trait WeightInfo {
4242
fn sudo_set_weights_set_rate_limit() -> Weight;
4343
fn sudo_set_weights_version_key() -> Weight;
4444
fn sudo_set_bonds_moving_average() -> Weight;
45+
fn sudo_set_bonds_penalty() -> Weight;
4546
fn sudo_set_max_allowed_validators() -> Weight;
4647
fn sudo_set_difficulty() -> Weight;
4748
fn sudo_set_adjustment_interval() -> Weight;
@@ -182,6 +183,19 @@ impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {
182183
}
183184
/// Storage: SubtensorModule NetworksAdded (r:1 w:0)
184185
/// Proof Skipped: SubtensorModule NetworksAdded (max_values: None, max_size: None, mode: Measured)
186+
/// Storage: SubtensorModule BondsPenalty (r:0 w:1)
187+
/// Proof Skipped: SubtensorModule BondsPenalty (max_values: None, max_size: None, mode: Measured)
188+
fn sudo_set_bonds_penalty() -> Weight {
189+
// Proof Size summary in bytes:
190+
// Measured: `1111`
191+
// Estimated: `4697`
192+
// Minimum execution time: 46_099_000 picoseconds.
193+
Weight::from_parts(47_510_000, 4697)
194+
.saturating_add(T::DbWeight::get().reads(1_u64))
195+
.saturating_add(T::DbWeight::get().writes(1_u64))
196+
}
197+
/// Storage: SubtensorModule NetworksAdded (r:1 w:0)
198+
/// Proof Skipped: SubtensorModule NetworksAdded (max_values: None, max_size: None, mode: Measured)
185199
/// Storage: SubtensorModule MaxAllowedUids (r:1 w:0)
186200
/// Proof Skipped: SubtensorModule MaxAllowedUids (max_values: None, max_size: None, mode: Measured)
187201
/// Storage: SubtensorModule MaxAllowedValidators (r:0 w:1)
@@ -559,6 +573,19 @@ impl WeightInfo for () {
559573
}
560574
/// Storage: SubtensorModule NetworksAdded (r:1 w:0)
561575
/// Proof Skipped: SubtensorModule NetworksAdded (max_values: None, max_size: None, mode: Measured)
576+
/// Storage: SubtensorModule BondsPenalty (r:0 w:1)
577+
/// Proof Skipped: SubtensorModule BondsPenalty (max_values: None, max_size: None, mode: Measured)
578+
fn sudo_set_bonds_penalty() -> Weight {
579+
// Proof Size summary in bytes:
580+
// Measured: `1111`
581+
// Estimated: `4697`
582+
// Minimum execution time: 46_099_000 picoseconds.
583+
Weight::from_parts(47_510_000, 4697)
584+
.saturating_add(RocksDbWeight::get().reads(1_u64))
585+
.saturating_add(RocksDbWeight::get().writes(1_u64))
586+
}
587+
/// Storage: SubtensorModule NetworksAdded (r:1 w:0)
588+
/// Proof Skipped: SubtensorModule NetworksAdded (max_values: None, max_size: None, mode: Measured)
562589
/// Storage: SubtensorModule MaxAllowedUids (r:1 w:0)
563590
/// Proof Skipped: SubtensorModule MaxAllowedUids (max_values: None, max_size: None, mode: Measured)
564591
/// Storage: SubtensorModule MaxAllowedValidators (r:0 w:1)

pallets/subtensor/src/epoch/math.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1023,7 +1023,7 @@ pub fn weighted_median_col_sparse(
10231023
}
10241024

10251025
// Element-wise interpolation of two matrices: Result = A + ratio * (B - A).
1026-
// ratio is has intended range [0, 1]
1026+
// ratio has intended range [0, 1]
10271027
// ratio=0: Result = A
10281028
// ratio=1: Result = B
10291029
#[allow(dead_code)]
@@ -1055,7 +1055,7 @@ pub fn interpolate(mat1: &[Vec<I32F32>], mat2: &[Vec<I32F32>], ratio: I32F32) ->
10551055
}
10561056

10571057
// Element-wise interpolation of two sparse matrices: Result = A + ratio * (B - A).
1058-
// ratio is has intended range [0, 1]
1058+
// ratio has intended range [0, 1]
10591059
// ratio=0: Result = A
10601060
// ratio=1: Result = B
10611061
#[allow(dead_code)]

0 commit comments

Comments
 (0)