-
Notifications
You must be signed in to change notification settings - Fork 273
fix: SwapHotkey self-loop check for childkeys #2318
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?
Conversation
|
@juniuszhou would you review this PR? |
|
Thank you for your feedback, let me update all |
|
@juniuszhou merry christmas! |
|
run scripts/fix_rust.sh will fix format issues. |
@juniuszhou I just ran and updated! |
Description
This fix addresses the constraint errors seen on mainnet where self-looped child/parent key relationships cause cycle detection errors.
Closes #2109
1. Automatic Self-Loop Prevention During Swap
Instead of rejecting swaps when
new_hotkeyis a child ofold_hotkey, the implementation now allows the swap to proceed but automatically filters out the self-loop edge. This is a simpler and more user-friendly approach.Implementation:
new_hotkeyis a child ofold_hotkey, it is automatically removed from the children list before the swap completesPendingChildKeysentriesunlink_childmethod toPCRelationsto support this functionality2. Existing Migration Handles Self-Loops
The existing
migrate_fix_childkeysmigration already removes self-looped entries fromChildKeysandParentKeysstorage by callingclean_self_loops(). This migration:child == parentinChildKeysparent == childinParentKeysHasMigrationRunbefore executing)Changes Made
Files Modified
pallets/subtensor/src/swap/swap_hotkey.rsparent_child_swap_hotkeycall site (no changes needed - filtering happens in the swap function)pallets/subtensor/src/staking/set_children.rsunlink_childmethod toPCRelationsto remove a child from relationsparent_child_swap_hotkeyto automatically filter outnew_hotkeyfrom children if it exists (prevents self-loop)new_hotkeyfrom pending childrenpallets/subtensor/src/tests/swap_hotkey.rstest_swap_hotkey_to_child_removes_self_loop- verifies self-loop is removed when swapping to a childtest_swap_hotkey_filters_pending_child_self_loop- verifies PendingChildKeys self-loops are filteredtest_swap_hotkey_to_child_preserves_other_children- verifies other children are preservedtest_swap_parent_hotkey_self_loops_in_pending- now expects success with self-loop removalTesting
The implementation:
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.
Contribution by Gittensor, learn more at https://gittensor.io/