Skip to content

Commit

Permalink
Revert "Merge branch 'devnet-ready' into main"
Browse files Browse the repository at this point in the history
This reverts commit c9202c9, reversing
changes made to a2b8d70.
  • Loading branch information
Samuel Dare committed Jul 22, 2024
1 parent c9202c9 commit 2bb1557
Show file tree
Hide file tree
Showing 14 changed files with 338 additions and 417 deletions.
485 changes: 208 additions & 277 deletions Cargo.lock

Large diffs are not rendered by default.

139 changes: 69 additions & 70 deletions Cargo.toml

Large diffs are not rendered by default.

6 changes: 1 addition & 5 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,4 @@ lint:
@echo "Running cargo clippy with automatic fixes on potentially dirty code..."
just clippy-fix
@echo "Running cargo clippy..."
just clippy

production:
@echo "Running cargo build with metadata-hash generation..."
cargo +{{RUSTV}} build --profile production --features="runtime-benchmarks metadata-hash"
just clippy
1 change: 0 additions & 1 deletion node/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ sp-io = { workspace = true }
sp-timestamp = { workspace = true }
sp-inherents = { workspace = true }
sp-keyring = { workspace = true }
frame-metadata-hash-extension = { workspace = true }
frame-system = { workspace = true }
pallet-transaction-payment = { workspace = true }
pallet-commitments = { path = "../pallets/commitments" }
Expand Down
2 changes: 0 additions & 2 deletions node/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,6 @@ pub fn create_benchmark_extrinsic(
pallet_transaction_payment::ChargeTransactionPayment::<runtime::Runtime>::from(0),
pallet_subtensor::SubtensorSignedExtension::<runtime::Runtime>::new(),
pallet_commitments::CommitmentsSignedExtension::<runtime::Runtime>::new(),
frame_metadata_hash_extension::CheckMetadataHash::<runtime::Runtime>::new(true),
);

let raw_payload = runtime::SignedPayload::from_raw(
Expand All @@ -153,7 +152,6 @@ pub fn create_benchmark_extrinsic(
(),
(),
(),
None,
),
);
let signature = raw_payload.using_encoded(|e| sender.sign(e));
Expand Down
2 changes: 1 addition & 1 deletion pallets/subtensor/src/benchmarks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ benchmarks! {
// This is a whitelisted caller who can make transaction without weights.
let caller: T::AccountId = whitelisted_caller::<AccountIdOf<T>>();
let caller_origin = <T as frame_system::Config>::RuntimeOrigin::from(RawOrigin::Signed(caller.clone()));
let netuid: u16 = 0;
let netuid: u16 = 1;
let version_key: u64 = 1;
let tempo: u16 = 1;
let modality: u16 = 0;
Expand Down
2 changes: 2 additions & 0 deletions pallets/subtensor/src/epoch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,8 @@ impl<T: Config> Pallet<T> {
// =================================

// Compute emission scores.

// Compute normalized emission scores. range: I32F32(0, 1)
// Compute normalized emission scores. range: I32F32(0, 1)
let combined_emission: Vec<I32F32> = incentive
.iter()
Expand Down
7 changes: 3 additions & 4 deletions pallets/subtensor/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2045,10 +2045,9 @@ pub mod pallet {

/// Attempt to adjust the senate membership to include a hotkey
#[pallet::call_index(63)]
#[pallet::weight((Weight::from_parts(50_000_000, 0)
.saturating_add(Weight::from_parts(0, 4632))
.saturating_add(T::DbWeight::get().reads(5))
.saturating_add(T::DbWeight::get().writes(1)), DispatchClass::Normal, Pays::Yes))]
#[pallet::weight((Weight::from_parts(0, 0)
.saturating_add(T::DbWeight::get().reads(0))
.saturating_add(T::DbWeight::get().writes(0)), DispatchClass::Normal, Pays::Yes))]
pub fn adjust_senate(origin: OriginFor<T>, hotkey: T::AccountId) -> DispatchResult {
Self::do_adjust_senate(origin, hotkey)
}
Expand Down
85 changes: 48 additions & 37 deletions pallets/subtensor/src/math.rs
Original file line number Diff line number Diff line change
Expand Up @@ -889,48 +889,59 @@ pub fn weighted_median(
score: &[I32F32],
partition_idx: &[usize],
minority: I32F32,
mut partition_lo: I32F32,
mut partition_hi: I32F32,
partition_lo: I32F32,
partition_hi: I32F32,
) -> I32F32 {
let mut current_partition_idx = partition_idx.to_vec();
while !current_partition_idx.is_empty() {
let n = current_partition_idx.len();
if n == 1 {
return score[current_partition_idx[0]];
}
let mid_idx: usize = n.saturating_div(2);
let pivot: I32F32 = score[current_partition_idx[mid_idx]];
let mut lo_stake: I32F32 = I32F32::from_num(0);
let mut hi_stake: I32F32 = I32F32::from_num(0);
let mut lower: Vec<usize> = vec![];
let mut upper: Vec<usize> = vec![];
for &idx in &current_partition_idx {
if score[idx] == pivot {
continue;
}
if score[idx] < pivot {
lo_stake = lo_stake.saturating_add(stake[idx]);
lower.push(idx);
} else {
hi_stake = hi_stake.saturating_add(stake[idx]);
upper.push(idx);
}
let n = partition_idx.len();
if n == 0 {
return I32F32::from_num(0);
}
if n == 1 {
return score[partition_idx[0]];
}
assert!(stake.len() == score.len());
let mid_idx: usize = n.saturating_div(2);
let pivot: I32F32 = score[partition_idx[mid_idx]];
let mut lo_stake: I32F32 = I32F32::from_num(0);
let mut hi_stake: I32F32 = I32F32::from_num(0);
let mut lower: Vec<usize> = vec![];
let mut upper: Vec<usize> = vec![];
for &idx in partition_idx {
if score[idx] == pivot {
continue;
}
if partition_lo.saturating_add(lo_stake) <= minority
&& minority < partition_hi.saturating_sub(hi_stake)
{
return pivot;
} else if (minority < partition_lo.saturating_add(lo_stake)) && (!lower.is_empty()) {
current_partition_idx = lower;
partition_hi = partition_lo.saturating_add(lo_stake);
} else if (partition_hi.saturating_sub(hi_stake) <= minority) && (!upper.is_empty()) {
current_partition_idx = upper;
partition_lo = partition_hi.saturating_sub(hi_stake);
if score[idx] < pivot {
lo_stake = lo_stake.saturating_add(stake[idx]);
lower.push(idx);
} else {
return pivot;
hi_stake = hi_stake.saturating_add(stake[idx]);
upper.push(idx);
}
}
I32F32::from_num(0)
if (partition_lo.saturating_add(lo_stake) <= minority)
&& (minority < partition_hi.saturating_sub(hi_stake))
{
return pivot;
} else if (minority < partition_lo.saturating_add(lo_stake)) && (!lower.is_empty()) {
return weighted_median(
stake,
score,
&lower,
minority,
partition_lo,
partition_lo.saturating_add(lo_stake),
);
} else if (partition_hi.saturating_sub(hi_stake) <= minority) && (!upper.is_empty()) {
return weighted_median(
stake,
score,
&upper,
minority,
partition_hi.saturating_sub(hi_stake),
partition_hi,
);
}
pivot
}

/// Column-wise weighted median, e.g. stake-weighted median scores per server (column) over all validators (rows).
Expand Down
9 changes: 4 additions & 5 deletions pallets/subtensor/tests/mock.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
#![allow(clippy::arithmetic_side_effects, clippy::unwrap_used)]

use frame_support::derive_impl;
use frame_support::dispatch::DispatchResultWithPostInfo;
use frame_support::weights::constants::RocksDbWeight;
// use frame_support::weights::constants::WEIGHT_PER_SECOND;
use frame_support::weights::Weight;
use frame_support::{
assert_ok, derive_impl,
dispatch::DispatchResultWithPostInfo,
parameter_types,
assert_ok, parameter_types,
traits::{Everything, Hooks},
weights::constants::RocksDbWeight,
};
use frame_system as system;
use frame_system::{limits, EnsureNever, EnsureRoot, RawOrigin};
Expand Down
3 changes: 0 additions & 3 deletions runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ pallet-timestamp = { workspace = true }
pallet-transaction-payment = { workspace = true }
pallet-utility = { workspace = true }
frame-executive = { workspace = true }
frame-metadata-hash-extension = { workspace = true }
sp-api = { workspace = true }
sp-block-builder = { workspace = true }
sp-consensus-aura = { workspace = true }
Expand Down Expand Up @@ -112,7 +111,6 @@ std = [
"codec/std",
"scale-info/std",
"frame-executive/std",
"frame-metadata-hash-extension/std",
"frame-support/std",
"frame-system-rpc-runtime-api/std",
"frame-system/std",
Expand Down Expand Up @@ -206,4 +204,3 @@ try-runtime = [
"pallet-commitments/try-runtime",
"pallet-registry/try-runtime"
]
metadata-hash = ["substrate-wasm-builder/metadata-hash"]
11 changes: 1 addition & 10 deletions runtime/build.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,10 @@
fn main() {
#[cfg(all(feature = "std", not(feature = "metadata-hash")))]
#[cfg(feature = "std")]
{
substrate_wasm_builder::WasmBuilder::new()
.with_current_project()
.export_heap_base()
.import_memory()
.build();
}
#[cfg(all(feature = "std", feature = "metadata-hash"))]
{
substrate_wasm_builder::WasmBuilder::new()
.with_current_project()
.export_heap_base()
.import_memory()
.enable_metadata_hash("TAO", 9)
.build();
}
}
1 change: 0 additions & 1 deletion runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1282,7 +1282,6 @@ pub type SignedExtra = (
pallet_transaction_payment::ChargeTransactionPayment<Runtime>,
pallet_subtensor::SubtensorSignedExtension<Runtime>,
pallet_commitments::CommitmentsSignedExtension<Runtime>,
frame_metadata_hash_extension::CheckMetadataHash<Runtime>,
);

type Migrations = pallet_grandpa::migrations::MigrateV4ToV5<Runtime>;
Expand Down
2 changes: 1 addition & 1 deletion scripts/build.sh
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
cargo build --profile production --features "runtime-benchmarks metadata-hash"
cargo build --profile production --features runtime-benchmarks

0 comments on commit 2bb1557

Please sign in to comment.