Skip to content

fix(gossip,node): enforce rule-2 staked-node check against the live registry (#1170) - #1221

Merged
thiras merged 2 commits into
mainfrom
fix/1170-gossip-rule2-live-registry
Jul 16, 2026
Merged

thiras merged 2 commits into
mainfrom
fix/1170-gossip-rule2-live-registry

Conversation

@yigitdot

@yigitdot yigitdot commented Jul 16, 2026 •

Copy link
Copy Markdown
Contributor

What & why

Closes #1170. NodeAnnounce admission (ADR 001 rule 2) checked a static gossip.allowlist config field that was always documented as a stand-in "until the on-chain staking registry contract lands." Because gossip still trusted that static list, a deregistered or slashed node could pass envelope validation and enter peer tables during its stale-cache window — the security gap this PR closes.

Rule 2 now enforces against the live on-chain staker set (ChainStakerSet, kept fresh by the CapacityBond NodeRegistered/NodeDeregistered/NodeAutoEjected event tail), which was already constructed at startup and Arc-cloned into the DHT/probe/reputation paths.

How

  • Live enforcement. validate_envelope now takes Option<&dyn StakedNodeSet> and checks the announcer's node_id against the live set. Reject reason NotAllowlisted → NotStaked (metric label not_allowlisted → not_staked).
  • Reused the shipped seam. Renamed the existing reputation-lane trait StakedReporterSet → StakedNodeSet (the predicate is identical for both lanes) and reused the NodeStakedNodeSet adapter. Keying is the identity function over the 32-byte iroh pubkey — no Address↔NodeId mapping needed. Threaded a staked gate through GossipService::spawn → subscriber_task, wired at runtime with Some(live set).
  • Gate semantics. None (tests / unstaked modes) accepts any signature-valid announce; Some strictly enforces with no empty-set bypass — an empty active registry rejects all announces, which is correct (no staked peers to learn). This is safe because ChainStakerSet::bootstrap is fatal on failure, so the gate is never wired with a half-initialized set; the runtime always passes Some.

Config-breaking

gossip.allowlist is removed (field, resolver, parse_node_id_hex/hex_val, reload wiring, sample-config line). Because [gossip] uses deny_unknown_fields, a config file that still sets gossip.allowlist now fails decdn config validate and node startup — a loud, intended break. Documented in CHANGELOG under Security.

Reviewer notes

  • The empty-set semantic inverts vs. the old allowlist (empty allowlist = accept-all → empty staked set = reject-all). This is intentional and the ADR-correct behavior; see the validate_envelope doc comment and the empty_staked_set_rejects_all test.
  • StreamError/wire format untouched — this is envelope admission, not delivery.
  • ADR 001 body needs no edit: it already specifies rule 2 as the on-chain registry check (line 77) and the event-followed cache (line 73). Only the code comments that called this a "stand-in" were updated.

Verification

  • cargo build + cargo clippy --workspace --all-targets -- -D warnings clean
  • cargo nextest run -p decdn-gossip -p decdn-common -p decdn-node -p decdn-cli --no-fail-fast — 1554 passed, 0 failed
  • New tests: staked_node_gate_enforced, empty_staked_set_rejects_all, staked_none_accepts_any, node_staked_node_set_delegates_to_staker_set; the two-node self_hosted_discovery integration test now runs through a Some(gate).
  • cargo fmt --check clean
  • Manual: a config with gossip.allowlist now fails with unknown field 'allowlist'; a config without it resolves the gossip section cleanly.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Security

    • Gossip announcements are now accepted only from nodes currently recorded as staked on-chain.
    • Staking status is updated from live registration, deregistration, and auto-ejection events.
  • Configuration

    • Removed the obsolete gossip.allowlist setting. Existing configurations containing it will fail validation and require updating.
    • Added an optional maximum limit for gossip peer entries.
  • Monitoring

    • Updated rejection metrics to use the not_staked label.

…egistry (#1170)

NodeAnnounce admission (ADR 001 rule 2) checked a static config allowlist
that was always documented as a stand-in until the on-chain registry
landed. A deregistered or slashed node could still pass validation and
enter peer tables during its stale-cache window.

Enforce against the live on-chain staker set instead. `validate_envelope`
now takes `Option<&dyn StakedNodeSet>` and queries the live ChainStakerSet
(kept fresh by the CapacityBond NodeRegistered/Deregistered/AutoEjected
event tail). Reuses the trait+adapter seam already shipped for the
reputation lane: rename StakedReporterSet -> StakedNodeSet and reuse the
NodeStakedNodeSet adapter. Keying is the identity function over the 32-byte
iroh pubkey, so no Address<->NodeId mapping is needed.

Gate is `Option`: None (tests/unstaked modes) accepts all; Some strictly
enforces with no empty-set bypass -- an empty active registry rejects all,
which is correct (no staked peers to learn). Safe because ChainStakerSet
bootstrap is fatal, so the gate is never wired with a half-initialized set;
the runtime always passes Some. Reject reason NotAllowlisted -> NotStaked
(metric label not_allowlisted -> not_staked).

Config-breaking: remove `gossip.allowlist` (field, resolver,
parse_node_id_hex/hex_val, reload wiring, sample-config line). Because
[gossip] uses deny_unknown_fields, a stale allowlist key now fails
`decdn config validate` and node startup -- documented in CHANGELOG.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@coderabbitai

coderabbitai Bot commented Jul 16, 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: 46 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: 51fe170b-e49c-4336-981e-ab26220dfebe

📥 Commits

Reviewing files that changed from the base of the PR and between 4a979e4 and 4d693ef.

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

Walkthrough

Gossip rule-2 admission now checks the live staked-node registry instead of a configured allowlist. Configuration schemas, validation APIs, service wiring, runtime integration, rejection metrics, tests, and documentation are updated accordingly.

Changes

Gossip staked-node admission

Layer / File(s) Summary
Remove the gossip allowlist configuration
CHANGELOG.md, crates/cli/..., crates/common/src/config/..., crates/node/src/runtime/reload.rs, crates/node/tests/sighup_signal.rs
The gossip.allowlist field and its parsing, resolved representation, templates, fixtures, validation tests, and reload references are removed.
Introduce staked-node validation contracts
crates/gossip/src/lib.rs, crates/gossip/src/reputation.rs, crates/gossip/src/validation.rs
StakedNodeSet replaces StakedReporterSet; announcement validation accepts an optional staked set and reports NotStaked with the not_staked label.
Thread staking through the gossip service
crates/gossip/src/service.rs
GossipService::spawn, subscriber tasks, and reputation wiring pass StakedNodeSet values instead of an allowlist.
Connect the live staker registry
crates/node/src/reputation_wiring.rs, crates/node/src/runtime/mod.rs, crates/node/tests/self_hosted_discovery.rs, crates/reputation/src/settlement.rs
Runtime wiring adapts the live StakerSet through NodeStakedNodeSet, passes it into gossip, and updates end-to-end test coverage and references.

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

Sequence Diagram(s)

sequenceDiagram
  participant NodeRuntime
  participant GossipService
  participant Subscriber
  participant LiveStakerSet
  NodeRuntime->>LiveStakerSet: create NodeStakedNodeSet
  NodeRuntime->>GossipService: spawn with staked gate
  GossipService->>Subscriber: pass staked gate
  Subscriber->>LiveStakerSet: contains(node_id)
  LiveStakerSet-->>Subscriber: staked membership result
  Subscriber-->>GossipService: accept or reject announcement
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

Copy link
Copy Markdown

Gas snapshot

No gas changes vs base.

@github-actions

github-actions Bot commented Jul 16, 2026 •

Copy link
Copy Markdown

Contracts coverage

Line coverage: 88.92% (2488/2798 lines)
▲ +0.00pp vs base (88.92% → 88.92%)
Run: 29504253864

@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 replaces the static, file-configured gossip.allowlist with a live, on-chain staked-node check (StakedNodeSet) to enforce Gossip rule-2 (NodeAnnounce admission) against the live registry. This removes the gossip.allowlist configuration field and updates the validation logic to check announcers against the live staker set, preventing deregistered or slashed nodes from entering peer tables. The StakedReporterSet trait has been renamed to StakedNodeSet to reflect its broader use in gating both node announcements and reputation reports. 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 16, 2026 •

Copy link
Copy Markdown

Coverage report

Total: 80.51% (was 80.53%, ▼ 0.02%) — 47644/59181 lines

File Coverage Lines Δ
crates/cli/src/commands/config.rs 69.53% 178/256 ● 0.00%
crates/common/src/config/mod.rs 97.02% 6567/6769 ▼ 0.01%
crates/common/src/config/resolved.rs 100.00% 48/48 ● 0.00%
crates/gossip/src/reputation.rs 100.00% 335/335 ● 0.00%
crates/gossip/src/service.rs 79.98% 663/829 ▲ +0.05%
crates/gossip/src/validation.rs 100.00% 324/324 ● 0.00%
crates/node/src/reputation_wiring.rs 95.30% 345/362 ▲ +2.06%
crates/node/src/runtime/mod.rs 49.61% 1083/2183 ▼ 0.09%
crates/node/src/runtime/reload.rs 95.28% 1472/1545 ▼ 0.01%
crates/reputation/src/settlement.rs 100.00% 116/116 ● 0.00%
History
Commit Total Δ vs base
4a979e4 80.51% ▼ 0.02%
4d693ef (HEAD) 80.51% ▼ 0.02%

Address PR #1221 review: the validate_envelope/spawn docs described None
as being for "unstaked/subscribe-only modes", but no such production path
exists — the runtime always passes Some. Tighten to "tests only" so a
future maintainer isn't invited to wire None in production (which would be
fail-open). Also rename the `_reporter` params in three test stubs to
`_node_id`, matching the trait method after the StakedNodeSet rename.

No behavior change.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@thiras
thiras merged commit 6a1e1a6 into main Jul 16, 2026
23 checks passed
@thiras
thiras deleted the fix/1170-gossip-rule2-live-registry branch July 16, 2026 15:09
thiras added a commit that referenced this pull request Jul 16, 2026
…tions (#1110)

`ChainStakerSet` (membership) and `ChainNodeAddressDirectory` (node→address
bindings) are both derived from the same CapacityBond contract, but each ran its
own bootstrap and its own `eth_getLogs` loop against the same address — with
node-address's two topics a strict SUBSET of staker-set's five. Two paginated
`getActiveNodes` reads at boot, two poll loops forever after.

Add `dht::capacity_bond_registry`: one enumeration, one loop, demuxing to both
projections. Watchers drop 7 → 6 (6 → 6 in the default config, where pull-through
is off — see below). `chain_staker_set` and `node_address` keep their facades,
trait impls, projection helpers and all their existing tests; each loses its
bootstrap/sink/hooks/pagination and gains `from_parts`.

The correctness point that shapes the sink: only the ENUMERATION differs between
the two views. The live arms are a clean union — `NodeRegistered` inserts into
both unfiltered, because staker-set's live arm applies no `isActive` check either
(its filter is bootstrap-only). Reading "staker-set is the filtered view" as a
live-path difference and encoding it in the sink would drop registrations from the
active set.

- One sink with match arms, not a `Tee<A,B>`: `NodeRegistered` is the only shared
  topic and is the whole point — one `decode_log_data` feeds both. A tee decodes
  twice and needs `log.clone()` (`apply` takes `Log` by value). Follows the
  `ChainOriginDirectory` precedent (2 addresses x 7 topics, one sink).
- `NodeAutoEjected` deactivates WITHOUT clearing the binding: ejection flips
  `isActive` only, and the operator may still be owed payment on an open channel.
  This is the most plausible silent bug in the merge and has a dedicated test.
- Bindings are `Option`-gated on `node_to_node_pull_through_enabled`. The reason
  is metric semantics, not cost: building it unconditionally would publish
  `node_address_directory_size` on every default node, meaning "registered nodes"
  rather than "resolvable payout targets".
- Both gauge families are kept, node-address's gated on the projection existing.
  They now describe one shared loop, so they are perfectly correlated — but
  freezing `node_address_watcher_down_seconds` at 0 forever would be an alert that
  can never fire, which is worse than deleting it. Retiring one is a follow-up.
- `seed_cursor: Some(snapshot_block)` closes a latent gap both watchers had:
  events landing between the enumeration and the first tick's head read were
  missed. Head is read BEFORE the enumeration (the `ChainOriginDirectory`
  ordering) — the reverse would lose exactly the events being recovered.
  This matters more since #1221 made gossip announce ACCEPTANCE depend on live
  registry freshness.
- `RegistryChainReads` makes the event handlers unit-testable without a provider:
  these two modules had ZERO tests before, and now have 11.

Removing a non-fatal error path (deliberate, and unreachable): node-address
bootstrap failure used to log-and-disable pull-through. `getActiveNodes` failure
was ALREADY fatal — the unconditional staker-set bootstrap ran first and
propagated it, so node-address's arm was never reached on that path. With the read
shared, the bindings projection has no RPC of its own; it derives from page data
already in hand and cannot fail independently. No node that boots today loses
pull-through; none that boots today starts failing.

fmt/clippy(--all-targets, incl. anvil-e2e)/doc clean; 806 node tests pass.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
thiras added a commit that referenced this pull request Jul 16, 2026
…tions (#1110)

`ChainStakerSet` (membership) and `ChainNodeAddressDirectory` (node→address
bindings) are both derived from the same CapacityBond contract, but each ran its
own bootstrap and its own `eth_getLogs` loop against the same address — with
node-address's two topics a strict SUBSET of staker-set's five. Two paginated
`getActiveNodes` reads at boot, two poll loops forever after.

Add `dht::capacity_bond_registry`: one enumeration, one loop, demuxing to both
projections. Watchers drop 7 → 6 (6 → 6 in the default config, where pull-through
is off — see below). `chain_staker_set` and `node_address` keep their facades,
trait impls, projection helpers and all their existing tests; each loses its
bootstrap/sink/hooks/pagination and gains `from_parts`.

The correctness point that shapes the sink: only the ENUMERATION differs between
the two views. The live arms are a clean union — `NodeRegistered` inserts into
both unfiltered, because staker-set's live arm applies no `isActive` check either
(its filter is bootstrap-only). Reading "staker-set is the filtered view" as a
live-path difference and encoding it in the sink would drop registrations from the
active set.

- One sink with match arms, not a `Tee<A,B>`: `NodeRegistered` is the only shared
  topic and is the whole point — one `decode_log_data` feeds both. A tee decodes
  twice and needs `log.clone()` (`apply` takes `Log` by value). Follows the
  `ChainOriginDirectory` precedent (2 addresses x 7 topics, one sink).
- `NodeAutoEjected` deactivates WITHOUT clearing the binding: ejection flips
  `isActive` only, and the operator may still be owed payment on an open channel.
  This is the most plausible silent bug in the merge and has a dedicated test.
- Bindings are `Option`-gated on `node_to_node_pull_through_enabled`. The reason
  is metric semantics, not cost: building it unconditionally would publish
  `node_address_directory_size` on every default node, meaning "registered nodes"
  rather than "resolvable payout targets".
- Both gauge families are kept, node-address's gated on the projection existing.
  They now describe one shared loop, so they are perfectly correlated — but
  freezing `node_address_watcher_down_seconds` at 0 forever would be an alert that
  can never fire, which is worse than deleting it. Retiring one is a follow-up.
- `seed_cursor: Some(snapshot_block)` closes a latent gap both watchers had:
  events landing between the enumeration and the first tick's head read were
  missed. Head is read BEFORE the enumeration (the `ChainOriginDirectory`
  ordering) — the reverse would lose exactly the events being recovered.
  This matters more since #1221 made gossip announce ACCEPTANCE depend on live
  registry freshness.
- `RegistryChainReads` makes the event handlers unit-testable without a provider:
  these two modules had ZERO tests before, and now have 11.

Removing a non-fatal error path (deliberate, and unreachable): node-address
bootstrap failure used to log-and-disable pull-through. `getActiveNodes` failure
was ALREADY fatal — the unconditional staker-set bootstrap ran first and
propagated it, so node-address's arm was never reached on that path. With the read
shared, the bindings projection has no RPC of its own; it derives from page data
already in hand and cannot fail independently. No node that boots today loses
pull-through; none that boots today starts failing.

fmt/clippy(--all-targets, incl. anvil-e2e)/doc clean; 806 node tests pass.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
thiras added a commit that referenced this pull request Jul 16, 2026
…tions (#1110)

`ChainStakerSet` (membership) and `ChainNodeAddressDirectory` (node→address
bindings) are both derived from the same CapacityBond contract, but each ran its
own bootstrap and its own `eth_getLogs` loop against the same address — with
node-address's two topics a strict SUBSET of staker-set's five. Two paginated
`getActiveNodes` reads at boot, two poll loops forever after.

Add `dht::capacity_bond_registry`: one enumeration, one loop, demuxing to both
projections. Watchers drop 7 → 6 (6 → 6 in the default config, where pull-through
is off — see below). `chain_staker_set` and `node_address` keep their facades,
trait impls, projection helpers and all their existing tests; each loses its
bootstrap/sink/hooks/pagination and gains `from_parts`.

The correctness point that shapes the sink: only the ENUMERATION differs between
the two views. The live arms are a clean union — `NodeRegistered` inserts into
both unfiltered, because staker-set's live arm applies no `isActive` check either
(its filter is bootstrap-only). Reading "staker-set is the filtered view" as a
live-path difference and encoding it in the sink would drop registrations from the
active set.

- One sink with match arms, not a `Tee<A,B>`: `NodeRegistered` is the only shared
  topic and is the whole point — one `decode_log_data` feeds both. A tee decodes
  twice and needs `log.clone()` (`apply` takes `Log` by value). Follows the
  `ChainOriginDirectory` precedent (2 addresses x 7 topics, one sink).
- `NodeAutoEjected` deactivates WITHOUT clearing the binding: ejection flips
  `isActive` only, and the operator may still be owed payment on an open channel.
  This is the most plausible silent bug in the merge and has a dedicated test.
- Bindings are `Option`-gated on `node_to_node_pull_through_enabled`. The reason
  is metric semantics, not cost: building it unconditionally would publish
  `node_address_directory_size` on every default node, meaning "registered nodes"
  rather than "resolvable payout targets".
- Both gauge families are kept, node-address's gated on the projection existing.
  They now describe one shared loop, so they are perfectly correlated — but
  freezing `node_address_watcher_down_seconds` at 0 forever would be an alert that
  can never fire, which is worse than deleting it. Retiring one is a follow-up.
- `seed_cursor: Some(snapshot_block)` closes a latent gap both watchers had:
  events landing between the enumeration and the first tick's head read were
  missed. Head is read BEFORE the enumeration (the `ChainOriginDirectory`
  ordering) — the reverse would lose exactly the events being recovered.
  This matters more since #1221 made gossip announce ACCEPTANCE depend on live
  registry freshness.
- `RegistryChainReads` makes the event handlers unit-testable without a provider:
  these two modules had ZERO tests before, and now have 11.

Removing a non-fatal error path (deliberate, and unreachable): node-address
bootstrap failure used to log-and-disable pull-through. `getActiveNodes` failure
was ALREADY fatal — the unconditional staker-set bootstrap ran first and
propagated it, so node-address's arm was never reached on that path. With the read
shared, the bindings projection has no RPC of its own; it derives from page data
already in hand and cannot fail independently. No node that boots today loses
pull-through; none that boots today starts failing.

fmt/clippy(--all-targets, incl. anvil-e2e)/doc clean; 806 node tests pass.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
thiras added a commit that referenced this pull request Jul 16, 2026
…tions (#1110) (#1226)

* refactor(node): hoist AbortOnDrop into chain_events (#1110)

`struct AbortOnDrop(JoinHandle<()>)` plus its `Drop` impl was copy-pasted SEVEN
times — slash, reputation-indexer, node-address, settlement, origin-directory,
buyer-channel, and staker-set — all byte-identical. That made it read as though
each watcher had its own teardown policy when they never differed.

Pure move: one definition in `chain_events`, seven local copies deleted. No
behavior change. Prepares the CapacityBond watcher merge, where two of those
copies have to unify anyway.

clippy/fmt clean; 795 node tests pass.

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

* refactor(node): one CapacityBond watcher feeding both registry projections (#1110)

`ChainStakerSet` (membership) and `ChainNodeAddressDirectory` (node→address
bindings) are both derived from the same CapacityBond contract, but each ran its
own bootstrap and its own `eth_getLogs` loop against the same address — with
node-address's two topics a strict SUBSET of staker-set's five. Two paginated
`getActiveNodes` reads at boot, two poll loops forever after.

Add `dht::capacity_bond_registry`: one enumeration, one loop, demuxing to both
projections. Watchers drop 7 → 6 (6 → 6 in the default config, where pull-through
is off — see below). `chain_staker_set` and `node_address` keep their facades,
trait impls, projection helpers and all their existing tests; each loses its
bootstrap/sink/hooks/pagination and gains `from_parts`.

The correctness point that shapes the sink: only the ENUMERATION differs between
the two views. The live arms are a clean union — `NodeRegistered` inserts into
both unfiltered, because staker-set's live arm applies no `isActive` check either
(its filter is bootstrap-only). Reading "staker-set is the filtered view" as a
live-path difference and encoding it in the sink would drop registrations from the
active set.

- One sink with match arms, not a `Tee<A,B>`: `NodeRegistered` is the only shared
  topic and is the whole point — one `decode_log_data` feeds both. A tee decodes
  twice and needs `log.clone()` (`apply` takes `Log` by value). Follows the
  `ChainOriginDirectory` precedent (2 addresses x 7 topics, one sink).
- `NodeAutoEjected` deactivates WITHOUT clearing the binding: ejection flips
  `isActive` only, and the operator may still be owed payment on an open channel.
  This is the most plausible silent bug in the merge and has a dedicated test.
- Bindings are `Option`-gated on `node_to_node_pull_through_enabled`. The reason
  is metric semantics, not cost: building it unconditionally would publish
  `node_address_directory_size` on every default node, meaning "registered nodes"
  rather than "resolvable payout targets".
- Both gauge families are kept, node-address's gated on the projection existing.
  They now describe one shared loop, so they are perfectly correlated — but
  freezing `node_address_watcher_down_seconds` at 0 forever would be an alert that
  can never fire, which is worse than deleting it. Retiring one is a follow-up.
- `seed_cursor: Some(snapshot_block)` closes a latent gap both watchers had:
  events landing between the enumeration and the first tick's head read were
  missed. Head is read BEFORE the enumeration (the `ChainOriginDirectory`
  ordering) — the reverse would lose exactly the events being recovered.
  This matters more since #1221 made gossip announce ACCEPTANCE depend on live
  registry freshness.
- `RegistryChainReads` makes the event handlers unit-testable without a provider:
  these two modules had ZERO tests before, and now have 11.

Removing a non-fatal error path (deliberate, and unreachable): node-address
bootstrap failure used to log-and-disable pull-through. `getActiveNodes` failure
was ALREADY fatal — the unconditional staker-set bootstrap ran first and
propagated it, so node-address's arm was never reached on that path. With the read
shared, the bindings projection has no RPC of its own; it derives from page data
already in hand and cannot fail independently. No node that boots today loses
pull-through; none that boots today starts failing.

fmt/clippy(--all-targets, incl. anvil-e2e)/doc clean; 806 node tests pass.

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

* fix(node): bound the sink's nodeIdOf read, and test timed's timeout arm (#1110)

Review on #1226 flagged `rpc_call_timeout: None` as an unbounded RPC and asked for
`Some(Duration::from_secs(10))`. That premise is wrong: `timed` does
`unwrap_or(DEFAULT_RPC_CALL_TIMEOUT)`, so `None` already IS 10s. The suggestion is
a behavioural no-op that would hardcode the constant at the call site and diverge
from `DEFAULT_RPC_CALL_TIMEOUT`, and 5 of 6 watchers pass `None` as the convention.

But the rule behind it is right, and points at a real unbounded call the review
missed 300 lines up: `ContractReads::node_id_of` did a bare
`.nodeIdOf(op).call().await`. `WatcherConfig::rpc_call_timeout` covers only the
loop's own `get_logs` — `timed`'s own doc says sink follow-ups stay unbounded
unless the sink wraps itself.

This matters more BECAUSE of the merge, and the regression is this PR's own: a
stalled `nodeIdOf` used to wedge only the staker-set loop, since node-address ran
its own; now one loop feeds both projections, so it wedges bindings too. Bound it
here rather than defer, following the `blacklist_watcher::scope_check` precedent.
A timeout surfaces as `Err`, which `on_operator_change` already counts via
`staker_set_watcher_resolve_failure` and skips without tripping the stream
backoff — the path `node_id_of_failure_bumps_resolve_failure_and_returns_ok`
already covers.

`timed` now takes `IntoFuture` rather than `Future`, so an alloy `.call()` (an
`EthCall`, not a future) wraps directly instead of every caller spelling
`.into_future()`. Every `Future` is an `IntoFuture`, so this is a strict widening
and existing callers are untouched. `tokio::time::timeout` already accepted
`IntoFuture` — the wrapper was what narrowed it.

`timed`'s timeout arm had NO test, so the bound rested on untested code. Added
three (paused clock, no wall-clock cost): a hanging call times out at the default
and names itself, an explicit timeout wins over the default, and a prompt success
passes through.

fmt/clippy/doc clean; 809 node tests pass.

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

---------

Co-authored-by: Claude Opus 4.8 (1M context) <[email protected]>
thiras pushed a commit that referenced this pull request Jul 17, 2026
…est + Some regression guard (#1222) (#1232)

* test(gossip,node): subscriber-level not_staked reject test + announce-gate Some regression guard (#1222)

Hardening follow-ups spun out of the #1170/#1221 review of the gossip
rule-2 staked-node gate. Neither is a correctness fix.

Item 2: add a subscriber-level reject integration test
(non_staked_announce_is_dropped_at_subscriber) that wires the receiver's
gate to exclude the publisher, drives a real announce through the
spawn -> subscriber_task -> validate_envelope path, and asserts the peer
table stays empty while the not_staked reject metric increments. Closes
the Err(reject) arm, previously proven only at the pure-function level.

Item 3: factor the runtime's announce-gate construction into a named,
unit-tested announce_staked_gate() helper that always returns Some, so a
future refactor cannot silently drop rule 2 to None (fail-open) with
every existing test still passing.

Item 1 (enum AnnounceGate vs Option) is deferred: it diverges from the
ReputationWiring.staked: Option<...> precedent, and #1221's doc-comment
tightening already mitigates the risk.

Co-Authored-By: Claude Opus 4.8 <[email protected]>

* test(node): assert reject end-state invariant after the loop (#1232 review)

Add a final post-loop non-insertion assertion so the reject state is
verified right up to teardown and the invariant survives future edits to
the loop's break condition. Not a race fix — NoneStaked rejects
unconditionally, so A can never be admitted — but it documents the
end-state explicitly.

Co-Authored-By: Claude Opus 4.8 <[email protected]>

* test(node): pin gate enforcement + document reject-attribution assumption (#1232 review)

Item 3 test: assert the gate returned by announce_staked_gate actually
enforces (member admitted, non-member rejected) via .expect(), not just
is_some() — so a refactor returning Some(<admit-all stub>) can't pass
while silently disabling rule 2. Renamed to
announce_staked_gate_enforces_never_fails_open.

Reject test: document that not_staked > 0 attributes to A only because
there are two nodes and plumtree never echoes to origin; otherwise
NoneStaked would reject B's self-echo in validate_envelope (before the
self-echo Ok arm) and satisfy the check without A's announce arriving.

Co-Authored-By: Claude Opus 4.8 <[email protected]>

---------

Co-authored-by: Claude Opus 4.8 <[email protected]>
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: enforce rule-2 staked-node check against the live registry, not a static allowlist

2 participants