Skip to content

No test covers the per-chunk ChannelContext rebuild (spent-nonce regression is invisible) #1302

Closed as not planned

Description

@yigitdot

Found during a follow-up review of #1293.

ChunkFetcher::fetch (crates/cli/src/commands/fetch.rs) rebuilds the ChannelContext for every chunk. That is load-bearing: the context snapshots the channel's voucher watermark (prior_nonce), and fetch_blob advances it in the store as it pays. A hoisted context would re-sign a spent nonce on chunk 2 and the node would reject it as StaleNonce.

Nothing in the repo tests this. The correctness chain is:

  1. fetch_blob persists the acked watermark via store.advance_progress
  2. build_channel_ctx -> open_or_reuse re-reads it
  3. the next voucher signs prior_nonce + 1 against the new watermark

Links 1 and 2 have individual coverage (crates/node/tests/anvil_settlement_e2e.rs asserts open_or_reuse resumes from recorded progress), but that test seeds the watermark by calling record_progress directly. No test exercises the composed loop — N sequential paid pulls each rebuilding the context and each producing a strictly increasing nonce.

The file_manifest unit tests structurally cannot cover it: reconstruct is generic over F: Fn([u8;32]) -> Fut and the test double takes only a hash, so the payment layer is outside what they can observe.

Failure mode: someone hoists build_channel_ctx out of the per-chunk loop as an obvious-looking optimization (it does an on-chain reuse check per chunk). It compiles, every test passes, and every multi-chunk download breaks at chunk 2 in production. The saving grace is that it fails loudly rather than corrupting payment state.

Suggested: an anvil-backed test serving a 3-chunk manifest through the real client path, asserting recorded nonces are 1, 2, 3. #1301 makes this materially easier by routing the part directory through the resolved data_dir (it previously hardcoded ~/.decdn/downloads, so any such test would have written to the real $HOME).

Note the anvil-e2e stale-binary gotcha if driving it through the CLI binaries rather than the library path.

Activity

  1. yigitdot commented on Jul 19, 2026

    @yigitdot
    ContributorAuthor

    Closing as already covered — I filed this on a stale reading and should have checked before opening it.

    crates/e2e/tests/cli_fetch_manifest.rs does exercise the composed loop. It serves a 3-chunk manifest from a real node, drives decdn fetch through the real paid path, and then asserts against the persisted store:

    state.last_nonce >= U256::from(chunks.len() as u64)

    Its own comment makes the regression argument explicitly: a hoisted ChannelContext would re-sign a spent nonce, the node would refuse the voucher, and the fetch would fail outright before reaching the assertion — so arriving there already proves per-chunk signing, with the nonce floor as a second check.

    Why I got it wrong: that test landed in the squash-merge of #1293 (b9c2b0a), after the branch state my review ran against (6619dcb). The review correctly reported no coverage for the code as it stood at the time, and I repeated that conclusion without re-checking it against main.

    The one real gap left is narrower and now closed by #1301: nothing asserted chunk parts honor --data-dir. That assertion is added to this same test.

  2. added
    kind:test
    rust
    prio:medium
    on Jul 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    kind:testprio:mediumrust

    Type

    No type

    Fields

    Priority

    None yet

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions