-
Notifications
You must be signed in to change notification settings - Fork 163
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
fix storage item typos #834
Draft
JohnReedV
wants to merge
2
commits into
devnet-ready
Choose a base branch
from
fix-storage-item-typos
base: devnet-ready
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -780,7 +780,7 @@ pub mod pallet { | |
pub type HotkeyEmissionTempo<T> = | ||
StorageValue<_, u64, ValueQuery, DefaultHotkeyEmissionTempo<T>>; | ||
#[pallet::storage] | ||
/// Map ( hot ) --> emission | Accumulated hotkey emission. | ||
/// Name corrected: PendingdHotkeyEmission => PendingHotkeyEmission | ||
pub type PendingdHotkeyEmission<T: Config> = StorageMap< | ||
_, | ||
Blake2_128Concat, | ||
|
@@ -790,6 +790,16 @@ pub mod pallet { | |
DefaultAccumulatedEmission<T>, | ||
>; | ||
#[pallet::storage] | ||
/// Map ( hot ) --> emission | Accumulated hotkey emission. | ||
pub type PendingHotkeyEmission<T: Config> = StorageMap< | ||
_, | ||
Blake2_128Concat, | ||
T::AccountId, | ||
u64, | ||
ValueQuery, | ||
DefaultAccumulatedEmission<T>, | ||
>; | ||
#[pallet::storage] | ||
/// Map ( hot, cold ) --> block_number | Last add stake increase. | ||
pub type LastAddStakeIncrease<T: Config> = StorageDoubleMap< | ||
_, | ||
|
@@ -939,10 +949,14 @@ pub mod pallet { | |
pub type BlocksSinceLastStep<T> = | ||
StorageMap<_, Identity, u16, u64, ValueQuery, DefaultBlocksSinceLastStep<T>>; | ||
#[pallet::storage] | ||
/// --- MAP ( netuid ) --> last_mechanism_step_block | ||
/// Name corrected: LastMechansimStepBlock => LastMechanismStepBlock | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same |
||
pub type LastMechansimStepBlock<T> = | ||
StorageMap<_, Identity, u16, u64, ValueQuery, DefaultLastMechanismStepBlock<T>>; | ||
#[pallet::storage] | ||
/// --- MAP ( netuid ) --> last_mechanism_step_block | ||
pub type LastMechanismStepBlock<T> = | ||
StorageMap<_, Identity, u16, u64, ValueQuery, DefaultLastMechanismStepBlock<T>>; | ||
#[pallet::storage] | ||
/// --- MAP ( netuid ) --> subnet_owner | ||
pub type SubnetOwner<T: Config> = | ||
StorageMap<_, Identity, u16, T::AccountId, ValueQuery, DefaultSubnetOwner<T>>; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
pallets/subtensor/src/migrations/migrate_fix_storage_typos.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
use super::*; | ||
use frame_support::{traits::Get, weights::Weight}; | ||
use scale_info::prelude::string::String; | ||
|
||
/// Migrates storage items with typos to their correctly named counterparts. | ||
/// | ||
/// - `PendingdHotkeyEmission` is migrated to `PendingHotkeyEmission`. | ||
/// - `LastMechansimStepBlock` is migrated to `LastMechanismStepBlock`. | ||
/// | ||
/// # Returns | ||
/// The cumulative weight of the migration process. | ||
pub fn migrate_rename_storage_items<T: Config>() -> Weight { | ||
let migration_name = b"migrate_rename_storage_items_v1".to_vec(); | ||
|
||
let mut weight = T::DbWeight::get().reads(1); | ||
|
||
// Check if the migration has already been run. | ||
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) | ||
); | ||
|
||
// === Migrate `PendingdHotkeyEmission` to `PendingHotkeyEmission` and wipe old storage === | ||
for (account_id, emission) in PendingdHotkeyEmission::<T>::drain() { | ||
// Insert the value into the new storage | ||
PendingHotkeyEmission::<T>::insert(account_id, emission); | ||
|
||
// Add weight for the write operation (the `drain` method takes care of the removal) | ||
weight = weight.saturating_add(T::DbWeight::get().writes(1)); | ||
} | ||
|
||
// === Migrate `LastMechansimStepBlock` to `LastMechanismStepBlock` and wipe old storage === | ||
for (netuid, block) in LastMechansimStepBlock::<T>::drain() { | ||
// Insert the value into the new storage | ||
LastMechanismStepBlock::<T>::insert(netuid, block); | ||
|
||
// Add weight for the write operation (the `drain` method takes care of the removal) | ||
weight = weight.saturating_add(T::DbWeight::get().writes(1)); | ||
} | ||
|
||
// === Mark Migration as Completed === | ||
HasMigrationRun::<T>::insert(&migration_name, true); | ||
weight = weight.saturating_add(T::DbWeight::get().writes(1)); | ||
|
||
log::info!( | ||
"Migration '{:?}' completed.", | ||
String::from_utf8_lossy(&migration_name) | ||
); | ||
|
||
weight | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need this comment ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's useful for people who index the chain like me. When I search the updated name there's nothing relevant, but the old name gives results:
I happened to be aware of this typo, but if I wasn't and wanted to understand why my storage calls weren't working in earlier blocks this comment in the code would make it a lot easier to discover the reason.