Skip to content

Commit d7fd308

Browse files
authored
Merge pull request #664 from opentensor/main-fix
Revert "Merge branch 'devnet-ready' into main"
2 parents c9202c9 + 2bb1557 commit d7fd308

File tree

14 files changed

+338
-417
lines changed

14 files changed

+338
-417
lines changed

Diff for: Cargo.lock

+208-277
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: Cargo.toml

+69-70
Large diffs are not rendered by default.

Diff for: justfile

+1-5
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,4 @@ 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
51-
52-
production:
53-
@echo "Running cargo build with metadata-hash generation..."
54-
cargo +{{RUSTV}} build --profile production --features="runtime-benchmarks metadata-hash"
50+
just clippy

Diff for: node/Cargo.toml

-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ 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 }
5857
frame-system = { workspace = true }
5958
pallet-transaction-payment = { workspace = true }
6059
pallet-commitments = { path = "../pallets/commitments" }

Diff for: node/src/benchmarking.rs

-2
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,6 @@ 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),
140139
);
141140

142141
let raw_payload = runtime::SignedPayload::from_raw(
@@ -153,7 +152,6 @@ pub fn create_benchmark_extrinsic(
153152
(),
154153
(),
155154
(),
156-
None,
157155
),
158156
);
159157
let signature = raw_payload.using_encoded(|e| sender.sign(e));

Diff for: pallets/subtensor/src/benchmarks.rs

+1-1
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 = 0;
83+
let netuid: u16 = 1;
8484
let version_key: u64 = 1;
8585
let tempo: u16 = 1;
8686
let modality: u16 = 0;

Diff for: pallets/subtensor/src/epoch.rs

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

190190
// Compute emission scores.
191+
192+
// Compute normalized emission scores. range: I32F32(0, 1)
191193
// Compute normalized emission scores. range: I32F32(0, 1)
192194
let combined_emission: Vec<I32F32> = incentive
193195
.iter()

Diff for: pallets/subtensor/src/lib.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -2045,10 +2045,9 @@ 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(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))]
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))]
20522051
pub fn adjust_senate(origin: OriginFor<T>, hotkey: T::AccountId) -> DispatchResult {
20532052
Self::do_adjust_senate(origin, hotkey)
20542053
}

Diff for: pallets/subtensor/src/math.rs

+48-37
Original file line numberDiff line numberDiff line change
@@ -889,48 +889,59 @@ pub fn weighted_median(
889889
score: &[I32F32],
890890
partition_idx: &[usize],
891891
minority: I32F32,
892-
mut partition_lo: I32F32,
893-
mut partition_hi: I32F32,
892+
partition_lo: I32F32,
893+
partition_hi: I32F32,
894894
) -> I32F32 {
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-
}
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;
918912
}
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);
913+
if score[idx] < pivot {
914+
lo_stake = lo_stake.saturating_add(stake[idx]);
915+
lower.push(idx);
929916
} else {
930-
return pivot;
917+
hi_stake = hi_stake.saturating_add(stake[idx]);
918+
upper.push(idx);
931919
}
932920
}
933-
I32F32::from_num(0)
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
934945
}
935946

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

Diff for: pallets/subtensor/tests/mock.rs

+4-5
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
#![allow(clippy::arithmetic_side_effects, clippy::unwrap_used)]
2-
2+
use frame_support::derive_impl;
3+
use frame_support::dispatch::DispatchResultWithPostInfo;
4+
use frame_support::weights::constants::RocksDbWeight;
35
// use frame_support::weights::constants::WEIGHT_PER_SECOND;
46
use frame_support::weights::Weight;
57
use frame_support::{
6-
assert_ok, derive_impl,
7-
dispatch::DispatchResultWithPostInfo,
8-
parameter_types,
8+
assert_ok, parameter_types,
99
traits::{Everything, Hooks},
10-
weights::constants::RocksDbWeight,
1110
};
1211
use frame_system as system;
1312
use frame_system::{limits, EnsureNever, EnsureRoot, RawOrigin};

Diff for: runtime/Cargo.toml

-3
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ pallet-timestamp = { workspace = true }
4141
pallet-transaction-payment = { workspace = true }
4242
pallet-utility = { workspace = true }
4343
frame-executive = { workspace = true }
44-
frame-metadata-hash-extension = { workspace = true }
4544
sp-api = { workspace = true }
4645
sp-block-builder = { workspace = true }
4746
sp-consensus-aura = { workspace = true }
@@ -112,7 +111,6 @@ std = [
112111
"codec/std",
113112
"scale-info/std",
114113
"frame-executive/std",
115-
"frame-metadata-hash-extension/std",
116114
"frame-support/std",
117115
"frame-system-rpc-runtime-api/std",
118116
"frame-system/std",
@@ -206,4 +204,3 @@ try-runtime = [
206204
"pallet-commitments/try-runtime",
207205
"pallet-registry/try-runtime"
208206
]
209-
metadata-hash = ["substrate-wasm-builder/metadata-hash"]

Diff for: runtime/build.rs

+1-10
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,10 @@
11
fn main() {
2-
#[cfg(all(feature = "std", not(feature = "metadata-hash")))]
2+
#[cfg(feature = "std")]
33
{
44
substrate_wasm_builder::WasmBuilder::new()
55
.with_current_project()
66
.export_heap_base()
77
.import_memory()
88
.build();
99
}
10-
#[cfg(all(feature = "std", feature = "metadata-hash"))]
11-
{
12-
substrate_wasm_builder::WasmBuilder::new()
13-
.with_current_project()
14-
.export_heap_base()
15-
.import_memory()
16-
.enable_metadata_hash("TAO", 9)
17-
.build();
18-
}
1910
}

Diff for: runtime/src/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1282,7 +1282,6 @@ pub type SignedExtra = (
12821282
pallet_transaction_payment::ChargeTransactionPayment<Runtime>,
12831283
pallet_subtensor::SubtensorSignedExtension<Runtime>,
12841284
pallet_commitments::CommitmentsSignedExtension<Runtime>,
1285-
frame_metadata_hash_extension::CheckMetadataHash<Runtime>,
12861285
);
12871286

12881287
type Migrations = pallet_grandpa::migrations::MigrateV4ToV5<Runtime>;

Diff for: scripts/build.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
cargo build --profile production --features "runtime-benchmarks metadata-hash"
1+
cargo build --profile production --features runtime-benchmarks
22

0 commit comments

Comments
 (0)