Skip to content

Rebase devnet #666

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 55 commits into from
Jul 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
55 commits
Select commit Hold shift + click to select a range
b43bed6
draft: hotkey swap for senate
Jul 9, 2024
9d1f6c9
feat: remove schedule coldkey swap
Jul 12, 2024
90512c2
chore: fix tests
Jul 12, 2024
dd87bca
Merge branch 'fix/hotkeyswap_senate' into feat/remove_schedule_coldke…
Jul 12, 2024
606b771
fixes for network resumption
Jul 12, 2024
8ebcf2d
chore: bump spec
Jul 12, 2024
7b84d3c
fix: add back arbitration check
Jul 12, 2024
2455082
fix: hotkey
Jul 12, 2024
f49bb55
fix: coldkey arb swap hotkey
Jul 12, 2024
884a179
Merge pull request #631 from opentensor/feat/remove_schedule_coldkey_…
distributedstatemachine Jul 12, 2024
76f20ce
swap delegate stake also
camfairchild Jul 13, 2024
4ccb879
add test for this
camfairchild Jul 13, 2024
73533b9
swap over stakinghotkeys map
camfairchild Jul 13, 2024
c370aad
check map first
camfairchild Jul 13, 2024
9b8c0e4
add staking hotkeys test
camfairchild Jul 13, 2024
baec581
no take
camfairchild Jul 13, 2024
a84ac6b
keep old stake
camfairchild Jul 13, 2024
221d320
add check to test
camfairchild Jul 13, 2024
f9164fc
fix some tests
camfairchild Jul 13, 2024
2a14df7
fix delegate test
camfairchild Jul 13, 2024
b970f50
update staking hotekys maps
camfairchild Jul 13, 2024
ad57e2b
init
camfairchild Jul 13, 2024
1cc7d3c
comment out
camfairchild Jul 13, 2024
6dcd0a1
add admin swap
camfairchild Jul 13, 2024
f474112
fix swap
camfairchild Jul 13, 2024
b708c1d
..
camfairchild Jul 13, 2024
5b30256
hotkey staking maps fix
Jul 13, 2024
fc245f8
remove staking hotkeys
Jul 13, 2024
494796e
remove commented code
Jul 13, 2024
f041ed9
cargo fmt
sam0x17 Jul 13, 2024
54ec750
cargo fix --workspace
sam0x17 Jul 13, 2024
ca51109
bump spec_version to 165
sam0x17 Jul 13, 2024
4dafd88
swap hotkey benchmark removed
Jul 15, 2024
d95a7df
add migration and tests for total coldkey hotfix
Jul 15, 2024
5e6fc7e
adds new test for missing hotkey value
Jul 15, 2024
3c61aa8
bump migration values
Jul 15, 2024
ff23b6f
fmt
Jul 15, 2024
0c2ad41
Merge pull request #636 from opentensor/total_coldkey_migration
unconst Jul 15, 2024
b3fa487
feat: try runtime passing
Jul 16, 2024
8766c98
chore: remove commented code
Jul 16, 2024
92fc1f0
chore: make logs human readable
Jul 16, 2024
c255d92
chore: remove comments
Jul 16, 2024
0478596
Update pallets/subtensor/src/lib.rs
distributedstatemachine Jul 16, 2024
5adbbd9
Merge pull request #644 from opentensor/hotfix/storage_version_incons…
distributedstatemachine Jul 16, 2024
8f6e8d6
add test first
camfairchild Jul 16, 2024
f25bdda
clear map before rest of migration
camfairchild Jul 16, 2024
e009ff1
track weight for clear/removal
camfairchild Jul 16, 2024
480b1c5
add comment
camfairchild Jul 16, 2024
eb4a57c
rename test
camfairchild Jul 16, 2024
23f540c
add test for emission appends staking hotkeys map
camfairchild Jul 16, 2024
a2b8d70
Merge pull request #645 from opentensor/fix/total-coldkey-stake-migra…
distributedstatemachine Jul 16, 2024
c9202c9
Merge branch 'devnet-ready' into main
unconst Jul 22, 2024
2bb1557
Revert "Merge branch 'devnet-ready' into main"
Jul 22, 2024
d7fd308
Merge pull request #664 from opentensor/main-fix
unconst Jul 22, 2024
fde92e4
chore: bump spec version
Jul 22, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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();
}
}
3 changes: 1 addition & 2 deletions runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
// `spec_version`, and `authoring_version` are the same between Wasm and native.
// This value is set to 100 to notify Polkadot-JS App (https://polkadot.js.org/apps) to use
// the compatible custom types.
spec_version: 195,
spec_version: 188,
impl_version: 1,
apis: RUNTIME_API_VERSIONS,
transaction_version: 1,
Expand Down 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

Loading