Skip to content

selection: decide the unknown-stake policy at the lookup layer before wiring on-chain stake #1470

Closed

Description

@thiras

Follow-up to #1459, split out so the tracked decision survives that issue being closed by #1469.

What #1469 settled

The tier-2 comment in crates/node/src/selection.rs claimed None is "the lowest possible stake". It is not — filter_map drops None before max, so unknown ranks strictly below Some(0). That behaviour is deliberate and pinned by three tests dating to #380 (some_stake_beats_none_stake, some_zero_stake_beats_none_stake, three_way_zero_stake_falls_through_to_random_tier), so the comment was the defect, not the code. #1469 corrected the comment and documented the two-axis meaning on Candidate.stake.

What is still open

Candidate.stake: Option<u64> conflates "not looked up" with "looked up, holds no bond". Today that is harmless: all three construction sites pass None (node_origin.rs:1177, :1256, plus the test helper), so tier 2 is a uniform no-op.

It stops being harmless the moment on-chain stake lookup is wired, because an RPC read succeeds for some peers and fails for others — a mixed population is the steady state for a chain read, not an edge case. If a failed read is encoded as None alongside successful ones, one flaky call silently sinks a well-staked peer below a zero-stake one.

The decision to make

Make it at the lookup layer, when that layer lands:

  1. Resolve at the boundary. Lookup returns u64; a failed read is retried or the candidate is dropped, never folded to 0. Keeps tier 2 exactly as-is.
  2. Distinguish failure from absence. Widen to a three-state type (Known(u64) / NoBond / Unavailable) and have tier 2 skip entirely when any candidate is Unavailable — unknown poisons the tier rather than losing it.

Option 2 is safer under partial reads; option 1 is simpler and matches what the tests already assert. Either way the three existing tests encode the current contract and should be revisited deliberately, not incidentally.

Pointers

  • crates/node/src/selection.rs — Candidate.stake field doc and the tier-2 comment in pick_best_in_group both reference this issue
  • ADR 001 § Node Selection Algorithm; ADR 019 for the capacity-bond interface that will populate the field
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

rust

Type

No type

Fields

Priority

None yet

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions