Skip to content

NodeCandidate.region_hint should be Option<Region>, not String #1348

Closed

Description

@yigitdot

crates/client-pull/src/discovery.rs carries region_hint: String with a doc comment saying it is an ISO 3166-1 alpha-2 code (ADR 030), but nothing enforces that. The workspace already owns the validator — decdn_protocol::is_valid_region (crates/protocol/src/region.rs:23) — and decdn-protocol is already a client-pull dependency, so this costs no new edge.

Two consequences today:

  1. select_candidates compensates at the call site with trim() + eq_ignore_ascii_case, because one side of the comparison (chain.region) is already normalized by normalize_region (crates/common/src/config/mod.rs:564) and the other is raw. That is an invariant enforced by every call site instead of by the type.
  2. The PartialEq/Eq derives added in feat(client-pull): retry + peer-cache fallback for registry bootstrap #1341 compare region_hint structurally, so the same node registered as us vs US compares unequal. Only tests consume Eq today, so it is latent — but any future dedup/contains/retain over candidates would fail to dedupe.

Option<Region> rather than a required Region: CapacityBond.sol permits any string up to 16 bytes and ADR 030 § Cross-ADR Impact explicitly declines to tighten it, so rejecting a candidate for an unrecognized region would be stricter than the source of truth and would silently shrink the fetchable node set for a purely advisory field. An unrecognized code should parse to None and sort into the "rest" bucket — today's behavior — while Some is guaranteed normalized. That deletes the trim()/eq_ignore_ascii_case from select_candidates, makes the derived Eq correct for free, and restores the 16-byte bound on the peer-cache read path.

Note this changes the peers.json encoding, so it needs a PEER_CACHE_VERSION bump.

Out of scope for #1341 (the String predates it; that PR only added the derives).

Activity

  1. added
    rust
    prio:low
    on Jul 21, 2026
  2. self-assigned this
    on Jul 21, 2026
  3. thiras commented on Jul 21, 2026

    @thiras
    Contributor

    Fixed in #1362 (merged as e73fa04).

    Note the batch's review round revised the framing of this issue's premise where it was wrong — see the PR description and the ADR/NatSpec updates for the corrected account.

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

Metadata

Metadata

Assignees

Labels

prio:lowrust

Type

No type

Fields

Priority

None yet

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions