Skip to content

Fix the ability to revert hotkey swap#2487

Open
evgeny-s wants to merge 25 commits intoopentensor:devnet-readyfrom
evgeny-s:evgeny-revert-swap-key
Open

Fix the ability to revert hotkey swap#2487
evgeny-s wants to merge 25 commits intoopentensor:devnet-readyfrom
evgeny-s:evgeny-revert-swap-key

Conversation

@evgeny-s
Copy link
Collaborator

@evgeny-s evgeny-s commented Mar 5, 2026

Description

This PR fixes the inability to revert a hotkey swap by disabling is_hotkey_registered_on_any_network for cases where netuid is provided.

More changes:

  • Updated HotkeySwapOnSubnetInterval from 5 days to 1 day.
  • Added hotkey swap revert tests for: Parent keys, Child keys, Pending child keys, Auto stake destination, Subnet ownership, Dividend records, Voting Power, Root Reclaimable.
  • Removed test test_swap_hotkey_registered_on_other_subnet, since it tests the condition that is no longer valid.

Related Issue(s)

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update
  • Other (please describe):

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

  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have run ./scripts/fix_rust.sh to ensure my code is formatted and linted correctly
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged and published in downstream modules

Screenshots (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.

@open-junius
Copy link
Contributor

please cargo fmt the code and bump runtime version.

@evgeny-s evgeny-s changed the title Check if hotkey is registered in any network only if netuid is not provided. Fix the ability to revert hotkey swap Mar 10, 2026
ales-otf
ales-otf previously approved these changes Mar 10, 2026
@ales-otf ales-otf added the skip-cargo-audit This PR fails cargo audit but needs to be merged anyway label Mar 10, 2026
open-junius
open-junius previously approved these changes Mar 10, 2026
hotkey: T::AccountId,
new_hotkey: T::AccountId,
netuid: Option<NetUid>,
maybe_keep_stake: Option<bool>,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to notify @basfroman @ibraheem-abe about this because some changes may be required from their end.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's create a new extrinsic for this specific reason with the keep_stake parameter. It doesn't make sense to bother the clients. WDYT?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can also mark the current extrinsic as deprecated, so they will have plenty of time to migrate.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hotkey: T::AccountId,
new_hotkey: T::AccountId,
netuid: Option<NetUid>,
maybe_keep_stake: Option<bool>,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are None and Some(false) supposed to have the same behavior? If yes then maybe just having a bool is sufficient?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't like the fact that we add a required parameter after the optional. In this case, clients need to explicitly specify netuid: None and maybe_keep_stake: false, even if they don't want it, but they would just ignore it, since both are optional. I would keep it optional.

weight.saturating_accrue(T::DbWeight::get().reads_writes(1, 1));
}

// 3. Swap all subnet specific info.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When keep_stake is true, we only keep the top hotkey stake, right? Because we still run this in both cases:

// 4. Swap ChildKeys.
// 5. Swap ParentKeys.
// 6. Swap PendingChildKeys.
Self::parent_child_swap_hotkey(old_hotkey, new_hotkey, netuid, weight)?;

/// is transferred to the new hotkey.
#[pallet::call_index(70)]
#[pallet::weight((Weight::from_parts(275_300_000, 0)
.saturating_add(T::DbWeight::get().reads(52_u64))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we should put this in Pays::Yes

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see we have a rate limit for this extrinsic. So, we should be fine.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

skip-cargo-audit This PR fails cargo audit but needs to be merged anyway

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants