B6: atomic UTXO reservation, bet signed by the worker and saved before broadcast, broadcast verdicts (BET-30..33)
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
2acd4ccd1c
commit
feff993584
25 files changed
+995
-53
No files matched your search
@@ -986,7 +986,7 @@ non è rimosso le sezioni precedenti descrivono lo stato storico. Scelte: [ADR-5
|
||||
cifrata e la chiave che la cifra, due file diversi) si carica solo se `PROCESS_ROLE=worker` e i file sono montati; in
|
||||
qualunque altro processo `signing_account_key()` fallisce con `SigningKeyUnavailable`, anche se i file ci fossero.
|
||||
`manage.py init_keys` crea le chiavi una tantum, scrive i file con modo `0600` e stampa la sola chiave pubblica.
|
||||
*Stato:* implementato (B4); il montaggio dei file nel solo servizio `worker` arriva con B6, quando il worker firma ·
|
||||
*Stato:* implementato (B4); i file sono montati, in sola lettura, nel solo servizio `worker` del compose (`./data/keys`, B6) ·
|
||||
*Codice:* `apps/lottery/keys.py`, `apps/lottery/management/commands/init_keys.py` ·
|
||||
*Test:* `tests/django/test_chain_models.py::test_the_web_process_cannot_load_the_signing_key`, `test_the_worker_can_and_the_files_are_private`
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
|
||||
## Project status (old stack)
|
||||
|
||||
All 10 stages of the original build order are code-complete and unit-tested — 1263 tests, the old stack's under `tests/unit/` and the Django ones under `tests/django/` (`tests/integration/` needs the local regtest node and skips itself without it). Beyond them: Docker + Caddy deployment, admin dashboard (`/admin`), static test UI (`/`), pending-inclusive balance display, an SSE push channel layered over the original polling, self-service password change + admin password reset, and the reconciliation/corroboration machinery below.
|
||||
All 10 stages of the original build order are code-complete and unit-tested — 1288 tests, the old stack's under `tests/unit/` and the Django ones under `tests/django/` (`tests/integration/` needs the local regtest node and skips itself without it). Beyond them: Docker + Caddy deployment, admin dashboard (`/admin`), static test UI (`/`), pending-inclusive balance display, an SSE push channel layered over the original polling, self-service password change + admin password reset, and the reconciliation/corroboration machinery below.
|
||||
|
||||
Verified on mainnet with real money: registration + address derivation, deposit crediting (at the time, 1-conf; deposits now need `deposit_confirmations`), a real 10 PLM bet (broadcast → confirmed → change credited back), and one full round cycle (close → draw on a real block hash → 70/30 payout with sat math checked against the broadcast tx → confirmation → close → next round auto-opened). **Withdrawal and the RBF bump path have never been exercised against a live broadcast** — unit-tested only.
|
||||
|
||||
@@ -30,7 +30,7 @@ PYTHONPATH=. python scripts/decrypt_master_key.py # ops recovery: decrypt+pr
|
||||
PYTHONPATH=. python scripts/encrypt_master_key.py # ops bootstrap: import an externally-generated xprv (--overwrite to replace)
|
||||
PYTHONPATH=. python scripts/electrum_smoke_test.py # manual check: connect, handshake, subscribe to headers, print the tip
|
||||
|
||||
python -m pytest # all 1263 tests
|
||||
python -m pytest # all 1288 tests
|
||||
python -m pytest tests/unit/test_hd.py # one file
|
||||
python -m pytest tests/unit/test_hd.py::test_derivation_is_deterministic # one test
|
||||
```
|
||||
|
||||
@@ -1500,7 +1500,7 @@ Le tabelle di catena (UTXO, versioni delle transazioni, depositi, indici HD) son
|
||||
si elimina. Ogni importo è un intero in unità minime ([DAT-01]) e ogni timestamp è in UTC con fuso ([DAT-02]).
|
||||
*Stato:* implementato (A2) · *Codice:* `apps/lottery/models.py` · *Test:* `tests/django/test_models.py::test_rows_that_carry_money_cannot_be_deleted_with_their_owner`
|
||||
- **[DAT-77]** **Parametri e pause: `LotteryConfig`.** Una sola riga (`id = 1`, vincolo) con quota (10 PLM),
|
||||
durata (600 s), pausa fra round (30 s), conferme richieste a un deposito (1–100, default 6, [DAT-62]; si cambia da `/admin/` con audit e vale subito per gli accrediti successivi), conferme del blocco di estrazione (1–20, default 3), tetto del
|
||||
durata (600 s), pausa fra round (30 s), conferme richieste a un deposito (1–100, default 6, [DAT-62]; si cambia da `/admin/` con audit e vale subito per gli accrediti successivi), conferme del blocco di estrazione (1–20, default 3), commissione di rete in sat/vB (1–5 000, default 1: vale per le transazioni costruite dopo), tetto del
|
||||
montepremi (0 = nessuno) e i tre interruttori di [ADR-57](adr/ADR-57-due-pause-distinte-dopo-round-e-incidente.md):
|
||||
`pause_after_round`, `new_bets_suspended`, `withdrawals_suspended`. Valori non positivi o fuori intervallo
|
||||
sono rifiutati dal database. I parametri si **copiano su `Round` all'apertura** ([DAT-61]); la copia la fa il
|
||||
|
||||
@@ -349,3 +349,39 @@ un solo processo (vedi [architettura.md](architettura.md) e
|
||||
|
||||
Cosa succede a una transazione dopo l'invio — conferma, RBF, abbandono — è
|
||||
descritto in [transazioni-e-riconciliazione.md](transazioni-e-riconciliazione.md).
|
||||
|
||||
## Scommessa reale sul sito Django (B6)
|
||||
|
||||
Con `LEDGER_BACKEND=chain` la scommessa muove monete vere. Le regole di ammissione ([BET-01]…[BET-23]: round, quota, limiti,
|
||||
una scommessa per giocatore e round, saldo in conferma) sono le stesse del ledger simulato. Cambia ciò che segue l'ammissione.
|
||||
|
||||
- **[BET-30]** **Prenotazione atomica degli input.** L'ammissione sceglie le monete del giocatore (confermate, accreditate,
|
||||
non spese e **non prenotate**: i depositi ancora in attesa non contano, [DEP-23]) e le **prenota** nella stessa transazione del
|
||||
database che scrive la scommessa: `Utxo.reserved_by` punta alla transazione della piattaforma, con un `UPDATE` condizionato a
|
||||
`reserved_by` vuoto e a un numero di righe uguale a quello scelto. Due richieste concorrenti non possono quindi spendere la
|
||||
stessa moneta, qualunque sia l'ordine: una prenota, l'altra non trova monete libere. Una moneta prenotata non è mai offerta
|
||||
a un'altra operazione. L'importo che il saldo derivato ([DAT-80]) toglie al giocatore è la quota, subito.
|
||||
*Stato:* implementato (B6) · *Codice:* `apps/lottery/reservation.py`, `apps/lottery/ledger.py:ChainLedger.place_bet` ·
|
||||
*Test:* `tests/django/test_chain_bets.py::test_two_requests_never_reserve_the_same_coin`, `test_a_reserved_coin_is_not_offered_again`, `test_waiting_deposits_are_not_spendable`
|
||||
- **[BET-31]** **Il web non firma; il worker salva prima di trasmettere.** La richiesta web lascia una `ChainTransaction` `building`
|
||||
senza txid, con le monete prenotate e una `Participation` `pending`. Il **worker** (il solo con la chiave, [ARC-78]) costruisce e firma la
|
||||
transazione e, **in una transazione del database**, registra la versione col txid e la transazione grezza ([DAT-83]) e aggiorna
|
||||
la scommessa con l'importo effettivo al montepremi (quota meno commissione di rete, [BET-04]) e l'outpoint ([DAT-63]); **solo dopo**
|
||||
trasmette. Un arresto fra i due passi lascia la transazione firmata e salvata: al giro dopo si ritrasmette la stessa.
|
||||
Senza la chiave (processo non worker, file assenti) il worker non firma nulla e lo dice nei log.
|
||||
*Stato:* implementato (B6) · *Codice:* `apps/lottery/bets.py:sign_pending`, `apps/lottery/keys.py` ·
|
||||
*Test:* `tests/django/test_chain_bets.py::test_the_transaction_is_saved_before_it_is_broadcast`, `test_without_the_signing_key_nothing_is_signed`, `test_the_stake_in_the_pool_is_the_quota_minus_the_fee`
|
||||
- **[BET-32]** **Verdetto della trasmissione** ([TX-04], [TX-20], [TX-21]). Una trasmissione finisce in uno di tre modi: **accettata**
|
||||
(il server risponde col txid, o rifiuta ma almeno un server conosce la transazione, anche con «già nota»), **rifiutata**
|
||||
(rifiuto esplicito **e** il server attivo più il quorum minimo degli altri dicono di non conoscerla) o **incerta** (qualunque altra
|
||||
cosa: timeout, connessione caduta, rifiuto non verificabile). Solo la rifiutata libera le monete: la scommessa passa a `rejected`, il movimento
|
||||
a `failed`, le monete tornano libere, la transazione è `failed` con il motivo. L'accettata porta la transazione a `pending` e la
|
||||
trasmette anche agli altri server. L'incerta non cambia nulla: resta `building` e al giro dopo si ritrasmette la stessa transazione, che un server
|
||||
che l'ha già vista accetta come «già nota».
|
||||
*Stato:* implementato (B6); conferma, RBF e abbandono con prova sono B7 · *Codice:* `apps/lottery/electrum_chain.py:ElectrumChain.broadcast`, `apps/lottery/bets.py:broadcast_pending` ·
|
||||
*Test:* `tests/django/test_chain_bets.py::test_an_accepted_broadcast_makes_the_bet_pending`, `test_a_proven_refusal_frees_the_coins`, `test_an_uncertain_broadcast_frees_nothing_and_is_retried`, `test_already_known_counts_as_accepted`
|
||||
- **[BET-33]** **Esito scritto solo se lo stato non è cambiato** ([TX-26]). Prima di scrivere l'esito di una trasmissione il worker rilegge la
|
||||
transazione nella propria transazione del database e non fa nulla se lo stato o il `current_txid` non sono più quelli con cui ha
|
||||
interrogato la rete.
|
||||
*Stato:* implementato (B6) · *Codice:* `apps/lottery/bets.py:_settle` · *Test:* `tests/django/test_chain_bets.py::test_an_outcome_is_not_written_over_a_changed_row`
|
||||
|
||||
Reference in new issue
Block a user