Skip to content

3.x.x: Export node peers, initial block download, observation age and hashrate-rollup lag (#467) - #470

Merged
kiwidream merged 3 commits into
3.x.xfrom
p2-hardening/node-rollup-gauges
Sep 24, 2026
Merged

kiwidream merged 3 commits into
3.x.xfrom
p2-hardening/node-rollup-gauges

Conversation

@kiwidream

@kiwidream kiwidream commented Sep 18, 2026 •

Copy link
Copy Markdown
Member

Part of #467 (remaining P2 of #278). Base 3.x.x at d78659de.

What

Four label-less gauges from the native registry, recorded at one observation site (readiness::chain_info_with_metrics, which adds no RPC call) and from the rollup loop:

  • qbit_prism_node_peers, qbit_prism_node_initial_block_download: from the latest observation; -1 when unknown, never a carried-over value (RPC refused, IBD/header short-circuit, regtest).
  • qbit_prism_node_observation_age_seconds: monotonic age of the last answered getblockchaininfo, computed at render; grows while the node is unreachable.
  • qbit_prism_hashrate_rollup_watermark_lag_seconds: the watermark is a share sequence, so lag is defined as monotonic time since this frontend's last caught-up pass (advanced && scanned < batch); -1 until the first; declared without a sample when PRISM_HASHRATE_ROLLUP_ENABLED=0. Alerts should take the minimum across instances (a frontend that keeps losing the race reads high).
    A late, slower observation cannot overwrite a newer one; the age keeps the latest answer. Metrics-only call swaps at coordinator.rs (observe_chain_info) and broadcaster.rs.

Evidence

  • Fake node refusing getnetworkinfo → peers -1, not the last value; refusing getblockchaininfo → age keeps growing: tests/readiness_rpc.rs:214; below-floor count is an answered count: :258; out-of-order guard: :295, :320.
  • Rollup disabled → HELP/TYPE, no sample; idle pool stays caught up; full batch or lost race leaves the stamp: src/rollups/tests.rs:428, :439.
  • Census: 47→51 families, 166→169 startup series, 264→268 populated (tests/observability/cardinality.rs, contract.rs); scripts/generate_prism_metrics.py --check clean; allocation-free setters (tests/metrics_allocation.rs).
  • Mutations "keep last peers on failure" and "export lag while disabled" each fail the named tests (verified by an independent adversarial pass and by hand).
  • fmt, clippy -D warnings, check_gate_env_reads, check_prism_settings, check_toolchain_pin pass; suites readiness_rpc 11, observability 17, metrics_allocation 4, lib 481.

Not covered

No Postgres-backed rollup-lag test (no gated entry); no alert rule or dashboard for the four families; per-worker series, threads/FDs and payout build duration stay parked; a cancelled readiness attempt records nothing (honest, documented). Coordinates with #458 (same census counts) and with #468 (six refusal reasons: combined census is 173 startup / 272 populated series).

Merge order: this PR first, then #468's, then #469's.

🤖 Generated with Claude Code


View with [code]smith Autofix with [code]smith
Need help on this PR? Tag @codesmith-bot with what you need. Autofix is disabled.

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, add credits to your account and enable them for code reviews in your settings.

kiwidream and others added 3 commits September 24, 2026 13:56
The remaining P2 of #278 adds four label-less gauges to the native registry.

Node observation gets one site: readiness::chain_info_with_metrics records
only what the attempt already fetched, so it adds no RPC call. A check that
short-circuits before getnetworkinfo - regtest, initial block download, or
blocks disagreeing with headers - leaves the peer count unknown at -1 rather
than keeping an earlier reading that would advertise an unconfirmed peer
floor; an answered zero stays a real zero. The sync flag is recorded whenever
getblockchaininfo answers with the boolean, including the 1 that then makes
readiness fail. The observation age is stamped on that answered call rather
than on a fully successful check, so an unready-but-reachable node keeps a
small age while an unreachable node's age grows. Concurrent refresh,
block-wait, candidate and broadcaster observations are ordered by the instant
each attempt began, and the publish happens under the same guard that
authorised it, so a slower older attempt cannot roll back a newer one.

The rollup watermark is a share sequence, not a time, so the lag is defined as
the monotonic time since this frontend's last pass that advanced the watermark
within its batch bound. A lost race or a full batch leaves the stamp alone, so
alerts must take the minimum across instances. With the rollup disabled the
family is declared without any sample, because a frontend that never runs it
has no lag to report.

All four are live, so every scrape recomputes them from one registry read.
Unknown is -1, never NaN and never a stale value. The setters reuse reserved
closed keys and allocate nothing.

Co-Authored-By: Claude Opus 5 <[email protected]>
Moving the peer recording below the min_peers check passed every named suite,
so the invariant that a count below the floor is still an answered count was
unguarded. The new test drives the real entry point with a node answering 0 and
1 peers against a floor of 2: readiness refuses it, yet the gauge reads the
answered count rather than -1, so the exposition cannot hide the very shortfall
that closed admission, and an answered zero stays a real zero.

The observation age also discarded a later answer whenever its attempt had
started earlier than the one already published. The age asks when the node last
answered, not which attempt owns the published peer and sync pair, so it now
keeps the latest answer any attempt received; the ordering guard still governs
that pair alone. This adds no RPC call and leaves the setters allocation-free.

Co-Authored-By: Claude Opus 5 <[email protected]>
@kiwidream

Copy link
Copy Markdown
Member Author

Rebased onto 3.x.x at 6575f595 (after #503 and #507); head is now b64f09ab, the same three commits with the registry-before-node lock-order fix intact (events.rs byte-identical to the previous head). Conflicts were the two census sites only, both additive: tests/observability/cardinality.rs and docs/prism-metrics-cardinality-privacy.md. Census is now 64 families / 244 startup series / 679 populated series (the base doc had stale numbers at 56/669/235 and now carries the measured ones). Verified: fmt, workspace clippy -D warnings, observability 17/17, metrics_allocation 4/4 in 0.6 s, readiness_rpc 11/11 under the gate, gate scripts.

@kiwidream
kiwidream force-pushed the p2-hardening/node-rollup-gauges branch from f58fd0e to b64f09a Compare September 24, 2026 17:59
@kiwidream
kiwidream merged commit 2255a86 into 3.x.x Sep 24, 2026
21 checks passed
@kiwidream
kiwidream deleted the p2-hardening/node-rollup-gauges branch September 24, 2026 18:34
djh58 added a commit that referenced this pull request Sep 25, 2026
Brings in #470, #512, #513, #514 and #515. #515 opens the share append's
transaction through AppendConnection::begin, which records BEGIN completion
so that a future cancelled before the reply retires the connection instead
of returning it to the pool; this branch opens the same transaction with
"BEGIN; SET LOCAL plan_cache_mode = force_generic_plan" so the share_id
probe is planned once per connection.

Resolution keeps both: AppendConnection::begin takes the opening statement
and the append passes APPEND_TRANSACTION_BEGIN. SQLx reads every reply of
that simple query through its ReadyForQuery before begin returns, so the
guard records completion only once the whole batch is in.

ledger_cancelled_begin now cancels the append on the custom BEGIN, and a
new case holds only the batch's closing ReadyForQuery (the execution proxy
gains pause_statement_ready) and proves the connection is still retired.
The pool-acquire inventory, the gated-test manifest and the #482 ops notes
follow the new call sites.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
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.

1 participant