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

Diff for: Cargo.lock

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

Diff for: Cargo.toml

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

Diff for: justfile

+5-1
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"

Diff for: node/Cargo.toml

+1
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" }

Diff for: node/src/benchmarking.rs

+2
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));

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 = 1;
83+
let netuid: u16 = 0;
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,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()

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

+4-3
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
}

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

+37-48
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).

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

+5-4
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};

Diff for: runtime/Cargo.toml

+3
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ 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 }
4445
sp-api = { workspace = true }
4546
sp-block-builder = { workspace = true }
4647
sp-consensus-aura = { workspace = true }
@@ -111,6 +112,7 @@ std = [
111112
"codec/std",
112113
"scale-info/std",
113114
"frame-executive/std",
115+
"frame-metadata-hash-extension/std",
114116
"frame-support/std",
115117
"frame-system-rpc-runtime-api/std",
116118
"frame-system/std",
@@ -204,3 +206,4 @@ try-runtime = [
204206
"pallet-commitments/try-runtime",
205207
"pallet-registry/try-runtime"
206208
]
209+
metadata-hash = ["substrate-wasm-builder/metadata-hash"]

Diff for: runtime/build.rs

+10-1
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,19 @@
11
fn main() {
2-
#[cfg(feature = "std")]
2+
#[cfg(all(feature = "std", not(feature = "metadata-hash")))]
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+
}
1019
}

Diff for: runtime/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1282,6 +1282,7 @@ 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>,
12851286
);
12861287

12871288
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
1+
cargo build --profile production --features "runtime-benchmarks metadata-hash"
22

0 commit comments

Comments
 (0)