-
Notifications
You must be signed in to change notification settings - Fork 308
Added migration to remove total hk/ck stakes this interval #1539
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
sam0x17
merged 7 commits into
devnet-ready
from
migration/total-hk-ck-stakes-this-interval-clear
Apr 21, 2025
Merged
Changes from 3 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
fc84df2
added migration to remove total hk/ck stakes this interval
l0r1s bc85189
rework
l0r1s beab08a
bump spec version
l0r1s e681721
Merge branch 'devnet-ready' into migration/total-hk-ck-stakes-this-in…
l0r1s f6bc0ca
run ci
l0r1s ce1c35d
Merge branch 'devnet-ready' into migration/total-hk-ck-stakes-this-in…
l0r1s 6bcb63b
set migration as ran only if all entry removed
l0r1s 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 hidden or 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
52 changes: 52 additions & 0 deletions
52
pallets/subtensor/src/migrations/migrate_remove_total_hotkey_coldkey_stakes_this_interval.rs
This file contains hidden or 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,52 @@ | ||
| use super::*; | ||
| use crate::HasMigrationRun; | ||
| use frame_support::{traits::Get, weights::Weight}; | ||
| use sp_io::{KillStorageResult, hashing::twox_128, storage::clear_prefix}; | ||
|
|
||
| pub fn migrate_remove_total_hotkey_coldkey_stakes_this_interval<T: Config>() -> Weight { | ||
| let migration_name = "migrate_remove_total_hotkey_coldkey_stakes_this_interval"; | ||
| let migration_name_bytes = migration_name.as_bytes().to_vec(); | ||
|
|
||
| let mut weight = T::DbWeight::get().reads(1); | ||
| if HasMigrationRun::<T>::get(&migration_name_bytes) { | ||
| log::info!( | ||
| "Migration '{:?}' has already run. Skipping.", | ||
| migration_name | ||
| ); | ||
| return weight; | ||
| } | ||
|
|
||
| log::info!("Running migration '{}'", migration_name); | ||
|
|
||
| let pallet_name = twox_128(b"SubtensorModule"); | ||
| let storage_name = twox_128(b"TotalHotkeyColdkeyStakesThisInterval"); | ||
| let prefix = [pallet_name, storage_name].concat(); | ||
|
|
||
| // Remove all entries. | ||
| let removed_entries_count = match clear_prefix(&prefix, Some(u32::MAX)) { | ||
| KillStorageResult::AllRemoved(removed) => removed as u64, | ||
| KillStorageResult::SomeRemaining(removed) => { | ||
| log::info!("Failed to remove all entries from {:?}", migration_name); | ||
| removed as u64 | ||
| } | ||
| }; | ||
|
|
||
| weight = weight.saturating_add(T::DbWeight::get().writes(removed_entries_count as u64)); | ||
|
|
||
| log::info!( | ||
| "Removed {:?} entries from TotalHotkeyColdkeyStakesThisInterval.", | ||
| removed_entries_count | ||
| ); | ||
|
|
||
| // Mark migration as completed | ||
| HasMigrationRun::<T>::insert(&migration_name_bytes, true); | ||
| weight = weight.saturating_add(T::DbWeight::get().writes(1)); | ||
|
|
||
| log::info!( | ||
| "Migration '{:?}' completed successfully. {:?} entries removed.", | ||
| migration_name, | ||
| removed_entries_count | ||
| ); | ||
|
|
||
| weight | ||
| } | ||
This file contains hidden or 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 hidden or 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 hidden or 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.
Uh oh!
There was an error while loading. Please reload this page.