Repository navigation
feat(node): add rpc connectivity watchdog with rpc_healthy gauge - #366
Conversation
Periodically poll the configured JSON-RPC endpoint and expose the result as `decdn_rpc_healthy` (1 = reachable, 0 = unreachable) so dashboards can alert on a sustained outage rather than relying on the one-shot startup check. Logs `warn` on the down transition and `info` on recovery; steady- state ticks are silent. Interval is configurable via `blockchain.rpc_watchdog_interval_sec` (default 30, `0` disables). The watchdog shares its probe with the existing startup `check_rpc_reachability` so success/failure semantics stay aligned. Shutdown is plumbed via `oneshot` and awaited in the runtime drain phase next to the gossip handles. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]> Closes #283
There was a problem hiding this comment.
Code Review
This pull request implements an RPC connectivity watchdog that periodically probes the configured RPC endpoint and updates a health metric. It includes changes to the configuration system to support a probe interval, new metrics for monitoring reachability, and a background task to perform the checks. The review feedback suggests initializing the health metric regardless of whether the watchdog is enabled, removing redundant seeding logic within the task, and improving security by redacting raw RPC URLs from log messages to prevent potential credential leakage.
There was a problem hiding this comment.
Pull request overview
Adds an RPC reachability watchdog to the node runtime and exposes its status via a new Prometheus gauge, making RPC outages observable during steady-state operation (not just at startup).
Changes:
- Introduces a periodic JSON-RPC
net_versionprobe loop that updates a newdecdn_rpc_healthygauge and logs on up/down transitions. - Factors the existing startup RPC check into a shared
probe_rpchelper to keep success/failure semantics aligned. - Wires a new
blockchain.rpc_watchdog_interval_secconfig field through config resolution and validates/reporting; adds a wiremock-based runtime test.
Reviewed changes
Copilot reviewed 8 out of 9 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| crates/node/src/runtime/mod.rs | Spawns/shuts down the watchdog task, factors out probe_rpc, and adds a transition test. |
| crates/node/src/metrics.rs | Adds rpc_healthy gauge plus helpers for setting/reading it (test-only read). |
| crates/node/src/config/types.rs | Adds TOML config field rpc_watchdog_interval_sec. |
| crates/node/src/config/resolved.rs | Adds resolved config field for the watchdog interval. |
| crates/node/src/config/mod.rs | Adds default interval constant and resolves the new field into ResolvedBlockchain. |
| crates/node/src/commands/mod.rs | Prints the resolved watchdog interval in config validate output and documents it in the sample config. |
| crates/node/tests/config_validate.rs | Updates resolved-config test fixture to include the new required field. |
| crates/node/Cargo.toml | Adds wiremock dev-dependency for the new runtime test. |
| Cargo.lock | Locks the new wiremock dependency. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Address review feedback on PR #366: - Seed `rpc_healthy(true)` from `run()` right after the successful startup `check_rpc_reachability` probe, before the watchdog-spawn branch. Covers the `rpc_watchdog_interval_sec == 0` (disabled) case too, so a registered Prometheus gauge no longer defaults to 0 and trips outage alerts on a healthy node. - Drop the redundant in-watchdog seed and update its doc comment to match (caller seeds, watchdog only writes on tick boundaries). - Drop `%url` from the RPC-healthy / RPC-unhealthy transition logs. The URL may carry basic-auth credentials in its userinfo component, and the node configures one RPC endpoint so the log doesn't need to identify which one. `%err` is kept on the warn. - Fix the `mount_healthy` test helper doc comment so it no longer claims to return a guard the function doesn't return. - Update the runtime test to mirror the new seeding contract. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Resolves conflicts with PRs #363/#364/#365/#366 that landed on main while this branch was in review. Conflict resolution: - crates/node/Cargo.toml: keep both new dev-deps (nix from this branch for SIGHUP integration tests, wiremock from #366 for the rpc-watchdog test). - crates/node/src/runtime/mod.rs: union the test-module clippy allows ([unwrap_used, expect_used, panic, indexing_slicing]); keep both new test bodies (rpc_watchdog_tracks_endpoint_transitions from #366 plus shutdown_streams_recv_resolves_on_sigterm from this branch). - Test fixtures across config/mod.rs, runtime/reload.rs, and tests/sighup_signal.rs gained the rpc_watchdog_interval_sec field (Option::None for FileConfig literals; literal 30u64 for ResolvedBlockchain). Verified post-merge: cargo fmt --check, cargo clippy --workspace --all-targets -- -D warnings, cargo nextest run -p decdn-node (179/179), RUSTDOCFLAGS=-D warnings cargo doc --workspace --no-deps --document-private-items, all clean. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Summary
decdn_rpc_healthyPrometheus gauge (1 = reachable, 0 = unreachable per the watchdog task).blockchain.rpc_watchdog_interval_sec(default 30s;0disables). Logswarnon the down transition andinfoon recovery; steady-state ticks are silent.net_versionprobe with the existing startupcheck_rpc_reachabilityso success/failure semantics stay aligned, and plumbs clean shutdown through the existingoneshot+ runtime drain pattern.Test plan
cargo fmt -- --checkcargo clippy --workspace --all-targets -- -D warningscargo nextest run -p decdn-node(135/135 passing, including newruntime::tests::rpc_watchdog_tracks_endpoint_transitionscovering healthy -> unhealthy -> healthy gauge transitions via wiremock)cargo deny checkcurl localhost:9090/metrics | grep rpc_healthyafter starting a node against a reachable RPCCloses #283
🤖 Generated with Claude Code