A3: simulated ledger with idempotency (WEB-22, WEB-23, ADR-59, ARC-75..77, DAT-80)

One Ledger interface (deposit, bet, confirm, reject, exclude, payout) with a
simulated implementation chosen by LEDGER_BACKEND, refused on mainnet. Every
operation is a single write-locked transaction with its audit row; the same
request key is the same operation, a key reused for something else is an
error. The server validates round, deadline, the round's own quota, limits and
funds. The balance is derived from the ledger. Tests include six processes
racing on one SQLite file; the idempotency tests were checked to fail when
the replay is removed.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
davideandClaude Sonnet 5.5 committed 2026-11-16 13:23:29 +01:00
1 parent 0eba7bcfe6
commit eded058dbb
12 files changed
+924 -4

No files matched your search

+6
View File
@@ -1525,3 +1525,9 @@ Le tabelle di catena (UTXO, versioni delle transazioni, depositi, indici HD) arr
[ADR-56](adr/ADR-56-staff-account-individuali-permessi-mfa-dopo-pilota.md)); username unico senza distinzione fra
maiuscole ([DAT-06]), memorizzato come digitato.
*Stato:* implementato (A1) · *Codice:* `apps/accounts/models.py` · *Test:* `tests/django/test_scaffold.py::test_usernames_are_unique_ignoring_case`
- **[DAT-80]** **Il saldo si deriva dal libro mastro.** `balance_of(user)` somma le righe di `Movement`:
**spendibile** = righe `confirmed` + addebiti `pending` (una puntata o un prelievo in corso riserva subito il suo
importo); **in conferma** = accrediti `pending`; le righe `failed` non contano. Non esiste un saldo memorizzato
accanto alle righe, quindi non può divergere da esse.
*Stato:* implementato (A3) · *Codice:* `apps/lottery/balances.py:balance_of` ·
*Test:* `tests/django/test_ledger.py::test_a_pending_deposit_is_incoming_not_spendable`, `test_a_whole_round_conserves_the_money`