Skip to main content

Module serve_economics

Module serve_economics 

Source
Expand description

Buy-side profitability gate for cache-miss relay legs (ADR 041).

Node-local, config-selectable. Sibling to the ADR-040 cache policies, not part of them: cache policy decides what a node keeps; this decides what a node buys to serve. The policy returns a per-MB buy ceiling; the node_origin buy loop does the candidate scan and the refusal.

Structs§

MarginPolicy
Two-regime ceiling. amortized = (operator_bps/10_000) · n_hat · sell with n_hat = clamp(round(discount · heat), 1, n_max). While the source has warming allowance, buy at the market price max(sell, amortized) (warming); once spent, buy only at amortized (grief-proof). See ADR 041 § The buy ceiling.
OffPolicy
Disables the economic gate; only cache.max_rate_per_mb bounds the buy.
ServeEconomicsCtx
Inputs to the buy ceiling, gathered per cache-miss.

Traits§

ServeEconomicsPolicy
A node-local decision on the most the node pays upstream, per MB.

Functions§

select_policy
Build the configured policy. Unknown names are impossible: config validation restricts policy to "off" | "margin" at load; anything else here falls back to OffPolicy (safe: only the static ceiling applies).