Repository navigation
refactor(gossip): name the announce gate's disabled state (#1222) - #1335
Conversation
Replace the announce-path `Option<_ StakedNodeSet>` gate with a named
`AnnounceGate { Enforce, Disabled }` enum so the fail-open intent is
self-documenting at every call site. The old `Option` distinguished two
safety-opposite states (`None` = accept any signature-valid announce,
`Some` = enforce ADR 001 rule 2) only by nullability — and was
identically typed to `ReputationWiring.staked`, whose `None` has the
opposite (fail-closed) polarity.
- `validate_envelope` takes `AnnounceGate<&dyn StakedNodeSet>`;
`GossipService::spawn` / `subscriber_task` take the owned
`OwnedAnnounceGate` alias, bridged via `OwnedAnnounceGate::as_gate`.
- `announce_staked_gate` now returns `AnnounceGate::Enforce`, never the
fail-open `Disabled`; its unit test destructures the variant.
- `ReputationWiring.staked` is left as `Option` (a wiring-presence flag,
different semantics).
Pure refactor: no behavior change; rule-2 enforcement is identical.
Closes #1222.
Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Free Run ID: 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (2)
WalkthroughChangesThe PR replaces optional staked-node admission with typed Announce gate migration
Estimated code review effort: 3 (Moderate) | ~20 minutes Sequence Diagram(s)sequenceDiagram
participant NodeRuntime
participant GossipService
participant subscriber_task
participant validate_envelope
NodeRuntime->>GossipService: pass announce_gate
GossipService->>subscriber_task: pass OwnedAnnounceGate
subscriber_task->>validate_envelope: validate envelope with gate.as_gate()
validate_envelope-->>subscriber_task: accept or reject NodeAnnounce
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 |
There was a problem hiding this comment.
Code Review
This pull request replaces the use of Option<Arc<dyn StakedNodeSet>> with a new AnnounceGate enum to explicitly distinguish between enforcing staked membership and failing open. This type safety improvement is propagated across the gossip service, validation logic, runtime, and tests. The feedback suggests importing AnnounceGate in service.rs to prevent cargo doc link resolution failures in the updated documentation.
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.
The `GossipService::spawn` doc links to `AnnounceGate::{Enforce,Disabled}`,
but `AnnounceGate` is not imported in service.rs (only `OwnedAnnounceGate`
is used in code) — breaking `cargo doc -D warnings` in CI. Importing the
type instead trips `unused_imports` under clippy `-D warnings`, since it is
referenced only in the doc comment. Point the links at the full crate path
so both jobs pass without an otherwise-unused import.
Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Coverage reportTotal: 81.74% (was 81.72%, ▲ +0.02%) — 51417/62904 lines
History
|
…contained Post-review polish (PR #1335, no behavior change): - Note that `Copy` on `AnnounceGate` is conditional — it applies only to the borrowed `&dyn` form; the owned `Arc` alias is `Clone`-only — so the derive isn't misread as copying the set. - Reword the `AnnounceGate` and `as_gate` docs to state what they are/do rather than what they replaced (the removed `Option` / `Option::as_deref`), so the docs don't become dangling references. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Gas snapshotNo gas changes vs base. |
Contracts coverageLine coverage: 88.94% (2500/2811 lines) |
Two low-severity coverage gaps from the #1335 review: - `as_gate_preserves_variant`: the owned→borrowed projection (`OwnedAnnounceGate::as_gate`) was only exercised for the `Enforce` arm via the multi-node integration tests; the `Disabled` arm never ran through it. Pin both arms (Enforce hit/miss + Disabled) directly. - `debug_reports_variant_only`: the hand-written variant-only `Debug` (written that way because the `S` handle isn't `Debug`) had no test; pin the format strings so a future derive-simplify that leaks the set contents is caught. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Review summary (5-agent pass)Ran a comprehensive multi-agent review (general code, type-design, comments, silent-failure, test-coverage). Approve — zero critical, zero important issues. The "no behavior change" claim holds: Highlights the reviewers called out:
Follow-up applied in this PR (c01f2eb)Two low-severity coverage gaps the review surfaced, now closed:
Deferred (out of scope)The one design note left open: |
… states (#1338) (#1340) * refactor(gossip): name the reputation-report gate's staked-membership states (#1338) `ReputationWiring.staked` was an `Option<Arc<dyn StakedNodeSet>>` whose `None` means fail-CLOSED, sitting one field away from the `AnnounceGate<S>` introduced by #1335 whose `Disabled` means fail-OPEN. Two identically-shaped gates with opposite polarity is the exact hazard #1222 set out to remove. Give the reputation path its own `ReportGate<S> { Enforce(S), Disabled }` (plus `OwnedReportGate`), mirroring `AnnounceGate`'s shape: hand-written `Debug` naming the variant, and a hand-written `Default` (the trait-object handle has none) that keeps the unwired state `Disabled`. Both enums carry a doc cross-reference to the other's inverse polarity. Node-side, the runtime now builds the gate via a named `report_staked_gate` constructor alongside `announce_staked_gate`. No behavior change: `sink` and the gate remain one combined check with the same warning, and `ReputationWiring::default()` still runs no reputation gossip. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]> * docs+test(gossip): correct ReportGate docs, name both wiring halves in the warning Post-review fixes on #1340 (no wire or behavior change). - Derive `Default` on `ReportGate` with `#[default]` on `Disabled` and drop the hand-written impl. Its doc justified itself with "a derive would demand `S: Default`", which is false: `#[derive(Default)]` on an enum with a `#[default]` unit variant emits an unbounded impl. Verified against the exact shape on rustc 1.94 / edition 2024 — the enum compiles for `ReportGate<Arc<dyn StakedNodeSet>>` while the struct control case does not. - `ReputationWiring`'s doc claimed "the publisher needs `report_drain`". The publisher spawns on the same enforcing branch as the subscriber, so it also needs `sink` and `Enforce` — as this PR's own `disabled_report_gate_spawns_no_reputation_tasks` asserts. - The unwired warning said "no reputation sink/staker wired", which reads as "neither", but a wired sink with a `Disabled` gate trips it too. Report `sink_wired` and `gate_enforcing` as separate fields, via a new `ReportGate::is_enforcing`. - Drop the "a sink with no gate would admit unvetted reports" comment: there is no such state, and `reputation_subscriber_task` takes the set by value, so an ungated subscriber is unrepresentable. - Stop defining the gate by the `Option` it replaced (`reputation.rs`, `reputation_wiring.rs`) and stop re-describing the fail-closed mechanism in `validation.rs` — bc83b16 reworded `AnnounceGate` away from exactly this so the docs would not become dangling references. Also soften "every signature-valid announce is admitted": `AnnounceGate::Disabled` skips only the membership check. - New `report_gate_debug_reports_variant_only`, mirroring `AnnounceGate`'s test, pins both `Debug` arms. Confirmed fails-before: mislabelling the `Enforce` arm as `"ReportGate::Disabled"` was caught by this test alone, with the other 69 gossip tests green. cargo clippy --workspace --all-targets -D warnings, cargo fmt --check, RUSTDOCFLAGS=-D warnings cargo doc, cargo deny check, and 2520/2520 workspace tests all pass. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]> --------- Co-authored-by: Claude Opus 4.8 (1M context) <[email protected]>
Item 1 of #1222 — name the gossip rule-2 staked-node gate's disabled state at the type level. Items 2 and 3 shipped in #1232; this closes the remaining item.
Problem
The announce gate was threaded as
Option<&dyn StakedNodeSet>(validate_envelope) andOption<Arc<dyn StakedNodeSet>>(spawn/subscriber_task), whereNone= fail-open (accept any signature-valid announce) andSome= enforce ADR 001 rule 2. These two safety-opposite states were distinguished only by nullability. Worse,ReputationWiring.stakedis the identically-typedOption<Arc<dyn StakedNodeSet>>with opposite polarity (None= fail-closed, reputation gossip not wired) — two same-typed fields, opposite safety meaning.Change
Replace the announce-path
Optionwith a named enum:validate_envelopetakesAnnounceGate<&dyn StakedNodeSet>;GossipService::spawn/subscriber_tasktake the ownedOwnedAnnounceGatealias, bridged viaOwnedAnnounceGate::as_gate()(replacing the oldOption::as_deref).announce_staked_gatenow returnsAnnounceGate::Enforce, never the fail-openDisabled; itsannounce_staked_gate_enforces_never_fails_openunit test destructures the variant.ReputationWiring.stakedis left asOption— a wiring-presence flag with different (fail-closed) semantics, exactly the precedent the issue flagged.Debug(sinceStakedNodeSetisn'tDebug-bound),derive(Clone, Copy)(the borrowed instantiation isCopy).Pure refactor: no behavior change — rule-2 enforcement is byte-for-byte identical.
Verification
cargo clippy --workspace --all-targets -- -D warnings— cleancargo fmt -- --check— cleancargo nextest run -p decdn-gossip— 65/65 passcargo nextest run -p decdn-node reputation_wiring+--test self_hosted_discovery— pass, including the load-bearingnon_staked_announce_is_dropped_at_subscriberreject-direction test (from test(gossip,node): harden the rule-2 staked-node gate — reject-path test + Some regression guard (#1222) #1232) provingEnforcestill drops non-staked announcers.Closes #1222.
🤖 Generated with Claude Code
Summary by CodeRabbit