Skip to content

fix(node): serve stored readiness from the peer ping route - #641

Merged
beardthelion merged 2 commits into
mainfrom
fix/ping-peer-stored-state-269
Nov 30, 2026
Merged

beardthelion merged 2 commits into
mainfrom
fix/ping-peer-stored-state-269

Conversation

@beardthelion

@beardthelion beardthelion commented Nov 30, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

GET /api/v1/peers/{did}/ping now returns the readiness stored on the peer row and sends no request to the peer. Before, any anonymous caller could make the node issue an outbound request to a registered peer URL on every call, with no limit.

Motivation & context

The route is anonymous and each call sent /ready (then a /health fallback) to the peer's stored http_url. Since #248 the /ready request also makes the target run a database query. A caller who registers a peer can repeat that at will.

I took the second option from the issue (stop probing) over a per-IP limit. A limit leaves the reflector in place at the allowed rate, and it would depend on proxy-peer trust that is not settled yet (#207).

Closes #269

Kind of change

  • Bug fix
  • Feature
  • Security fix
  • Docs
  • Tests / CI
  • Refactor (no behavior change)
  • Breaking or protocol change (issue required first)

What changed

twigpine-node only, plus one docs sentence.

  • api/peers.rs: ping_peer returns peer.last_ping_ok instead of calling the readiness probe. Response keys (did, http_url, reachable) are unchanged and the route still writes nothing. The periodic gossip ping is untouched and remains the only thing that probes peers and records the result.
  • api/peers.rs tests: a healthy mock peer receives no request and a stored false is returned anyway; a stored true is not replaced by a probe result; a private-URL peer returns immediately instead of waiting on a connection; an unknown DID still returns 404.
  • db/mod.rs: the peers-write ledger row now names the renamed test fixture.
  • docs/RUN-A-NODE.md: one sentence described the old behavior and now describes this one.

How a reviewer can verify

The new tests fail on the old handler (for example left: Bool(true) right: false) and pass here.

DATABASE_URL=postgresql://gitlawb:changeme@localhost:5432/gitlawb \
  cargo test -p twigpine-node --lib ping_peer

Before you request review

  • Scope is one logical change; no unrelated churn
  • cargo test --workspace passes locally (I ran the api::peers tests, the peers-write ledger test and the twigpine-cli peer tests, not the whole workspace)
  • New behavior is covered by tests (required for fixes)
  • cargo fmt --all and cargo clippy --workspace --all-targets -- -D warnings are clean
  • Commit titles use Conventional Commits (feat(...), fix(...), docs(...))
  • Docs / .env.example updated if behavior or config changed (or N/A)
  • Checked existing PRs so this isn't a duplicate

Protocol & signing impact

  • Touches DID / did:key, Ed25519 / RFC 9421 signatures, UCAN, ref certs, or P2P wire formats
  • Discussed in an issue before implementation
  • Backward-compatible with existing nodes and previously signed history

Notes for reviewers

reachable is now the node's last gossip observation, not a live check, so twigpine peer ping can lag a peer's real state by one gossip interval. The route still loads the whole peers table to find one DID; that predates this change and I left it.

#634 edits the same sentence in docs/RUN-A-NODE.md, so whichever of the two lands second needs a one-line rebase.

Summary by CodeRabbit

  • Bug Fixes
    • Peer ping checks now return the readiness status recorded by periodic checks, without sending an outbound request or changing federation state. Unknown peers continue to return a not-found response.
  • Documentation
    • Updated the node guide to clarify that peer ping checks report readiness from the most recent periodic gossip ping and do not make outbound requests.

Return the peer row's stored readiness instead of probing the peer URL. The anonymous diagnostic now sends no outbound request and writes nothing.
@coderabbitai

coderabbitai Bot commented Nov 30, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

GET /api/v1/peers/{did}/ping now returns the peer’s stored last_ping_ok value. The handler makes no outbound request or federation-state write. Tests and the node guide reflect this behavior.

Changes: Peer ping readiness

Layer / File(s) Summary
Return stored readiness
crates/twigpine-node/src/api/peers.rs, crates/twigpine-node/src/db/mod.rs, docs/RUN-A-NODE.md
The endpoint returns the stored last_ping_ok value without probing the peer or writing federation state. Tests cover stored values, no outbound requests, and unknown peers. The writer ledger and node guide reflect the behavior.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix · Severity of issue fixed: High

Suggested labels: crate:node, kind:bug, kind:security, subsystem:peers

Suggested reviewers: miketomlin19, kevincodex1

Merge Risk: Minimal · up to ae06f

The ping endpoint now reports the readiness last recorded by periodic gossip and no longer contacts peers, so its reachable value can lag real peer state by one gossip interval. No actionable merge-blocking risk was found, and the change is easy to revert.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title "fix(node): serve stored readiness from the peer ping route" matches the main change. The ping route now returns the stored last_ping_ok value instead of probing the peer's /ready or /health…
Description check Passed The description follows the template well. It has a summary, motivation with the linked issue (Closes #269), kind of change, a what-changed list naming the crate, a verification command, the review ch…
Linked Issues check Passed [#269] The issue asks that anonymous GET /api/v1/peers/{did}/ping stop letting callers trigger outbound requests to peer-controlled URLs. It allows either a per-IP brake or serving the last gossip-o…
Out of Scope Changes check Passed The PR-side changes support the objective. api/peers.rs contains the handler fix and its tests. db/mod.rs renames the peers-write ledger entry and expected-writer entry to the seed_ping_peer_row…
Full details: Title check

Explanation

The title "fix(node): serve stored readiness from the peer ping route" matches the main change. The ping route now returns the stored last_ping_ok value instead of probing the peer's /ready or /health endpoints. The title is specific, follows Conventional Commits, and names the node crate.

Full details: Description check

Explanation

The description follows the template well. It has a summary, motivation with the linked issue (Closes #269), kind of change, a what-changed list naming the crate, a verification command, the review checklist, protocol impact, and reviewer notes. It explains the security reason for the change and the trade-off between the two options in the issue. The full workspace test run is unchecked, and the author states that only targeted tests were run. That gap is disclosed, so it does not block the check.

Full details: Linked Issues check

Explanation

[#269] The issue asks that anonymous GET /api/v1/peers/{did}/ping stop letting callers trigger outbound requests to peer-controlled URLs. It allows either a per-IP brake or serving the last gossip-observed state with no outbound request. The PR uses the second option. The previous review read ping_peer in crates/twigpine-node/src/api/peers.rs at commit 44cee71. That handler returns the stored last_ping_ok as reachable, makes no outbound request, and writes nothing. Response keys did, http_url, and reachable are unchanged. Tests cover the stored-true and stored-false cases, zero outbound requests to a mock peer, the private-URL case, and the unknown-DID 404. Since the previous review, the head moved to ae06f01, which merges origin/main. The history shows only main-side commits (#634, #635, #637, #638, #640, #643, and others) and the merge commit. The author reports the conflict was only in docs/RUN-A-NODE.md, with peers.rs merging cleanly. I could not re-read the whole-PR diff at head because the changed blobs were unavailable in the checkout, so I did not re-verify the handler body at ae06f01. The previous PASS is preserved on the basis of the unchanged-handler report and the merge history. Known limit: reachable can lag live peer state by one gossip interval. The issue accepts this trade-off for the stored-state option.

Full details: Out of Scope Changes check

Explanation

The PR-side changes support the objective. api/peers.rs contains the handler fix and its tests. db/mod.rs renames the peers-write ledger entry and expected-writer entry to the seed_ping_peer_row test fixture, which the new tests use. docs/RUN-A-NODE.md changes one sentence that described the old probing behavior. The merge of origin/main at ae06f01 brings in main-side commits that are not part of this PR's own change set, and the merge base is fe6f63d. The docs conflict was resolved by keeping the #634 proxy client-IP section and this PR's stored-readiness wording, which is a valid resolution. I did not re-read the whole-PR diff at head because the changed blobs were unavailable, so the db and docs hunks rest on the PR summary and the matching names in the test code. No unrelated change was found in the evidence available.

Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 4320524f-7fad-425e-ab38-a7220ecd20fd
Commits

Reviewing files that changed from the base of the PR and between 44cee71 and ae06f01.

Files selected for processing: 3

  • crates/twigpine-node/src/api/peers.rs
  • crates/twigpine-node/src/db/mod.rs
  • docs/RUN-A-NODE.md
Files skipped from review as they are similar to previous changes: 1

  • docs/RUN-A-NODE.md

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.

@beardthelion
beardthelion requested a review from jatmn November 30, 2026 02:35

@jatmn jatmn left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Merge readiness

Rebase onto current main before merge. GitHub reports mergeStateStatus: DIRTY / mergeable: CONFLICTING. A three-way merge of origin/main against this head shows overlapping edits in crates/twigpine-node/src/api/peers.rs (same file as this change). Resolve conflicts and re-run CI on the rebased head.

The author noted PR #634 edits the same sentence in docs/RUN-A-NODE.md. Whichever lands second needs a one-line doc reconciliation.

Required check test (stable) failed on head 44cee716 (job log). The failing test is test_support::tests::sweep_backs_off_after_a_run_that_repairs_nothing in crates/twigpine-node/src/test_support.rs, which is outside this PR’s three-file diff. test (beta) passed on the same run. Treat the stable failure as unrelated until reproduced on a rebased head; if it persists after rebase, triage separately from this security fix.

Other PR checks on this head: fmt + clippy, build --release, MSRV, and CodeRabbit passed.


🟢 Thanks for the contribution. I do not see any actionable issues from my review.

The handler change matches issue #269 option 2: ping_peer returns stored last_ping_ok, sends no outbound request, and still does not mutate federation state. Tests cover no-probe behavior (mockito expect(0)), stored true/false, private-URL non-blocking response, unknown-DID 404, and unchanged response keys. list_peers and resolve already exposed reachable as last_ping_ok, so semantics are now consistent across read surfaces.

Resolves the docs/RUN-A-NODE.md conflict with the proxy client-IP section
that landed on main: main's section is kept and the ping sentence keeps the
stored-readiness wording from this branch.
@beardthelion

Copy link
Copy Markdown
Collaborator Author

Brought the branch current by merging origin/main (ae06f01) instead of rebasing, so the approved commits are unchanged. The only conflict was docs/RUN-A-NODE.md: main's new proxy client-IP section from #634 is kept as is, and the ping sentence keeps this PR's stored-readiness wording. peers.rs and db/mod.rs merged without conflicts, and the two existing rate limiter fixtures in peers.rs already carry main's new trusted_peers field.

On the merged head, cargo check, cargo fmt --check and cargo clippy -D warnings are clean, and cargo test --workspace --no-fail-fast passes, including the four ping tests.

sweep_backs_off_after_a_run_that_repairs_nothing passes run alone three times on 44cee71 and in the full workspace run on the merged head. I did not reproduce the stable-job failure, so I can't say what caused it. It is a wall-clock window test, outside this diff. If it fails again on the new run, I'll treat it separately.

@beardthelion
beardthelion added this pull request to the merge queue Nov 30, 2026
Merged via the queue into main with commit 1ba71bc Nov 30, 2026
21 of 22 checks passed
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.

Anonymous /api/v1/peers/{did}/ping has no auth or per-IP brake, and now probes the target's database

2 participants