Skip to content

Commit c9202c9

Browse files
authored
Merge branch 'devnet-ready' into main
2 parents a2b8d70 + 1c50295 commit c9202c9

File tree

14 files changed

+417
-338
lines changed

14 files changed

+417
-338
lines changed

Cargo.lock

Lines changed: 277 additions & 208 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 70 additions & 69 deletions
Large diffs are not rendered by default.

justfile

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,4 +47,8 @@ lint:
4747
@echo "Running cargo clippy with automatic fixes on potentially dirty code..."
4848
just clippy-fix
4949
@echo "Running cargo clippy..."
50-
just clippy
50+
just clippy
51+
52+
production:
53+
@echo "Running cargo build with metadata-hash generation..."
54+
cargo +{{RUSTV}} build --profile production --features="runtime-benchmarks metadata-hash"

node/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ sp-io = { workspace = true }
5454
sp-timestamp = { workspace = true }
5555
sp-inherents = { workspace = true }
5656
sp-keyring = { workspace = true }
57+
frame-metadata-hash-extension = { workspace = true }
5758
frame-system = { workspace = true }
5859
pallet-transaction-payment = { workspace = true }
5960
pallet-commitments = { path = "../pallets/commitments" }

node/src/benchmarking.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ pub fn create_benchmark_extrinsic(
136136
pallet_transaction_payment::ChargeTransactionPayment::<runtime::Runtime>::from(0),
137137
pallet_subtensor::SubtensorSignedExtension::<runtime::Runtime>::new(),
138138
pallet_commitments::CommitmentsSignedExtension::<runtime::Runtime>::new(),
139+
frame_metadata_hash_extension::CheckMetadataHash::<runtime::Runtime>::new(true),
139140
);
140141

141142
let raw_payload = runtime::SignedPayload::from_raw(
@@ -152,6 +153,7 @@ pub fn create_benchmark_extrinsic(
152153
(),
153154
(),
154155
(),
156+
None,
155157
),
156158
);
157159
let signature = raw_payload.using_encoded(|e| sender.sign(e));

pallets/subtensor/src/benchmarks.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ benchmarks! {
8080
// This is a whitelisted caller who can make transaction without weights.
8181
let caller: T::AccountId = whitelisted_caller::<AccountIdOf<T>>();
8282
let caller_origin = <T as frame_system::Config>::RuntimeOrigin::from(RawOrigin::Signed(caller.clone()));
83-
let netuid: u16 = 1;
83+
let netuid: u16 = 0;
8484
let version_key: u64 = 1;
8585
let tempo: u16 = 1;
8686
let modality: u16 = 0;

pallets/subtensor/src/epoch.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,8 +188,6 @@ impl<T: Config> Pallet<T> {
188188
// =================================
189189

190190
// Compute emission scores.
191-
192-
// Compute normalized emission scores. range: I32F32(0, 1)
193191
// Compute normalized emission scores. range: I32F32(0, 1)
194192
let combined_emission: Vec<I32F32> = incentive
195193
.iter()

pallets/subtensor/src/lib.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2045,9 +2045,10 @@ pub mod pallet {
20452045

20462046
/// Attempt to adjust the senate membership to include a hotkey
20472047
#[pallet::call_index(63)]
2048-
#[pallet::weight((Weight::from_parts(0, 0)
2049-
.saturating_add(T::DbWeight::get().reads(0))
2050-
.saturating_add(T::DbWeight::get().writes(0)), DispatchClass::Normal, Pays::Yes))]
2048+
#[pallet::weight((Weight::from_parts(50_000_000, 0)
2049+
.saturating_add(Weight::from_parts(0, 4632))
2050+
.saturating_add(T::DbWeight::get().reads(5))
2051+
.saturating_add(T::DbWeight::get().writes(1)), DispatchClass::Normal, Pays::Yes))]
20512052
pub fn adjust_senate(origin: OriginFor<T>, hotkey: T::AccountId) -> DispatchResult {
20522053
Self::do_adjust_senate(origin, hotkey)
20532054
}

pallets/subtensor/src/math.rs

Lines changed: 37 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -889,59 +889,48 @@ pub fn weighted_median(
889889
score: &[I32F32],
890890
partition_idx: &[usize],
891891
minority: I32F32,
892-
partition_lo: I32F32,
893-
partition_hi: I32F32,
892+
mut partition_lo: I32F32,
893+
mut partition_hi: I32F32,
894894
) -> I32F32 {
895-
let n = partition_idx.len();
896-
if n == 0 {
897-
return I32F32::from_num(0);
898-
}
899-
if n == 1 {
900-
return score[partition_idx[0]];
901-
}
902-
assert!(stake.len() == score.len());
903-
let mid_idx: usize = n.saturating_div(2);
904-
let pivot: I32F32 = score[partition_idx[mid_idx]];
905-
let mut lo_stake: I32F32 = I32F32::from_num(0);
906-
let mut hi_stake: I32F32 = I32F32::from_num(0);
907-
let mut lower: Vec<usize> = vec![];
908-
let mut upper: Vec<usize> = vec![];
909-
for &idx in partition_idx {
910-
if score[idx] == pivot {
911-
continue;
895+
let mut current_partition_idx = partition_idx.to_vec();
896+
while !current_partition_idx.is_empty() {
897+
let n = current_partition_idx.len();
898+
if n == 1 {
899+
return score[current_partition_idx[0]];
900+
}
901+
let mid_idx: usize = n.saturating_div(2);
902+
let pivot: I32F32 = score[current_partition_idx[mid_idx]];
903+
let mut lo_stake: I32F32 = I32F32::from_num(0);
904+
let mut hi_stake: I32F32 = I32F32::from_num(0);
905+
let mut lower: Vec<usize> = vec![];
906+
let mut upper: Vec<usize> = vec![];
907+
for &idx in &current_partition_idx {
908+
if score[idx] == pivot {
909+
continue;
910+
}
911+
if score[idx] < pivot {
912+
lo_stake = lo_stake.saturating_add(stake[idx]);
913+
lower.push(idx);
914+
} else {
915+
hi_stake = hi_stake.saturating_add(stake[idx]);
916+
upper.push(idx);
917+
}
912918
}
913-
if score[idx] < pivot {
914-
lo_stake = lo_stake.saturating_add(stake[idx]);
915-
lower.push(idx);
919+
if partition_lo.saturating_add(lo_stake) <= minority
920+
&& minority < partition_hi.saturating_sub(hi_stake)
921+
{
922+
return pivot;
923+
} else if (minority < partition_lo.saturating_add(lo_stake)) && (!lower.is_empty()) {
924+
current_partition_idx = lower;
925+
partition_hi = partition_lo.saturating_add(lo_stake);
926+
} else if (partition_hi.saturating_sub(hi_stake) <= minority) && (!upper.is_empty()) {
927+
current_partition_idx = upper;
928+
partition_lo = partition_hi.saturating_sub(hi_stake);
916929
} else {
917-
hi_stake = hi_stake.saturating_add(stake[idx]);
918-
upper.push(idx);
930+
return pivot;
919931
}
920932
}
921-
if (partition_lo.saturating_add(lo_stake) <= minority)
922-
&& (minority < partition_hi.saturating_sub(hi_stake))
923-
{
924-
return pivot;
925-
} else if (minority < partition_lo.saturating_add(lo_stake)) && (!lower.is_empty()) {
926-
return weighted_median(
927-
stake,
928-
score,
929-
&lower,
930-
minority,
931-
partition_lo,
932-
partition_lo.saturating_add(lo_stake),
933-
);
934-
} else if (partition_hi.saturating_sub(hi_stake) <= minority) && (!upper.is_empty()) {
935-
return weighted_median(
936-
stake,
937-
score,
938-
&upper,
939-
minority,
940-
partition_hi.saturating_sub(hi_stake),
941-
partition_hi,
942-
);
943-
}
944-
pivot
933+
I32F32::from_num(0)
945934
}
946935

947936
/// Column-wise weighted median, e.g. stake-weighted median scores per server (column) over all validators (rows).

pallets/subtensor/tests/mock.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
#![allow(clippy::arithmetic_side_effects, clippy::unwrap_used)]
2-
use frame_support::derive_impl;
3-
use frame_support::dispatch::DispatchResultWithPostInfo;
4-
use frame_support::weights::constants::RocksDbWeight;
2+
53
// use frame_support::weights::constants::WEIGHT_PER_SECOND;
64
use frame_support::weights::Weight;
75
use frame_support::{
8-
assert_ok, parameter_types,
6+
assert_ok, derive_impl,
7+
dispatch::DispatchResultWithPostInfo,
8+
parameter_types,
99
traits::{Everything, Hooks},
10+
weights::constants::RocksDbWeight,
1011
};
1112
use frame_system as system;
1213
use frame_system::{limits, EnsureNever, EnsureRoot, RawOrigin};

0 commit comments

Comments
 (0)