Repository navigation
test(gossip,node): harden the rule-2 staked-node gate — reject-path test + Some regression guard (#1222) - #1232
Conversation
…-gate Some regression guard (#1222) Hardening follow-ups spun out of the #1170/#1221 review of the gossip rule-2 staked-node gate. Neither is a correctness fix. Item 2: add a subscriber-level reject integration test (non_staked_announce_is_dropped_at_subscriber) that wires the receiver's gate to exclude the publisher, drives a real announce through the spawn -> subscriber_task -> validate_envelope path, and asserts the peer table stays empty while the not_staked reject metric increments. Closes the Err(reject) arm, previously proven only at the pure-function level. Item 3: factor the runtime's announce-gate construction into a named, unit-tested announce_staked_gate() helper that always returns Some, so a future refactor cannot silently drop rule 2 to None (fail-open) with every existing test still passing. Item 1 (enum AnnounceGate vs Option) is deferred: it diverges from the ReputationWiring.staked: Option<...> precedent, and #1221's doc-comment tightening already mitigates the risk. Co-Authored-By: Claude Opus 4.8 <[email protected]>
|
Warning Review limit reached
Next review available in: 9 minutes Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Free Run ID: 📒 Files selected for processing (3)
Note 🎁 Summarized by CodeRabbit FreeYour organization is on the Free plan. CodeRabbit will generate a high-level summary and a walkthrough for each pull request. For a comprehensive line-by-line review, please upgrade your subscription to CodeRabbit Pro by visiting https://app.coderabbit.ai/login. Comment |
Gas snapshotNo gas changes vs base. |
Contracts coverageLine coverage: 88.92% (2488/2798 lines) |
There was a problem hiding this comment.
Code Review
This pull request introduces a robust mechanism to enforce ADR 001 rule 2, ensuring that node announcements are only accepted from staked nodes. It adds a new announce_staked_gate helper function in reputation_wiring.rs to guarantee that the admission gate is always initialized, and includes a comprehensive integration test in self_hosted_discovery.rs to verify that non-staked announcements are correctly rejected at the subscriber level. The review feedback highlights a potential race condition in the new test and provides a code suggestion to add a final assertion to ensure the rejection state remains stable.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
| assert!( | ||
| rejected, | ||
| "B's subscriber must reject A's announce with not_staked — proving the \ | ||
| announce reached B's validator and was dropped, not silently lost in the mesh" | ||
| ); |
There was a problem hiding this comment.
This assertion correctly verifies that a rejection occurred. However, there's a small race condition window: a subsequent announce from node A could theoretically be processed and inserted into B's peer table after the loop breaks but before the test's shutdown sequence begins.
To make the test more robust and cover this edge case, I suggest adding a final assertion after this block to re-verify that node B has not learned about node A, ensuring the rejection state is stable until shutdown.
| assert!( | |
| rejected, | |
| "B's subscriber must reject A's announce with not_staked — proving the \ | |
| announce reached B's validator and was dropped, not silently lost in the mesh" | |
| ); | |
| assert!( | |
| rejected, | |
| "B's subscriber must reject A's announce with not_staked — proving the \ | |
| announce reached B's validator and was dropped, not silently lost in the mesh" | |
| ); | |
| assert!( | |
| !learned_peer(&b_peers, &a_id, "US").await, | |
| "receiver B must never insert the non-staked publisher A (rule-2 reject), even after rejection is confirmed" | |
| ); |
There was a problem hiding this comment.
Added the final assertion in f1be115, but for a different reason than stated. The described race — a later A announce being inserted after the loop breaks — cannot occur here: B's gate is NoneStaked, whose contains() returns false unconditionally, so validate_envelope returns Err(NotStaked) for every announce from A regardless of timing; there is no code path that inserts A into B's peer table. The per-iteration !learned_peer assertion also already runs on the same iteration that observes the reject, so non-insertion is verified at the moment of rejection.
I still added the post-loop assertion, but as an explicit end-state invariant and a guard against future edits to the loop's break condition, not as a race fix — the comment reflects that.
Coverage reportTotal: 80.97% (was 80.96%, ▲ +0.01%) — 48245/59586 lines
History
|
…eview) Add a final post-loop non-insertion assertion so the reject state is verified right up to teardown and the invariant survives future edits to the loop's break condition. Not a race fix — NoneStaked rejects unconditionally, so A can never be admitted — but it documents the end-state explicitly. Co-Authored-By: Claude Opus 4.8 <[email protected]>
ReviewVerified the diff against What's good
Suggestions
Nothing blocking — LGTM with suggestion 1 as the one I'd actually make before merge. |
…tion (#1232 review) Item 3 test: assert the gate returned by announce_staked_gate actually enforces (member admitted, non-member rejected) via .expect(), not just is_some() — so a refactor returning Some(<admit-all stub>) can't pass while silently disabling rule 2. Renamed to announce_staked_gate_enforces_never_fails_open. Reject test: document that not_staked > 0 attributes to A only because there are two nodes and plumtree never echoes to origin; otherwise NoneStaked would reject B's self-echo in validate_envelope (before the self-echo Ok arm) and satisfy the check without A's announce arriving. Co-Authored-By: Claude Opus 4.8 <[email protected]>
|
Both suggestions applied in 507fcf2. 1 — gate enforcement pinned. `announce_staked_gate_is_always_some` was renamed to `announce_staked_gate_enforces_never_fails_open` and now asserts the returned gate actually delegates to the staker set (member admitted, non-member rejected) via `.expect(...)`, not just `is_some()` — so a refactor returning `Some()` no longer passes. 2 — attribution caveat documented. Confirmed the ordering: `validate_envelope` runs the staked check first, and the self-echo drop is in the later `Ok(is_self_announce)` arm — so with `NoneStaked`, B's own echoed announce would hit the `Err(NotStaked)` arm and bump the counter before that drop. Added a comment at the counter check noting `not_staked > 0` attributes to A only under (a) two nodes and (b) plumtree not echoing to origin, and to revisit if either changes. No code change — the metrics API carries no announcer id. |
Implements items 2 and 3 of #1222 — non-blocking hardening follow-ups spun out of the #1170 / #1221 review of the gossip
NodeAnnouncerule-2 staked-node gate. Neither is a correctness fix; they close a test-coverage gap and a silent-regression hole.Item 2 — Subscriber-level
not_stakedreject integration testThe reject path was proven only at the pure-function level (
staked_node_gate_enforced,empty_staked_set_rejects_all). The two-node e2e test wired both sides withAllStakedand exercised only the accept direction — theErr(reject)→ "drop + inc_rejected, no insert" arm at the subscriber was untested.New test
non_staked_announce_is_dropped_at_subscriber(crates/node/tests/self_hosted_discovery.rs):NoneStakedstub that excludes publisher A.NodeAnnouncefrom A through B's productionspawn → subscriber_task → validate_envelopepath.not_stakedreject counter increments — proving the announce reached B's validator and was dropped there, not silently lost in the mesh (a metric is needed becauseNoopMetricscan't observe counters; added a smallNotStakedRejectCounter).not_staked > 0attributes the reject to A only under two nodes plus plumtree never echoing to origin.Item 3 — Assert the runtime wires the gate as
SomeThe runtime built the gate as
Some(Arc::new(NodeStakedNodeSet::new(...)))inline;run()is only reachable via the heavyweight anvil e2e, so a future refactor setting it toNonewould silently disable rule 2 (fail-open) with every existing test still green — reopening the exact hole #1170 closed.announce_staked_gate()helper incrates/node/src/reputation_wiring.rsthat always returnsSome, and wiredruntime/mod.rsto it.announce_staked_gate_enforces_never_fails_openasserting the returned gate isSomeand actually enforces (staked member admitted, non-member rejected), so a refactor returningSome(<admit-all stub>)cannot pass while disabling rule 2. Reuses the existingstaker_set_withbuilder; no anvil e2e needed.Deferred — Item 1 (
enum AnnounceGatevsOption)Left out by decision: it diverges from the existing
ReputationWiring.staked: Option<...>precedent, and #1221's doc-comment tightening ("Noneis tests-only — no production path disables the gate") already mitigates the immediate risk. Item 3's named helper delivers the same self-documenting-intent benefit without a workspace-wide type change.Verification
cargo fmt -- --check✓cargo clippy --workspace --all-targets -- -D warnings✓cargo nextest run -p decdn-node -p decdn-gossip --no-fail-fast→ 853 passed, 0 failedAllStakedmakes the new reject test fail (B learns A), confirming the assertions actually exercise the reject path.f1be115,507fcf2) re-verified withcargo fmt --check,cargo clippy -p decdn-node --all-targets -- -D warnings, and the two affected tests.Addresses items 2 and 3 of #1222. Item 1 (the
enum AnnounceGaterefactor) is intentionally deferred, so this PR does not close the issue — #1222 stays open to track item 1.🤖 Generated with Claude Code