Skip to content

feat(subtensor): reset subnet identity on subnet create#2601

Open
ArtificialXai wants to merge 1 commit intoopentensor:mainfrom
ArtificialXai:artificialxai/reset-subnet-identity-on-create
Open

feat(subtensor): reset subnet identity on subnet create#2601
ArtificialXai wants to merge 1 commit intoopentensor:mainfrom
ArtificialXai:artificialxai/reset-subnet-identity-on-create

Conversation

@ArtificialXai
Copy link
Copy Markdown

Summary

Closes #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 (wrong name, wrong GitHub repo, wrong Discord, etc.).

This PR makes the identity argument authoritative, matching the natural intuition of "the caller of register_network fully 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 emit SubnetIdentityRemoved; no-op if the slot is already empty.

No runtime migration required — the fix is forward-only and only kicks in when do_register_network is called, so existing subnets are unaffected.

Changes

  • pallets/subtensor/src/subnets/subnet.rs — step 17 of do_register_network now uses a match identity instead of if let Some(..), with a None branch that clears any stale SubnetIdentitiesV3 entry and emits the existing SubnetIdentityRemoved event (already used by do_dissolve_network in coinbase/root.rs).
  • pallets/subtensor/src/tests/networks.rs — three regression tests:
    • register_network_with_none_identity_clears_stale_entry — pre-inserts a stale SubnetIdentityV3 at the predicted next netuid, calls do_register_network(..., None), asserts the entry is gone.
    • register_network_with_some_identity_overwrites_stale_entry — same setup but passes Some(new_identity), asserts the stored entry equals new_identity.
    • register_network_with_none_identity_no_op_when_slot_empty — registers with None against an empty slot, asserts no SubnetIdentitiesV3 entry is created.

Test plan

  • cargo check -p pallet-subtensor
  • cargo test -p pallet-subtensor --features pow-faucet -- tests::networks::register_network_with_none_identity_clears_stale_entry
  • cargo test -p pallet-subtensor --features pow-faucet -- tests::networks::register_network_with_some_identity_overwrites_stale_entry
  • cargo test -p pallet-subtensor --features pow-faucet -- tests::networks::register_network_with_none_identity_no_op_when_slot_empty
  • Full cargo test -p pallet-subtensor (CI)

Notes

  • SubnetIdentityRemoved event is already emitted by do_dissolve_network when a subnet is torn down, so consumers that index events should already handle it gracefully.
  • The new None-branch behavior only removes stale state; it can never overwrite a caller's current subnet identity, since it runs inside do_register_network which creates the subnet.
  • Fixes the user-visible symptom of a newly registered subnet appearing with a previous owner's subnet_name / github_repo / discord until the new owner manually calls set_subnet_identity.

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.
@open-junius
Copy link
Copy Markdown
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.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Reset subnet identity upon subnet create

2 participants