Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
8 changes: 4 additions & 4 deletions pallets/subtensor/src/epoch/run_epoch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@ impl<T: Config> Pallet<T> {
.iter()
.map(|updated| updated.saturating_add(activity_cutoff) < current_block)
.collect();
log::trace!("Inactive: {:?}", inactive.clone());
log::debug!("Inactive: {:?}", inactive.clone());

// Logical negation of inactive.
let active: Vec<bool> = inactive.iter().map(|&b| !b).collect();
Expand All @@ -406,14 +406,14 @@ impl<T: Config> Pallet<T> {
let hotkeys: Vec<(u16, T::AccountId)> =
<Keys<T> as IterableStorageDoubleMap<u16, u16, T::AccountId>>::iter_prefix(netuid)
.collect();
log::trace!("hotkeys: {:?}", &hotkeys);
log::debug!("hotkeys: {:?}", &hotkeys);

// Access network stake as normalized vector.
let (mut total_stake, _alpha_stake, _tao_stake): (Vec<I64F64>, Vec<I64F64>, Vec<I64F64>) =
Self::get_stake_weights_for_network(netuid);
inplace_normalize_64(&mut total_stake);
let stake: Vec<I32F32> = vec_fixed64_to_fixed32(total_stake);
log::trace!("Normalised Stake: {:?}", &stake);
log::debug!("Normalised Stake: {:?}", &stake);

// =======================
// == Validator permits ==
Expand Down Expand Up @@ -448,7 +448,7 @@ impl<T: Config> Pallet<T> {

// Normalize active stake.
inplace_normalize(&mut active_stake);
log::trace!("Active Stake:\n{:?}\n", &active_stake);
log::debug!("Active Stake:\n{:?}\n", &active_stake);

// =============
// == Weights ==
Expand Down
12 changes: 0 additions & 12 deletions pallets/subtensor/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -998,18 +998,6 @@ pub mod pallet {
#[pallet::storage] // --- MAP ( cold ) --> Vec<hot> | Returns the vector of hotkeys controlled by this coldkey.
pub type OwnedHotkeys<T: Config> =
StorageMap<_, Blake2_128Concat, T::AccountId, Vec<T::AccountId>, ValueQuery>;
#[pallet::storage]
/// (DEPRECATED) DMAP ( hot, cold ) --> stake | Returns the stake under a coldkey prefixed by hotkey.
pub type Stake<T: Config> = StorageDoubleMap<
_,
Blake2_128Concat,
T::AccountId,
Identity,
T::AccountId,
u64,
ValueQuery,
DefaultZeroU64<T>,
>;

#[pallet::storage] // --- DMAP ( cold ) --> () | Maps coldkey to if a coldkey swap is scheduled.
pub type ColdkeySwapScheduled<T: Config> =
Expand Down
10 changes: 3 additions & 7 deletions pallets/subtensor/src/macros/hooks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,6 @@ mod hooks {
// Populate OwnedHotkeys map for coldkey swap. Doesn't update storage vesion.
// Storage version v6 -> v7
.saturating_add(migrations::migrate_populate_owned_hotkeys::migrate_populate_owned::<T>())
// Populate StakingHotkeys map for coldkey swap. Doesn't update storage vesion.
// Storage version v7 -> v8
.saturating_add(migrations::migrate_populate_staking_hotkeys::migrate_populate_staking_hotkeys::<T>())
// Fix total coldkey stake.
// Storage version v8 -> v9
.saturating_add(migrations::migrate_fix_total_coldkey_stake::migrate_fix_total_coldkey_stake::<T>())
// Migrate Delegate Ids on chain
.saturating_add(migrations::migrate_chain_identity::migrate_set_hotkey_identities::<T>())
// Migrate Commit-Reval 2.0
Expand All @@ -83,7 +77,9 @@ mod hooks {
// Set the min burn across all subnets to a new minimum
.saturating_add(migrations::migrate_set_min_burn::migrate_set_min_burn::<T>())
// Set the min difficulty across all subnets to a new minimum
.saturating_add(migrations::migrate_set_min_difficulty::migrate_set_min_difficulty::<T>());
.saturating_add(migrations::migrate_set_min_difficulty::migrate_set_min_difficulty::<T>())
// Remove Stake map entries
.saturating_add(migrations::migrate_remove_stake_map::migrate_remove_stake_map::<T>());
weight
}

Expand Down

This file was deleted.

This file was deleted.

48 changes: 24 additions & 24 deletions pallets/subtensor/src/migrations/migrate_rao.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ use frame_support::IterableStorageMap;
use frame_support::{traits::Get, weights::Weight};
use sp_runtime::format;
use substrate_fixed::types::I96F32;
use substrate_fixed::types::U64F64;

use super::*;

Expand Down Expand Up @@ -36,29 +35,30 @@ pub fn migrate_rao<T: Config>() -> Weight {
DynamicBlock::<T>::set(Pallet::<T>::get_current_block_as_u64());

// Migrate all TAO to root.
Stake::<T>::iter().for_each(|(hotkey, coldkey, stake)| {
// Increase SubnetTAO on root.
SubnetTAO::<T>::mutate(0, |total| {
*total = total.saturating_add(stake);
});
// Increase SubnetAlphaOut on root.
SubnetAlphaOut::<T>::mutate(0, |total| {
*total = total.saturating_add(stake);
});
// Set all the stake on root 0 subnet.
Alpha::<T>::mutate((hotkey.clone(), coldkey.clone(), 0), |total| {
*total = total.saturating_add(U64F64::saturating_from_num(stake))
});
TotalHotkeyShares::<T>::mutate(hotkey.clone(), 0, |total| {
*total = total.saturating_add(U64F64::saturating_from_num(stake))
});
// Set the total stake on the hotkey
TotalHotkeyAlpha::<T>::mutate(hotkey.clone(), 0, |total| {
*total = total.saturating_add(stake)
});
// 6 reads and 6 writes.
weight = weight.saturating_add(T::DbWeight::get().reads_writes(6, 6));
});
// This migration has already run, leaving this only for reference for now, since this is a recent migration
// Stake::<T>::iter().for_each(|(hotkey, coldkey, stake)| {
// // Increase SubnetTAO on root.
// SubnetTAO::<T>::mutate(0, |total| {
// *total = total.saturating_add(stake);
// });
// // Increase SubnetAlphaOut on root.
// SubnetAlphaOut::<T>::mutate(0, |total| {
// *total = total.saturating_add(stake);
// });
// // Set all the stake on root 0 subnet.
// Alpha::<T>::mutate((hotkey.clone(), coldkey.clone(), 0), |total| {
// *total = total.saturating_add(U64F64::saturating_from_num(stake))
// });
// TotalHotkeyShares::<T>::mutate(hotkey.clone(), 0, |total| {
// *total = total.saturating_add(U64F64::saturating_from_num(stake))
// });
// // Set the total stake on the hotkey
// TotalHotkeyAlpha::<T>::mutate(hotkey.clone(), 0, |total| {
// *total = total.saturating_add(stake)
// });
// // 6 reads and 6 writes.
// weight = weight.saturating_add(T::DbWeight::get().reads_writes(6, 6));
// });

// Convert subnets and give them lock.
// Set global weight to 18% from the start
Expand Down
62 changes: 62 additions & 0 deletions pallets/subtensor/src/migrations/migrate_remove_stake_map.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
use super::*;
use crate::HasMigrationRun;
use frame_support::{traits::Get, weights::Weight};
use scale_info::prelude::string::String;
use sp_io::{KillStorageResult, hashing::twox_128, storage::clear_prefix};

pub fn migrate_remove_stake_map<T: Config>() -> Weight {
let migration_name = b"migrate_remove_stake_map".to_vec();
let mut weight = T::DbWeight::get().reads(1);

if HasMigrationRun::<T>::get(&migration_name) {
log::info!(
"Migration '{:?}' has already run. Skipping.",
migration_name
);
return weight;
}

log::info!(
"Running migration '{}'",
String::from_utf8_lossy(&migration_name)
);

// ------------------------------
// Step 1: Remove Stake entries
// ------------------------------

let mut stake_prefix = Vec::new();
stake_prefix.extend_from_slice(&twox_128("SubtensorModule".as_bytes()));
stake_prefix.extend_from_slice(&twox_128("Stake".as_bytes()));

let removal_results = clear_prefix(&stake_prefix, Some(u32::MAX));

let removed_entries_count = match removal_results {
KillStorageResult::AllRemoved(removed) => removed as u64,
KillStorageResult::SomeRemaining(removed) => {
log::info!("Failed To Remove Some Items During {:?}", migration_name);
removed as u64
}
};

weight = weight.saturating_add(T::DbWeight::get().writes(removed_entries_count));

log::info!(
"Removed {:?} entries from Stake map.",
removed_entries_count
);

// ------------------------------
// Step 2: Mark Migration as Completed
// ------------------------------

HasMigrationRun::<T>::insert(&migration_name, true);
weight = weight.saturating_add(T::DbWeight::get().writes(1));

log::info!(
"Migration '{:?}' completed successfully.",
String::from_utf8_lossy(&migration_name)
);

weight
}
11 changes: 7 additions & 4 deletions pallets/subtensor/src/migrations/migrate_total_issuance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,13 @@ pub fn migrate_total_issuance<T: Config>(test: bool) -> Weight {
// Execute migration if the current storage version is 5 or if in test mode
if Pallet::<T>::on_chain_storage_version() == StorageVersion::new(5) || test {
// Calculate the sum of all stake values
let stake_sum: u64 =
Stake::<T>::iter().fold(0, |acc, (_, _, stake)| acc.saturating_add(stake));
// Add weight for reading all stake entries
weight = weight.saturating_add(T::DbWeight::get().reads(Stake::<T>::iter().count() as u64));
let stake_sum: u64 = Owner::<T>::iter()
.map(|(hotkey, _coldkey)| Pallet::<T>::get_total_stake_for_hotkey(&hotkey))
.fold(0, |acc, stake| acc.saturating_add(stake));
// Add weight for reading all Owner and TotalHotkeyStake entries
weight = weight.saturating_add(
T::DbWeight::get().reads((Owner::<T>::iter().count() as u64).saturating_mul(2)),
);

// Calculate the sum of all locked subnet values
let locked_sum: u64 =
Expand Down
Loading
Loading