Bugfix for: hotkey_swap on a single subnet wipes all root dividend accumulations#2527
Bugfix for: hotkey_swap on a single subnet wipes all root dividend accumulations#2527evgeny-s wants to merge 10 commits intodevnet-readyfrom
hotkey_swap on a single subnet wipes all root dividend accumulations#2527Conversation
hotkey_swap on a single subnet wipes all root dividend accumulations
| pub const InitialStartCallDelay: u64 = 0; | ||
| pub const SubtensorInitialKeySwapOnSubnetCost: TaoBalance = TaoBalance::new(1_000_000); // 0.001 TAO | ||
| pub const HotkeySwapOnSubnetInterval : BlockNumber = 24 * 60 * 60 / 12; // 1 day | ||
| pub const HotkeySwapOnSubnetInterval : BlockNumber = prod_or_fast!(24 * 60 * 60 / 12, 1); // 1 day |
There was a problem hiding this comment.
For zombinet tests
shamil-gadelshin
left a comment
There was a problem hiding this comment.
The fix makes sense but I have a couple of questions about the migration.
| let mut fixed_count: u64 = 0; | ||
| let mut total_count: u64 = 0; | ||
|
|
||
| for ((netuid, hotkey, coldkey), claimed) in RootClaimed::<T>::iter() { |
There was a problem hiding this comment.
It's a huge iteration. Did you have a chance to verify the migration time on the mainnet clone?
There was a problem hiding this comment.
Not yet, but this was my plan. I tried to do it on chopsticks, but I will do the same on the clone.
There was a problem hiding this comment.
Checked the migration, it's pretty heavy.
It was applied on the fifth attempt; all the others had been rejected.
As an option, we can hardcode the affected hotkeys/coldkeys and netuids, because they are known from the indexer.
Will be updating it.
Thanks!
There was a problem hiding this comment.
@shamil-gadelshin
Updated the migration.
Now we update only affected storage items, instead of resetting rootClaimed, we revert RootClaimable.
It took less than a second to migrate:
2026-03-24 15:03:12 Running migration 'migrate_fix_root_claimed_overclaim'
2026-03-24 15:03:12 Restored 43 RootClaimable entries for hotkey=d0622986d748433d484b9b351b9a38737ee869ef2a50b75e5f890bee2c3afb18 (5GmvyePN...)
2026-03-24 15:03:12 Restored 118 RootClaimable entries for hotkey=e824c935940357af73c961bdd7387e1ab821ec2939ecd19daafe6081ae9ae674 (5HK5tp6t...)
2026-03-24 15:03:12 Migration 'migrate_fix_root_claimed_overclaim' completed. Restored 161 RootClaimable entries.
Also checked the state before the swap and after the migration:
State before tx:
{
2: {
bits: 49,801,631
}
4: {
bits: 9,560,554
}
5: {
bits: 48,963,505
}
6: {
bits: 52,417,040
}
State before the migration:
{
2: {
bits: 11,243,617
}
5: {
bits: 10,894,161
}
6: {
bits: 10,840,707
}
State after the migration:
{
2: {
bits: 61,045,248
}
4: {
bits: 9,560,554
}
5: {
bits: 59,857,666
}
6: {
bits: 63,257,747
}
The diff looks correct (additive).
pallets/subtensor/src/migrations/migrate_fix_root_claimed_overclaim.rs
Outdated
Show resolved
Hide resolved
| continue; | ||
| } | ||
|
|
||
| RootClaimable::<T>::mutate(&hotkey, |claimable_map| { |
There was a problem hiding this comment.
Shouldn't we subtract the same value from the other hotkey?
Description
Fixes #2515
Related Issue(s)
Type of Change
Breaking Change
If this PR introduces a breaking change, please provide a detailed description of the impact and the migration path for existing applications.
Checklist
./scripts/fix_rust.shto ensure my code is formatted and linted correctlyScreenshots (if applicable)
Please include any relevant screenshots or GIFs that demonstrate the changes made.
Additional Notes
Please provide any additional information or context that may be helpful for reviewers.