Skip to content

feat(node): probe-time stake-lane probe-acceptance reservation (#757) - #782

Merged
thiras merged 2 commits into
mainfrom
feat/757-probe-stake-lane
Jun 2, 2026
Merged

thiras merged 2 commits into
mainfrom
feat/757-probe-stake-lane

Conversation

@thiras

@thiras thiras commented Jun 2, 2026

Copy link
Copy Markdown
Contributor

What

Implements optional stake-lane prioritization at probe-acceptance time (issue #757), per ADR 003 § Admission and Priority.

Under probe-hold-budget pressure, a node reserves the last N probe-hold slots for stake-lane requesters — registered operators issuing node-to-node cache-miss probes — so end-client probe load cannot starve them. Strictly operator opt-in and default-off.

How

  • Eligibility = CapacityBond.isActive, resolved from the existing chain-followed StakerSet (keyed by iroh NodeId via conn.remote_id()). No per-probe chain read, no new chain wiring (the issue's constraint).
  • Under pressure (probe_hold_slots_used >= max_probe_holds − stake_lane_reserved_holds), end-client probes get a signed has_blob: false (never a phantom-slash risk; identical wire behaviour to budget exhaustion). Stake-lane requesters always pass the gate.
  • New metric decdn_probe_stake_lane_reserved_total, kept distinct from probe_hold_violations (budget) and probe_holds_disabled (config) — their alerts have different remedies. The gate fires before try_probe_hold, so it's a content-independent admission decision (cache not consulted).
  • Operator knob [cache] stake_lane_reserved_holds (file + CLI flag --stake-lane-reserved-holds + DECDN_STAKE_LANE_RESERVED_HOLDS). Default 0 ⇒ None policy ⇒ probe hot path unchanged. The amount is NonZeroUsize so "off" is unrepresentable in StakeLanePolicy; reserved>0 with max_probe_holds=0 is warned and left off.

Scope note

Stake-lane is the binary isActive predicate (registered + bond ≥ minBond), not ADR 003's finer bondOf >= bond_required(declared_capacity) tiering — the latter needs a per-probe capacity read, explicitly out of scope ("no new chain wiring"). End-client lane eligibility (reputation/region/allow-list) and cdn/client/v1 stream-time admission remain out of scope per the issue.

Tests

  • 5 unit tests on the pure stake_lane_reserved_out decision fn (all guard conditions + both boundary sides)
  • 2 loopback integration tests: end-client shed (with valid has_blob=false signature + correct metric attribution) / stake-lane requester keeps headroom
  • 3 config-resolution tests (default / file / CLI-over-file) + env-var-wiring test updated

cargo fmt --check, cargo clippy --all-targets, and cargo nextest run all clean locally (full suite 1325/1325).

Review

Went through a 5-agent review (code / tests / comments / silent-failure / type-design). Fixes applied: corrected the metric docstrings (the gate is content-independent, not "present, holdable"), added the NonZeroUsize invariant + dead-config warning. Deferred: a staker-set watcher-health metric (pre-existing ChainStakerSet observability gap) — filed as a follow-up.

Closes #757

🤖 Generated with Claude Code

Implement optional stake-lane prioritization at probe-acceptance time
per ADR 003 §Admission and Priority. Under probe-hold-budget pressure,
a node reserves the last N hold slots for stake-lane requesters —
registered operators issuing node-to-node cache-miss probes — so
end-client probe load cannot starve them.

Stake-lane eligibility is the CapacityBond.isActive predicate, resolved
from the existing chain-followed StakerSet (keyed by iroh NodeId via
conn.remote_id()); no per-probe chain read and no new chain wiring.
End-client probes over the ceiling get a signed has_blob:false (never a
phantom-slash risk), counted by a new decdn_probe_stake_lane_reserved_total
metric kept distinct from budget-exhaustion and config-disable.

Strictly operator opt-in via the new cache.stake_lane_reserved_holds knob
(default 0 ⇒ None policy ⇒ unchanged hot path). The reservation amount is
typed NonZeroUsize so "off" is unrepresentable in StakeLanePolicy; a
reservation paired with max_probe_holds=0 is warned and left off.

- crates/node/src/handlers/probe.rs: StakeLanePolicy + pure
  stake_lane_reserved_out gate, wired into serve() before try_probe_hold
- crates/node/src/runtime/mod.rs: build the staker set before the probe
  handler; gate policy construction on the config knob
- crates/node/src/metrics.rs: decdn_probe_stake_lane_reserved_total
- crates/common: [cache] stake_lane_reserved_holds (file + CLI flag + env
  + resolver + resolved struct + template)
- adr/appendix-observability.md: register the new counter

Tests: 5 unit tests on the decision fn, 2 loopback integration tests
(end-client shed / stake-lane keeps headroom), 3 config-resolution tests,
env-var-wiring test updated.

Closes #757

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

@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 implements a stake-lane probe-acceptance reservation policy to protect node-to-node cache-miss probes from being starved by end-client load under hold-budget pressure. It introduces the stake_lane_reserved_holds configuration, integrates the active-staker set into the probe handler, adds a dedicated metric, and includes comprehensive tests. The review feedback suggests a valuable performance optimization on the hot path to cache the slots_used value, avoiding a redundant lock acquisition and sweep when updating metrics.

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.

Comment thread crates/node/src/handlers/probe.rs Resolved

Copilot AI 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.

Pull request overview

This PR adds an optional “stake-lane” reservation at probe-acceptance time to prevent end-client probe load from starving registered operators’ node-to-node cache-miss probes, implemented using the existing chain-followed StakerSet and guarded behind an operator opt-in config knob.

Changes:

  • Add an optional StakeLanePolicy to the cdn/probe/v1 handler that can reserve the last N probe-hold slots for stake-lane requesters and count reserved-out events in a dedicated metric.
  • Extend configuration (file/CLI/env) with [cache] stake_lane_reserved_holds (default 0), plus resolution tests and updated sample configs.
  • Add unit + loopback integration tests covering the reserved-out decision, signature correctness, and metric attribution.

Reviewed changes

Copilot reviewed 14 out of 14 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
crates/node/src/handlers/probe.rs Implements optional stake-lane reservation gate ahead of try_probe_hold, plus unit tests for the decision function.
crates/node/src/metrics.rs Adds decdn_probe_stake_lane_reserved_total counter and an increment helper.
crates/node/src/runtime/mod.rs Builds shared chain-backed StakerSet, wires optional StakeLanePolicy into ProbeHandler, warns on dead config (reserved>0 with max=0).
crates/common/src/config/types.rs Adds stake_lane_reserved_holds to cache config schema with operator-facing docs.
crates/common/src/config/resolved.rs Adds resolved stake_lane_reserved_holds: usize to ResolvedCache.
crates/common/src/config/mod.rs Adds default constant, resolves the new knob from CLI/file, updates env-var wiring list, and adds resolution tests.
crates/common/src/cli/run.rs Adds CLI flag + env var DECDN_STAKE_LANE_RESERVED_HOLDS.
crates/cli/src/commands/config.rs Updates default config template with commented stake_lane_reserved_holds.
adr/appendix-observability.md Extends canonical metric registry to include decdn_probe_stake_lane_reserved_total.
crates/node/tests/probe_loopback.rs Adds loopback integration tests for end-client shedding vs stake-lane admission, validating signature + metrics.
crates/node/tests/probe_0rtt.rs Updates handler construction for new ProbeHandler::new parameter.
crates/node/tests/sighup_signal.rs Updates resolved-config seeding to include the new cache field.
crates/node/src/runtime/reload.rs Updates resolved-config seeding for runtime reload state/tests to include the new cache field.
crates/cli/tests/config_validate.rs Updates sample resolved config to include stake_lane_reserved_holds.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread crates/node/src/handlers/probe.rs Resolved
Comment thread crates/node/src/metrics.rs Resolved
Comment thread crates/common/src/config/types.rs Resolved
@github-actions

github-actions Bot commented Jun 2, 2026 •

Copy link
Copy Markdown

Coverage report

Total: 86.57% (was 86.58%, ● 0.00%) — 25993/30024 lines

File Coverage Lines Δ
crates/cli/src/commands/config.rs 61.60% 77/125 ● 0.00%
crates/common/src/config/mod.rs 96.22% 4638/4820 ▲ +0.04%
crates/common/src/config/resolved.rs 100.00% 13/13 ● 0.00%
crates/node/src/handlers/probe.rs 87.23% 239/274 ▲ +1.73%
crates/node/src/metrics.rs 83.63% 419/501 ▲ +0.10%
crates/node/src/runtime/mod.rs 45.86% 515/1123 ▼ 0.53%
crates/node/src/runtime/reload.rs 95.50% 1400/1466 ▲ +0.01%
History
Commit Total Δ vs base
360273e 86.76% ▼ 0.01%
c1af3dc (HEAD) 86.57% ● 0.00%

- probe.rs: sample probe_hold_slots_used() once in the stake-lane gate and
  reuse it for the slots gauge on the shed path, avoiding a redundant
  lock+sweep on the loaded path the gate fires under.
- probe.rs: make stake_lane_reserved_out take is_stake_lane as a lazy
  FnOnce, evaluated only after the cheap ceiling guards pass, so the
  staker-set RwLock read + NodeId conversion is skipped on the uncongested
  common path. Add a test asserting the lookup is short-circuited below the
  ceiling.
- metrics.rs: fix "two counters below" -> "above" (the referenced counters
  are declared above the field).
- types.rs: clarify that reserved >= max_probe_holds sheds every end-client
  probe whenever holds are enabled, regardless of usage (not only under
  pressure).

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@thiras
thiras merged commit dfee529 into main Jun 2, 2026
36 of 38 checks passed
@thiras
thiras deleted the feat/757-probe-stake-lane branch June 2, 2026 17:48
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.

Implement probe-time stake-lane eligibility in probe handler

2 participants