Skip to content

feat(cli,client): decdn get ends with a verifiable pull receipt (#2599) - #2627

Merged
thiras merged 2 commits into
mainfrom
feat/pull-receipt-2599
Oct 26, 2026
Merged

thiras merged 2 commits into
mainfrom
feat/pull-receipt-2599

Conversation

@thiras

@thiras thiras commented Oct 26, 2026

Copy link
Copy Markdown
Contributor

What

decdn get ends with a pull receipt: what the pull landed, which nodes served it, what it paid, and the signatures that prove it. A receipt is assembled from messages the pull already exchanges, so nothing changes on the wire, in the contracts or in the economics.

  • Block at the end of every paid get: the hash, the bytes verified and paid, each node and the bytes it was paid for, the USDC and pool, and the start and end times. It goes to stdout, or to stderr when stdout carries data (-o -) or JSON (--json).

  • --receipt <FILE> writes the receipt as JSON (decdn-receipt/1). Per (pool, signer, provider) lane it holds:

    • the node's first signed StreamResponse for each hash it served;
    • a proof: the voucher that signs the lane's anchor, the deepest revealed chain preimage, and the claim the two prove.

    The path is checked before the pull pays anything. A run that pays nothing writes no receipt, says so, and removes a stale file at that path. A failed or interrupted pull still writes a receipt, marked incomplete, which lists the started blobs that did not land.

  • decdn receipt verify <FILE> re-checks every signature offline against the receipt's chain id, PaymentPool and SlashJudge. On a known chain it also checks those contracts against the build's own; on any other chain it says they went unchecked.

  • decdn receipt settle <FILE> verifies first. It then scans PaymentPool.PoolRedeemed from an hour before the receipt's start, and records for each lane the redemption that covers its claim, or the highest one short of it.

  • adr/appendix-pull-receipts.md says what a receipt proves and what it doesn't. It adds no slashing offense or evidence path, and the appendix covers the privacy cost of publishing one.

Closes #2599

Reviewer notes

  • Read first: crates/client/src/receipt.rs (the collector, the schema, verify), then PoolLedger::proved_frontier and the amount baseline in crates/client/src/ledger.rs.
  • Design decision: the receipt carries no client-signed statement. The fields it would add are self-attested, so a client can sign anything; every check verify runs rests on a node signature or a payer signature.
  • Collection is opt-in: a ReceiptEvidence collector attaches a slot to each lane's PoolLedger, set through LaneDeps::evidence or BundlePullerBuilder::receipt_evidence. Only decdn get sets one, so the node's long-lived upstream ledgers and the gateway keep nothing.
  • The claim is what the kept signatures prove. A rejected or unconfirmed voucher can only make the receipt under-report, never over-report.
  • The prior watermark is the ledger's baseline, now tracked on the amount axis too. A reseed or rebase therefore never counts as the pull's payment.
  • The gateway's /_receipt/<id> page is left to gateway: hosted public HTTP gateway at <ns>.decdn.link that pays a pool behind the scenes #2593.
  • get prints more lines. The block adds lines to stdout after the existing summary line.
  • A known chain's receipts pin to the build's addresses. After a testnet redeploy, older receipts fail verify on a newer build; the error names the mismatched contract.
  • Two small changes outside the feature:
    • The date parser rejects a signed number. This also tightens node earnings --since.
    • Four scan helpers in node::earnings_chain become pub(crate) so that settle can reuse them.

Verification

  • pre-commit run on every changed file (cargo-deny reports the existing crypto-bigint/ctutils advisories, non-blocking)
  • cargo clippy --workspace --all-targets --all-features -- -D warnings
  • cargo nextest run -p decdn-client -p decdn-cli -p decdn-common -p decdn-node: 4515 passed
  • cargo nextest run -p decdn-e2e --features anvil-e2e -E 'binary(/^cli_/) | binary(/^gateway_/) | binary(smoke)': 32 passed, including the new cli_receipt. It covers:
    • blob and bundle get --receipt, then verify;
    • a flipped node-signature bit that fails by name;
    • -o - for a blob and for one entry (two ledgers merged into one lane);
    • a repeat pull that paid nothing;
    • settle after the node's own redemption.
  • Public API of decdn-client: .snap regenerated and re-checked
  • adr/: make -C adr check-refs check-book-list, appendix registered in architecture.md and the book list
  • CARGO_BUILD_WARNINGS=deny cargo doc --workspace --no-deps --document-private-items
  • CHANGELOG.md entry

🤖 Generated with Claude Code

)

Every `decdn get` that paid ends with a receipt block, and `--receipt
<FILE>` writes the receipt as JSON (`decdn-receipt/1`): per lane, the
node's first signed `StreamResponse` for each hash it served and a proof
of the lane's claim (the voucher that signs its anchor and the deepest
revealed chain preimage). `decdn receipt verify` re-checks every
signature offline; `decdn receipt settle` verifies, then records the
`PoolRedeemed` event that covers each lane's claim.

Collection is opt-in through a `ReceiptEvidence` collector attached to
each lane's `PoolLedger`, so node and gateway ledgers keep nothing. The
ledger now tracks an amount baseline beside its byte baseline, and a
lane's prior watermark is that baseline, so a reseed or rebase never
counts as the pull's payment. `adr/appendix-pull-receipts.md` says what
a receipt proves, and that it adds no slashing offense or evidence path.

Closes #2599

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@thiras thiras self-assigned this Oct 26, 2026
Copilot AI balanced review requested due to automatic review settings October 26, 2026 14:27
@github-code-quality

github-code-quality Bot commented Oct 26, 2026 •

Copy link
Copy Markdown

Code coverage overview

Languages: Rust

Rust / code-coverage/cargo-llvm-cov

main e3627ad feat/pull-receipt-25... 4de1563 +/-
77% 77% 0%
View coverage of the 10 most impacted files.
File main e3627ad feat/pull-receipt-25... 4de1563 +/-
crates/cli/src/commands/get.rs 97% 93% -4%
crates/cli/src/main.rs 81% 78% -3%
crates/cli/src/.../bundle_pull.rs 54% 53% -1%
crates/client/s...undle/engine.rs 66% 65% -1%
crates/client/src/bundle.rs 37% 36% -1%
crates/client/src/lanes.rs 66% 65% -1%
crates/cli/src/...mmands/fetch.rs 49% 48% -1%
crates/client/src/scheduler.rs 94% 94% 0%
crates/cli/src/...ands/receipt.rs 0% 67% +67%
crates/client/src/receipt.rs 0% 91% +91%

ℹ️ Calculations represent line coverage. Results may change as calculations are updated.


Updated October 26, 2026 15:37 UTC

@thiras
thiras requested a balanced review from Copilot and removed request for Copilot October 26, 2026 14:49

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.

🟡 Changes recommended

Unresolved file-safety, receipt-accounting, and settlement-validation issues can destroy output or produce misleading receipts.

6 open issues
What changed in this PR

Adds verifiable pull receipts to decdn get, preserving existing node responses and payer signatures without changing the wire protocol or contracts.

Changes:

  • Collects receipt evidence and prints a summary after paid downloads, with optional JSON output.
  • Adds offline signature verification and on-chain settlement lookup.
  • Documents receipt guarantees and privacy limits, with unit and end-to-end coverage.
File Description
README.md Documents receipt commands and usage.
crates/​e2e/​tests/​cli_receipt.rs Tests download, verification, and settlement journeys.
crates/​common/​src/​cli/​receipt.rs Defines verify and settle arguments.
crates/​common/​src/​cli/​mod.rs Registers the receipt command.
crates/​common/​src/​cli/​get.rs Adds the --receipt option.
crates/​client/​tests/​snapshots/​public_api__public_api.snap Updates the SDK API snapshot.
crates/​client/​src/​receipt/​tests.rs Tests collection, accounting, signatures, and serialization.
crates/​client/​src/​receipt.rs Implements receipt collection, schema, and verification.
crates/​client/​src/​lib.rs Captures signed responses and vouchers.
crates/​client/​src/​ledger.rs Exposes receipt evidence and tracks amount baselines.
crates/​client/​src/​lanes/​tests.rs Updates lane fixtures for optional evidence.
crates/​client/​src/​lanes.rs Attaches collectors to lane ledgers.
crates/​client/​src/​lane_sources/​tests.rs Updates the lane-source fixture.
crates/​client/​src/​bundle/​engine.rs Records bundle evidence and landed sizes.
crates/​client/​src/​bundle.rs Adds the receipt collector builder option.
crates/​cli/​src/​main.rs Dispatches receipt commands.
crates/​cli/​src/​commands/​receipt/​tests.rs Tests receipt output, files, and settlement handling.
crates/​cli/​src/​commands/​receipt.rs Implements receipt persistence, display, and commands.
crates/​cli/​src/​commands/​node/​earnings_chain.rs Exposes scan helpers for reuse.
crates/​cli/​src/​commands/​node.rs Makes earnings helpers crate-accessible.
crates/​cli/​src/​commands/​mod.rs Exports the receipt command module.
crates/​cli/​src/​commands/​get.rs Adds receipt preflight and finalization.
crates/​cli/​src/​commands/​fetch.rs Collects evidence during blob fetches.
crates/​cli/​src/​commands/​civil_time/​tests.rs Tests timestamp formatting and strict parsing.
crates/​cli/​src/​commands/​civil_time.rs Adds receipt timestamps and tightens date parsing.
crates/​cli/​src/​commands/​bundle_pull/​tests.rs Updates bundle fixtures for receipt collection.
crates/​cli/​src/​commands/​bundle_pull.rs Passes collectors through bundle pulls.
CHANGELOG.md Records the receipt feature and parser change.
adr/​Makefile Includes the receipt appendix in the book.
adr/​architecture.md Links the receipt appendix.
adr/​appendix-pull-receipts.md Defines receipt evidence, limits, and privacy implications.

Review effort: Balanced

Comment thread crates/cli/src/commands/get.rs Resolved
Comment thread crates/cli/src/commands/get.rs Resolved
Comment thread crates/cli/src/commands/receipt.rs Resolved
Comment thread crates/cli/src/commands/fetch.rs Resolved
Comment thread crates/client/src/receipt.rs Resolved
Comment thread crates/client/src/receipt.rs Resolved
…nt, sizes, merges

- `--receipt` may not name the blob's destination or a bundle entry's;
  a dry run and a failed run leave an existing receipt alone.
- `settle` rebuilds every settlement from the events it scans, so one
  the file holds and the chain does not show is dropped.
- A fetched blob is recorded at the length it verified to, not at the
  first size claim.
- An incomplete pull lists its requested hash in `unlanded` when a node
  accepted it and it did not land.
- Two ledgers on one lane merge to the sum of what each paid, so a
  reseed in the second never counts as the pull's payment.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@thiras
thiras merged commit 3b079e7 into main Oct 26, 2026
34 checks passed
@thiras
thiras deleted the feat/pull-receipt-2599 branch October 26, 2026 15:41
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.

client: decdn get ends with a signed receipt (hash, bytes, nodes, USDC paid, settlement once it lands)

2 participants