Skip to content

refactor(node): generate the ~125 one-liner metric recorders with a macro #1247

Closed

Description

@thiras

Problem

crates/node/src/metrics.rs (3,616 lines) is structurally sound — registration is already macro-generated via #[derive(MetricsGroup)] (metrics.rs:34-36) — but the Metrics wrapper (metrics.rs:1207-2356) hand-writes ~152 recorder methods, of which ~125 are trivial one-liners (self.decdn.<field>.inc() / .set()), each carrying its own doc comment (e.g. metrics.rs:1256-1300). That's ~350-400 mechanical lines whose only content is field-name repetition.

All 149 metric fields were verified live (no dead recorders — the indirect ones route via connection_guard() at metrics.rs:2672/2679 and the SettleParty dispatch enum at metrics.rs:2438-2510), so this is pure mechanical collapse, not surface reduction.

Proposed fix

A declarative macro (e.g. metric!(field, Counter, "doc") or a small macro_rules! block over the field list) that generates the struct field and its trivial recorder together. Doc comments stay attached; non-trivial recorders (the ones taking args, doing role dispatch, or setting gauges from computed values) stay hand-written.

Compiler-checked, zero behavior change; the /metrics encode path and SettleParty are untouched.

Acceptance

  • No hand-written recorder whose body is a single bare .inc()/.set() on a same-named field.
  • cargo doc output for the recorder surface unchanged (docs preserved through the macro).
  • Metrics endpoint output byte-identical for the same event sequence.

Activity

  1. added
    rust
    prio:low
    on Jul 17, 2026
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