Repository navigation
fix(client): pay only for bytes the decoder has verified - #2395
Conversation
The client released a payment per 1 MiB chunk as bytes arrived, before the bao decoder checked them. A peer that sent a bad group was paid for up to one interval of it, and frames past a steal split were paid twice. The client now pays per chunk only once its decoder has verified the chunk's last byte. The node's credit window floor grows to one chunk plus one chunk group (VERIFY_LAG_BYTES), and its recoup phase collects the newest chunk only once the leaf that completes it is on the wire, so a stream at the floor never waits on a proof the payer cannot send. ADR 003, 037 and 038 state the rule. floor_micro, which priced the old one-chunk floor and had no production caller, is removed. Co-Authored-By: Claude Opus 5.5 <[email protected]>
There was a problem hiding this comment.
🔵 Needs a closer look
It rewrites payment-metering and credit-window economics across the client, node, and three ADRs on a money-handling path with a documented new-client/old-node stall hazard, so a human should give final sign-off even though no defect was found.
0 open findings
What changed in this PR
This PR tightens the paid-pull payment model so the client pays for a wire chunk only once its bao decoder has verified that chunk, rather than paying as bytes arrive. It follows up on #2377 (which observed wasted/duplicate paid bytes) by stopping payment for unverified bytes entirely, so a bad group earns its sender nothing and steal-overrun/lane-fault double payments disappear. Because a payer can only verify a chunk's last byte once the bao leaf that holds it (up to one 16 KiB chunk group past the boundary) arrives, the credit-window floor is raised from one chunk to one chunk + one chunk group (VERIFY_LAG_BYTES), and the node's recoup phase holds back the newest owed chunk until that lag is on the wire.
Changes:
- Client (
decdn-client):UpstreamPullgains averifiedcounter andmark_verified; payment is driven by verified bytes through a newpay_verified, called at the top ofnext_chunk/finishand instop.PullReadercounts bytes handed to the decoder and reports them as verified. - Node (
decdn-node): credit-window floor isCHUNK_BYTES + VERIFY_LAG_BYTES; the recoup loops usepop_payableto defer the newest chunk until its verify lag is sent or the range is fully delivered;ensure_unpaid_bytes_trackedaccounts for held chunks. - Specs/cleanup: ADR 003/037/038 updated to state "pay only for verified bytes" and the new floor; dead
decdn_incentive::floor_microremoved (test callers price the floor directly); extensive test-harness updates.
| File | Description |
|---|---|
crates/client/src/lib.rs |
Adds verified/mark_verified/pay_verified; next_chunk/finish/stop/arrived_rejection now meter verified bytes. |
crates/client/src/sink.rs |
PullReader tracks consumed and reports it verified in fill_to/into_inner. |
crates/client/src/pacer.rs (+tests) |
New VERIFY_LAG_BYTES; PULL_WINDOW_FLOOR carries it. |
crates/client/src/lib.rs exports |
Re-exports VERIFY_LAG_BYTES; doc updates. |
crates/node/.../voucher.rs (+tests) |
Adds pop_payable; ensure_unpaid_bytes_tracked counts held owed chunks. |
crates/node/.../delivery.rs, serve_leg.rs |
Recoup loops collect via pop_payable; collected_any recomputed. |
crates/node/.../mod.rs, ramp.rs |
Credit-window floor adds VERIFY_LAG_BYTES; doc updates. |
crates/incentive/src/rate.rs, lib.rs (+tests) |
Removes floor_micro and its re-export. |
crates/common/src/config/{types,resolved}.rs, cli/.../config.rs |
Config docs reflect the new floor. |
crates/e2e/tests/*, crates/node/tests/* |
Harnesses model the new floor and verify-lag; tightened payment bounds. |
adr/003, adr/037, adr/038 |
Spec text for verified-byte payment and the one-chunk-group floor. |
I verified: all node floor-pricing sites route through credit_window(CHUNK_BYTES, 0) (so the new lag propagates uniformly to the deposit/signer guards), meter.pay correctly emits one reveal per whole chunk for multi-chunk unproved, pop_payable always leaves a payable chunk at the front whenever the window is shut (no deadlock, and the no-progress guard remains the safety net), the pay_verified gating is correct at every boundary, the floor_micro removal leaves no dangling references, and the ADR cross-reference #payment-metering resolves. I found no concrete defects.
🧠 Review effort: Balanced
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
The refused leg verifies every byte before its refusal, so the re-ask after the settle step is the fill's last chance. A fixed 100 ms delay let a slow runner re-ask first. The upstream now catches up as soon as the refused leg records its progress, which precedes the step. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Code Coverage OverviewLanguages: Rust, Solidity Rust / code-coverage/cargo-llvm-covThe overall line coverage in commit 4c2cd95 in the Solidity / code-coverage/forgeThe overall line coverage in commit 4c2cd95 in the Updated |
Gas snapshotNo gas changes vs base. |
What
The client pays for a 1 MiB chunk only once its bao decoder has verified the chunk's last byte. Before this change it paid as bytes arrived, before verification.
Follows up on #2377: rather than report wasted paid bytes, stop paying for unverified ones.
Why
stop()no longer pays for them. The stealer pays for that tail once.How
Client (
decdn-client)PullReadercounts the wire bytes it hands to the decoder. The decoder checks each item before it reads the next one, so that count is the verified count, andUpstreamPull::mark_verifiedmakes it payable.next_chunkpays for verified bytes before it reads, because the node may be waiting on that payment.finish()sends the closing voucher before it drains toStreamEnd, andstop()settles only verified bytes.VERIFY_LAG_BYTES(one 16 KiB chunk group) is the most wire a payer receives past a chunk boundary before it can verify that boundary.PULL_WINDOW_FLOORcarries it.Node (
decdn-node)CHUNK_BYTES + VERIFY_LAG_BYTES.delivery.rs,serve_leg.rs) collects the newest owed chunk only onceVERIFY_LAG_BYTEShave gone out after it, or once the range is fully sent (voucher::pop_payable). Without this, a node parked exactly on a chunk boundary waits for a proof the payer cannot yet make.Specs: ADR 003 § Credit Window, ADR 037, and ADR 038 § Payment metering state the rule.
Cleanup:
decdn_incentive::floor_micropriced the old one-chunk floor and had no production caller. It is removed, and its test callers price the floor directly.Rollout order
New clients against old nodes stall. An old node parks at exactly 1 MiB, and a new client cannot verify, so cannot pay for, the leaf that straddles that boundary, until the node's 10 s proof timeout fires. Old clients against new nodes are fine. Upgrade testnet nodes before releasing this client.
Behaviour changes worth knowing
a_landing_short_of_the_owed_debt_ends_the_fill_after_one_steppins this.BlobTooLargeceiling inside the first chunk, the upstream receives nothing for up to about 1 MiB of verified bytes.Tests
cargo nextest run --workspace: 4776/4776 pass.cargo docdeny-warnings gate all pass.pop_payable, and theVERIFY_LAG_BYTESterm in the pull-window liveness test.client_loopback.rsandnode_origin_pull.rsnow model the new floor and send throughVERIFY_LAG_BYTESbefore parking.Follow-up (not in this PR)
When a stream's last two proofs are a reveal followed by a closing voucher and the node refuses the reveal,
PoolLedger::resolve_rejectrewinds the closing voucher instead. The client's books then run one interval ahead of what the node credited. This is safe (the node holds the preimage), but the persisted watermark overstates acceptance. The path predates this PR.🤖 Generated with Claude Code