Skip to content

fix(node): redeem a delegated lane when its serve cutoff passes - #2312

Merged
thiras merged 3 commits into
mainfrom
fix/2233-redeem-at-serve-cutoff
Oct 5, 2026
Merged

thiras merged 3 commits into
mainfrom
fix/2233-redeem-at-serve-cutoff

Conversation

@thiras

@thiras thiras commented Oct 5, 2026 •

Copy link
Copy Markdown
Contributor

What

The redeemer now runs its sweep one second after a delegated lane's serve cutoff (expiry − margin, the point where the voucher path starts to refuse the lane with CapabilityExpired). The lane's value is final there, and the sweep has one redeem interval plus the 120 s landing slack to land before the capability expires.

  • serve_cutoff_wake / next_serve_cutoff: the earliest future wake over owed lanes this node provides with a finite expiry.
  • redeemer_loop gains a third select! arm. The wake is seeded from the lane store at start (restart-safe), taken from each hint (redeem_one returns the lane's wake), and recomputed from each sweep's own scan. A failed scan keeps every future cutoff and drops a passed one; the tick retries.
  • redeem_sweep takes the loaded states, so the loop schedules the next cutoff from the same load_all it sweeps.
  • Reveals are gated too. commit_one_preimage now applies the voucher path's expiry-margin check (shared inside_capability_expiry_margin in decdn-common). Without it, a stream anchored before the margin could keep growing the claim after the cutoff sweep read it.
  • Restart. At start, a lane whose cutoff passed while the node was down, and that is not yet inside the landing slack, is swept at once (startup_cutoff). Otherwise the skipped first tick pushes its only sweep past the slack.
  • The floor is unchanged. Lanes that are each sub-floor but clear it together go out in one redeemMany; a value still below the floor at the cutoff is not redeemed, as with other dust (refactor(node): drop PaymentPool close monitor; lean on the redeem sweep #1761).
  • ADR 003 (§Revocation, §Owner reclaims item 2) and the module doc describe the cutoff sweep. CHANGELOG entry under Fixed.

Why

The issue's premise is partly stale: #2263 (#2242) already made the node stop accepting vouchers redeem_interval + 120 s before expiry. What remained was the redemption timing. The last voucher lands just before expiry − interval − 120, and only the next tick could redeem it — a tick that had to fire on time to the second. The redeemer loop is serial, and a hint or sweep can sit in a receipt wait for up to 3 min 37 s, so a late tick fell inside the landing slack, skipped the lane as expired, and forfeited the whole tail.

Reviewer notes

  • Kept out (spec-discipline pass): a lower "expiring" floor (a second number with nothing to set it from), per-lane timers (one Option<u64> suffices), and any serve-side change. Shrinking the margin to a constant remains fix(client,node,cli): bar refused pull-through, refuse over-ceiling ranges, heal stale under-fold, hold expiry margins #2263's deferred per-node CapabilityExpired item.
  • Review follow-up (second commit): the reveal gate, the overdue-cutoff start sweep, the load-failure fix, and tests for the hint-fed wake, no re-fire after a cutoff sweep, the restart case, a failed load, the self-tick arm, and a loopback reveal refused inside the margin. Each guard was mutation-checked: removing it fails at least one test.
  • The loop tests run in real time (~3 s each): unix_now reads SystemTime, which paused tokio time does not move. Each uses a one-hour tick so only the cutoff can trigger the sweep. Both fail (time out) with the cutoff sleep stubbed to pending().

Verification

  • cargo fmt -- --check
  • cargo clippy --workspace --all-targets --all-features -- -D warnings
  • cargo nextest run -p decdn-node -p decdn-common -p decdn-protocol: 2209/2209 passed
  • decdn-protocol public-api snapshot passes
  • RUSTDOCFLAGS="-D warnings" cargo doc --workspace --no-deps --document-private-items
  • cargo build --bin decdn-node + anvil_settlement_e2e, anvil_bringup_shutdown_e2e (node) and anvil_pool_redeem (e2e): all passed
  • Acceptance test sub_floor_lanes_are_redeemed_together_at_their_serve_cutoff fails without the fix

Closes #2233

🤖 Generated with Claude Code

The voucher path refuses a lane once its capability expires within one
redeem interval plus the 120 s landing slack. The periodic sweep was the
only thing that redeemed the lane's final value, and the timing left it
no room: a tick delayed by a receipt wait in the serial redeemer loop
fell inside the landing slack and skipped the lane as expired.

The redeemer now also sweeps one second after the earliest serve cutoff
(expiry - margin) of an owed lane with a finite expiry. The wake is
seeded from the lane store at start, taken from each hint, and
recomputed from each sweep's scan. The sweep packs every owed lane, so
sub-floor lanes that share an expiry and clear the floor together go
out in one redeemMany with a full interval plus slack to land.

Closes #2233

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Copilot AI balanced review requested due to automatic review settings October 5, 2026 08:20
@thiras thiras self-assigned this Oct 5, 2026

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.

Copilot review overview

🟡 Changes recommended

Cutoffs can still be missed after restart, transient store failures, or blocking redemption work.

Review effort: Balanced
Findings: 2 High severity

Open (2)
What changed in this PR

Adds expiry-aware redemption sweeps so delegated lane value is redeemed after serving stops.

Changes:

  • Schedules sweeps at capability serve cutoffs.
  • Adds restart and aggregate sub-floor redemption tests.
  • Updates payment ADR and changelog documentation.
File Description
crates/​node/​src/​payment_settlement.rs Implements cutoff scheduling and tests.
adr/​003-payments.md Documents cutoff redemption behavior.
CHANGELOG.md Records the delegated-lane fix.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread crates/node/src/payment_settlement.rs Resolved
Comment thread crates/node/src/payment_settlement.rs Resolved
@github-code-quality

github-code-quality Bot commented Oct 5, 2026 •

Copy link
Copy Markdown

Code Coverage Overview

Languages: Rust

Rust / code-coverage/cargo-llvm-cov

The overall line coverage in commit b88520e in the fix/2233-redeem-at-s... branch remains at 87%, unchanged from commit 07be3bf in the main branch.

Show a line coverage summary of the most impacted files.
File main 07be3bf fix/2233-redeem-at-s... b88520e +/-
crates/client/src/scheduler.rs 95% 95% 0%
crates/client/src/streamer.rs 91% 91% 0%
crates/client/s...c/connection.rs 97% 97% 0%
crates/protocol/src/framing.rs 97% 97% 0%
crates/common/s...c/config/mod.rs 98% 98% 0%
crates/incentiv...eth_identity.rs 98% 99% +1%
crates/node/src...ient/voucher.rs 96% 97% +1%
crates/node/src...t_settlement.rs 84% 88% +4%

Updated October 05, 2026 09:23 UTC

thiras and others added 2 commits October 5, 2026 11:57
…s at start

Review follow-ups for #2233:

- The preimage path now applies the voucher path's capability-expiry
  gate (shared `inside_capability_expiry_margin` in decdn-common). A
  stream anchored before the margin could otherwise keep extending the
  claim after the cutoff sweep had read it.
- At start, a lane whose cutoff passed while the node was down, and
  that is not yet inside the landing slack, is swept at once
  (`startup_cutoff`). Before, the skipped first tick pushed its only
  sweep past the slack and forfeited it.
- A failed lane load keeps every cutoff still ahead and drops only a
  passed one.
- Tests: hint-fed wake, no re-fire after a cutoff sweep, restart with
  an overdue cutoff, failed load without spin, the self-tick arm, the
  wake/margin-gate tie, and a loopback reveal refused inside the margin.
  Each guard was mutation-checked.
- Docs: ADR 003/005, appendix-observability, the CapabilityExpired doc
  and the config margin doc describe the cutoff sweep accurately.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The redeemer keeps the time of its last sweep scan. A lane's cutoff is
due at once when it has passed and no scan has run since, whether the
node was down at the cutoff or the lane's first hint waited behind
redemption work until after it. This one rule replaces startup_cutoff.
A scan after the cutoff already read the final claim, so a later hint
for that lane schedules nothing.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@thiras
thiras merged commit de1893b into main Oct 5, 2026
30 checks passed
@thiras
thiras deleted the fix/2233-redeem-at-serve-cutoff branch October 5, 2026 09:28
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.

node: a delegated lane's unredeemed tail is forfeit when its capability expires between sweeps

2 participants