Skip to content

fix(node): gate listeners on blacklist sync - #1275

Merged
thiras merged 5 commits into
mainfrom
fix/1171-gate-listener-blacklist-sync
Jul 18, 2026
Merged

thiras merged 5 commits into
mainfrom
fix/1171-gate-listener-blacklist-sync

Conversation

@altanoruc

@altanoruc altanoruc commented Jul 17, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • require a valid ContentBlacklist contract address during paid-delivery node config resolution
  • complete the initial full blacklist replay and operator-scope enforcement before spawning the iroh Router or registering Probe, Client, DHT, and gossip ALPNs
  • fail startup closed on initial chain/cache enforcement errors while preserving the established watcher loop and shutdown ordering after readiness

Impact

Nodes can no longer accept paid-delivery traffic before local blacklist compliance is established. Missing configuration or an unavailable initial sync now produces a startup error instead of running without local protection.

Validation

  • cargo test -p decdn-common --lib (402 passed)
  • cargo test -p decdn-node --lib (647 passed)
  • cargo clippy -p decdn-common -p decdn-node --all-targets -- -D warnings
  • cargo fmt --all -- --check
  • git diff --check

cargo-nextest, cargo-deny, and pre-commit were not installed in the validation environment. No dependency changes are included.

Closes #1171

Summary by CodeRabbit

  • New Features

    • Content blacklist configuration is now required for node startup.
    • Nodes complete an initial blacklist synchronization before accepting network connections.
    • Startup now fails clearly if the initial synchronization cannot enforce all entries.
  • Bug Fixes

    • Prevented network listeners from starting before blacklist compliance is ready.
    • Improved validation and error reporting for missing or invalid blacklist contract addresses.

@gemini-code-assist

Copy link
Copy Markdown

Caution

The consumer version of Gemini Code Assist on GitHub has been sunset. All code review activity has officially ceased.

@coderabbitai

coderabbitai Bot commented Jul 17, 2026 •

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

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

Next review available in: 16 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: 5830f599-6d8f-4702-bbb9-79d695576fe7

📥 Commits

Reviewing files that changed from the base of the PR and between 6fcdf39 and 7288f2f.

📒 Files selected for processing (2)
  • crates/node/src/blacklist_watcher.rs
  • crates/node/src/runtime/mod.rs

Walkthrough

The ContentBlacklist contract address is now required during configuration resolution. The blacklist watcher reports initial synchronization status through a one-shot channel, and runtime startup delays ALPN listener registration until synchronization succeeds.

Changes

ContentBlacklist startup synchronization

Layer / File(s) Summary
Require and validate ContentBlacklist configuration
crates/common/src/config/*, crates/common/src/cli/run.rs, crates/cli/tests/config_validate.rs
Configuration resolution now reports missing or invalid content_blacklist_address values, with documentation, fixtures, and aggregated validation assertions updated accordingly.
Signal initial watcher synchronization
crates/node/src/blacklist_watcher.rs
The watcher tracks initial replay and re-scope status and sends exactly one success or failure result through a readiness channel.
Gate router startup on readiness
crates/node/src/runtime/mod.rs
Runtime startup always launches the watcher and constructs the Router only after successful readiness signaling; startup and gating tests cover both outcomes.

Estimated code review effort: 4 (Complex) | ~45 minutes

Sequence Diagram(s)

sequenceDiagram
  participant NodeRuntime
  participant BlacklistWatcher
  participant ReadinessGate
  participant QUICRouter

  NodeRuntime->>BlacklistWatcher: start initial replay and re-scope
  BlacklistWatcher-->>ReadinessGate: report success or failure
  alt synchronization succeeds
    ReadinessGate->>QUICRouter: construct and register ALPN listeners
  else synchronization fails
    ReadinessGate-->>NodeRuntime: return startup error
  end
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.

@github-actions

github-actions Bot commented Jul 17, 2026 •

Copy link
Copy Markdown

Coverage report

Total: 81.73% (was 81.51%, ▲ +0.22%) — 49172/60161 lines

File Coverage Lines Δ
crates/common/src/config/mod.rs 97.00% 6701/6908 ● 0.00%
crates/common/src/config/resolved.rs 100.00% 48/48 ● 0.00%
crates/node/src/blacklist_watcher.rs 62.75% 219/349 ▲ +37.85%
crates/node/src/runtime/mod.rs 50.56% 1081/2138 ▲ +1.75%
History
Commit Total Δ vs base
e296258 81.62% ▲ +0.13%
fbc8d4f 81.65% ▲ +0.14%
7288f2f (HEAD) 81.73% ▲ +0.22%

@altanoruc
altanoruc marked this pull request as ready for review July 18, 2026 04:24

Copy link
Copy Markdown
Contributor Author

Review: gate listeners on blacklist sync

Security-motivated change with genuinely good test coverage. The core idea — no paid-delivery ALPN may accept before the mandatory ContentBlacklist replay + operator-scope pass establishes local compliance — is implemented correctly on the happy path: the gate opens only after a full backfill to head and a clean re-scope (the on_tick_complete bail keeps a dirty initial pass from ever signalling Ok). A few points worth discussing before merge.

What looks good

  • Config change mirrors the existing required-address convention exactly (resolve_contract_address + zero-address reject, same shape as slash_judge_address), including the fail-open-trap rationale for the zero address.
  • InitialSyncGate is a clean idempotent one-shot (Mutex<Option<Sender>>, take-on-signal, PoisonError::into_inner rather than unwrap) — no await-under-lock, no panic surface.
  • Thorough tests: gate pending/success/failure, missing-config error, initial-head-failure → startup error; coverage on blacklist_watcher.rs jumps ~25pp.

1. The gate defers more than the ALPN listeners (main concern)

gate_listener_on_blacklist_sync(...).await? sits at crates/node/src/runtime/mod.rs:1104, ahead of the DHT bootstrap (:1111), the metrics listener bind (:1126), the admin listener bind (:1358), and the "node runtime ready" banner (:1842). So a slow initial replay now blocks observability and the local admin control surface, not just the paid-delivery listeners the security goal actually requires.

Startup already blocks on a bounded, retrying check_rpc_reachability preflight (:289), but that's a lightweight reachability ping; the blacklist gate is a full historical getLogs replay + per-hash re-scope, and (see #2) it aborts on the first backoff. Net effect: during exactly the window an operator would want to inspect why a node isn't serving, metrics + admin are down.

Suggestion: keep the metrics/admin binds and bootstrap ahead of the gate and gate only Router::spawn on readiness. All of Router's inputs (ep, handlers, gossip, limiter) are already built before :1094, so the reorder is mechanical and preserves the #1109 intent (observability/control independent of the heavy chain round-trips) while still keeping every ALPN closed until compliant.

2. First transient backoff at startup is fatal — intended?

on_backoff fires on every failed tick and on_established on the first success (crates/node/src/chain_events/resumable_watcher.rs:457-468), and InitialSyncGate::signal is one-shot. Because the backoff hook resolves the gate with Err, the first transient RPC / head / getLogs error during the initial sync resolves the gate to failure and run() returns — even though the watcher's own backoff loop would retry and establish moments later (that later on_established is then a no-op). So a single blip at boot (common when a co-located RPC is still warming up) aborts the whole process rather than being ridden out.

If "fail closed = exit, let the supervisor restart" is the deliberate choice, worth a one-line comment saying so. If you'd rather tolerate transient blips while still failing closed, resolve the gate on on_established and only fail after a bounded timeout / N consecutive backoffs, instead of on the first on_backoff.

3. Needs a non-trivial rebase (mergeable_state: dirty)

main has since moved WatcherConfig to a builder (WatcherConfig::new(...).on_established(...).on_backoff(...), #1251/#1281) and reworked the cursor (CursorStart/Checkpoint, #1238/#1280). This PR still builds WatcherConfig as a struct literal with seed_cursor / on_established: None, so it won't merge as-is. The good news: the builder already exposes .on_established()/.on_backoff() and the blacklist watcher leaves them unset on main, so the readiness hooks drop straight into those free seams — but please rebase and re-validate against the new API rather than resolving line-by-line.

Minor

  • ResolvedBlockchain.content_blacklist_address stays Option<String> with an "always Some" invariant enforced only at runtime via .context(...). Fine given directly-constructed test configs — just noting the type no longer reflects the requirement.
  • Validation notes say nextest / cargo-deny / pre-commit weren't run. Given the clippy/Solidity-in-CI gotchas in CLAUDE.md, worth running cargo nextest run + pre-commit run --all-files before merge.

Overall the compliance-gating direction is right and the happy path is correct; the main ask is reordering so the gate covers the ALPN listeners without taking down metrics/admin, plus a decision on the first-backoff-is-fatal behavior.


Generated by Claude Code

claude and others added 3 commits July 18, 2026 19:31
… bring-up

The initial blacklist-sync gate was awaited before the DHT bootstrap, the
metrics listener bind, the admin listener bind, and the "node runtime ready"
banner. A slow or failed initial ContentBlacklist replay therefore took down
observability and the local admin control surface as well as the paid-delivery
listeners — regressing the #1109 intent that the metrics/admin binds and the
startup banner come up independent of chain RPC, and blinding operators exactly
when they would want to see why a node is not serving.

Move the gate to just after the startup banner, immediately before the serve
loop, so it covers only the Router (Probe/Client/DHT/gossip ALPNs). The watcher
is still spawned near the top of bring-up, so its initial replay now runs
concurrently with bootstrap, the metrics/admin binds, and every background task,
and is often already complete by the time control reaches the gate. The security
invariant is unchanged: no ALPN accepts a connection before the first global +
operator-scope replay/scope pass succeeds, and a failed initial sync still fails
startup closed.

No behavior change to the gate helper or the watcher; the block is relocated.
Validated: cargo build, clippy -D warnings, fmt --check, and cargo test -p
decdn-node --lib (647 passed).

Co-Authored-By: Claude Opus 4.8 <[email protected]>
Claude-Session: https://claude.ai/code/session_01PpNWr8dWZ1tk3rkV3WmKzM
…r-blacklist-sync

# Conflicts:
#	crates/node/src/blacklist_watcher.rs
#	crates/node/src/runtime/mod.rs
…gate; tidy merge

Follow-ups from the post-merge review of the #1171 reconciliation:

- Add initial_clean_replay_signals_ready: asserts a clean first replay drives
  on_established -> signal(Ok) through the real blacklist_watcher::spawn wiring,
  so a hook swap or mis-cloned InitialSyncGate can't wedge listeners closed
  while the failure-path test stays green.
- Add listener_fails_closed_when_watcher_drops_readiness: the gate must treat a
  dropped readiness sender (watcher aborted before signaling) as a hard failure.
- Move `let mut tasks = JoinSet::new()` back to its first use; the blacklist
  watcher spawns via its own WatcherHandle, not into the JoinSet.
- Correct the router-gate comment: a *failed* initial sync exits the process
  (it does not keep observability up); only a still-pending sync does.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@thiras
thiras merged commit 2c919aa into main Jul 18, 2026
23 checks passed
@thiras
thiras deleted the fix/1171-gate-listener-blacklist-sync branch July 18, 2026 21:41
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.

Node: gate QUIC listener on completed Phase-3 state-sync; make blacklist sync mandatory

3 participants