Skip to content

refactor(gossip): name the reputation-report gate's staked-membership states (#1338) - #1340

Merged
thiras merged 2 commits into
mainfrom
refactor/1338-report-gate
Jul 21, 2026
Merged

thiras merged 2 commits into
mainfrom
refactor/1338-report-gate

Conversation

@yigitdot

@yigitdot yigitdot commented Jul 21, 2026 •

Copy link
Copy Markdown
Contributor

Problem

#1335 (part of #1222) replaced the NodeAnnounce admission gate's Option<Arc<dyn StakedNodeSet>> with a purpose-named AnnounceGate<S> { Enforce(S), Disabled }, because nullability was overloaded to encode two safety-opposite states. That left the reputation-report gate one field over in the same file still shaped as Option<Arc<dyn StakedNodeSet>> — and with the opposite polarity:

Gate Disabled / None means
AnnounceGate fail-OPEN (tests only)
Reputation report fail-CLOSED (no reputation gossip)

Same type, opposite meaning: not a bug today, but a copy-paste between them would be silently wrong-way-round.

Change (issue Option 2, symmetric treatment)

  • New ReportGate<S> { Enforce(S), Disabled } + OwnedReportGate alias in crates/gossip/src/reputation.rs, mirroring AnnounceGate's shape: hand-written Debug that names the variant (the StakedNodeSet handle isn't Debug) and a hand-written Default returning Disabled — derived Default would demand S: Default, which a trait-object handle has not. No as_gate() borrow projection: the reputation path resolves the gate once at spawn and never re-checks it per message, so it doesn't need one.
  • ReputationWiring.staked is now OwnedReportGate; spawn_reputation_tasks destructures it in the same single let-else as sink (let (Some(sink), ReportGate::Enforce(staked)) = ...), so the combined check and its existing warning are unchanged.
  • Cross-references both ways, as the acceptance criteria ask: ReportGate's doc spells out that its Disabled is fail-CLOSED, the inverse of AnnounceGate::Disabled, and AnnounceGate's doc points at ReportGate for the same reason.
  • Node side: new report_staked_gate() constructor next to the existing announce_staked_gate(), so the runtime's always-enforce choice is explicit and unit-tested on both gates rather than implied by a Some(..).

No functional or wire behavior change.

Tests

  • reputation_wiring_default_gate_is_disabled — pins the newly-expressed invariant: the default gate is Disabled (pattern match) and Debug names the variant. Verified fails-before: against pre-change code it rendered ReputationWiring { sink: false, staked: false, report_drain: false } and failed the assertion.
  • disabled_report_gate_spawns_no_reputation_tasks — behavior pin for the fail-CLOSED half: a wired sink + drain with a Disabled gate and subscribe_reputation = true joins no reputation topic (4 tasks, no publish trigger). This combination had no coverage before.
  • report_staked_gate_enforces_over_the_live_set — the node-side mirror of announce_staked_gate_enforces_never_fails_open: Enforce over the real staker set, not an admit-everyone stub.

Verification

  • cargo build — clean
  • cargo clippy --workspace --all-targets -- -D warnings — clean
  • cargo nextest run -p decdn-gossip — 69/69 pass
  • cargo nextest run --no-fail-fast — 2519/2519 pass. (A first run flaked on decdn-node::node_origin_pull a_reserved_open_slot_does_not_starve_the_candidate_loop, a timing test unrelated to this diff; it passes in isolation and on the clean re-run.)
  • cargo fmt -- --check — clean

🤖 Generated with Claude Code

Closes #1338

Summary by CodeRabbit

  • New Features

    • Added staked-membership admission controls for inbound reputation reports.
    • Reputation gossip is now enabled only when staked-node verification is configured.
    • Added fail-closed behavior that suppresses reputation gossip when verification is unavailable.
    • Node runtime wiring now automatically applies the staked-node admission gate.
  • Bug Fixes

    • Prevented reputation reports from being accepted without valid staked-node verification.
  • Documentation

    • Clarified the differing fail-open and fail-closed behaviors of gossip admission controls.

… 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]>
@coderabbitai

coderabbitai Bot commented Jul 21, 2026 •

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@yigitdot, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 19 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

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 configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Free

Run ID: 1a804fa7-b77e-4bac-a5cb-666da2ae2770

📥 Commits

Reviewing files that changed from the base of the PR and between 3c7104a and 78fc60b.

📒 Files selected for processing (4)
  • crates/gossip/src/reputation.rs
  • crates/gossip/src/service.rs
  • crates/gossip/src/validation.rs
  • crates/node/src/reputation_wiring.rs

Walkthrough

Reputation gossip now uses an explicit ReportGate that defaults to fail-closed. Node runtime wiring supplies an enforcing staker-set gate, while the gossip service skips reputation tasks unless both the sink and enforcing gate are present.

Changes

Reputation report admission

Layer / File(s) Summary
Report gate contract
crates/gossip/src/lib.rs, crates/gossip/src/reputation.rs, crates/gossip/src/validation.rs
Adds ReportGate with enforcing and disabled states, an owned alias, disabled default behavior, and documentation distinguishing report and announce gate semantics.
Staker-backed gate wiring
crates/node/src/reputation_wiring.rs, crates/node/src/runtime/mod.rs
Adds report_staked_gate, tests membership admission, and uses the enforcing gate in runtime reputation wiring.
Service admission and validation
crates/gossip/src/service.rs
Requires an enforcing gate and sink before spawning reputation tasks, updates wiring consumers, and tests disabled-gate suppression.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Sequence Diagram(s)

sequenceDiagram
  participant NodeRuntime
  participant report_staked_gate
  participant ReputationWiring
  participant spawn_reputation_tasks
  participant ReputationTasks
  NodeRuntime->>report_staked_gate: provide staker set
  report_staked_gate-->>ReputationWiring: return Enforce gate
  ReputationWiring->>spawn_reputation_tasks: provide sink and gate
  spawn_reputation_tasks->>ReputationTasks: spawn only for Enforce gate
Loading

Note

🎁 Summarized by CodeRabbit Free

Your 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 @coderabbitai help to get the list of available commands.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a dedicated ReportGate enum to manage the admission of inbound reputation reports, replacing the previous Option<Arc<dyn StakedNodeSet>> representation. This ensures a fail-closed behavior by default (ReportGate::Disabled) and prevents potential copy-paste errors with the sibling AnnounceGate (which is fail-open). The changes include updating the ReputationWiring struct, modifying task spawning logic, and adding corresponding unit tests to verify the fail-closed behavior. There are no review comments, so I have no feedback to provide.

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.

@github-actions

github-actions Bot commented Jul 21, 2026 •

Copy link
Copy Markdown

Coverage report

Total: 81.77% (was 81.74%, ▲ +0.03%) — 51510/62994 lines

File Coverage Lines Δ
crates/gossip/src/reputation.rs 100.00% 343/343 ● 0.00%
crates/gossip/src/service.rs 82.24% 741/901 ▲ +1.78%
crates/gossip/src/validation.rs 100.00% 367/367 ● 0.00%
crates/node/src/reputation_wiring.rs 95.08% 367/386 ▼ 0.11%
crates/node/src/runtime/mod.rs 46.30% 1106/2389 ▲ +0.04%
History
Commit Total Δ vs base
3c7104a 81.77% ▲ +0.03%
78fc60b (HEAD) 81.77% ▲ +0.03%

…n 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]>
@yigitdot

Copy link
Copy Markdown
Contributor Author

Multi-agent review pass (code / tests / comments / type-design) plus independent verification. The refactor itself is behavior-preserving and CI-clean; findings were concentrated in the prose. Fixed in 78fc60b:

Corrected a false claim. The Default impl justified itself with "a derive would demand S: Default". That rule does not exist — #[derive(Default)] on an enum with a #[default] unit variant emits an unbounded impl (the struct case is where the bound appears). Verified by compiling the exact shape on rustc 1.94 / edition 2024: the enum compiles for ReportGate<Arc<dyn StakedNodeSet>>, the struct control case fails. Since it was the sole stated reason for the hand-written impl, the impl is now derived and the claim is gone — including from the commit message, which repeated it.

Fixed a doc this PR's own test contradicts. ReputationWiring's doc said "the publisher needs report_drain", but the publisher spawns on the same enforcing branch as the subscriber — which is exactly what disabled_report_gate_spawns_no_reputation_tasks asserts ("must suppress the publisher too").

Covered the Enforce Debug arm. Only Disabled was ever rendered, so mislabelling one arm would report every live enforcing gate as fail-closed in the logs with nothing failing — the exact polarity confusion this PR exists to prevent. AnnounceGate got this test in #1335's own review round. Confirmed fails-before: with the arm mislabelled, the new test is the only one of 70 that goes red.

Stopped defining the gate by the Option it replaced (reputation.rs, reputation_wiring.rs) and stopped re-describing the fail-closed mechanism a third time in validation.rs. bc83b16 reworded AnnounceGate away from precisely this so the docs would not become dangling references; the pattern had crept back in.

Warning now names which half is missing. "no reputation sink/staker wired" reads as "neither", but a wired sink with a Disabled gate trips it too. Now emits sink_wired and gate_enforcing separately, via a new ReportGate::is_enforcing. Also dropped the adjacent comment claiming "a sink with no gate would admit unvetted reports" — there is no such state, and reputation_subscriber_task takes the set by value, so an ungated subscriber is unrepresentable.

Verification: clippy --workspace --all-targets -D warnings, fmt --check, RUSTDOCFLAGS=-D warnings cargo doc, cargo deny check, and 2520/2520 workspace tests.

Deferred to follow-ups rather than growing scope: #1342 (ReportGate's vestigial <S> generic and dead Clone/Copy derives), #1343 (reputation_publish_trigger doc), #1344 (untested sink: None + Enforce, and no end-to-end enforcing-subscriber test), #1345 (staked -> report_gate rename, NodeStakedNodeSet visibility, AnnounceGate fail-open wording).

@thiras
thiras merged commit 984a9dd into main Jul 21, 2026
22 of 23 checks passed
@thiras
thiras deleted the refactor/1338-report-gate branch July 21, 2026 14:38
thiras added a commit that referenced this pull request Jul 21, 2026
…#1350, #1355) (#1358)

Follow-ups filed off the reviews of #1340, #1341 and #1353. Closes #1342, #1343,
#1344, #1345, #1350 and #1355; #1356 was closed as a duplicate of #1347, which
stays open for the deferred swap-revert tests.

BREAKING: `ReportGate` and `ReputationWiring`'s struct literal are gone —
`ReputationWiring` is now a sum type (`Disabled` / `Enabled { sink, staked,
publish }`), so an admission set without a sink is unrepresentable rather than
warned about at runtime. That deletes the test #1344 asked for instead of adding
it. `GossipRuntimeConfig::subscribe_reputation` is also gone; the operator-facing
`[gossip] subscribe_reputation` key is unchanged, but `decdn-node` now resolves
it into the wiring variant at the one site that builds it, so there is a single
off-switch instead of two.

`AnnounceGate::Disabled` is `#[cfg(test)]`. It fails OPEN on ADR 001 rule 2 and
was guarded only by a doc comment plus a test on `announce_staked_gate`, which
would have stayed green if a future edit passed `Disabled` to `spawn` — the hole
#1170 closed. It no longer exists in production builds.

Transaction submission is unified in `decdn_incentive::tx::send`, including both
swap venues (they spend USDC and read the hash after `get_receipt()`, so a
receipt timeout named no transaction at all). `send` takes a caller-owned
`landed` slot: `Some` means "may have taken effect" — including the unreadable-
receipt case — and is cleared on a confirmed revert. `bond`, `setup`, `register`
and `appeal` use it. `channel` deliberately does not: it classifies a revert as
an expected outcome rather than an error.

That slot is what makes the re-run guidance safe. The earlier wording asserted
"no TOKEN was transferred" / "on-chain state is unchanged" and told the operator
to re-run immediately; alloy's nonce filler resolves against the pending block,
so re-running while a bond tx is in flight submits a second one and doubles the
bond.

`setup`'s live phases are one fallible section with a single reporting site, so a
failure at any phase emits the aggregated `--json` summary with whatever landed —
previously a register-phase failure printed nothing and a landed swap's hash had
no machine-readable carrier at all. `build_summary` emits one shape on both paths
with a `partial` flag.

Note for the record: commit `edb3e80`'s message asserts a symbol
(`bundle_pull::discover_candidates`) that does not exist — copied from #1350's
text without verifying, in a commit about fixing inaccurate comments. The code is
correct; the message could not be amended.

Tests: new `cli_setup_partial` e2e journey drives the production binary against
anvil (with a new `ChainFixture::pause_capacity_bond` lever, since starving the
operator of TOKEN trips the pre-flight instead of entering the live phase); the
gossip integration test's drain now varies its payload per round, because
plumtree dedups byte-identical messages for 90s and a constant payload collapsed
a 50-round budget to ~6. Every new test was mutation-verified.
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.

gossip: reputation-report staked gate still uses Option with inverse polarity to AnnounceGate (#1222 follow-up)

2 participants