-
Notifications
You must be signed in to change notification settings - Fork 302
Bugfix for: hotkey_swap on a single subnet wipes all root dividend accumulations
#2527
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
evgeny-s
wants to merge
21
commits into
devnet-ready
Choose a base branch
from
fix-hotkey-swap-root-claimable
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.
+902
−31
Open
Changes from 12 commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
44a39d7
- Fixes the issue for hotkey swap for the single subnet
evgeny-s 057fa2f
- fmt
evgeny-s bb59c0c
Merge branch 'devnet-ready' into fix-hotkey-swap-root-claimable
evgeny-s 34d3b61
- Added migration + updated transfer_root_claimable_for_new_hotkey
evgeny-s 495e90f
- clipppy fix
evgeny-s ce1f225
- added read/writes for weights
evgeny-s e8d7abe
- Fixed the migration
evgeny-s 872fa29
- fixed clippy
evgeny-s 502b531
- add checker for mainnet only
evgeny-s 38f37c5
Merge branch 'devnet-ready' into fix-hotkey-swap-root-claimable
evgeny-s 46e57ae
- Transfer Root claimable and root claimed only for root subnet swap
evgeny-s 542b571
- Fixed tests
evgeny-s 04627d6
- fixed migration
evgeny-s 93a61e7
Tests for swap:
evgeny-s b9722c7
- Added migration
evgeny-s bc77a99
- Added migration
evgeny-s a538eac
- updated comment
evgeny-s ac35533
Added TS tests
evgeny-s f28e120
Merge branch 'devnet-ready' into fix-hotkey-swap-root-claimable
evgeny-s 20a3aba
- cargo fmt
evgeny-s 330d668
- fixes for clippy
evgeny-s 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
Some comments aren't visible on the classic Files Changed page.
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
60 changes: 60 additions & 0 deletions
60
pallets/subtensor/src/migrations/migrate_fix_root_claimed_overclaim.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,60 @@ | ||
| use super::*; | ||
| use frame_support::pallet_prelude::Weight; | ||
| use frame_system::pallet_prelude::BlockNumberFor; | ||
| use scale_info::prelude::string::String; | ||
|
|
||
| /// Fixes the consequences of a bug in `perform_hotkey_swap_on_one_subnet` where | ||
| /// `transfer_root_claimable_for_new_hotkey` unconditionally transferred the **entire** | ||
| /// `RootClaimable` BTreeMap (all subnets) from the old hotkey to the new hotkey, even | ||
| /// during a single-subnet swap. | ||
| /// | ||
| /// This left the old hotkey with: | ||
| /// - `RootClaimable[old_hotkey]` = empty (wiped for ALL subnets) | ||
| /// - `RootClaimed[(subnet, old_hotkey, coldkey)]` = old watermarks (for non-swapped subnets) | ||
| /// | ||
| /// Resulting in `owed = claimable_rate * root_stake - root_claimed = 0 - positive = negative → 0`, | ||
| /// effectively freezing root dividends for the old hotkey. | ||
| /// | ||
| /// Remediation: restore the pre-swap `RootClaimable` rates (from chain history snapshots) | ||
| /// back to the affected old_hotkeys, excluding subnets that were legitimately swapped. | ||
| /// This adds the snapshot rates to whatever has re-accumulated since the bug, making | ||
| /// `owed = (restored_rate + new_increments) * stake - claimed ≈ new_increments * stake > 0`. | ||
| pub fn migrate_fix_root_claimed_overclaim<T: Config>() -> Weight { | ||
| let migration_name = b"migrate_fix_root_claimed_overclaim".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) | ||
| ); | ||
|
|
||
| // Only run on mainnet. | ||
| // Mainnet genesis: 0x2f0555cc76fc2840a25a6ea3b9637146806f1f44b090c175ffde2a7e5ab36c03 | ||
| let genesis_hash = frame_system::Pallet::<T>::block_hash(BlockNumberFor::<T>::zero()); | ||
| let genesis_bytes = genesis_hash.as_ref(); | ||
| let mainnet_genesis = | ||
| hex_literal::hex!("2f0555cc76fc2840a25a6ea3b9637146806f1f44b090c175ffde2a7e5ab36c03"); | ||
| if genesis_bytes == mainnet_genesis { | ||
| // TODO | ||
| } | ||
|
Contributor
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. make sure to only clear the RootClaim- able/ed maps if the root stake is still |
||
|
|
||
| // Mark migration as completed | ||
| HasMigrationRun::<T>::insert(&migration_name, true); | ||
| weight.saturating_accrue(T::DbWeight::get().writes(1)); | ||
|
|
||
| log::info!( | ||
| "Migration 'migrate_fix_root_claimed_overclaim' completed. \ | ||
| Restored {} RootClaimable entries.", | ||
| restored_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
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.
would be a nice macro @sam0x17