Repository navigation
fix: origin deny-set & authorized-origin gate correctness (#1398, #1368) - #1426
Conversation
#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]>
|
Warning Review limit reached
Next review available in: 47 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 (2)
WalkthroughThe 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. ChangesDeny policy consistency
Origin blacklist propagation
Namespace-scoped origin authorization
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
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.
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
ContentDenylistatClientHandlerDeps::new, plus add a real retry queue for failednodeIdOforigin peer ops. - Add an announce-gate
NodeIddeny-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.
| 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(), |
There was a problem hiding this comment.
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.)
| Err(err) => { | ||
| let msg = format!("{err:#}"); | ||
| anyhow::ensure!( | ||
| msg.contains("OriginBlacklisted"), | ||
| "refusal must be the origin-blacklist reason, got: {msg}" | ||
| ); | ||
| Ok(Some(())) | ||
| } |
There was a problem hiding this comment.
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).
Coverage reportTotal: 81.10% (was 81.01%, ▲ +0.08%) — 52351/64555 lines
History
|
- 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]>
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
set_originapplies 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.ClientHandlerDeps.content_denyis now a requirednew()param (was seeded empty then overwritten — a construction site that forgot the wiring silently denied nothing).nodeIdOfnow queues inpending_origin_peer_ops, drained every tick (the oldRecheck::Failedonly re-ran the hash re-scope, which has no origin leg).AnnounceOriginDenySetbars an origin-blacklisted operator from re-announcing even whileCapacityBondstill lists it active (setOriginBlacklist/emergencyAddOrigindon't eject). Fed by the watcher (both directions + boot rebuild).isOriginBlacklistednode binding + stale comments; removed deadDeniedHashes::diff; operator-EOA-appropriatedenied_originszero-address message.#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-targetsclean,cargo fmt --checkclean, 1813 unit tests + both anvil journeys pass.Closes #1398
Closes #1368
🤖 Generated with Claude Code
Summary by CodeRabbit
New Features
Bug Fixes