feat(subtensor): reset subnet identity on subnet create#2601
Open
ArtificialXai wants to merge 1 commit intoopentensor:mainfrom
Open
feat(subtensor): reset subnet identity on subnet create#2601ArtificialXai wants to merge 1 commit intoopentensor:mainfrom
ArtificialXai wants to merge 1 commit intoopentensor:mainfrom
Conversation
Closes opentensor#2572. `do_register_network` previously only *set* a `SubnetIdentityV3` entry when the caller passed `Some(identity)` and left the storage map untouched otherwise. Storage migrations and legacy code paths can leave an orphan `SubnetIdentitiesV3` entry on a netuid slot that later gets assigned to a new owner; that orphan then leaks into the fresh subnet and misrepresents what the subnet is about. This change makes the `identity` argument authoritative: * `Some(identity)` — validate and insert (existing behavior). * `None` — if an entry already exists for the target netuid, remove it and emit `SubnetIdentityRemoved`; no-op if the slot is already empty. Three regression tests in `tests::networks` cover the three branches.
Contributor
|
can you identity the "Storage migrations and legacy code paths can leave an orphan SubnetIdentitiesV3 entry". then we fix it, instead of add the check in registration. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Closes #2572.
do_register_networkpreviously only set aSubnetIdentityV3entry when the caller passedSome(identity)and left the storage map untouched otherwise. Storage migrations and legacy code paths can leave an orphanSubnetIdentitiesV3entry on a netuid slot that later gets assigned to a new owner; that orphan then leaks into the fresh subnet and misrepresents what the subnet is about (wrong name, wrong GitHub repo, wrong Discord, etc.).This PR makes the
identityargument authoritative, matching the natural intuition of "the caller ofregister_networkfully owns the resulting subnet's presentation":Some(identity)— validate and insert (existing behavior, unchanged).None— if an entry already exists for the target netuid, remove it and emitSubnetIdentityRemoved; no-op if the slot is already empty.No runtime migration required — the fix is forward-only and only kicks in when
do_register_networkis called, so existing subnets are unaffected.Changes
pallets/subtensor/src/subnets/subnet.rs— step 17 ofdo_register_networknow uses amatch identityinstead ofif let Some(..), with aNonebranch that clears any staleSubnetIdentitiesV3entry and emits the existingSubnetIdentityRemovedevent (already used bydo_dissolve_networkincoinbase/root.rs).pallets/subtensor/src/tests/networks.rs— three regression tests:register_network_with_none_identity_clears_stale_entry— pre-inserts a staleSubnetIdentityV3at the predicted next netuid, callsdo_register_network(..., None), asserts the entry is gone.register_network_with_some_identity_overwrites_stale_entry— same setup but passesSome(new_identity), asserts the stored entry equalsnew_identity.register_network_with_none_identity_no_op_when_slot_empty— registers withNoneagainst an empty slot, asserts noSubnetIdentitiesV3entry is created.Test plan
cargo check -p pallet-subtensorcargo test -p pallet-subtensor --features pow-faucet -- tests::networks::register_network_with_none_identity_clears_stale_entrycargo test -p pallet-subtensor --features pow-faucet -- tests::networks::register_network_with_some_identity_overwrites_stale_entrycargo test -p pallet-subtensor --features pow-faucet -- tests::networks::register_network_with_none_identity_no_op_when_slot_emptycargo test -p pallet-subtensor(CI)Notes
SubnetIdentityRemovedevent is already emitted bydo_dissolve_networkwhen a subnet is torn down, so consumers that index events should already handle it gracefully.None-branch behavior only removes stale state; it can never overwrite a caller's current subnet identity, since it runs insidedo_register_networkwhich creates the subnet.subnet_name/github_repo/discorduntil the new owner manually callsset_subnet_identity.