Skip to content
Closed
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
4 changes: 3 additions & 1 deletion pallets/subtensor/src/macros/hooks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,9 @@ mod hooks {
// Set subtoken enabled for all existed subnets
.saturating_add(migrations::migrate_set_subtoken_enabled::migrate_set_subtoken_enabled::<T>())
// Remove all entries in TotalHotkeyColdkeyStakesThisInterval
.saturating_add(migrations::migrate_remove_total_hotkey_coldkey_stakes_this_interval::migrate_remove_total_hotkey_coldkey_stakes_this_interval::<T>());
.saturating_add(migrations::migrate_remove_total_hotkey_coldkey_stakes_this_interval::migrate_remove_total_hotkey_coldkey_stakes_this_interval::<T>())
// Remove unused root values from yuma maps
.saturating_add(migrations::migrate_remove_unused_root_values::migrate_remove_unused_root_values::<T>());
weight
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
use super::*;
use crate::HasMigrationRun;
use frame_support::{traits::Get, weights::Weight};
use scale_info::prelude::string::String;

pub fn migrate_remove_unused_root_values<T: Config>() -> Weight {
let migration_name = b"migrate_remove_unused_root_values".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)
);

let netuid = 0;

Incentive::<T>::remove(netuid);
Dividends::<T>::remove(netuid);
Rank::<T>::remove(netuid);
Trust::<T>::remove(netuid);
ValidatorTrust::<T>::remove(netuid);
ValidatorPermit::<T>::remove(netuid);
Consensus::<T>::remove(netuid);
StakeWeight::<T>::remove(netuid);
Active::<T>::remove(netuid);
Emission::<T>::remove(netuid);
PruningScores::<T>::remove(netuid);

// Mark Migration as Completed
HasMigrationRun::<T>::insert(&migration_name, true);
weight = weight.saturating_add(T::DbWeight::get().writes(12));

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

weight
}
1 change: 1 addition & 0 deletions pallets/subtensor/src/migrations/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ pub mod migrate_rao;
pub mod migrate_remove_stake_map;
pub mod migrate_remove_total_hotkey_coldkey_stakes_this_interval;
pub mod migrate_remove_unused_maps_and_values;
pub mod migrate_remove_unused_root_values;
pub mod migrate_remove_zero_total_hotkey_alpha;
pub mod migrate_set_first_emission_block_number;
pub mod migrate_set_min_burn;
Expand Down
54 changes: 54 additions & 0 deletions pallets/subtensor/src/tests/migration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -617,3 +617,57 @@ fn test_migrate_remove_total_hotkey_coldkey_stakes_this_interval() {
assert!(!weight.is_zero(),"Migration weight should be non-zero.");
});
}

// SKIP_WASM_BUILD=1 RUST_LOG=debug cargo test --package pallet-subtensor --lib -- tests::migration::test_migrate_remove_unused_root_values --exact --show-output
#[test]
fn test_migrate_remove_unused_root_values() {
new_test_ext(1).execute_with(|| {
const MIGRATION_NAME: &str = "migrate_remove_unused_root_values";

// Some test data
let test_u16 = vec![u16::MAX; 64];
let test_u64 = vec![1_000_000_u64; 64];
let test_bool = vec![true; 64];

// Set up entries to be deleted.
let netuid = 0;
Incentive::<Test>::insert(netuid, test_u16.clone());
Dividends::<Test>::insert(netuid, test_u16.clone());
Rank::<Test>::insert(netuid, test_u16.clone());
Trust::<Test>::insert(netuid, test_u16.clone());
ValidatorTrust::<Test>::insert(netuid, test_u16.clone());
ValidatorPermit::<Test>::insert(netuid, test_bool.clone());
Consensus::<Test>::insert(netuid, test_u16.clone());
StakeWeight::<Test>::insert(netuid, test_u16.clone());
Active::<Test>::insert(netuid, test_bool.clone());
Emission::<Test>::insert(netuid, test_u64.clone());
PruningScores::<Test>::insert(netuid, test_u16.clone());

assert!(
!HasMigrationRun::<Test>::get(MIGRATION_NAME.as_bytes().to_vec()),
"Migration should not have run yet."
);

// Run migration
let weight = crate::migrations::migrate_remove_unused_root_values::migrate_remove_unused_root_values::<Test>();

// Verify storage is cleared
assert_eq!(Incentive::<Test>::get(netuid).len(), 0);
assert_eq!(Dividends::<Test>::get(netuid).len(), 0);
assert_eq!(Rank::<Test>::get(netuid).len(), 0);
assert_eq!(Trust::<Test>::get(netuid).len(), 0);
assert_eq!(ValidatorTrust::<Test>::get(netuid).len(), 0);
assert_eq!(ValidatorPermit::<Test>::get(netuid).len(), 0);
assert_eq!(Consensus::<Test>::get(netuid).len(), 0);
assert_eq!(StakeWeight::<Test>::get(netuid).len(), 0);
assert_eq!(Active::<Test>::get(netuid).len(), 0);
assert_eq!(Emission::<Test>::get(netuid).len(), 0);
assert_eq!(PruningScores::<Test>::get(netuid).len(), 0);

assert!(
HasMigrationRun::<Test>::get(MIGRATION_NAME.as_bytes().to_vec()),
"Migration should be marked as run."
);
assert!(!weight.is_zero(),"Migration weight should be non-zero.");
});
}
2 changes: 1 addition & 1 deletion runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,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: 262,
spec_version: 263,
impl_version: 1,
apis: RUNTIME_API_VERSIONS,
transaction_version: 1,
Expand Down
Loading