fix: map to hotkey not uid #1774
Draft
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
This PR improves the user experience and data integrity of EVM address associations by changing the storage from UID-based to hotkey-based. Since UIDs can be recycled when neurons are deregistered and re-registered, the current implementation leads to confusing UX where querying by UID might return EVM associations from previous neuron owners.
Problem
The current implementation stores EVM address associations using the storage map:
Additionally, the association logic already requires signing with the hotkey, making it more logical to store the association by hotkey rather than by UID.
This creates a suboptimal user experience:
Solution
This PR changes the storage to use hotkeys instead of UIDs:
Hotkeys are permanent and unique to each account, preventing any inheritance issues.
Changes Made
1. Storage Map Update
pallets/subtensor/src/lib.rs
AssociatedEvmAddress
to map from(netuid, uid: u16)
to(netuid, hotkey: T::AccountId)
2. Core Function Updates
pallets/subtensor/src/utils/evm.rs
do_associate_evm_key
to store by hotkey instead of uiduid_lookup
tohotkey_lookup
with updated return type3. Precompile Updates
precompiles/src/hotkey_lookup.rs
(renamed fromuid_lookup.rs
),precompiles/src/lib.rs
UidLookupPrecompile
toHotkeyLookupPrecompile
4. Admin Utils Update
pallets/admin-utils/src/lib.rs
PrecompileEnum::UidLookup
toPrecompileEnum::HotkeyLookup
5. Migration Implementation
pallets/subtensor/src/migrations/migrate_evm_address_to_hotkey.rs
,pallets/subtensor/src/migrations/mod.rs
,pallets/subtensor/src/macros/hooks.rs
Breaking Changes
This is a breaking change that affects:
uid_lookup
function is nowhotkey_lookup
and returns hotkeys instead of UIDsuidLookup
tohotkeyLookup
AssociatedEvmAddress
storage will need to update their code to use hotkeys instead of UIDsTesting
do_associate_evm_key
correctly stores by hotkeyhotkey_lookup
returns correct hotkeys for given EVM addressesMigration Plan
A storage migration has been implemented in
migrate_evm_address_to_hotkey.rs
that:(netuid, uid) -> (evm_address, block)
entriesKeys
storage map(netuid, hotkey) -> (evm_address, block)
The migration is automatically executed during runtime upgrade.
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
cargo fmt
andcargo clippy
to 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.