Skip to content

test(node): pin no-double-spend coalescing for concurrent same-hash pulls (#895) - #924

Merged
thiras merged 2 commits into
mainfrom
test/895-concurrent-coalesce-single-upstream-pull
Jun 17, 2026
Merged

thiras merged 2 commits into
mainfrom
test/895-concurrent-coalesce-single-upstream-pull

Conversation

@thiras

@thiras thiras commented Jun 17, 2026

Copy link
Copy Markdown
Contributor

Summary

Closes #895. Adds an E2E test pinning the no-double-spend guarantee (#305) at the handler layer: two concurrent same-hash leaf requests against a node B with an empty cache must open exactly one upstream pull.

  • The first request owns the tee sink and pulls from A; the second hits TeeOpen::InFlight and waits on await_coalesced_fill instead of opening a second upstream pull (which would double-spend real USDC on the B↔A channel).
  • The cache-level coalescing primitive is already unit-tested (crates/cache/src/engine.rs::tee_sink_coalesces_concurrent_fills); this test pins the handler-side consequence at the layer that actually spends — the gap noted in the feat(node): window-paced pull-through for regional proxy warming (#856) #893 review.

How it stays deterministic

A gated honest upstream (spawn_gated_node_a / serve_gated_correct_bytes, modeled on the existing serve_wrong_bytes / spawn_lying_node_a) signals once B's single upstream StreamRequest lands, then blocks until released. Because B opens its tee sink before dialing upstream, that signal proves the owner pull is in flight and B's cache is still empty — so the second leaf, launched while the gate is held, coalesces.

The headline assertion (progress_log().len() == 1) is timing-independent: it reads the buyer-side persisted watermark log, so any second upstream pull records a second entry regardless of interleaving. The test also asserts both leaves complete with correct bytes/hash, the blob is promoted, and the honest upstream doesn't trip the verify-failed counter.

Supporting changes (test-only)

  • Refactor build_node_b into build_node_b_with_leaves(&[(channel, addr, deposit)]); the single-leaf form is a thin wrapper, so existing callers are untouched.
  • Add spawn_server_concurrent — the existing inline support::spawn_server awaits handler.accept inline and serializes connections, so while the first serve parks on the in-flight pull the second leaf's connect times out.

Test plan

  • cargo nextest run -p decdn-node window_pull_through_concurrent_same_hash_single_upstream_pull — passes, stable across repeated runs (~0.8s).
  • cargo nextest run -p decdn-node — full suite green (645 tests).
  • cargo clippy -p decdn-node --tests --all-targets and cargo fmt --check — clean.

Reviewed via the PR-review toolkit (code/test/comment/silent-failure agents); no critical issues. Coverage follow-ups noted but deferred as out of scope for this low-priority item: N>2 fan-in, the owner-pull-fails coalescer-miss path, and a dedicated coalesced-wait metric.

🤖 Generated with Claude Code

…ulls (#895)

Add an E2E test that two concurrent same-hash leaf requests against a node
B with an empty cache open exactly ONE upstream pull. The first request owns
the tee sink and pulls from A; the second hits `TeeOpen::InFlight` and waits
on the coalesced fill (`await_coalesced_fill`) rather than opening a second
upstream pull — which would double-spend real USDC on the B<->A channel (#305).
The cache-level coalescing primitive is already unit-tested
(`engine.rs::tee_sink_coalesces_concurrent_fills`); this pins the handler-side
consequence at the layer that actually spends.

Determinism comes from a gated honest upstream (`spawn_gated_node_a` /
`serve_gated_correct_bytes`): A signals once B's single upstream request lands,
then blocks until released. Because B opens its tee sink before dialing
upstream, that signal proves the owner pull is in flight and the cache empty,
so the second leaf coalesces. The headline assertion (`progress_log().len()
== 1`) is timing-independent — it reads the buyer-side watermark log, so a
second pull would record a second entry regardless of interleaving.

Supporting changes:
- refactor `build_node_b` into `build_node_b_with_leaves(&[...])`; the
  single-leaf form is a thin wrapper (zero churn to existing callers).
- add `spawn_server_concurrent`: the existing inline `support::spawn_server`
  serializes connections, so while the first serve parks on the in-flight
  pull the second leaf's connect times out.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Copilot AI review requested due to automatic review settings June 17, 2026 01:50

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 an end-to-end regression test in decdn-node to pin the “no double-spend” guarantee for window-paced pull-through: two concurrent same-hash leaf requests against an empty-cache node B must coalesce behind a single upstream pull from A (so B doesn’t pay twice on the B↔A channel). This complements the existing cache-engine coalescing unit test by asserting the handler-layer spend behavior.

Changes:

  • Introduces a gated, protocol-correct upstream server helper to deterministically hold the first upstream pull in-flight while a second same-hash leaf request starts.
  • Refactors node-B test setup to support registering multiple leaf channels (needed to avoid shared voucher state across concurrent leaves).
  • Adds a concurrent server accept helper so node B can handle multiple leaf connections in parallel in tests.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread crates/node/tests/node_origin_pull.rs Resolved
Comment thread crates/node/tests/node_origin_pull.rs Resolved

@gemini-code-assist gemini-code-assist Bot 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.

Code Review

This pull request introduces integration tests and helper functions to verify that concurrent same-hash leaf requests against a node with an empty cache coalesce into a single upstream pull, preventing double-spending. It adds a gated upstream server simulation and refactors Node B's test builder to support multiple concurrent leaf channels. There are no review comments, so I have no feedback to provide.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

@github-actions

github-actions Bot commented Jun 17, 2026 •

Copy link
Copy Markdown

Coverage report

Total: 85.74% (was 85.71%, ▲ +0.03%) — 37241/43436 lines

No coverage data for changed Rust files.

History
Commit Total Δ vs base
5ec1b79 85.74% ▲ +0.02%
06d2e8c (HEAD) 85.74% ▲ +0.03%

Address PR review: the gated upstream's closing-voucher handling silently
ignored a non-Voucher message and still sent StreamEnd. Make it
`let … else { bail! }` so a protocol drift fails server-side with a clear
message instead of an opaque buyer-side stall.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@thiras
thiras merged commit 56733ee into main Jun 17, 2026
20 checks passed
@thiras
thiras deleted the test/895-concurrent-coalesce-single-upstream-pull branch June 17, 2026 02: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.

node: E2E test that concurrent same-hash window pull-through requests open ONE upstream pull (no double spend)

2 participants