refactor(symbols): replace get_name_for_subnet match with static NAMES table#2607
Open
boskodev790 wants to merge 1 commit intoopentensor:mainfrom
Open
refactor(symbols): replace get_name_for_subnet match with static NAMES table#2607boskodev790 wants to merge 1 commit intoopentensor:mainfrom
boskodev790 wants to merge 1 commit intoopentensor:mainfrom
Conversation
boskodev790
commented
Apr 22, 2026
…S table Closes opentensor#1520. `get_name_for_subnet` was a 439-arm `match` over `netuid` where every arm called `b"name".to_vec()`. Each call to the function allocated a fresh `Vec<u8>` regardless of the hit, even though the subnet names are compile-time constants. The per-call allocation is wasted work, and the massive match made the function painful to scan during review. Replace the match with a parallel `pub static NAMES: [&[u8]; 439]` lookup table that mirrors `SYMBOLS` by netuid. `get_name_for_subnet` now: * prefers a non-empty `SubnetIdentitiesV3::subnet_name` (unchanged), * falls back to `NAMES[netuid]` as `&'static [u8]`, * returns `b"unknown"` for out-of-range netuids, * pays exactly one `.to_vec()` at the return boundary instead of one per match arm. All 439 name-to-netuid mappings are preserved byte-for-byte, including the deliberate `b"unknown"` sentinel slots at indices 55 and 60 and the single multi-word entry `b"red team"` at index 61 (cross-checked programmatically against the original match). Add `pallets/subtensor/src/tests/symbols.rs` covering: * first / last / space-containing / sentinel entries, * out-of-range netuid (439, 1000, u16::MAX) falling back to `b"unknown"`, * a stored `SubnetIdentitiesV3` with a non-empty name winning over the table, * a stored identity with an empty `subnet_name` still falling through to the table, * a length invariant between `NAMES` and `SYMBOLS` so a future edit to one without the other fails fast in CI. External contract is unchanged: the function signature still returns `Vec<u8>` and all three callsites (`rpc_info::dynamic_info::subnet_name`, `rpc_info::metagraph::name` and its helper) continue to receive the same bytes.
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.