Skip to content

discover: admit only CNPeers members into the CN storage - #1013

Open
hyunsooda wants to merge 2 commits into
kaiachain:devfrom
hyunsooda:fix/authenticate-cn-discovery-entries
Open

discover: admit only CNPeers members into the CN storage#1013
hyunsooda wants to merge 2 commits into
kaiachain:devfrom
hyunsooda:fix/authenticate-cn-discovery-entries

Conversation

@hyunsooda

@hyunsooda hyunsooda commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

Proposed changes

The node type in a discovery packet is supplied by the sender and the CN storage is unbounded, so any reachable key pair can fill the list the dial scheduler samples for CN candidates. The CN storage now accepts an entry only when its address is in CNPeers or its NodeId is a configured bootnode, bounding the list by an authenticated set instead of a capacity limit. Discovery stays open elsewhere: the filter is off before the hard fork and whenever CNPeers is unavailable, bootnodes are exempt so they keep seeding CN lookups, and peer admission is unchanged.

Types of changes

  • 🐛 Bug fix
  • ✨ Non-hardfork changes (node upgrade not required)
  • 💥 Hardfork / consensus-breaking changes
  • 🧪 Test improvements
  • 🧰 CI / build tool
  • ♻️ Chore / Refactor / Non-functional changes

Checklist

  • 📖 I have read the CONTRIBUTING GUIDELINES doc
  • 📝 I have signed in the PR comment I have read the CLA Document and I hereby sign the CLA in first time contribute after having read CLA
  • 🟢 Lint and unit tests pass locally with my changes ($ make test)

Related issues

Further comments

The node type in a discovery packet is a sender-supplied field and the CN
storage has no cardinality bound, so any reachable key pair can occupy the
list the dial scheduler samples for CN candidates. The CN storage now takes
an entry only when its address is in CNPeers or its NodeId is a configured
bootnode, bounding the list by an authenticated set rather than a capacity
limit. Discovery stays open otherwise: the filter is nil before the fork and
whenever CNPeers is unavailable, and peer admission is unchanged.

Constraint: KIP-311 R2 forbids a BN from filtering discovery by CNPeers, so only nodes running the CN service push the list down
Constraint: KIP-311 L206 keeps CNPeers out of EN admission, so only discovery entry selection changed
Rejected: Bound the flat storages by capacity | eviction turns dilution into a deterministic lockout, since revalidation replaces one entry per 10s
Rejected: Enforce CNPeers on EN admission | would reject the nonCNPeers CN that R7 requires an EN to serve
Directive: Keep the check keyed on the destination storage, not the claimed node type, or the bootnode fan-out path bypasses it
Confidence: high
Scope-risk: narrow
Not-tested: a self-declared CN outside CNPeers on a live network

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@hyunsooda hyunsooda self-assigned this Aug 5, 2026
ian0371
ian0371 previously approved these changes Aug 7, 2026

@2dvorak 2dvorak left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

We could have better coverage with the following test cases:

  1. BaseServerntab forwardnil ntab in both existing tests means the three new added lines are dead to CI.
  2. Table-level shrink — dropsOutsiders only covers nil → {member}, i.e. startup. No allowlist-to-allowlist case exists.

And one minor thing is: TestServerENBypassesCNPeerFilter says SetCNPeers is no-op for PN/EN, but it became stale comment.

The push into the discovery table ran only when srv.ntab was set, which no test did,
so nothing pinned it ahead of the CN-only early return. Exercise it on an EN, the
only path where moving it below that return is observable.

The table test covered a first allowlist arriving but not one replacing another, so
nothing required an update to drop a member that left rather than accumulate.

The EN test also still described SetCNPeers as a no-op there, which stopped being
true once the discovery filter applied to every node type.

Confidence: high
Scope-risk: narrow

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@hyunsooda

Copy link
Copy Markdown
Contributor Author

@2dvorak All added. Thank you

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.

3 participants