Repository navigation
test(node): pin no-double-spend coalescing for concurrent same-hash pulls (#895) - #924
Conversation
…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]>
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
Coverage reportTotal: 85.74% (was 85.71%, ▲ +0.03%) — 37241/43436 lines No coverage data for changed Rust files. History
|
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]>
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.
TeeOpen::InFlightand waits onawait_coalesced_fillinstead of opening a second upstream pull (which would double-spend real USDC on the B↔A channel).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 existingserve_wrong_bytes/spawn_lying_node_a) signals once B's single upstreamStreamRequestlands, 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)
build_node_bintobuild_node_b_with_leaves(&[(channel, addr, deposit)]); the single-leaf form is a thin wrapper, so existing callers are untouched.spawn_server_concurrent— the existing inlinesupport::spawn_serverawaitshandler.acceptinline 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-targetsandcargo 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