Skip to content

test(payments): exercise concurrent same-lane aggregate voucher accounting (#1689) - #1690

Merged
alpergundogdu merged 1 commit into
mainfrom
claude/dreamy-tesla-42b95d
Aug 14, 2026
Merged

alpergundogdu merged 1 commit into
mainfrom
claude/dreamy-tesla-42b95d

Conversation

@alpergundogdu

Copy link
Copy Markdown
Contributor

Closes #1689.

What

Concurrent streams sharing one (pool_id, signer, provider) lane are an ADR 005 capability — one aggregate byte counter, one voucher-signing clock, cumulative vouchers routed on any stream — but until now no test crossed an aggregate 4 MiB VOUCHER_INTERVAL_BYTES boundary or settled vouchers out of order. Adds the two tests the issue asks for.

1. Node/protocol-side (crates/node/tests/client_loopback.rs)

concurrent_same_lane_streams_aggregate_across_the_voucher_interval: opens two same-lane deliveries (3 MiB + 2 MiB) on one connection. Each blob is under one voucher interval, so neither stream crosses the boundary alone, but their aggregate does — so the shared lane counter carries the crossing. Both serve legs park at their closing voucher simultaneously, then settle in the reverse of open order. Asserts the node reconstructs each voucher's cumulative bytes_delivered from the shared counter plus that stream's own delivered delta, so the persisted watermark is the exact aggregate (wire_a + wire_b) with the correct cumulative amount, independent of payment order.

2. Client-side e2e (crates/e2e/tests/cli_bundle_pull_pool_id.rs, anvil-gated)

Strengthens the existing two-same-provider-entry bundle-pull journey: sizes the entries so the shared lane watermark crosses the 4 MiB boundary across entries, and replaces the weak last_bytes > 0 check with an exact last_bytes == aggregate wire bytes assertion (monotone, never double-paid). This locks in that the per-provider serialization holds and the second same-lane pull resumes from the first's cumulative watermark rather than racing or restarting it.

Result

Both tests pass — no bug surfaced. The node's lane-shared reconstruction is correct under out-of-order settlement and aggregate-boundary crossing, and the client-side serialization guard is now pinned against a future refactor silently dropping it into a race.

Verification

  • cargo nextest run -p decdn-node --test client_loopback --no-fail-fast → 74/74 pass (also verified serially).
  • cargo clippy --all-targets -- -D warnings and cargo clippy -p decdn-e2e --tests --features anvil-e2e -- -D warnings → clean.
  • cargo fmt -- --check → clean.
  • The anvil-gated e2e compiles (cargo test --no-run -p decdn-e2e --features anvil-e2e); its runtime pass is left to CI (local disk was at 99%/ENOSPC). The exact-bytes assertion is sound by the EIP-712 signature-agreement invariant: client-pull sums bao wire bytes (chunk.bytes().len()) into the cumulative the node reconstructs and both sign over, so a successful delivery means the buyer's recorded last_bytes equals the node's wire-byte watermark, computed identically via align_range + bao_encoded_size.

🤖 Generated with Claude Code

…nting (#1689)

Concurrent streams sharing one `(pool_id, signer, provider)` lane are an ADR
005 capability (one aggregate byte counter, one cumulative-voucher watermark)
but no test crossed an aggregate voucher-interval boundary or settled vouchers
out of order. Add two:

- Node-side loopback (`concurrent_same_lane_streams_aggregate_across_the_voucher_interval`):
  two same-lane deliveries, each under one 4 MiB `VOUCHER_INTERVAL_BYTES` but
  aggregating over it, both parked at their closing voucher, then settled in the
  REVERSE of open order. Pins that the node reconstructs each voucher's
  cumulative `bytes_delivered` from the shared lane counter plus that stream's
  own delivered delta, so the persisted watermark is the exact aggregate
  regardless of payment order.

- Client-side e2e (`cli_bundle_pull_uses_one_pool_for_the_whole_bundle`):
  size the two same-provider bundle entries so the shared lane watermark crosses
  the 4 MiB boundary across entries, and assert the EXACT aggregate wire bytes
  (monotone, never double-paid) instead of merely `> 0` — locking in that the
  per-provider serialization holds and the second pull resumes from the first's
  cumulative watermark.

Both hold: the node's lane-shared reconstruction is correct under
out-of-order settlement and aggregate-boundary crossing.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
Copilot AI lite review requested due to automatic review settings August 14, 2026 14:03

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.

Pull request overview

Adds coverage for cumulative voucher accounting when multiple deliveries share the same (pool_id, signer, provider) payment lane, specifically exercising (1) aggregate crossing of the 4 MiB VOUCHER_INTERVAL_BYTES boundary and (2) out-of-order voucher settlement / exact persisted watermark assertions.

Changes:

  • Add a node/protocol loopback test that opens two same-lane deliveries, stalls both at the closing voucher, then settles them in reverse order while asserting the final persisted lane watermark equals the aggregate wire bytes.
  • Strengthen the anvil-gated CLI bundle-pull e2e to use interval-crossing blob sizes and assert the persisted lane watermark equals the exact aggregate bao wire bytes (not just > 0).

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
crates/node/tests/client_loopback.rs Adds a new concurrent same-lane test that crosses the voucher interval in aggregate and settles vouchers out-of-order.
crates/e2e/tests/cli_bundle_pull_pool_id.rs Sizes blobs to cross the voucher interval across entries and tightens assertions to exact aggregate wire-byte watermark.
Suppressed comments (1)

crates/e2e/tests/cli_bundle_pull_pool_id.rs:226

  • whole_blob_wire_bytes silently falls back to returning total on align_range error. That fallback is not the same as bao wire bytes (it omits proof bytes) and could make the test pass with an incorrect expected watermark, masking real regressions. Since (0, 0, total) should always be alignable for whole-blob pulls, it’s safer to fail the test if alignment ever errors and bubble the error up.
fn whole_blob_wire_bytes(total: u64) -> u64 {
    // `byte_len == 0` means "to the blob end"; the whole range always aligns.
    match align_range(0, 0, total) {
        Ok(aligned) => bao_encoded_size(total, aligned.chunk_ranges()),
        Err(_) => total,
    }
}

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

Comment on lines +91 to +96
// The exact wire bytes each whole-blob pull vouchers for: bao content plus its
// interleaved proof over the 16 KiB chunk-group-aligned whole range (ADR 038),
// the same quantity the node meters and persists as the lane watermark.
let wire_a = whole_blob_wire_bytes(blob_a.len() as u64);
let wire_b = whole_blob_wire_bytes(blob_b.len() as u64);
let aggregate_wire = wire_a
@github-actions

Copy link
Copy Markdown

Coverage report

Total: 80.76% (was 80.76%, ● 0.00%) — 59246/73363 lines

No coverage data for changed Rust files.

History
Commit Total Δ vs base
7951c86 (HEAD) 80.76% ● 0.00%

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.

test: concurrent same-lane voucher accounting is unexercised (bundle pull, same provider)

2 participants