Skip to main content

Crate decdn_incentive

Crate decdn_incentive 

Source
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

AreaModules
Vouchers and meteringvoucher (sign and verify), chain (hash chains), rate (rate checks), credit (credit window), client_bridge (to and from the wire decdn_protocol::Voucher)
Spend delegationcapability (the signed capability), capability_grant (its transferable dcap1: form)
Lane statelane (the seller’s per-lane watermark), store (persistence traits and in-memory stores), deployment (which PaymentPool a state belongs to)
Buyer bookkeepingbuyer_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 signaturesprobe_sig and stream_sig (the slash_sig on probe and stream responses), bind_sig (client bindings), sig_canon (canonical s)
Keyseth_identity (Web3 Secret Storage keystores and the PrivateKeySigner they load)
Contract bindingspayment_pool, capacity_bond, node_register, erc20, slash_judge, slash_appeal, origin_assignment, publisher_registry, content_blacklist
Transactionstx (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 BindNodeId verification for ephemeral client bindings.
buyer_pool
Buyer-side payment-pool bookkeeping (#744).
buyer_pool_redbredb
redb-backed persistent BuyerPoolStore for client-side use (#940).
buyer_pool_tablebuyer-store-core
The buyer-pool redb table: its on-disk record codec and its operations (#1246).
capability
EIP-712 spending capabilities for the PaymentPool contract.
capability_grant
dcap1: — the transferable encoding of a pool owner’s spending crate::capability::SignedCapability.
capacity_bond
CapacityBond contract ABI bindings (ADR 003 § Node Registry, ADR 019).
chain
PayWord hash 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/v1 wire vouchers and the incentive voucher state machine.
content_blacklist
ContentBlacklist contract ABI bindings (ADR 011 § Content Takedown).
credit
Ramped delivery credit window (ADR 003 §Credit window).
deployment
The PaymentPool deployment 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.registerNode signing inputs (ADR 019 § Step 2.3).
origin_assignment
OriginAssignment contract ABI bindings (ADR 011 § Origin Assignment Authority, ADR 022 § FIND_VALUE Flow “Origin discovery”).
payment_pool
PaymentPool contract ABI bindings (ADR 003 § PaymentPool).
pool_open_error
PaymentPool revert decoding: the failure-class taxonomy for the buyer-side openPool path (#966) and the pool-lifecycle reverts.
probe_sig
EIP-712 slash_sig signatures for cdn/probe/v1 ProbeResponse messages.
publisher_registry
PublisherRegistry contract ABI bindings (ADR 002 § Contract: PublisherRegistry).
rate
Rate enforcement for incremental voucher payments.
sig_canon
Canonical-s enforcement for off-chain ECDSA signature verification (#836).
slash_appeal
SlashAppeal contract ABI bindings (ADR 028 § Slashing Appeals).
slash_judge
SlashJudge contract ABI bindings (ADR 014 § Slashing & Disputes).
store
Persistent storage for per-lane voucher state.
stream_sig
EIP-712 slash_sig signatures for cdn/client/v1 StreamResponse messages.
tx
One place to submit a transaction and resolve its outcome (#1355).
voucher
EIP-712 payment vouchers for the PaymentPool contract.

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).