Skip to content

remove unused SubnetName map and use identity instead #1501

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

Open
wants to merge 2 commits into
base: devnet-ready
Choose a base branch
from
Open
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
3 changes: 0 additions & 3 deletions pallets/subtensor/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1061,9 +1061,6 @@ pub mod pallet {
#[pallet::storage] // --- MAP ( netuid ) --> token_symbol | Returns the token symbol for a subnet.
pub type TokenSymbol<T: Config> =
StorageMap<_, Identity, u16, Vec<u8>, ValueQuery, DefaultUnicodeVecU8<T>>;
#[pallet::storage] // --- MAP ( netuid ) --> subnet_name | Returns the name of the subnet.
pub type SubnetName<T: Config> =
StorageMap<_, Identity, u16, Vec<u8>, ValueQuery, DefaultUnicodeVecU8<T>>;

/// ============================
/// ==== Global Parameters =====
Expand Down
4 changes: 3 additions & 1 deletion pallets/subtensor/src/macros/hooks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,9 @@ mod hooks {
// Remove all zero value entries in TotalHotkeyAlpha
.saturating_add(migrations::migrate_remove_zero_total_hotkey_alpha::migrate_remove_zero_total_hotkey_alpha::<T>())
// Wipe existing items to prevent bad decoding for new type
.saturating_add(migrations::migrate_upgrade_revealed_commitments::migrate_upgrade_revealed_commitments::<T>());
.saturating_add(migrations::migrate_upgrade_revealed_commitments::migrate_upgrade_revealed_commitments::<T>())
// Wipe unused SubnetName map
.saturating_add(migrations::migrate_remove_subnet_name_map::migrate_remove_subnet_name_map::<T>());
weight
}

Expand Down
61 changes: 61 additions & 0 deletions pallets/subtensor/src/migrations/migrate_remove_subnet_name_map.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
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};

fn remove_prefix<T: Config>(old_map: &str, weight: &mut Weight) {
let mut prefix = Vec::new();
prefix.extend_from_slice(&twox_128("SubtensorModule".as_bytes()));
prefix.extend_from_slice(&twox_128(old_map.as_bytes()));

let removal_results = clear_prefix(&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");
removed as u64
}
};

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

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

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

// Remove SubnetName
remove_prefix::<T>("SubnetName", &mut weight);

// 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
}
1 change: 1 addition & 0 deletions pallets/subtensor/src/migrations/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ pub mod migrate_init_total_issuance;
pub mod migrate_populate_owned_hotkeys;
pub mod migrate_rao;
pub mod migrate_remove_stake_map;
pub mod migrate_remove_subnet_name_map;
pub mod migrate_remove_unused_maps_and_values;
pub mod migrate_remove_zero_total_hotkey_alpha;
pub mod migrate_set_first_emission_block_number;
Expand Down
Loading
Loading