Skip to content

Add a reusable chain_id query-param parser to the common library #141

Description

@CryptoFewka

Context

Raised in review of optimum-measurements #66 by @abergasov (comment): a chain_id query-param parser written for the measurements HTTP handlers is likely useful beyond that one service, so it should live in optimum-common and be reused.

What measurements has today (to be replaced by the shared helper)

Two small parsers for the chain_id query param, differing only in how they treat 0:

  • internal/routes/block_latency.go parseChainIDValue(raw string) (uint64, bool) — empty means "all chains" (0); a present value must be a non-zero uint64; 0 or malformed is rejected.
  • internal/routes/operator_mump2p_first_seen.go parseOptionalChainID(raw string) (uint64, error) — empty means "all chains" (0); a literal 0 is allowed; present values parse as uint64.

Proposal

Add a reusable chain-id query-param parser to optimum-common (candidate homes: pkg/net for HTTP query helpers, or pkg/chain). It should cover both semantics above, e.g. a single function with an "allow zero" option, or two clearly-named variants:

  • "all-chains-or-specific, zero is the all-chains sentinel and not a valid explicit value" (block_latency semantics), and
  • "all-chains-or-specific, zero is an acceptable explicit value" (mump2p semantics).

Then have optimum-measurements adopt it and delete the two local copies (and fold the existing unit tests into the common package).

Acceptance

  • Helper(s) + table tests in optimum-common.
  • optimum-measurements uses the shared helper in both handlers; local parseChainIDValue / parseOptionalChainID removed.

Written with Claude Code

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions