Skip to content

Follow-ups from #1170 review: harden the gossip rule-2 staked-node gate #1222

Closed

Description

@yigitdot

Spun out of the #1221 review (the #1170 fix that made NodeAnnounce rule-2 enforce the live on-chain staker set). The PR shipped with no fail-open defect and strong unit coverage; these are non-blocking hardening follow-ups the review surfaced. None is required for correctness today.

1. Name the gate's disabled state at the type level (design)

validate_envelope / GossipService::spawn take the gate as Option<&dyn StakedNodeSet> / Option<Arc<dyn StakedNodeSet>>, where None = accept any signature-valid announce (fail-open) and Some = enforce. The two states sit at opposite ends of the safety spectrum but are distinguished only by Option; a future call site could wire None (reading as a benign "not configured") and silently disable rule 2.

Consider a named enum so the fail-open intent is self-documenting at every call site:

enum AnnounceGate<'a> { Enforce(&'a dyn StakedNodeSet), Disabled }

Trade-off: the existing ReputationWiring.staked: Option<...> precedent argues for Option consistency. The #1221 doc-comment tightening (None is "tests only — no production path disables the gate") already mitigates the immediate risk, so this is a refinement, not a fix.

  • Files: crates/gossip/src/validation.rs (validate_envelope), crates/gossip/src/service.rs (spawn).

2. Subscriber-level rejection integration test

The reject path is currently proven only at the pure-function level (staked_node_gate_enforced, empty_staked_set_rejects_all in validation.rs). The end-to-end test two_nodes_exchange_node_announce_via_self_hosted_discovery (crates/node/tests/self_hosted_discovery.rs) wires both nodes with Some(AllStaked) and only exercises the accept direction — it proves the gate is threaded through spawn → subscriber_task → validate_envelope and admits staked announcers, but never that a non-staked announcer is dropped.

Add a sibling test (or second assertion) where the receiver's gate excludes the publisher's node_id, publish the announce, and assert the peer table stays empty for a bounded wait and the not_staked reject metric increments. This closes the Err(reject) arm at crates/gossip/src/service.rs ("drop + inc_rejected, no insert"), which is untested at subscriber level for every reject variant.

Cost note: this means reusing/parameterizing the ~130-line two-node mesh harness plus a timing-based negative assertion — deferred from #1221 to avoid flakiness risk in that PR.

3. Assert the runtime wires the gate as Some

crates/node/src/runtime/mod.rs constructs announce_staked = Some(NodeStakedNodeSet::new(staker_set)) unconditionally and passes it to spawn. If a future refactor set this to None, rule 2 silently disables and every existing test still passes — the exact hole #1170 closed would reopen with zero failures. run() is only exercisable via the heavyweight anvil e2e harness, so a cheap mitigation (e.g. factor the Some(...) construction into a small named helper and unit-test that it returns Some, or a debug assertion) is preferable to a full e2e.

Refs

Activity

  1. added
    rust
    kind:test
    prio:low
    on Jul 16, 2026
  2. self-assigned this
    on Jul 16, 2026
  3. yigitdot commented on Jul 16, 2026

    @yigitdot
    ContributorAuthor

    PR #1232 addresses items 2 and 3 only; this issue stays open to track item 1.

    Done in #1232

    • Item 2 — subscriber-level not_staked reject integration test (non_staked_announce_is_dropped_at_subscriber): drives a real announce through B's spawn → subscriber_task → validate_envelope path with a gate that excludes the publisher, asserting 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 — factored the runtime gate construction into a named, unit-tested announce_staked_gate() helper that always returns Some and is asserted to actually enforce, so a future refactor can't silently drop rule 2 to None (fail-open) with every test still green.

    Still open — item 1 (name the gate's disabled state at the type level, e.g. enum AnnounceGate { Enforce, Disabled } replacing Option<&dyn StakedNodeSet> / Option<Arc<dyn StakedNodeSet>>).

    Deferred by decision rather than done: it diverges from the existing ReputationWiring.staked: Option<…> precedent (which the issue itself flags as the argument for Option consistency), and #1221's doc-comment tightening already mitigates the immediate risk. Item 3's named helper delivers the same self-documenting-intent benefit at the runtime call site without a workspace-wide type change. Leaving item 1 here as a standalone refinement to pick up (or close as wontfix) separately.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

kind:testprio:lowrust

Type

No type

Fields

Priority

None yet

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions