Repository navigation
fix(node): keep the post-top-up delivery leg in the delivery-speed score - #1604
Conversation
`pull_blob` captured `leg_started` from `awaiting_topup_settle` at the loop top, then charged the whole `stream_leg` to `paid_wait`. But `stream_leg` clears the flag via `note_successful_open()` between the open and `pull_to_sink`, so on the completing leg the entire remainder's transfer was folded into `paid_wait` and subtracted out of `elapsed`. A slow upstream that served through a reactive top-up (#1530) then scored as fast/instantaneous, corrupting the local per-peer delivery-speed EWMA (ADR 008) — and contradicting `PulledBlob::paid_wait`'s own doc. Move the timing into `stream_leg` so it wraps only `open_leg`: the re-open round trip (success or failure) stays charged to `paid_wait` as pure funding cost, while the `pull_to_sink` delivery stays in `elapsed` where the score measures it. Settle-sleep and topUp-receipt exclusions are unchanged. Add an integration test that pins the delivery speed for a topped-up pull: with `alpha = 1.0` a single delivery reads straight off the score, and a throttled resume leg caps an honest score at ~0.8 — the bug pins it at ~1.0. The existing tests only assert `score(provider) > 0.5`, which both pass. Fixes #1602 Co-Authored-By: Claude Opus 4.8 <[email protected]>
ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Free Run ID: 📒 Files selected for processing (2)
WalkthroughThe change moves settlement-wait timing into ChangesResume timing correction
Estimated code review effort: 3 (Moderate) | ~20 minutes Note 🎁 Summarized by CodeRabbit FreeYour organization is on the Free plan. CodeRabbit will generate a high-level summary and a walkthrough for each pull request. For a comprehensive line-by-line review, please upgrade your subscription to CodeRabbit Pro by visiting https://app.coderabbit.ai/login. Comment |
There was a problem hiding this comment.
Pull request overview
This PR fixes node-to-node resume timing accounting so the post-top-up content delivery time contributes to the upstream’s delivery-speed reputation signal (ADR 008), instead of being mistakenly charged as local funding wait (paid_wait). This aligns PulledBlob::paid_wait with its documented intent and prevents topped-up pulls from artificially inflating per-peer delivery-speed EWMA.
Changes:
- Move “paid-wait” timing from
pull_blobintostream_leg, and scope it to only theopen_leground trip whileawaiting_topup_settleis true. - Add a regression test that throttles the resumed delivery leg and asserts the provider score stays below an upper bound (catching the previous “instantaneous” mis-scoring).
- Extend the deposit-capped upstream test server harness to optionally delay only the RESUME-leg chunk stream (not the open/response).
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| crates/node/src/node_origin/resume.rs | Fixes timing attribution by charging only open_leg to paid_wait during settle-wait iterations, keeping resumed streaming in elapsed. |
| crates/node/tests/node_origin_pull.rs | Adds a targeted regression test and harness support to slow the resumed chunk stream and validate delivery-speed scoring. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Coverage reportTotal: 80.48% (was 80.47%, ▲ +0.01%) — 57980/72044 lines
History
|
Fixes #1602.
Problem
On the node-to-node buyer leg (
crates/node/src/node_origin/resume.rs),pull_blobcapturedleg_started = state.budgets.awaiting_topup_settle.then(Instant::now)at the loop top, then unconditionally addedstarted.elapsed()topaid_waitafterstream_legreturned — before the success check.But
stream_legclearsawaiting_topup_settlevianote_successful_open()internally: after the open, but beforepull_to_sinkstreams the remainder of the blob. So on the completing (successful) leg, the wholepull_to_sinkdelivery time was folded intopaid_wait, then subtracted fromelapsedinpull_from_candidate, which feedsOutcome::Delivered { elapsed }.The result: a slow upstream that served through a reactive top-up (#1530) scored as fast/instantaneous, corrupting the local per-peer delivery-speed EWMA (ADR 008) on any topped-up pull — and contradicting
PulledBlob::paid_wait's own doc ("Blocking on a transaction says nothing about how fast the upstream serves").Fix
Move the timing into
stream_legso it wraps onlyopen_leg, notpull_to_sink:paid_wait— success or failure — as pure funding cost. A failed one is a settle-wait probe; a successful one is the last probe before delivery resumes.pull_to_sinkdelivery stays inelapsed, where the delivery-speed score measures it.The settle-sleep and topUp-receipt exclusions are unchanged — only the successful-delivery-leg misattribution is corrected.
Test
Adds
a_slow_post_topup_delivery_scores_slow_not_instant, which pins the delivery speed for a topped-up pull instead of only assertingscore(provider) > 0.5(which an inflated score trivially passes). Withalpha = 1.0a single delivery reads straight off the score (score = 0.4·speed + 0.6); a throttled resume leg (served over 3s) caps an honest score at ~0.8, while the bug — excluding the transfer fromelapsed— saturates speed and pins the score at ~1.0. The test fails on the pre-fix code and passes on the fix.Verification
cargo build && cargo clippy -p decdn-node --tests— cleancargo fmt -- --check— cleancargo nextest run -p decdn-noderesume unit tests (13) + top-up integration tests (14) — all pass🤖 Generated with Claude Code
Summary by CodeRabbit
Bug Fixes
Tests