feat(network): NetworkHealth snapshot + write-readiness formula in ant-core (V2-1037) - #174
Conversation
|
Security Audit failure is inherited, not from this change: RUSTSEC-2026-0258 ( 🤖 Generated with Claude Code |
|
Review verdict: APPROVE (code) at The health snapshot is a coherent best-effort readiness signal, uses cheap live in-memory counts, saturates exported counts safely, and has boundary coverage for both signals. Local verification: Watch-outs: |
…runtime (V2-1046) Third time this cap has been outgrown (20 -> 40 -> 60): on PR WithAutonomi#174 the macOS leg passed at 57m09s and the Ubuntu leg was canceled at 60m20s mid-run with no test failure in the log — a pure timeout kill reading as a red X on an unrelated change. 90 min gives the observed ~60-min runtime real headroom while still catching genuine hangs; the neighboring E2E job has no explicit cap, so this stays the tighter bound. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
…t-core (V2-1037)
One implementation of the write-readiness/peer-count computation for
every embedded-client consumer (antd, ant-gui, ant-ffi, ant-tui), moved
down from antd (V2-1027):
- NetworkHealth { write_ready, connected_peers, routing_table_size,
rebootstrap_threshold }, built by NetworkHealth::from_counts.
write_ready = max(routing_table_size, connected_peers) >= threshold;
the max() is load-bearing: client-mode routing tables under-report
(observed rt=2 with 10 live connections and stores succeeding), while
the connected count alone misses the dead-network case (ant-sdk#232).
- Network::health() + Client::network_health() pass-through; both node
reads are in-memory, cheap enough to compute per call.
- REBOOTSTRAP_THRESHOLD mirrors saorsa-core's private
AUTO_REBOOTSTRAP_THRESHOLD until a release carries saorsa-core#153
(which makes the real const public).
Deliberately out: last_store_ok stays consumer-side (only consumers
know which operations count as stores); try_recover() via the
newly-public maybe_rebootstrap() waits for a saorsa-core release
carrying #153.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
7bc685f to
9817bef
Compare
jacderida
left a comment
There was a problem hiding this comment.
Approved. Additive read-only API with no consumers in this repo — Network::health() / Client::network_health() are two in-memory reads, and nothing calls them yet, so there is no behavioral surface on any existing path.
Verified the mirrored constant against the pinned dependency rather than the description: in saorsa-core 0.27.0 (the version in Cargo.lock), AUTO_REBOOTSTRAP_THRESHOLD is still private at dht_network_manager.rs:209 and equals 3, and maybe_rebootstrap is still private. So REBOOTSTRAP_THRESHOLD = 3 is correct against what ships today, and this PR does not depend on saorsa-core#153 — #153 is what will let the mirror be deleted, and the try_recover() rider that does depend on it is correctly deferred out of this PR.
Follow-up worth tracking: because this mirrors a private const, a future change to the saorsa-core value produces no compile error here — ant-core would silently disagree with the DHT. Worth deleting the mirror in favour of the real const once a release carries #153.
Rebased onto current main (7bc685f -> 9817bef, clean) to pick up #177 and #178, which clears both prior CI failures (RUSTSEC-2026-0258 in h2, and the 60m Merkle E2E cap). Verified locally on the rebased head: cargo fmt clean, clippy --all-targets --all-features -D warnings clean, cargo test -p ant-core --lib 463 passed / 0 failed including the 6 new NetworkHealth tests.
Linear issue
V2-1037
Risk tier
Additive read-only API: two in-memory reads of existing node state, no network-facing behavior change, no node/protocol surface.
Compatibility
NetworkHealthstruct,REBOOTSTRAP_THRESHOLDconst,Network::health(),Client::network_health(). No existing signature changes.Semver impact
Test evidence
NetworkHealth::from_countscovering the formula's observed failure modes: dead network (ant-sdk#232 shape: 1 connected / rt 0 → not ready), client-mode rt under-reporting (10 connected / rt 2 → ready, the false-negative caught live on the LAN devnet during V2-1027), exact-threshold boundaries on each signal, u32 saturation.cargo test -p ant-core --lib: 463 pass; 1 pre-existing, unrelated Windows-only failure (save_snapshot_to_unwritable_dir_does_not_panicassumes Unix root-write semantics; passes on Linux CI, fails on any Windows dev box).cargo clippy --all-targets --all-features -- -D warningsclean,cargo fmt --checkclean.New dependency
none
ADR
n/a
Mitigation / rollback
Additive API with no consumers in this repo — revert the single commit; downstream consumers (antd V2-1027, ant-gui V2-1038, ant-ffi V2-649) only adopt it in their own PRs.
Context: this is the single write-readiness implementation for all embedded-client consumers, moved down from antd (WithAutonomi/ant-sdk#241).
REBOOTSTRAP_THRESHOLDmirrors saorsa-core's privateAUTO_REBOOTSTRAP_THRESHOLDuntil a release carries saorsa-core#153, which makes it public; atry_recover()rider over the newly-publicmaybe_rebootstrap()is deferred to the same release.last_store_oktracking deliberately stays consumer-side.🤖 Generated with Claude Code