-
Notifications
You must be signed in to change notification settings - Fork 242
set auto hotkey per subnet #2041
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
Merged
Changes from all commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
b3c0900
set auto hotkey per subnet
open-junius 9a6f521
commit Cargo.lock
open-junius ce6e3d1
commit Cargo.lock
open-junius 342b1f5
bump version
open-junius 1210e99
rebase pr
open-junius d96f53c
commit Cargo.lock
open-junius d68dd39
rebase pr
open-junius a02d6d4
fix conflict
open-junius d9ac29b
commit Cargo.lock
open-junius 8842136
bump version
open-junius 7912fe4
Merge branch 'devnet-ready' into auto-hotkey-per-subnet
juniuszhou 32ef9cc
add migration
juniuszhou 9733f16
fix comments
open-junius 5cfa430
bump version
open-junius 8414776
cargo fmt
open-junius 7c83cd6
rebase pr
open-junius 6c7caff
add all check and unit tests
open-junius 36bbc4c
cargo clippy
open-junius e52c4b4
cargo fmt
open-junius a1c0eba
fix bench test
open-junius 5fc25cd
auto-update benchmark weights
github-actions[bot] 03826e6
rename error
open-junius bf3c4a5
fix conflict
open-junius 1dc5e0e
bump version
open-junius 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
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
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
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
82 changes: 82 additions & 0 deletions
82
pallets/subtensor/src/migrations/migrate_auto_stake_destination.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,82 @@ | ||
use super::*; | ||
use crate::AccountIdOf; | ||
use frame_support::{ | ||
IterableStorageMap, | ||
pallet_prelude::{Blake2_128Concat, OptionQuery}, | ||
storage_alias, | ||
traits::Get, | ||
weights::Weight, | ||
}; | ||
use scale_info::prelude::string::String; | ||
|
||
/// Module containing deprecated storage format for AutoStakeDestination | ||
pub mod deprecated_auto_stake_destination_format { | ||
use super::*; | ||
|
||
#[storage_alias] | ||
pub(super) type AutoStakeDestination<T: Config> = | ||
StorageMap<Pallet<T>, Blake2_128Concat, AccountIdOf<T>, AccountIdOf<T>, OptionQuery>; | ||
} | ||
|
||
/// Migrate the AutoStakeDestination map from single map to double map format | ||
pub fn migrate_auto_stake_destination<T: Config>() -> Weight { | ||
use deprecated_auto_stake_destination_format as old; | ||
|
||
let migration_name = b"migrate_auto_stake_destination".to_vec(); | ||
let mut weight = T::DbWeight::get().reads(1); | ||
|
||
if HasMigrationRun::<T>::get(&migration_name) { | ||
log::info!( | ||
"Migration '{:?}' has already run. Skipping.", | ||
String::from_utf8_lossy(&migration_name) | ||
); | ||
return weight; | ||
} | ||
|
||
log::info!( | ||
"Running migration '{}'", | ||
String::from_utf8_lossy(&migration_name) | ||
); | ||
|
||
// ------------------------------ | ||
// Step 1: Migrate AutoStakeDestination entries | ||
// ------------------------------ | ||
|
||
let curr_keys: Vec<AccountIdOf<T>> = old::AutoStakeDestination::<T>::iter_keys().collect(); | ||
let root_netuid = NetUid::ROOT; | ||
let netuids: Vec<NetUid> = <NetworksAdded<T> as IterableStorageMap<NetUid, bool>>::iter() | ||
.map(|(netuid, _)| netuid) | ||
.collect(); | ||
|
||
for coldkey in &curr_keys { | ||
weight.saturating_accrue(T::DbWeight::get().reads(1)); | ||
|
||
if let Some(hotkey) = old::AutoStakeDestination::<T>::get(coldkey) { | ||
for netuid in netuids.iter() { | ||
if *netuid == root_netuid { | ||
continue; | ||
} | ||
AutoStakeDestination::<T>::insert(coldkey, netuid, hotkey.clone()); | ||
} | ||
|
||
old::AutoStakeDestination::<T>::remove(coldkey); | ||
|
||
weight.saturating_accrue(T::DbWeight::get().writes(netuids.len() as u64)); | ||
} | ||
} | ||
|
||
// ------------------------------ | ||
// 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. {} entries migrated.", | ||
String::from_utf8_lossy(&migration_name), | ||
curr_keys.len() | ||
); | ||
|
||
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.
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.
Is this code already in use? Because it could requires a migration
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.
Thanks for the reminder. I was just wandering if we should add the old default key to all subnet, it is better to add migration process.