Skip to main content

decdn_incentive/
lib.rs

1//! Incentive layer for deCDN.
2//!
3//! Manages off-chain USDC payment pools, bonding interactions via
4//! `CapacityBond`, and voucher lifecycle (creation, validation, on-chain
5//! settlement).
6//!
7//! Exposes the off-chain payment-voucher primitives — EIP-712
8//! signing/verification ([`voucher`]) — required for `cdn/client/v1`, the
9//! keystore→signer bridge ([`eth_identity`], #406) used by both
10//! `decdn key-gen` and the runtime to load a `PrivateKeySigner`, and the
11//! `alloy::sol!` contract bindings for the on-chain surface the node consumes
12//! ([`capacity_bond`] reads, [`payment_pool`] reads + writes, [`erc20`]
13//! approve). A `PaymentPool` fans one owner's deposit out across many capped
14//! signers and many nodes: the owner opens a pool with `openPool`, authorizes
15//! each signer off-chain with a [`capability::Capability`], and a signer's
16//! per-`(pool, provider)` voucher lane accrues cumulative amount/bytes as
17//! `redeem`/`redeemMany` pays it down. The seller-side on-chain settlement
18//! path (`PoolOpened`/`Redeemed` → persist per-lane watermark in
19//! [`lane::LaneState`], `PoolCloseInitiated` → grace-window monitor,
20//! `PoolReclaimed` → forget) is fully driven by the `decdn-node` runtime. So
21//! is the buyer-side cache-miss path (one-time USDC approve,
22//! `openPool`/`topUp`, `closePool` + `reclaim` on abandonment; bookkeeping in
23//! [`buyer_pool`]): the runtime bootstraps the approval and the reclaim
24//! sweep, and its node-to-node pull-through origin drives pool open/reuse
25//! and voucher signing on a miss.
26
27pub mod bind_sig;
28pub mod buyer_pool;
29pub mod credit;
30pub mod deployment;
31// NOTE: no outer `///` docs on these two — each module's `//!` header is its
32// documentation. An outer doc here would be a second copy free to drift, and
33// rustdoc merges it with the `//!` block and resolves the result in *this*
34// module's scope, silently breaking the module's own intra-doc links.
35#[cfg(feature = "redb")]
36pub mod buyer_pool_redb;
37#[cfg(feature = "buyer-store-core")]
38pub mod buyer_pool_table;
39pub mod capability;
40pub mod capability_grant;
41pub mod capacity_bond;
42pub mod chain;
43pub mod client_bridge;
44pub mod content_blacklist;
45pub mod erc20;
46pub mod eth_identity;
47pub mod lane;
48pub mod node_register;
49pub mod origin_assignment;
50pub mod payment_pool;
51pub mod pool_open_error;
52pub mod probe_sig;
53pub mod publisher_registry;
54pub mod rate;
55pub mod sig_canon;
56pub mod slash_appeal;
57pub mod slash_judge;
58pub mod store;
59pub mod stream_sig;
60pub mod tx;
61pub mod voucher;
62
63pub use bind_sig::{
64    BindError, CAPACITY_BOND_DOMAIN_NAME, CAPACITY_BOND_DOMAIN_VERSION, EPHEMERAL_BINDING_NONCE,
65    bind_node_id_domain, binding_signing_hash, register_node_signing_hash, verify_binding,
66};
67pub use buyer_pool::{
68    AdvanceOutcome, BuyerLaneProgress, BuyerLoad, BuyerPoolState, BuyerPoolStore,
69    BuyerProgressError, DepositOutcome, MemoryBuyerPoolStore,
70};
71pub use capability::{Capability, CapabilityError, SignedCapability};
72pub use capability_grant::{CapabilityGrant, GrantError, GrantOwnerError};
73pub use chain::{
74    CHUNK_BYTES, ChainMeterError, MAX_CHAIN_LENGTH, pack_chain_meter, preimage_at, random_seed,
75    root_from_seed, verify_forward,
76};
77pub use client_bridge::{
78    RetrySignal, WireVoucherError, signed_to_wire_voucher, voucher_reject_reason,
79    wire_voucher_to_signed,
80};
81pub use credit::ramped_credit_window;
82pub use deployment::Deployment;
83pub use erc20::Erc20;
84pub use lane::{
85    FoldAxis, LaneChain, LaneKey, LaneState, PoolError, PoolId, PreimageApplied, RedeemClaim,
86    VoucherApplied,
87};
88pub use pool_open_error::{PoolOpenFailureReason, is_erc20_allowance_shortfall, is_pool_not_open};
89pub use probe_sig::{
90    PROBE_RESPONSE_TYPEHASH, ProbeSlashData, ProbeSlashError, SLASH_JUDGE_DOMAIN_NAME,
91    SLASH_JUDGE_DOMAIN_VERSION, slash_judge_domain,
92};
93pub use rate::{
94    BYTES_PER_MB, DEFAULT_TOLERANCE_BPS, RateError, min_payment, pool_budget_covers, verify_rate,
95};
96pub use store::{
97    CheckpointKey, KeyedCheckpointStore, MemoryPoolStateStore, PendingSettle, PendingSettleStore,
98    PoolStateStore, StoreError,
99};
100pub use stream_sig::{STREAM_RESPONSE_TYPEHASH, StreamSlashData, StreamSlashError};
101pub use voucher::{
102    DOMAIN_NAME, DOMAIN_VERSION, SignedVoucher, Voucher, VoucherError, voucher_domain,
103};