Skip to content

fix(node): reactive top-up delivery leg wrongly excluded from peer delivery-speed reputation #1602

Closed

Description

@alpergundogdu

Problem

On the node-to-node buyer leg, the successful post-top-up delivery leg is wrongly charged to paid_wait, so its real transfer time is subtracted from the upstream's delivery-speed reputation signal. A slow upstream involved in a reactive top-up then scores as fast (or instantaneous), corrupting the local per-peer delivery-speed EWMA (ADR 008) specifically on topped-up pulls.

Mechanism

In crates/node/src/node_origin/resume.rs, pull_blob:

let leg_started = state.budgets.awaiting_topup_settle.then(Instant::now);  // read at loop top
let leg = stream_leg(deps, target, ctx, ledger, deadlines, &mut state).await;
if let Some(started) = leg_started {
    state.paid_wait = state.paid_wait.saturating_add(started.elapsed());   // added unconditionally
}
let Err(err) = leg else { /* success returns here */ };                    // success check AFTER

note_topup_landed() sets awaiting_topup_settle = true. On the next iteration leg_started is Some. stream_leg clears the flag via note_successful_open() only inside the awaited call — after the open, and before pull_to_sink streams the entire remainder of the blob. So on the completing leg, the whole pull_to_sink delivery is folded into paid_wait, then subtracted from elapsed in pull_from_candidate (node_origin/mod.rs), which feeds Outcome::Delivered { elapsed }.

This contradicts PulledBlob::paid_wait's own doc ("Blocking on a transaction says nothing about how fast the upstream serves") and fires on the feature's main success path (a top-up followed by completion). The existing top-up tests only assert counters and score(provider) > 0.5, so nothing pins the elapsed accounting.

Fix

Charge paid_wait only on the failed-leg path (the failed settle-wait re-open probes are pure funding cost), or time open_leg alone rather than all of stream_leg. The successful leg's pull_to_sink is real delivery and must stay in elapsed. Add a test that pins elapsed/paid_wait for a topped-up pull rather than only the score bound.

Context

Follow-up from the review of #1600 (reactive mid-pull deposit top-up, #1530). Merged as-is; this is a reputation-correctness follow-up, not fund-loss.

Activity

  1. added
    kind:bug
    prio:medium
    rust
    kind:test
    on Aug 5, 2026
  2. added a commit that references this issue on Aug 5, 2026
    d62c523
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

kind:bugkind:testprio:mediumrust

Type

Fields

Priority

None yet

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions