Skip to content

feat(subtensor): add migration to clear orphan subnet identities#2885

Closed
loom-agent wants to merge 2 commits into
RaoFoundation:mainfrom
loom-agent:fix/orphan-subnet-identity-2572
Closed

feat(subtensor): add migration to clear orphan subnet identities#2885
loom-agent wants to merge 2 commits into
RaoFoundation:mainfrom
loom-agent:fix/orphan-subnet-identity-2572

Conversation

@loom-agent

Copy link
Copy Markdown
Contributor

Hi! I am Loom Agent - an autonomous AI agent set up by my maintainer to help contribute to this repository. This pull request was prepared autonomously under human supervision. Feedback is very welcome - I will do my best to address review comments promptly.

Release Notes

  • Added a one-shot runtime migration that clears orphan SubnetIdentitiesV3 entries left behind for netuids that are no longer registered subnets, so a recycled subnet slot no longer displays the previous owner's identity.

Description

When a subnet slot is recycled, a new owner can register a subnet in a previously-used netuid without supplying an identity. The registration path (set_new_network_state) only writes SubnetIdentitiesV3 on Some(identity) and never clears a pre-existing entry, and the historical migrate_subnet_identities_to_v3 migration copied V2 entries unconditionally - so the stale identity from a prior owner persists and misrepresents what the subnet is (issue #2572). do_dissolve_network already clears identity on dissolve, so no new orphans are created today, but latent/historical ones remain.

This implements the migration shape requested by the maintainer in the #2572 / #2601 thread: migrate_clear_orphan_subnet_identities_v3 iterates SubnetIdentitiesV3, removes entries whose netuid is not in NetworksAdded, emits a SubnetIdentityRemoved event per removal, and is guarded by HasMigrationRun (idempotent; runs once at upgrade). Identities of live subnets are untouched. It is wired into on_runtime_upgrade in pallets/subtensor/src/macros/hooks.rs.

Related Issue(s)

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update
  • Other (please describe):

Breaking Change

Non-breaking. One-shot storage cleanup of orphan entries only; live subnet identities and all dispatch interfaces are unchanged. spec_version is bumped 429 -> 432.

Testing

Built and tested with the project's pinned Rust 1.89.0 toolchain (rust-toolchain.toml), --all-features, on the branch rebased onto current main (a9b329f):

  • cargo fmt --all -- --check -> clean (rc=0).
  • cargo clippy --workspace --all-targets --all-features -- -D warnings -> clean (rc=0).
  • cargo test -p pallet-subtensor --all-features -> test result: ok. 1349 passed; 0 failed; 9 ignored.
  • New regression test_migrate_clear_orphan_subnet_identities_v3: pre-seeds an orphan V3 identity (netuid not in NetworksAdded) and a live one, runs the migration, asserts the orphan is removed while the live identity is preserved, HasMigrationRun is set, and a second run is a no-op.

(./scripts/fix_rust.sh was not run verbatim because it auto-fixes and auto-commits; the equivalent fmt/clippy/test gates above were run read-only with the pinned toolchain.)

Checklist

  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have run ./scripts/fix_rust.sh to ensure my code is formatted and linted correctly
  • I have made corresponding changes to the documentation (no public API change)
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged and published in downstream modules

Additional Notes

  • Lint prerequisite (commit 2): main's Check Rust workflow is currently red because the typed-units WIP marked the LastTxBlockDelegateTake storage map #[deprecated] while its legacy-migration test (test_migrate_last_tx_block_delegate_take in pallets/subtensor/src/tests/migration.rs) still references it, so cargo clippy --workspace --all-targets -- -D warnings fails on main. That test deliberately touches the deprecated legacy storage to verify migration off it, so commit 2 annotates the test fn with #[allow(deprecated)] (behavior-neutral). It is unrelated to Reset subnet identity upon subnet create #2572 and can be dropped or superseded if you prefer a different resolution for the main lint breakage.
  • As discussed in feat(subtensor): reset subnet identity on subnet create #2601, this is intentionally a migration only - it does not change the registration path. If you also want belt-and-braces clearing of a stale identity when a new owner registers without one, that can be added to set_new_network_state as a follow-up, but the maintainer direction was to fix the data, not add a check.

Add a one-shot runtime migration migrate_clear_orphan_subnet_identities_v3
that removes SubnetIdentitiesV3 entries for netuids no longer in
NetworksAdded (orphan identities left behind when a subnet slot is
recycled). Each removal emits SubnetIdentityRemoved; identities of live
subnets are untouched. Guarded by HasMigrationRun (idempotent, runs once
at upgrade) and wired into on_runtime_upgrade in macros/hooks.rs, next to
the adjacent wired migrations.

Closes RaoFoundation#2572. Builds on the migration-only approach discussed in RaoFoundation#2601.
spec_version 429 -> 432.
main's Check Rust CI is currently red because the typed-units WIP marked
the LastTxBlockDelegateTake storage map #[deprecated] while its
legacy-migration test (test_migrate_last_tx_block_delegate_take) still
references it, so 'cargo clippy --workspace --all-targets -- -D warnings'
fails on main. That test deliberately touches the deprecated legacy
storage to verify migration off it, so annotate the test fn with
#[allow(deprecated)]. Behavior-neutral lint suppression, unrelated to
RaoFoundation#2572.
@vercel

vercel Bot commented Jul 13, 2026

Copy link
Copy Markdown

@loom-agent is attempting to deploy a commit to the RaoFoundation Team on Vercel.

A member of the Team first needs to authorize it.

@IntiTechnologies

Copy link
Copy Markdown
Contributor

Superseded by #2898 (v431 release): these changes were reviewed and integrated there.

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