Repository navigation
Description
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
Metadata
Metadata
Assignees
Labels
Type
Fields
Priority
Activity
yigitdot commentedon Jul 16, 2026
PR #1232 addresses items 2 and 3 only; this issue stays open to track item 1.
Done in #1232
not_stakedreject integration test (non_staked_announce_is_dropped_at_subscriber): drives a real announce through B'sspawn → subscriber_task → validate_envelopepath with a gate that excludes the publisher, asserting the peer table stays empty while thenot_stakedreject metric increments. Closes theErr(reject)arm previously proven only at the pure-function level.announce_staked_gate()helper that always returnsSomeand is asserted to actually enforce, so a future refactor can't silently drop rule 2 toNone(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 }replacingOption<&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 forOptionconsistency), 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 aswontfix) separately.test(gossip,node): harden the rule-2 staked-node gate — reject-path t…
refactor(gossip): name the announce gate's disabled state (#1222) (#1335
refactor(gossip): name the reputation-report gate's staked-membership…