Skip to content

feat(protocol): ChunkPreimage wire message, drop voucher_interval_mb #1695

Closed as not planned

Description

@yigitdot

Implements the wire half of the PayWord model landed in ADR 003 / ADR 005 by #1692 (issue #1670).

Spec: ADR 005 § Preimage wire format, § Chunk cadence, ADR 003 § Chain length and rollover.

Scope

crates/protocol/src/client.rs

New ClientMessage variant at discriminant 4, pushing StreamEnd to 5. Pre-launch, so renumber in place — no shim, per CLAUDE.md.

ChunkPreimage { preimage: [u8; 32], index: u8 }

Fixed-width 33 bytes, preimage ‖ index, no length prefix and no varint. Unsigned — a preimage proves its own index by hashing forward to the voucher's chain_root.

The byte IS the index. Releasable indices are 1..=255 and encode directly. There is no index − 1 tag on send and no + 1 on receipt. Index 0 is the redeem-side settlement case and never travels; index == 0 on the wire is a protocol error. This is why the constant is 255 rather than 256 — an off-by-one here is a payment bug, so the encoding is built to have nowhere for one to live.

pub const MAX_CHAIN_LENGTH: u8 = 255;   // fits u8 exactly — no widening, no conversion
pub const CHUNK_BYTES: u64 = 1_048_576; // protocol constant, never negotiated

Wire Voucher (:639-645) gains chain_root and chunk_price — neither is derivable from stream context (the root is the payer's secret-derived value; the price is signed so the node cannot substitute its own).

Deletions — DEFAULT_VOUCHER_INTERVAL_MB (:59), MAX_VOUCHER_INTERVAL_MB (:65), the voucher_interval_mb fields on StreamRequest/StreamResponse, their range validation (:328-330, :493-495), and VoucherIntervalOutOfRange (message.rs:116-126). There is no cadence to negotiate.

VoucherRejectReason gains BadPreimage and ChainExhausted (mirrors #1694's PoolError variants). WatermarkBundle is now attached on four reasons, not three — BadPreimage joins, because the node's cumulative amount plus the signer's own chunk_price give the chain index, which is what the signer needs to re-derive and resume. A ChunkPreimage carries no signature, so the bundle gate on BadPreimage is the lane (an accepted voucher from the authorized signer already exists), not the rejected message's signature.

crates/client-pull/src/ledger.rs — next_voucher / Cumulative move to the claim model. Anchors compute amount = ⌈bytes_delivered × chunk_price / CHUNK_BYTES⌉ — the round-up moves from bytes to price, which is what makes 1.5 MB settle at 15 base units instead of 20. Preimage release replaces per-interval voucher signing on the steady path; a closing zero-root amount-voucher settles the remainder.

crates/common/src/config/mod.rs — remove DEFAULT_VOUCHER_INTERVAL_MB (:333) and the payment.voucher_interval_mb config key (types.rs:774-803, resolved.rs:434-446). credit_window_bytes stays (it is #1669's).

Tests worth having

  • ChunkPreimage round-trips at exactly 33 bytes; index 1 and index 255 both encode to the literal byte
  • index == 0 on the wire rejected as a protocol error
  • discriminant renumbering: StreamEnd decodes at 5
  • amount = ⌈bytes × chunk_price / CHUNK_BYTES⌉ — the 1.5 MB → 15 units case specifically
  • no voucher_interval_mb key survives config resolution

Blocked on #1692 merging. Pairs with #1693 (contracts) and #1694 (incentive) — the reject-reason mirror spans this issue and #1694, so they want landing together.

🤖 Generated with Claude Code

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

    No labels
    No labels

    Type

    No type

    Fields

    Priority

    None yet

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions