feat: add disassociate_hotkey extrinsic#2521
Open
Rapiiidooo wants to merge 9 commits intoopentensor:devnet-readyfrom
Open
feat: add disassociate_hotkey extrinsic#2521Rapiiidooo wants to merge 9 commits intoopentensor:devnet-readyfrom
Rapiiidooo wants to merge 9 commits intoopentensor:devnet-readyfrom
Conversation
f3f338d to
f58ab36
Compare
Author
|
Tested also with local-dev-node : |
open-junius
reviewed
Mar 20, 2026
open-junius
reviewed
Mar 20, 2026
open-junius
reviewed
Mar 20, 2026
e316985 to
2fbfb2b
Compare
open-junius
reviewed
Mar 24, 2026
Contributor
|
I think we can remove the storage added in create_account_if_non_existent function. For other data like AutoStakeDestination and AutoStakeDestinationColdkeys, I am not sure if we should remove them in disassociate method. will add team to review it. |
7250dab to
97e5a30
Compare
97e5a30 to
0961609
Compare
Implements the reverse of try_associate_hotkey (closes opentensor#2519). The new disassociate_hotkey extrinsic allows a coldkey owner to remove the ownership link to a hotkey, provided the hotkey is not registered on any subnet and has no outstanding stake. Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
- Remove AutoStakeDestination entries for coldkeys pointing to this hotkey - Remove AutoStakeDestinationColdkeys entries for this hotkey - Increase weight estimate to account for subnet iteration - Add test for auto-stake cleanup Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
…ociate Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
Clippy CI fails with clippy::expect_used denial on .expect() calls. Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
Use alpha_iter_single_prefix() which merges both legacy Alpha (U64F64) and new AlphaV2 (SafeFloat) storage maps. During the lazy migration, stake entries can exist in either map. Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
Ensures disassociation is blocked when stake exists in the new AlphaV2 storage map (SafeFloat format), not just the legacy Alpha map. Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
0961609 to
e231ddb
Compare
- account.rs: replace `alpha_iter_single_prefix` with direct `Alpha`/`AlphaV2` iter checks so the precondition short-circuits on the first entry instead of materializing both maps into a BTreeMap. - dispatches.rs: expand the docstring to document side-effect cleanups (`Delegates`, `AutoStakeDestination*`) and the error variants. Bump the hand-tuned weight to cover the per-subnet auto-stake cleanup loop until `WeightInfo::disassociate_hotkey()` is regenerated from the benchmark. - benchmarks.rs: populate `Delegates` and `AutoStakeDestination*` across several subnets/coldkeys so a future benchmark run reflects realistic worst-case storage churn. - tests/staking2.rs: add tests for `Delegates` cleanup, multi-subnet auto-stake cleanup, and `HotkeyDisassociated` event emission. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
- Fold the existence + ownership preconditions into a single `Owner::try_get(hotkey)` lookup. The previous pair of helpers (`hotkey_account_exists` + `coldkey_owns_hotkey`) re-read `Owner` three times to answer two questions; both errors are still raised distinctly for UX. - Replace the `for netuid in get_all_subnet_netuids()` cleanup loop with `AutoStakeDestinationColdkeys::iter_prefix(hotkey)` so we only touch subnets where this hotkey was actually an auto-stake target. Common case (no auto-stake usage) drops from O(N_subnets) reads to zero; worst case is unchanged. - Lower the hand-tuned weight to reflect the reduced worst-case storage footprint. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
- format account.rs: collapse let owner declaration onto one line - bump spec_version 397 -> 402 to clear the spec-version gate vs network - regenerate weights for pallet_subtensor (adds disassociate_hotkey) and pallet_subtensor_proxy from the validate-benchmarks job patch Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Description
Implements the reverse of
try_associate_hotkey. The newdisassociate_hotkeyextrinsic allows a coldkey owner to remove the ownership link to a hotkey, provided the hotkey is not registered on any subnet and has no outstanding stake.This was requested in #2519.
Related Issue(s)
Type of Change
Breaking Change
No breaking change. This is a purely additive extrinsic.
Checklist
./scripts/fix_rust.shto ensure my code is formatted and linted correctlyImplementation Details
New Extrinsic:
disassociate_hotkey(origin, hotkey)Preconditions (all enforced with descriptive errors)
HotKeyAccountNotExistsNonAssociatedColdKeyHotkeyIsStillRegisteredHotkeyHasOutstandingStakeState cleaned up on success
Ownerentry removedOwnedHotkeysStakingHotkeysDelegatesentry removed (if present)HotkeyDisassociatedevent emittedTests (6 cases)
HotKeyAccountNotExistsNonAssociatedColdKeyHotkeyIsStillRegisteredHotkeyHasOutstandingStakeBenchmark
Included for the new extrinsic.
Additional Notes
No runtime panics are possible in the implementation — all checks use
ensure!macros and safe storage operations. TheAlphaiterator check (iter_prefix().next().is_none()) short-circuits on the first entry, keeping the worst-case cost bounded.