Skip to content

Rework coldkey swap#2251

Merged
sam0x17 merged 110 commits intodevnet-readyfrom
rework-coldkey-swap
Jan 28, 2026
Merged

Rework coldkey swap#2251
sam0x17 merged 110 commits intodevnet-readyfrom
rework-coldkey-swap

Conversation

@l0r1s
Copy link
Collaborator

@l0r1s l0r1s commented Dec 4, 2025

Closes #2230

Summary

This PR refactors the coldkey swap mechanism from a scheduler-based system to an announcement-based system with a configurable delay period. This change improves security, simplifies the codebase, and provides better transparency for coldkey swap operations.

Key Changes

1. New Announcement-Based Flow

  • Added announce_coldkey_swap: Users must first announce their intention to swap coldkeys by providing a hash of the new coldkey
  • Added swap_coldkey_announced: After the announcement delay period, users can execute the swap by providing the actual new coldkey
  • Announcement validation: The system verifies that the new coldkey hash matches the announced hash and that sufficient time has passed
  • Sliding delay: Each new announcement resets the delay period to 5 days from the announcement time, allowing users to change their plans without restriction

2. Configuration Changes

  • Renamed: InitialColdkeySwapScheduleDurationInitialColdkeySwapAnnouncementDelay
  • Removed: InitialColdkeySwapRescheduleDuration (no longer needed)
  • Storage: ColdkeySwapScheduled map → ColdkeySwapAnnouncements map
  • Default delay: Maintained at 5 days (36,000 blocks)

3. Refactored Core Swap Logic

  • Simplified do_swap_coldkey: Consolidated swap logic with clearer separation of concerns
  • New helper functions:
    • transfer_subnet_ownership
    • transfer_auto_stake_destination
    • transfer_coldkey_stake
    • transfer_staking_hotkeys
    • transfer_hotkeys_ownership
  • Identity preservation: If new coldkey already has an identity, it's preserved instead of overwritten

4. Updated swap_coldkey Extrinsic

  • Now root-only for arbitrary coldkey swaps (doesn't require announcement)
  • Automatically removes any existing announcement when called
  • Returns DispatchResult instead of DispatchResultWithPostInfo

5. Admin Utilities

  • Deprecated: sudo_set_coldkey_swap_schedule_duration (call index 54)
  • Added: sudo_set_coldkey_swap_announcement_delay (call index 84)
  • Added: remove_coldkey_swap_announcement (call index 127) - root-only removal of announcements

6. Events

  • Removed: ColdkeySwapScheduled
  • Added:
    • ColdkeySwapAnnounced - emitted when an announcement is made
    • ColdkeySwapAnnouncementRemoved - emitted when an announcement is removed
  • Updated: ColdkeySwapAnnouncementDelaySet (renamed from ColdkeySwapScheduleDurationSet)

7. Error Handling

  • Removed: ColdkeyIsInArbitration, SwapAlreadyScheduled, FailedToSchedule, ColdkeySwapReannouncedTooEarly
  • Added:
    • ColdkeySwapAnnouncementNotFound
    • ColdkeySwapTooEarly
    • AnnouncedColdkeyHashDoesNotMatch
    • Deprecated (for the old schedule_swap_coldkey call)

8. Transaction Extension

  • Updated CustomTransactionError::ColdkeyInSwapScheduleColdkeySwapAnnounced

9. Migration

  • Added: migrate_coldkey_swap_scheduled_to_announcements to migrate existing scheduled swaps to the new announcement system
  • Only migrates future scheduled swaps (past ones are ignored)
  • Adjusts announcement time to be scheduled_time - delay so swaps can execute at the originally scheduled time

Benefits

  1. Improved Security: Announcement hash prevents front-running and ensures the exact coldkey is swapped
  2. Transparency: All announcements are publicly visible on-chain before execution
  3. Simplified Code: Removes complex scheduler integration and reduces storage requirements
  4. Flexibility: Users can reannounce at any time with a fresh 5-day delay period, allowing them to change their coldkey swap plans without restriction
  5. Root Override: Admins can still perform emergency swaps via the root-only swap_coldkey call

Breaking Changes

⚠️ BREAKING CHANGES:

  • The schedule_swap_coldkey extrinsic is deprecated and will return an error
  • Configuration parameters renamed (migration handled automatically)
  • Storage layout changed (migration included)

Migration Path

For users with existing scheduled coldkey swaps:

  • The migration will automatically convert scheduled swaps to announcements
  • Your swap can still be executed at the originally scheduled time using swap_coldkey_announced
  • You can reannounce at any time if you need to change your new coldkey, which will reset the delay to 5 days from the new announcement
  • Ensure you have the new coldkey available when the delay period expires

@l0r1s l0r1s force-pushed the rework-coldkey-swap branch from 59d349c to 2f1ad59 Compare December 4, 2025 22:22
@l0r1s l0r1s marked this pull request as ready for review December 5, 2025 16:25
}
}
// TODO: move into tx extension pipeline but require node upgrade
CheckColdkeySwap::<T>::new().validate(
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why do we need a node upgraded for this? Isn't it a runtime configuration?
Also, the current implementation works with EVM implicitly. It will stop working when adding to the tx extension pipeline without changing the EVM extensions.

Copy link
Collaborator Author

@l0r1s l0r1s Jan 26, 2026

Choose a reason for hiding this comment

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

Adding a new transaction extension require updating the MEV shield code because it uses the pipeline here

Copy link
Collaborator

Choose a reason for hiding this comment

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

Makes sense!

@shamil-gadelshin shamil-gadelshin mentioned this pull request Jan 26, 2026
13 tasks
@sam0x17 sam0x17 merged commit a19b44a into devnet-ready Jan 28, 2026
187 of 188 checks passed
@sam0x17 sam0x17 added the breaking-change This PR introduces a noteworthy breaking change label Feb 4, 2026
@github-actions
Copy link
Contributor

github-actions bot commented Feb 4, 2026

@opentensor/cerebrum / @opentensor/gyrus / @opentensor/cortex breaking change detected! Please prepare accordingly!

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

Labels

breaking-change This PR introduces a noteworthy breaking change 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.

6 participants