Skip to content

fix: origin deny-set & authorized-origin gate correctness (#1398, #1368) - #1426

Merged
thiras merged 6 commits into
mainfrom
fix/origin-deny-set-batch-1398-1368-1374
Jul 24, 2026
Merged

thiras merged 6 commits into
mainfrom
fix/origin-deny-set-batch-1398-1368-1374

Conversation

@thiras

@thiras thiras commented Jul 24, 2026 •

Copy link
Copy Markdown
Contributor

Batch fixing the tightly-coupled follow-ups from the #1380 (origin deny-set) and #1366 (G-NODE-08 authorized-origin gate) reviews.

#1398 — origin deny-set & AnnounceGate

  • Fail-open → fail-closed: set_origin applies the in-memory deny before the durable store write, so a store error no longer keeps a just-blacklisted origin serving. Regression test flipped to pin the new behavior.
  • Silent fail-open by omission: ClientHandlerDeps.content_deny is now a required new() param (was seeded empty then overwritten — a construction site that forgot the wiring silently denied nothing).
  • Inert retry made real: a failed nodeIdOf now queues in pending_origin_peer_ops, drained every tick (the old Recheck::Failed only re-ran the hash re-scope, which has no origin leg).
  • AnnounceGate origin deny-set (item 6): new AnnounceOriginDenySet bars an origin-blacklisted operator from re-announcing even while CapacityBond still lists it active (setOriginBlacklist/emergencyAddOrigin don't eject). Fed by the watcher (both directions + boot rebuild).
  • Config cross-check (item 7): reject a hash that is both pinned and denied; plus a runtime deny-wins-over-pin carve-out on the LRU eviction path.
  • Cleanups (items 3/8): dropped the dead isOriginBlacklisted node binding + stale comments; removed dead DeniedHashes::diff; operator-EOA-appropriate denied_origins zero-address message.
  • Item 5 (in-flight stream termination) was verified already implemented by feat(node): delivery-path deny gates for ADR 011 takedowns (#1168, #1179) #1380; unchanged here.

#1368 — authorized-origin gate scope

ADR 022/037 now state the gate is namespace-scoped, not operator-scoped (a non-assigned operator holding the bytes may still serve them — matches the implementation). Pinned by a two-operator anvil journey.

#1374

Closed separately as a finding: the gate is fully cache-backed, so a warm namespace serves stale during an RPC blip; "fail-closed-on-RPC-loss" is the cold path (already unit-tested). Documented in ADR 022.

Tests

New unit tests for every fix (drain driver, boot-rebuild, clear/ZERO branches, config wiring, cache carve-out) + two anvil journeys (origin_blacklist_compliance, g_node_08_namespace_scope). A multi-agent PR review found no correctness bugs; its comment/coverage feedback is folded in.

Verified: cargo clippy --all-targets clean, cargo fmt --check clean, 1813 unit tests + both anvil journeys pass.

Closes #1398
Closes #1368

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features

    • Added governance-controlled origin blacklisting, including automatic enforcement for announcements and content delivery.
    • Added support for namespace-scoped authorization when warming and serving cached content.
  • Bug Fixes

    • Denied content is now eligible for cache eviction even when pinned, helping reclaim unusable storage.
    • Authorization now fails closed when origin information cannot be confirmed, while safely supporting warm cached decisions.
    • Configuration validation now rejects hashes that are both pinned and denied.

thiras and others added 5 commits July 24, 2026 02:50
#1368)

Batch of tightly-coupled follow-ups from the #1380 / #1366 reviews on the origin
deny-set and authorized-origin gate. Node-side fixes + ADR clarifications + the
e2e write-surface; remaining e2e journeys tracked as follow-ups.

Deny-set correctness (#1398):
- set_origin applies the in-memory deny BEFORE the durable write, so a store
  error no longer skips it and leaves a just-blacklisted origin serving
  (fail-open -> fail-closed). Test updated to assert the new behavior.
- ClientHandlerDeps.content_deny is now a required new() parameter; the empty
  seed + runtime overwrite was itself a silent fail-open-by-omission.
- Drop the dead isOriginBlacklisted ABI + correct the stale boot-reconcile
  comments (the set is not enumerable on-chain; the durable projection is the
  guarantee).
- resolve_config rejects a hash that is both pinned and denied (held-forever yet
  serve-refused). Remove the dead DeniedHashes::diff; parse_denied_origins now
  gives operator-EOA-appropriate zero-address advice.

AnnounceGate origin deny-set (#1398 item 6, folds in the inert-retry item 1):
- New AnnounceOriginDenySet (ArcSwap, NodeId-keyed). NodeStakedNodeSet refuses an
  origin-blacklisted operator even while CapacityBond still lists it active
  (setOriginBlacklist/emergencyAddOrigin do not eject), closing the peer re-entry
  gap PeerTable::remove only papered over.
- apply_origin_peer feeds both directions; a failed nodeIdOf now queues a real
  retry in pending_origin_peer_ops (drained each tick) instead of the previously
  inert Recheck::Failed. Boot rebuilds the derived NodeId set from the durable
  origin projection via seeded pending ops.

#1368: ADR 037 and ADR 022 now state the gate is namespace-scoped, not
operator-scoped — a non-assigned operator holding the bytes may still serve them.
No gate-logic change (matches the implementation).

e2e (#1398 item 8): setOriginBlacklist sol! binding + ChainFixture helpers, and a
new origin_blacklist_compliance journey (serve -> blacklist -> refuse with
OriginBlacklisted -> un-blacklist -> serve) — the ABI-drift guard for the
watcher's hand-written origin declarations.

#1398 item 5 (in-flight stream termination) was verified already implemented by
#1380; unchanged here.

Verified: cargo clippy --all-targets clean, cargo fmt --check clean, 876 node +
1009 (gossip/common/config-types/incentive/cache) unit tests pass, and the new
anvil journey passes.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Executable companion to the ADR 022 / ADR 037 §85 clarification: node A runs the
armed authorized-origin gate and holds H backend-only; a distinct, onboarded
operator B is the SOLE authorized origin of namespace N. A still serves H under N
even though the DAO assigned N to a different operator — pinning that
authorization is a property of the namespace, not of the operator holding the
bytes. A negative control (N unauthorized → A refuses) keeps the positive from
passing vacuously. Passes against anvil.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
…1374)

The gate's authorization check is entirely cache-backed (cached origin set +
cached active-staker set; no live RPC read) and the caches are not invalidated on
a failed refresh. So the ADR 022 "fails closed on RPC loss" guarantee is the COLD
case — an empty or never-resolved namespace resolves to no authorized origin. A
WARM namespace (already resolved before the outage) serves stale through a
transient RPC blip, favoring availability; the staleness window is bounded by the
outage and its conservative direction is a lagging de-authorization, not an
un-authorized origin admitted. Documents the behavior #1374 probed.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
…em 7)

Defense-in-depth for the runtime deny-set ∩ pinned-hash collision. The takedown
path already handled it — the blacklist watcher's cache.evict() ignores the pin,
drops tags (GC-reclaimable) and durably logs, and is_chain_denied blocks serving
immediately. But the LRU/space-eviction path excluded pinned hashes WITHOUT
consulting refuses, so a pinned + governance-denied hash could sit on disk
(unservable) if the takedown evict() ever lagged or failed.

Carve the pin exemption out for a deny-listed hash on both space seams in
CacheEngine:
- eviction_candidates: a pinned hash that is is_denied/is_chain_denied stays a
  candidate (lock-free deny checks, not full refuses, to avoid inverting evict's
  access_times/evicted lock order — an evicted hash has no access_times entry
  anyway).
- release_for_eviction: the is_pinned early-return no longer exempts a refuses()
  hash from reclaim.

is_pinned itself is unchanged (it feeds the operator-visible inspect flag). No
watcher or cache.evict() change. This closes the last deferred item — nothing left
as a follow-up. +2 unit tests; full decdn-cache suite (279) green.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Follow-up from the multi-agent PR review (no correctness bugs were found).

Test hardening (the review's main finding — leaf functions were tested but the
integration seams were not):
- on_tick_complete_drains_pending_ops_into_the_deny_set: covers the actual retry
  DRIVER + the boot-rebuild reconstruction path (prior tests called
  apply_origin_peer directly, bypassing the tick drain).
- failed_nodeidof_on_clear_queues_a_retry_that_later_unbars: the clear-direction
  retry twin (was add-only).
- zero_node_id_is_a_settled_no_op_that_clears_pending: the ZERO branch the origin
  e2e silently takes.
- resolve_config_errors_when_a_hash_is_pinned_and_denied: drives the pinned∩denied
  check through resolve_config, guarding the wiring line (prior tests used the
  cfg(test) shim).
- local_denied_pinned_hash_is_also_an_eviction_candidate: the is_denied (local)
  half of the cache carve-out.
- Extracted origin_watcher_state test helper; deduped the two existing tests.

Comment/doc corrections:
- content_blacklist.rs: "removed as dead surface" now scoped to the node sol!
  binding — the on-chain isOriginBlacklisted view is alive (OriginAssignment
  unions against it; e2e binds it).
- engine.rs eviction_candidates: dropped the unfounded "invert evict's lock order"
  rationale (evict never nests those mutexes); kept the real redundancy+cheapness
  reason and hoisted the denied/chain_denied loads out of the loop. Documented that
  held wins over deny deliberately (transient hold; evict() is the actuator).
- config/mod.rs: softened "held forever" now that deny-wins-over-pin makes a
  denied+pinned hash reclaimable at runtime.
- blacklist_watcher.rs: "durably" → "reliably" for the in-memory (boot-rebuilt)
  announce deny-set; documented the blacklisted-before-registration ZERO
  limitation (bounded — delivery still refused by address).
- apply_origin_peer now consumes the AnnounceOriginDenySet insert/remove "changed"
  return to gate its log (was ignored despite the doc); split out
  apply_resolved_origin to keep cognitive complexity under the clippy gate.

Verified: clippy --all-targets clean, fmt clean, 1813 tests pass.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Copilot AI review requested due to automatic review settings July 24, 2026 00:56
@coderabbitai

coderabbitai Bot commented Jul 24, 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: 47 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: 8c456f12-7f76-4936-99e0-d849dbea15b8

📥 Commits

Reviewing files that changed from the base of the PR and between ebf2397 and 6a57c19.

📒 Files selected for processing (2)
  • crates/e2e/tests/origin_blacklist_compliance.rs
  • crates/node/src/blacklist_watcher.rs

Walkthrough

The PR updates deny-list handling across cache eviction and configuration, propagates origin blacklist state into node admission and content delivery, adds e2e coverage, and clarifies fail-closed and namespace-scoped authorization semantics.

Changes

Deny policy consistency

Layer / File(s) Summary
Deny conflicts and eviction behavior
crates/cache/src/engine.rs, crates/common/src/config/mod.rs
Denied pinned hashes remain eviction candidates and are reclaimable; configuration rejects hashes present in both pinned and denied sets, with tests covering the validation.
Origin parsing and hash API cleanup
crates/common/src/config/mod.rs, crates/config-types/src/hash.rs
Denied origins are parsed as operator EOAs with updated zero-address errors, and DeniedHashes::diff is removed.

Origin blacklist propagation

Layer / File(s) Summary
Blacklist contract bindings and fixtures
crates/e2e/src/bindings.rs, crates/e2e/src/chain.rs, crates/incentive/src/content_blacklist.rs
E2E helpers expose origin blacklist operations, while the incentive binding removes the blacklist view and documents event-tail tracking.
Announcement deny-set enforcement
crates/node/src/announce_gate.rs
A shared AnnounceOriginDenySet rejects denied NodeIds during announcement admission.
Watcher reconciliation and fail-closed ordering
crates/node/src/blacklist_watcher.rs
Origin blacklist events update content, peer, and announcement state; failed nodeIdOf lookups retry each tick, and in-memory denial precedes durable persistence.
Runtime compliance dependency wiring
crates/node/src/runtime/mod.rs, crates/node/src/handlers/client/mod.rs, crates/node/tests/support/mod.rs
The runtime shares the origin deny-set and passes the content denylist explicitly into client dependencies.
Origin blacklist end-to-end validation
crates/e2e/tests/origin_blacklist_compliance.rs
The test verifies delivery denial after blacklist projection and restoration after clearing the blacklist.

Namespace-scoped origin authorization

Layer / File(s) Summary
Namespace authorization behavior
adr/037-regional-proxy-warming.md, crates/e2e/tests/g_node_08_namespace_scope.rs
Documentation and e2e coverage define and verify authorization by request namespace rather than by the operator holding the content.

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

Sequence Diagram(s)

sequenceDiagram
  participant Chain
  participant BlacklistWatcher
  participant ContentDenylist
  participant AnnounceOriginDenySet
  participant NodeAnnounce
  Chain->>BlacklistWatcher: emit origin blacklist event
  BlacklistWatcher->>ContentDenylist: apply origin denial
  BlacklistWatcher->>AnnounceOriginDenySet: update resolved NodeId
  AnnounceOriginDenySet->>NodeAnnounce: reject denied origin announcement
  BlacklistWatcher->>BlacklistWatcher: retry unresolved nodeIdOf operations
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.

Copilot AI 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.

Pull request overview

This PR tightens correctness around ADR 011 deny enforcement (origin deny-set + announce admission) and clarifies/locks in the authorized-origin gate’s intended namespace-scoped semantics (ADR 022/037), adding targeted unit + anvil-e2e coverage to prevent the prior fail-open and retry gaps from regressing.

Changes:

  • Make origin blacklist enforcement fail-closed and eliminate silent “deny nothing” wiring by requiring ContentDenylist at ClientHandlerDeps::new, plus add a real retry queue for failed nodeIdOf origin peer ops.
  • Add an announce-gate NodeId deny-set (AnnounceOriginDenySet) fed by the blacklist watcher to prevent re-announces on the origin-only blacklist paths.
  • Add config cross-checks and cache behavior to ensure “deny wins over pin”, plus document and pin the authorized-origin gate’s namespace-scoped behavior (ADR 022/037 + new anvil journeys).

Reviewed changes

Copilot reviewed 15 out of 15 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
crates/node/tests/support/mod.rs Updates handler test scaffolding to supply an explicit empty ContentDenylist for the new required dep.
crates/node/src/runtime/mod.rs Wires shared AnnounceOriginDenySet through runtime: watcher feed + announce gate enforcement + required content_denylist in handler deps.
crates/node/src/handlers/client/mod.rs Makes content_deny a required ClientHandlerDeps::new parameter to prevent silent fail-open wiring.
crates/node/src/blacklist_watcher.rs Implements fail-closed origin apply ordering; adds pending origin peer ops retry drain; feeds announce deny-set on blacklist/clear + boot rebuild.
crates/node/src/announce_gate.rs Introduces AnnounceOriginDenySet and composes it into the staked-node announce gate.
crates/incentive/src/content_blacklist.rs Drops dead isOriginBlacklisted Rust binding and updates event docs accordingly.
crates/e2e/tests/origin_blacklist_compliance.rs New anvil-e2e journey exercising on-chain origin blacklist write → watcher projection → delivery refusal and subsequent un-blacklist restore.
crates/e2e/tests/g_node_08_namespace_scope.rs New anvil-e2e journey pinning namespace-scoped (not operator-scoped) authorized-origin gate behavior with a two-operator setup.
crates/e2e/src/chain.rs Adds ChainFixture helpers for setOriginBlacklist and isOriginBlacklisted.
crates/e2e/src/bindings.rs Adds dedicated ContentBlacklistOrigin binding to drive origin blacklist writes/reads in e2e.
crates/config-types/src/hash.rs Removes dead DeniedHashes::diff.
crates/common/src/config/mod.rs Adds cross-section validation to reject pinned∩denied hash collisions; improves denied-origin zero-address error messaging.
crates/cache/src/engine.rs Ensures “deny wins over pin” on LRU eviction candidate selection and release_for_eviction, with new unit tests.
adr/037-regional-proxy-warming.md Documents authorized-origin gate as namespace-scoped and clarifies implications.
adr/022-content-discovery.md Clarifies namespace-scoped authorization and documents warm-cache behavior during RPC outages.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread crates/node/src/blacklist_watcher.rs Outdated
capacity_bond: capacity_bond.clone(),
peer_table: Arc::clone(&peer_table),
announce_deny: Arc::clone(&announce_deny),
pending_origin_peer_ops: pending_origin_peer_ops.clone(),

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Confirmed — resumable_watcher::spawn takes make_sink: impl FnOnce (resumable_watcher.rs:648), and the map is not used after the sink is built. Moved it into WatcherState instead of cloning in 6a57c19. (The sibling known.clone() / Arc::clone are pre-existing and left as-is.)

Comment on lines +97 to +104
Err(err) => {
let msg = format!("{err:#}");
anyhow::ensure!(
msg.contains("OriginBlacklisted"),
"refusal must be the origin-blacklist reason, got: {msg}"
);
Ok(Some(()))
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed in 6a57c19: now downcasts to UpstreamRefused and asserts StreamError::OriginBlacklisted, matching g_node_08_namespace_scope. client.fetch wraps the error in .context(..), but anyhow preserves downcast_ref to the inner type. Verified against anvil (55s).

@github-actions

github-actions Bot commented Jul 24, 2026 •

Copy link
Copy Markdown

Coverage report

Total: 81.10% (was 81.01%, ▲ +0.08%) — 52351/64555 lines

File Coverage Lines Δ
crates/cache/src/engine.rs 90.57% 2631/2905 ▲ +0.24%
crates/common/src/config/mod.rs 97.00% 6852/7064 ▲ +0.03%
crates/config-types/src/hash.rs 90.67% 175/193 ▲ +3.17%
crates/e2e/src/chain.rs 0.94% 11/1172 ▼ 0.02%
crates/node/src/announce_gate.rs 95.83% 92/96 ▼ 4.17%
crates/node/src/blacklist_watcher.rs 94.09% 1401/1489 ▲ +1.35%
crates/node/src/handlers/client/mod.rs 88.86% 638/718 ▲ +0.03%
crates/node/src/runtime/mod.rs 46.81% 1085/2318 ▼ 0.10%
History
Commit Total Δ vs base
ebf2397 81.09% ▲ +0.08%
6a57c19 (HEAD) 81.10% ▲ +0.08%

- blacklist_watcher.rs: the resumable_watcher::spawn factory is FnOnce (constructed
  once), so move pending_origin_peer_ops into WatcherState instead of cloning the
  whole map.
- origin_blacklist_compliance.rs: assert on the typed UpstreamRefused /
  StreamError::OriginBlacklisted (as g_node_08_namespace_scope does) rather than a
  brittle formatted-string match, so a channel/connect/payment regression can't
  green the check for the wrong reason. Verified against anvil (55s).

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@thiras
thiras merged commit 3cf9883 into main Jul 24, 2026
24 checks passed
@thiras
thiras deleted the fix/origin-deny-set-batch-1398-1368-1374 branch July 24, 2026 01:18
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: origin deny-set follow-ups from the #1380 review Clarify authorized-origin gate scope: namespace-wide vs per-operator

2 participants