-
Notifications
You must be signed in to change notification settings - Fork 209
Disallow subnet owners to set AdjustmentAlpha greater than 0.97 #1606
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
keithtensor
wants to merge
6
commits into
devnet-ready
Choose a base branch
from
sudo-only-adjustment-alpha
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.
Open
Changes from 1 commit
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
0291efb
Make setting AdjustmentAlpha root only
keithtensor 4ba1b8f
Allow owner to set AdjustmentAlpha iff the value is between 0 and 0.5
keithtensor 6e5dd51
Add test
keithtensor 9fe8a9a
Change cap to 0.97
keithtensor 2da2ff3
Merge remote-tracking branch 'origin/devnet-ready' into sudo-only-adj…
keithtensor 5a13c39
Merge remote-tracking branch 'origin/devnet-ready' into sudo-only-adj…
keithtensor 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
59 changes: 59 additions & 0 deletions
59
pallets/subtensor/src/migrations/migrate_reset_adjustment_alpha.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,59 @@ | ||
use super::*; | ||
use frame_support::{traits::Get, weights::Weight}; | ||
use log; | ||
use scale_info::prelude::string::String; | ||
|
||
pub fn migrate_reset_adjustment_alpha<T: Config>() -> Weight { | ||
let migration_name = b"migrate_reset_adjustment_alpha".to_vec(); | ||
let mut weight = T::DbWeight::get().reads(1); | ||
|
||
// ------------------------------ | ||
// Step 0: Check if already 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) | ||
); | ||
|
||
// ------------------------------ | ||
// Step 1: Reset all subnet's adjustment alpha to 0.5 if the value exceeds 0.5 | ||
keithtensor marked this conversation as resolved.
Show resolved
Hide resolved
|
||
// ------------------------------ | ||
|
||
let mut reset_entries_count = 0u64; | ||
|
||
for netuid in AdjustmentAlpha::<T>::iter_keys() { | ||
AdjustmentAlpha::<T>::mutate(netuid, |adjustment| { | ||
*adjustment = (*adjustment).min(32768); // 0.5 | ||
keithtensor marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}); | ||
reset_entries_count = reset_entries_count.saturating_add(1); | ||
} | ||
|
||
weight = weight | ||
.saturating_add(T::DbWeight::get().reads_writes(reset_entries_count, reset_entries_count)); | ||
|
||
log::info!( | ||
"Reset {} subnets from AdjustmentAlpha.", | ||
reset_entries_count | ||
); | ||
|
||
// ------------------------------ | ||
// 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.", | ||
String::from_utf8_lossy(&migration_name) | ||
); | ||
|
||
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
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.