Expand description
The deCDN payment layer: USDC payment pools, the off-chain vouchers that pay them down, and the signatures and contract bindings that tie them to the chain.
A client pays a node per megabyte from a PaymentPool deposit (ADR 003).
The pool owner opens a pool on chain and authorizes spenders off chain with
a signed Capability. Each spender pays each node on its own lane, a
(pool, signer, provider) triple, with cumulative EIP-712 Vouchers. A
PayWord hash chain advances a voucher between signatures, one preimage per
delivered chunk (ADR 003 § Hash-chain metering). The node redeems the
highest voucher on each lane with redeem or redeemMany.
§Modules
| Area | Modules |
|---|---|
| Vouchers and metering | voucher (sign and verify), chain (hash chains), rate (rate checks), credit (credit window), client_bridge (to and from the wire decdn_protocol::Voucher) |
| Spend delegation | capability (the signed capability), capability_grant (its transferable dcap1: form) |
| Lane state | lane (the seller’s per-lane watermark), store (persistence traits and in-memory stores), deployment (which PaymentPool a state belongs to) |
| Buyer bookkeeping | buyer_pool (the buyer’s pools and lanes), buyer_pool_table and buyer_pool_redb (an on-disk redb store, behind the buyer-store-core and redb features) |
| Response signatures | probe_sig and stream_sig (the slash_sig on probe and stream responses), bind_sig (client bindings), sig_canon (canonical s) |
| Keys | eth_identity (Web3 Secret Storage keystores and the PrivateKeySigner they load) |
| Contract bindings | payment_pool, capacity_bond, node_register, erc20, slash_judge, slash_appeal, origin_assignment, publisher_registry, content_blacklist |
| Transactions | tx (send, await the receipt, fail on a revert), pool_open_error (PaymentPool revert decoding) |
§Sign and verify a voucher
use alloy::primitives::{Address, B256, U256};
use alloy::signers::local::PrivateKeySigner;
use decdn_incentive::{Voucher, voucher_domain};
let payer = PrivateKeySigner::random();
let domain = voucher_domain(421_614, Address::repeat_byte(0x11));
let voucher = Voucher {
pool_id: B256::repeat_byte(0x22),
signer: payer.address(),
provider: Address::repeat_byte(0x33),
amount: U256::from(1_000),
bytes_delivered: U256::from(1_048_576),
chain_root: B256::ZERO,
chunk_price: U256::ZERO,
};
let signed = voucher.sign(&payer, &domain)?;
signed.verify_signer(payer.address(), &domain)?;§Who drives settlement
This crate holds the primitives. The decdn-node daemon drives both sides
of settlement with them. As a seller, it records each lane’s watermark from
the PoolOpened and Redeemed events, redeems every lane worth the gas on a
sweep that runs well inside a closing pool’s grace window, and forgets a
reclaimed pool. As a buyer on a cache miss,
it approves USDC once, opens or tops up a pool, signs the vouchers, and
closes and reclaims a pool it no longer uses.
Re-exports§
pub use bind_sig::BindError;pub use bind_sig::CAPACITY_BOND_DOMAIN_NAME;pub use bind_sig::CAPACITY_BOND_DOMAIN_VERSION;pub use bind_sig::EPHEMERAL_BINDING_NONCE;pub use bind_sig::bind_node_id_domain;pub use bind_sig::binding_signing_hash;pub use bind_sig::register_node_signing_hash;pub use bind_sig::verify_binding;pub use buyer_pool::AdvanceOutcome;pub use buyer_pool::BuyerLaneProgress;pub use buyer_pool::BuyerLoad;pub use buyer_pool::BuyerPoolState;pub use buyer_pool::BuyerPoolStore;pub use buyer_pool::BuyerProgressError;pub use buyer_pool::DepositOutcome;pub use buyer_pool::MemoryBuyerPoolStore;pub use capability::Capability;pub use capability::CapabilityError;pub use capability::SignedCapability;pub use capability_grant::CapabilityGrant;pub use capability_grant::GrantError;pub use capability_grant::GrantOwnerError;pub use chain::ChainMeterError;pub use chain::pack_chain_meter;pub use chain::preimage_at;pub use chain::random_seed;pub use chain::root_from_seed;pub use chain::verify_forward;pub use client_bridge::RetrySignal;pub use client_bridge::WireVoucherError;pub use client_bridge::signed_to_wire_voucher;pub use client_bridge::voucher_reject_reason;pub use client_bridge::wire_voucher_to_signed;pub use credit::ramped_credit_window;pub use deployment::Deployment;pub use erc20::Erc20;pub use lane::FoldAxis;pub use lane::LaneChain;pub use lane::LaneKey;pub use lane::LaneState;pub use lane::PoolError;pub use lane::PoolId;pub use lane::PreimageApplied;pub use lane::RedeemClaim;pub use lane::VoucherApplied;pub use pool_open_error::PoolLifecycleRevert;pub use pool_open_error::PoolOpenFailureReason;pub use pool_open_error::is_erc20_allowance_shortfall;pub use pool_open_error::is_pool_not_open;pub use probe_sig::PROBE_RESPONSE_TYPEHASH;pub use probe_sig::ProbeSlashData;pub use probe_sig::ProbeSlashError;pub use probe_sig::SLASH_JUDGE_DOMAIN_NAME;pub use probe_sig::SLASH_JUDGE_DOMAIN_VERSION;pub use probe_sig::slash_judge_domain;pub use rate::BYTES_PER_MB;pub use rate::DEFAULT_TOLERANCE_BPS;pub use rate::RateError;pub use rate::min_payment;pub use rate::pool_budget_covers;pub use rate::verify_rate;pub use store::CheckpointKey;pub use store::KeyedCheckpointStore;pub use store::MemoryPoolStateStore;pub use store::PendingSettle;pub use store::PendingSettleStore;pub use store::PoolStateStore;pub use store::StoreError;pub use stream_sig::STREAM_RESPONSE_TYPEHASH;pub use stream_sig::StreamSlashData;pub use stream_sig::StreamSlashError;pub use voucher::DOMAIN_NAME;pub use voucher::DOMAIN_VERSION;pub use voucher::SignedVoucher;pub use voucher::Voucher;pub use voucher::VoucherError;pub use voucher::voucher_domain;
Modules§
- bind_
sig - EIP-712
BindNodeIdverification for ephemeral client bindings. - buyer_
pool - Buyer-side payment-pool bookkeeping (#744).
- buyer_
pool_ redb redb redb-backed persistentBuyerPoolStorefor client-side use (#940).- buyer_
pool_ table buyer-store-core - The buyer-pool
redbtable: its on-disk record codec and its operations (#1246). - capability
- EIP-712 spending capabilities for the
PaymentPoolcontract. - capability_
grant dcap1:— the transferable encoding of a pool owner’s spendingcrate::capability::SignedCapability.- capacity_
bond CapacityBondcontract ABI bindings (ADR 003 § Node Registry, ADR 019).- chain
PayWordhash chains: the per-lane meter that advances a voucher’s settlement anchor without a signature (ADR 003 §Hash-chain metering (PayWord)).- client_
bridge - Bridge between
cdn/client/v1wire vouchers and the incentive voucher state machine. - content_
blacklist ContentBlacklistcontract ABI bindings (ADR 011 § Content Takedown).- credit
- Ramped delivery credit window (ADR 003 §Credit window).
- deployment
- The
PaymentPooldeployment a piece of pool state belongs to. - erc20
- Minimal ERC-20 ABI binding for the buyer-side USDC approval flow (#744).
- eth_
identity - Ethereum keystore: generate, persist, and load a Web3 Secret Storage v3
file into a live
alloy::signers::local::PrivateKeySigner. - lane
- Per-lane voucher state tracking.
- node_
register - Off-chain construction of the
CapacityBond.registerNodesigning inputs (ADR 019 § Step 2.3). - origin_
assignment OriginAssignmentcontract ABI bindings (ADR 011 § Origin Assignment Authority, ADR 022 § FIND_VALUE Flow “Origin discovery”).- payment_
pool PaymentPoolcontract ABI bindings (ADR 003 §PaymentPool).- pool_
open_ error PaymentPoolrevert decoding: the failure-class taxonomy for the buyer-sideopenPoolpath (#966) and the pool-lifecycle reverts.- probe_
sig - EIP-712
slash_sigsignatures forcdn/probe/v1ProbeResponsemessages. - publisher_
registry PublisherRegistrycontract ABI bindings (ADR 002 § Contract:PublisherRegistry).- rate
- Rate enforcement for incremental voucher payments.
- sig_
canon - Canonical-
senforcement for off-chain ECDSA signature verification (#836). - slash_
appeal SlashAppealcontract ABI bindings (ADR 028 § Slashing Appeals).- slash_
judge SlashJudgecontract ABI bindings (ADR 014 § Slashing & Disputes).- store
- Persistent storage for per-lane voucher state.
- stream_
sig - EIP-712
slash_sigsignatures forcdn/client/v1StreamResponsemessages. - tx
- One place to submit a transaction and resolve its outcome (#1355).
- voucher
- EIP-712 payment vouchers for the
PaymentPoolcontract.
Constants§
- CHUNK_
BYTES - The payment quantum: one chunk of delivery, 1 MiB (ADR 003 §Chunk Cadence).
- MAX_
CHAIN_ LENGTH - The highest chain index: the hash chain’s incremental range over its anchor (ADR 003 §Chain length and rollover).