-
Notifications
You must be signed in to change notification settings - Fork 287
Hotfix/vune/recycle root alpha if no root sell #2191
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
10 commits
Select commit
Hold shift + click to select a range
e9c9424
add totalemission counter
camfairchild 5cafe0a
burn alpha not sold by root
camfairchild cfca5d0
chore: fmt
camfairchild 3975359
bump spec
camfairchild abef5e0
add pending server and pending vali emissions
camfairchild 6418911
fix args for em distr in tests
camfairchild 264d9c3
use new pending em storages
camfairchild 94d093b
use migration to clear the old pending em map
camfairchild c2e6ab7
amend comment
camfairchild e931123
Update pallets/subtensor/src/lib.rs
camfairchild 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
73 changes: 73 additions & 0 deletions
73
pallets/subtensor/src/migrations/migrate_pending_emissions.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,73 @@ | ||
| use super::*; | ||
| use frame_support::{storage_alias, traits::Get, weights::Weight}; | ||
| use substrate_fixed::types::U96F32; | ||
|
|
||
| pub mod deprecated_pending_emission_format { | ||
| use super::*; | ||
|
|
||
| #[storage_alias] | ||
| pub(super) type PendingEmission<T: Config> = | ||
| StorageMap<Pallet<T>, Identity, NetUid, AlphaCurrency, ValueQuery>; | ||
| } | ||
|
|
||
| pub fn migrate_pending_emissions<T: Config>() -> Weight { | ||
| let migration_name = b"migrate_pending_emissions".to_vec(); | ||
| let mut weight: Weight = T::DbWeight::get().reads(1); | ||
|
|
||
| // Skip if already executed | ||
| if HasMigrationRun::<T>::get(&migration_name) { | ||
| log::info!( | ||
| target: "runtime", | ||
| "Migration '{}' already run - skipping.", | ||
| String::from_utf8_lossy(&migration_name) | ||
| ); | ||
| return weight; | ||
| } | ||
| log::info!( | ||
| "Running migration '{}'", | ||
| String::from_utf8_lossy(&migration_name) | ||
| ); | ||
|
|
||
| // Pull from PendingEmission and distribute to PendingValidatorEmission and PendingServerEmission | ||
| for (netuid, pending_emission) in | ||
| deprecated_pending_emission_format::PendingEmission::<T>::iter() | ||
| { | ||
| // Split up the pending emission into server and validator emission | ||
| // Server emission is pending+root_alpha times the 50% miner cut. | ||
| let root_alpha: U96F32 = | ||
| U96F32::saturating_from_num(PendingRootAlphaDivs::<T>::get(netuid).to_u64()); | ||
| let server_emission_float: U96F32 = U96F32::saturating_from_num(pending_emission.to_u64()) | ||
| .saturating_add(root_alpha) | ||
| .saturating_div(U96F32::saturating_from_num(2)); | ||
| let server_emission: AlphaCurrency = | ||
| server_emission_float.saturating_to_num::<u64>().into(); | ||
| let validator_emission = pending_emission.saturating_sub(server_emission); | ||
|
|
||
| PendingValidatorEmission::<T>::mutate(netuid, |total| { | ||
| *total = total.saturating_add(validator_emission) | ||
| }); | ||
| PendingServerEmission::<T>::mutate(netuid, |total| { | ||
| *total = total.saturating_add(server_emission) | ||
| }); | ||
|
|
||
| weight = weight.saturating_add(T::DbWeight::get().reads_writes(1, 2)); | ||
| } | ||
|
|
||
| // Kill the map | ||
| let removal_result = | ||
| deprecated_pending_emission_format::PendingEmission::<T>::clear(u32::MAX, None); | ||
| weight = weight.saturating_add( | ||
| T::DbWeight::get().reads_writes(removal_result.loops as u64, removal_result.backend as u64), | ||
| ); | ||
|
|
||
| // 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
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.
Uh oh!
There was an error while loading. Please reload this page.