Skip to content

refactor(ethereum): collapse duplicate network_id->chain_id mapping#370

Merged
prasanna-anchorage merged 1 commit into
mainfrom
worktree-ba9d07e6
Jun 15, 2026
Merged

refactor(ethereum): collapse duplicate network_id->chain_id mapping#370
prasanna-anchorage merged 1 commit into
mainfrom
worktree-ba9d07e6

Conversation

@pepe-anchor

Copy link
Copy Markdown
Contributor

Why am I making this PR?

The visualsign-ethereum crate had two separate network_id -> chain_id mappings that could silently drift apart.

networks::network_id_to_chain_id is macro-generated from the networks! table: 28 networks, case-insensitive. token_metadata::parse_network_id was a hand-written match on 5 mainnets (ETHEREUM / POLYGON / ARBITRUM / OPTIMISM / BASE), case-sensitive.

Two sources of truth for the same mapping is the smell. No live divergence today (the registry caller is gated behind a commented-out TODO), but if wallet-token loading is ever re-enabled, a wallet declaring a valid network handled by networks! would be silently rejected by parse_network_id. The case-sensitivity gap is its own foot-gun.

What am I changing?

  • Delete parse_network_id from token_metadata.rs, plus the now-dead TokenMetadataError enum (its only consumer, including the unused HashError variant) and the 7 tests that only covered the 5 hardcoded networks. networks.rs already has full coverage of all 28.
  • Route registry::ContractRegistry::load_chain_metadata through networks::network_id_to_chain_id, mapping the Option<u64> into the registry's existing String error.
  • Migrate both live cli_plugin.rs ABI-signing call sites (ABI mappings + proxy ABI mappings) to network_id_to_chain_id, and rewrite the stale comment that defended the old narrow 5-mainnet behavior.
  • Update the crate's CLAUDE.md doc references to point at the canonical networks.rs table.

Files: token_metadata.rs, registry.rs, cli_plugin.rs, CLAUDE.md (all under src/chain_parsers/visualsign-ethereum/).

What is the Linear ticket?

N/A. Small internal refactor (single source of truth for the network mapping).

What are the rollback steps?

Revert the single commit on this branch. No migrations, no data changes, no config changes, no new dependencies.

Is this change backwards compatible?

Production gRPC path: yes, unchanged. The only registry caller (load_chain_metadata) is reached from a commented-out TODO block in lib.rs, so it is effectively dead and its behavior does not change in production.

One intentional behavior change in the CLI (called out deliberately, since the original task scope did not anticipate the cli_plugin.rs callers): ABI signing now resolves chain ids for all 28 networks instead of only the 5 mainnets. So --abi-json-mappings / --abi-proxy-mappings with a valid non-mainnet network (e.g. a testnet) now succeeds instead of erroring out. This is strictly more permissive; the no-ABI CLI path was already unaffected.

The chain_id <-> ABI-signature binding is preserved (the security audit confirmed the resolved chain_id is identical for the 5 prior mainnets and that cross-network signature replay remains impossible).

Does this require cross-team/service coordination?

No. No proto changes, no shared API changes, no deployment config touched. The deleted symbols (parse_network_id, TokenMetadataError) have no references outside this crate.

How do I know it works as designed? Which tests exercise this code?

  • cargo +1.88.0 fmt --check (from src/): clean.
  • cargo +1.88.0 clippy -p visualsign-ethereum --all-targets -- -D warnings: clean.
  • cargo +1.88.0 test -p visualsign-ethereum: green. 265 unit + 9 integration + 2 doc-tests, 0 failed.
  • grep -rn "parse_network_id\|TokenMetadataError" across src/: no references remain.
  • The 28-network coverage (including the 5 previously hardcoded mainnets, case-insensitivity, and unknown-network rejection) is already exercised by the existing network_id_to_chain_id tests in networks.rs.

Opened as a draft by /draft. CI / Sonar / Copilot gates are handled by /finish; mark ready for review once they are green.

token_metadata::parse_network_id hardcoded 5 mainnets (case-sensitive)
while networks::network_id_to_chain_id is macro-generated from the
networks! table (28 networks, case-insensitive). Two sources of truth
for the same mapping is a latent drift / foot-gun: if wallet-token
loading is re-enabled, a wallet declaring a valid network handled by
networks! would be silently rejected by parse_network_id.

Delete parse_network_id and its now-dead TokenMetadataError enum, and
route the registry plus both CLI ABI-signing sites through
network_id_to_chain_id. The registry caller is gated behind a
commented-out TODO so its behavior is unchanged. The CLI ABI-signing
paths were live callers (not anticipated by the original task): they
now resolve chain ids for all 28 networks instead of only the 5
mainnets, so signing ABIs for valid non-mainnet networks works instead
of erroring. This is strictly more permissive and the no-ABI path was
already unaffected.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR refactors the visualsign-ethereum crate to use a single canonical network_id -> chain_id mapping (networks::network_id_to_chain_id) by removing the duplicated, narrower mapping in token_metadata, then routing registry + CLI ABI-signing call sites through the canonical mapping and updating documentation accordingly.

Changes:

  • Removed token_metadata::parse_network_id and its TokenMetadataError + associated unit tests.
  • Updated ContractRegistry::load_chain_metadata to use networks::network_id_to_chain_id and map None into the registry’s existing String error.
  • Updated CLI ABI signing (ABI mappings + proxy ABI mappings) and docs to reference the canonical networks.rs table/mapping.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.

File Description
src/chain_parsers/visualsign-ethereum/src/token_metadata.rs Removes duplicate network-id parsing API/tests and updates docs to point at the canonical mapping.
src/chain_parsers/visualsign-ethereum/src/registry.rs Uses network_id_to_chain_id for wallet ChainMetadata loading.
src/chain_parsers/visualsign-ethereum/src/cli_plugin.rs Uses network_id_to_chain_id for ABI-signing chain id resolution.
src/chain_parsers/visualsign-ethereum/CLAUDE.md Updates documentation to reference networks.rs as the canonical mapping source.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/chain_parsers/visualsign-ethereum/src/token_metadata.rs
Comment thread src/chain_parsers/visualsign-ethereum/CLAUDE.md
Comment thread src/chain_parsers/visualsign-ethereum/CLAUDE.md

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated no new comments.

@pepe-anchor pepe-anchor marked this pull request as ready for review June 15, 2026 13:28
@prasanna-anchorage prasanna-anchorage merged commit 0fbbf7b into main Jun 15, 2026
11 checks passed
@prasanna-anchorage prasanna-anchorage deleted the worktree-ba9d07e6 branch June 15, 2026 14:00
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.

3 participants