spacedb-meter
SpaceDB Layer 6 — metering & settlement.
SpaceDB measures; it does not price or pay. This crate computes the three resource amounts deterministically, accumulates them, and drains them into amounts-only claims. What a claim is worth, and who actually gets paid, sits behind a seam.
Part of SpaceDB. Dual-licensed MIT OR Apache-2.0.
[]
= "0.5"
What gets measured
use Usage;
let = ;
let = ;
let = ;
storage; // byte-seconds × replicas
compute; // deterministic fuel + per-call
transit; // the MINIMUM of the two
Transit takes the minimum of what the server claims it served and what the consumer acknowledges receiving. Bilateral corroboration means neither side can inflate a bill unilaterally — over-claiming simply doesn't pay.
Ledger → claims
use ;
let = ;
let mut ledger = new;
ledger.record;
ledger.record;
// Drain a billing period into per-customer, per-class claims.
let claims = ledger.drain_claims;
A UsageClaim carries a deterministic claim_id (node:settles_to:class:
period_end) — so a retried or duplicated claim dedups instead of double-billing
— the amounts, the period bounds, and an optional ProofRef
(StorageProbe / ComputeAttestation / TransitReceipt) content-addressing
the artifact that backs it, e.g. a FunctionRun digest from
spacedb-query.
Pricing and budgets
RateCard prices storage per GiB-month, compute per megafuel plus per
invocation, and transit per GiB — multiplying before dividing so sub-unit usage
is never silently rounded to zero. estimate(&usages) gives a pre-deploy cost
before anything runs.
Budget is the agent spend cap: can_afford, charge (fails rather than
overdrawing), credit, remaining. An AI agent with a capability gets a
hard ceiling, not a monthly surprise.
The settlement seam
use ;
LocalSettlementships here: price against a rate card, tally per customer. Enough for a self-hoster; no tokens minted.- A host implements
Settlementover its own money plane. For MATA that is the existingUsageClaim → Maestro counter-sign → EarningRecord → Iron Bankloop — so SpaceDB usage settles through it without ever depending on it.
Open-core boundary
Depends on serde / postcard / thiserror only — no spacedb-* and no
mata-* crates.
Performance (0.7.0)
Measured on exact instruction counts (callgrind) with this crate's
deterministic driver, examples/ir_console.rs; outputs unchanged by every change.
Exercised by the console driver (spacedb-console).
LocalSettlementcopies a customer id into its tally only for a new customer.
Testing
The workspace defaults to wasm32; this crate is native. Test on your host
triple:
Suite: meter.rs — measurement determinism, transit corroboration, claim
dedup keys, rate-card rounding, budget exhaustion.
License
MIT OR Apache-2.0, at your option. See LICENSE-MIT and LICENSE-APACHE.