-
Notifications
You must be signed in to change notification settings - Fork 294
feat: add disassociate_hotkey extrinsic #2521
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
base: devnet-ready
Are you sure you want to change the base?
Changes from all commits
2804f43
6f54bfd
2fbfb2b
a0330d0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,4 +10,71 @@ impl<T: Config> Pallet<T> { | |
|
|
||
| Ok(()) | ||
| } | ||
|
|
||
| pub fn do_disassociate_hotkey(coldkey: &T::AccountId, hotkey: &T::AccountId) -> DispatchResult { | ||
| // Ensure the hotkey exists. | ||
| ensure!( | ||
| Self::hotkey_account_exists(hotkey), | ||
| Error::<T>::HotKeyAccountNotExists | ||
| ); | ||
|
|
||
| // Ensure the coldkey owns the hotkey. | ||
| ensure!( | ||
| Self::coldkey_owns_hotkey(coldkey, hotkey), | ||
| Error::<T>::NonAssociatedColdKey | ||
| ); | ||
|
|
||
| // Ensure the hotkey is not registered on any subnet. | ||
| ensure!( | ||
| !Self::is_hotkey_registered_on_any_network(hotkey), | ||
| Error::<T>::HotkeyIsStillRegistered | ||
| ); | ||
|
|
||
| // Ensure the hotkey has no outstanding stake from any coldkey. | ||
| ensure!( | ||
| Alpha::<T>::iter_prefix((hotkey,)).next().is_none(), | ||
| Error::<T>::HotkeyHasOutstandingStake | ||
| ); | ||
|
|
||
| // Remove Owner entry. | ||
| Owner::<T>::remove(hotkey); | ||
|
|
||
| // Remove hotkey from OwnedHotkeys. | ||
| let mut owned = OwnedHotkeys::<T>::get(coldkey); | ||
| owned.retain(|h| h != hotkey); | ||
| if owned.is_empty() { | ||
| OwnedHotkeys::<T>::remove(coldkey); | ||
| } else { | ||
| OwnedHotkeys::<T>::insert(coldkey, owned); | ||
| } | ||
|
|
||
| // Remove hotkey from StakingHotkeys. | ||
| let mut staking = StakingHotkeys::<T>::get(coldkey); | ||
| staking.retain(|h| h != hotkey); | ||
| if staking.is_empty() { | ||
| StakingHotkeys::<T>::remove(coldkey); | ||
| } else { | ||
| StakingHotkeys::<T>::insert(coldkey, staking); | ||
| } | ||
|
|
||
| // Remove Delegates entry if present. | ||
| Delegates::<T>::remove(hotkey); | ||
|
|
||
| // Clean up AutoStakeDestination references. | ||
| // Other coldkeys may have set this hotkey as their auto-stake destination. | ||
| for netuid in Self::get_all_subnet_netuids() { | ||
|
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. If the key not registered in any subnet, it can not be set as auto stake destination. Should we remove it?
Author
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. 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. But happy to remove it if I'm missing something!
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. 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.
Author
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. 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?
Author
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. My bad, seen in the benchmarks.rs the use of assert_*! instead. Should be solved now. |
||
| let coldkeys = AutoStakeDestinationColdkeys::<T>::get(hotkey, netuid); | ||
| for ck in &coldkeys { | ||
| AutoStakeDestination::<T>::remove(ck, netuid); | ||
| } | ||
| AutoStakeDestinationColdkeys::<T>::remove(hotkey, netuid); | ||
| } | ||
|
|
||
| Self::deposit_event(Event::HotkeyDisassociated { | ||
| coldkey: coldkey.clone(), | ||
| hotkey: hotkey.clone(), | ||
| }); | ||
|
|
||
| Ok(()) | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.