Skip to content

Commit 00dc331

Browse files
committed
Merge branch 'devnet-ready' into fix/evm-gas-estimation
2 parents 2cc05e8 + 4263d84 commit 00dc331

File tree

18 files changed

+615
-127
lines changed

18 files changed

+615
-127
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/mock.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ parameter_types! {
8686
pub const InitialImmunityPeriod: u16 = 2;
8787
pub const InitialMaxAllowedUids: u16 = 2;
8888
pub const InitialBondsMovingAverage: u64 = 900_000;
89+
pub const InitialBondsPenalty: u16 = 0;
8990
pub const InitialStakePruningMin: u16 = 0;
9091
pub const InitialFoundationDistribution: u64 = 0;
9192
pub const InitialDefaultDelegateTake: u16 = 11_796; // 18% honest number.
@@ -163,6 +164,7 @@ impl pallet_subtensor::Config for Test {
163164
type InitialMaxRegistrationsPerBlock = InitialMaxRegistrationsPerBlock;
164165
type InitialPruningScore = InitialPruningScore;
165166
type InitialBondsMovingAverage = InitialBondsMovingAverage;
167+
type InitialBondsPenalty = InitialBondsPenalty;
166168
type InitialMaxAllowedValidators = InitialMaxAllowedValidators;
167169
type InitialDefaultDelegateTake = InitialDefaultDelegateTake;
168170
type InitialMinDelegateTake = InitialMinDelegateTake;

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

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -741,6 +741,39 @@ fn test_sudo_set_bonds_moving_average() {
741741
});
742742
}
743743

744+
#[test]
745+
fn test_sudo_set_bonds_penalty() {
746+
new_test_ext().execute_with(|| {
747+
let netuid: u16 = 1;
748+
let to_be_set: u16 = 10;
749+
add_network(netuid, 10);
750+
let init_value: u16 = SubtensorModule::get_bonds_penalty(netuid);
751+
assert_eq!(
752+
AdminUtils::sudo_set_bonds_penalty(
753+
<<Test as Config>::RuntimeOrigin>::signed(U256::from(1)),
754+
netuid,
755+
to_be_set
756+
),
757+
Err(DispatchError::BadOrigin)
758+
);
759+
assert_eq!(
760+
AdminUtils::sudo_set_bonds_penalty(
761+
<<Test as Config>::RuntimeOrigin>::root(),
762+
netuid + 1,
763+
to_be_set
764+
),
765+
Err(Error::<Test>::SubnetDoesNotExist.into())
766+
);
767+
assert_eq!(SubtensorModule::get_bonds_penalty(netuid), init_value);
768+
assert_ok!(AdminUtils::sudo_set_bonds_penalty(
769+
<<Test as Config>::RuntimeOrigin>::root(),
770+
netuid,
771+
to_be_set
772+
));
773+
assert_eq!(SubtensorModule::get_bonds_penalty(netuid), to_be_set);
774+
});
775+
}
776+
744777
#[test]
745778
fn test_sudo_set_rao_recycled() {
746779
new_test_ext().execute_with(|| {

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: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1022,6 +1022,90 @@ pub fn weighted_median_col_sparse(
10221022
median
10231023
}
10241024

1025+
// Element-wise interpolation of two matrices: Result = A + ratio * (B - A).
1026+
// ratio has intended range [0, 1]
1027+
// ratio=0: Result = A
1028+
// ratio=1: Result = B
1029+
#[allow(dead_code)]
1030+
pub fn interpolate(mat1: &[Vec<I32F32>], mat2: &[Vec<I32F32>], ratio: I32F32) -> Vec<Vec<I32F32>> {
1031+
if ratio == I32F32::from_num(0) {
1032+
return mat1.to_owned();
1033+
}
1034+
if ratio == I32F32::from_num(1) {
1035+
return mat2.to_owned();
1036+
}
1037+
assert!(mat1.len() == mat2.len());
1038+
if mat1.is_empty() {
1039+
return vec![vec![]; 1];
1040+
}
1041+
if mat1.first().unwrap_or(&vec![]).is_empty() {
1042+
return vec![vec![]; 1];
1043+
}
1044+
let mut result: Vec<Vec<I32F32>> =
1045+
vec![vec![I32F32::from_num(0); mat1.first().unwrap_or(&vec![]).len()]; mat1.len()];
1046+
for (i, (row1, row2)) in mat1.iter().zip(mat2.iter()).enumerate() {
1047+
assert!(row1.len() == row2.len());
1048+
for (j, (&v1, &v2)) in row1.iter().zip(row2.iter()).enumerate() {
1049+
if let Some(res) = result.get_mut(i).unwrap_or(&mut vec![]).get_mut(j) {
1050+
*res = v1.saturating_add(ratio.saturating_mul(v2.saturating_sub(v1)));
1051+
}
1052+
}
1053+
}
1054+
result
1055+
}
1056+
1057+
// Element-wise interpolation of two sparse matrices: Result = A + ratio * (B - A).
1058+
// ratio has intended range [0, 1]
1059+
// ratio=0: Result = A
1060+
// ratio=1: Result = B
1061+
#[allow(dead_code)]
1062+
pub fn interpolate_sparse(
1063+
mat1: &[Vec<(u16, I32F32)>],
1064+
mat2: &[Vec<(u16, I32F32)>],
1065+
columns: u16,
1066+
ratio: I32F32,
1067+
) -> Vec<Vec<(u16, I32F32)>> {
1068+
if ratio == I32F32::from_num(0) {
1069+
return mat1.to_owned();
1070+
}
1071+
if ratio == I32F32::from_num(1) {
1072+
return mat2.to_owned();
1073+
}
1074+
assert!(mat1.len() == mat2.len());
1075+
let rows = mat1.len();
1076+
let zero: I32F32 = I32F32::from_num(0);
1077+
let mut result: Vec<Vec<(u16, I32F32)>> = vec![vec![]; rows];
1078+
for i in 0..rows {
1079+
let mut row1: Vec<I32F32> = vec![zero; columns as usize];
1080+
if let Some(row) = mat1.get(i) {
1081+
for (j, value) in row {
1082+
if let Some(entry) = row1.get_mut(*j as usize) {
1083+
*entry = *value;
1084+
}
1085+
}
1086+
}
1087+
let mut row2: Vec<I32F32> = vec![zero; columns as usize];
1088+
if let Some(row) = mat2.get(i) {
1089+
for (j, value) in row {
1090+
if let Some(entry) = row2.get_mut(*j as usize) {
1091+
*entry = *value;
1092+
}
1093+
}
1094+
}
1095+
for j in 0..columns as usize {
1096+
let v1 = row1.get(j).unwrap_or(&zero);
1097+
let v2 = row2.get(j).unwrap_or(&zero);
1098+
let interp = v1.saturating_add(ratio.saturating_mul(v2.saturating_sub(*v1)));
1099+
if zero < interp {
1100+
if let Some(res) = result.get_mut(i) {
1101+
res.push((j as u16, interp));
1102+
}
1103+
}
1104+
}
1105+
}
1106+
result
1107+
}
1108+
10251109
// Element-wise product of two matrices.
10261110
#[allow(dead_code)]
10271111
pub fn hadamard(mat1: &[Vec<I32F32>], mat2: &[Vec<I32F32>]) -> Vec<Vec<I32F32>> {

0 commit comments

Comments
 (0)