feat: add disassociate_hotkey extrinsic#2521
feat: add disassociate_hotkey extrinsic#2521Rapiiidooo wants to merge 3 commits intoopentensor:devnet-readyfrom
Conversation
f3f338d to
f58ab36
Compare
|
Tested also with local-dev-node : |
|
|
||
| // Clean up AutoStakeDestination references. | ||
| // Other coldkeys may have set this hotkey as their auto-stake destination. | ||
| for netuid in Self::get_all_subnet_netuids() { |
There was a problem hiding this comment.
If the key not registered in any subnet, it can not be set as auto stake destination. Should we remove it?
There was a problem hiding this comment.
Good question!
You're right that a hotkey can't have auto-stake set if it's not registered on any subnet.
However, I believe there might be a case where stale entries could exist: when a hotkey gets deregistered via replace_neuron or when a subnet is dissolved via remove_network, AutoStakeDestination and AutoStakeDestinationColdkeys don't seem to be cleaned up, so orphaned entries could remain in storage from before the deregistration.
For example, a coldkey could set a registered hotkey as its auto-stake destination.
Later, that hotkey gets deregistered, but since replace_neuron and remove_network don't clean up auto-stake entries, they remain orphaned in storage.
The cleanup here is the only place (along with swap_hotkey and swap_coldkey) that catches those.
But happy to remove it if I'm missing something!
There was a problem hiding this comment.
I agree with you, sometimes there are stale entries. You can see this PR #2513, we are working on such cases. But it is better to use process like migration to remove these storages.
I don't think the new extrinsic will be called frequently. It is fine to keep the extra check in it.
I will approve it after you fix the clippy in CI.
There was a problem hiding this comment.
The clippy issue was coming from the devnet-ready base being outdated. I've rebased on the latest devnet-ready and clippy passes clean locally. Could you re-trigger the CI?
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) <noreply@anthropic.com>
- 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) <noreply@anthropic.com>
…ociate Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
e316985 to
2fbfb2b
Compare
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.