Skip to content

Client blocks on VoucherAck for nothing: pure dead latency, and it serializes parallel streams to one provider #1484

Closed

Description

@alpergundogdu

Client half of #1477. Filed separately because it has no durability constraint and can land independently of both #1477's serve-side work and the #1483 fsync debate.

What happens

After sending a voucher, the client blocks until VoucherAck returns before reading another chunk:

  • crates/client-pull/src/lib.rs:2212 — self_pay awaits read_client_message(recv) for the ack.
  • crates/client-pull/src/lib.rs:1604-1620 (buffered path) and :2053 (progressive next_chunk) — both await self_pay inline in the receive loop.

Why this half is free to fix

Unlike the serve side, there is nothing behind the client's wait. ChannelLedger::issue commits purely in memory — *self.committed.lock() = next at crates/client-pull/src/ledger.rs:213-216, a std::sync::Mutex<Cumulative>. No store write, no fsync.

The client's fsynced buyer-store write (Durability::Immediate, crates/incentive/src/buyer_channel_redb.rs:37) happens once per pull, not per voucher — ledger.snapshot() at crates/client-pull/src/lib.rs:1154, or settlement() on the abandon path (#852).

So the client's blocking wait is pure dead latency: one full RTT per voucher interval, protecting nothing. None of the ADR 003 §Off-chain voucher state persistence reasoning in #1483 applies here — that rule binds the delivering node.

Second effect: it serializes parallel streams to one provider

ChannelLedger::issue holds the per-channel mutex across the entire send→ack exchange (ledger.rs:180-191), by design — it is what guarantees strict nonce ordering.

Ledgers are keyed per channel ((Address, ChannelId), crates/node/src/buyer_ledgers.rs:43), so this does not affect multi-source fetches across different providers, which hold different channels and different ledgers. But it does throttle parallel range streams to a single provider: every voucher round trip on any one stream blocks voucher issuance on all the others, so N parallel streams to one fast provider degrade toward serial at the payment layer.

That is precisely the shape of "download a large file, fast" from a well-provisioned peer.

Fix

Issue the voucher and keep receiving; process acks off the critical path.

Nonce ordering is preserved by serializing issuance — the lock need only cover compute → sign → send, not the ack wait. The node requires monotonically increasing nonces, never ack-before-next.

The in-flight/settlement machinery already models this correctly. ChannelLedger distinguishes committed, in-flight, and settlement watermarks precisely because a voucher's fate can be unresolved (#1122, #1145) — pipelining widens that existing window from one voucher to a bounded few rather than introducing a new state. settlement() already settles high on ambiguity, which stays correct with several vouchers outstanding, though it will need to track a set rather than a single slot.

Bound the outstanding vouchers so a silent provider cannot make the client pay unboundedly ahead — though note the client still never pays for bytes it has not received, since vouchers are cumulative over delivered bytes.

Why it matters

Large-file delivery is the first wedge. With #1477 and #1483 fixed on the serve side but this left in place, the client remains the binding constraint at exactly the RTTs that matter for a geographically distributed CDN — ~10 MiB/s at 100 ms RTT, per the table in #1477.

Related

Metadata

Metadata

Assignees

Labels

area:cliprio:highrust

Type

No type

Fields

Priority

None yet

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions