refine blockchain integration and protocols

This commit is contained in:
Dobromir Popov
2026-07-02 21:14:15 +02:00
parent c3d22c895e
commit 416ceba0f6
8 changed files with 306 additions and 6 deletions

View File

@@ -0,0 +1,25 @@
Status: ready-for-agent
# 31 — Billing ledger: per-token pricing, 90/10 split, pending balances
## What to build
Tracker-side off-chain billing per ADR-0015. Each model preset gets a USDT `price_per_1k_tokens` in tracker config. When a request completes, the tracker debits the client's API-key ledger balance (`price × total_tokens / 1000`) and credits 90% to the serving nodes' pending balances proportional to work units (layers × tokens, reusing the existing `ComputeAttribution`), with 10% accruing to the protocol cut. API keys with insufficient balance are rejected with HTTP 402 before any routing happens — no free work.
The ledger persists in the existing tracker SQLite store and replicates across the tracker hive so any follower can serve balance reads.
This story is pure off-chain accounting — no Solana calls.
## Acceptance criteria
- [ ] Per-model `price_per_1k_tokens` in tracker config with sane defaults
- [ ] Completed request debits client ledger: `price × total_tokens / 1000`
- [ ] 90% split across serving nodes by work_units; 10% accrues to `protocol_cut`
- [ ] Insufficient balance → HTTP 402 before routing
- [ ] Balances survive tracker restart (SQLite) and replicate to hive followers
- [ ] Unit tests: single-node route, 3-node split, exhausted balance, restart persistence
## Blocked by
- `23-heartbeat-stats.md`
- `25-rolling-rpm-stats.md`