B5: real deposits on the ORM, Electrum scan with quorum and merkle proof, configurable threshold (DEP-20..23, ELC-31)
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
f1d09075a1
commit
2acd4ccd1c
21 files changed
+1223
-49
No files matched your search
@@ -356,3 +356,15 @@ B-83).
|
||||
corrente resta visibile anche nella barra di stato della catena di `/` (da
|
||||
`chain_tip_height` di `GET /rounds/current`).
|
||||
*Codice:* `app/electrum/listener.py:ElectrumListener.current_endpoint`, `app/main.py:health` · *Test:* `tests/unit/test_observability.py`
|
||||
|
||||
## Server del sito Django (B5)
|
||||
|
||||
- **[ELC-31]** **Elenco dei server.** `ELECTRUM_SERVERS` elenca i server separati da virgola, nel formato di [ELC-19]
|
||||
(`host:porta[:notls][:pin=<sha256>]`); il primo è il preferito, gli altri la rotazione e il quorum. Il giro dei depositi usa il
|
||||
primo che risponde **e** ha il genesis del profilo di rete ([ELC-30]); gli altri sono interrogati per la corroborazione con
|
||||
la regola di [ELC-14]. Con `LEDGER_BACKEND=chain` il sito rifiuta di partire senza server o con meno di tre,
|
||||
salvo `ELECTRUM_ALLOW_NO_QUORUM=true`, che vale **solo fuori da `mainnet`** (regola ridotta di [ELC-14]).
|
||||
*Stato:* implementato (B5) · *Codice:* `config/settings.py` (`ELECTRUM_SERVERS`), `plm_engine/electrum/client.py:parse_server_list`,
|
||||
`apps/lottery/electrum_chain.py:ElectrumChain` ·
|
||||
*Test:* `tests/django/test_electrum_chain.py`, `tests/django/test_network_profile.py`
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
|
||||
## Project status (old stack)
|
||||
|
||||
All 10 stages of the original build order are code-complete and unit-tested — 1211 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 — 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.
|
||||
|
||||
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 1211 tests
|
||||
python -m pytest # all 1263 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 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), 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
|
||||
|
||||
@@ -393,3 +393,35 @@ corso (`has_pending`).
|
||||
la scommessa [scommesse-e-prelievi.md](scommesse-e-prelievi.md), B-96).
|
||||
*Codice:* `app/withdrawals/service.py:request_withdrawal`, `app/bets/service.py:place_bet` ·
|
||||
*Test:* `tests/unit/test_withdrawals.py`
|
||||
|
||||
## Depositi sul sito Django (B5)
|
||||
|
||||
Il sito Django riscrive i depositi sull'ORM con lo stesso comportamento di [DEP-01]…[DEP-08] dove non diversamente detto.
|
||||
Le parti dopo l'accredito (monete spese altrove, reintegro, riorganizzazioni oltre la soglia: [DEP-06]…[DEP-08]) sono B7.
|
||||
|
||||
- **[DEP-20]** **Tre fasi, il database mai aperto durante la rete.** Un giro del worker (`scan_deposits`) **legge** dal database
|
||||
indirizzi di deposito, monete note, txid della piattaforma e soglie; **interroga** i server Electrum senza alcuna
|
||||
transazione aperta; **scrive** solo i casi verificati, ricontrollando lo stato di ogni moneta al salvataggio. Un
|
||||
server che non risponde non produce scritture: l'indirizzo si riprova al giro dopo. Il giro gira solo con `LEDGER_BACKEND=chain`.
|
||||
*Stato:* implementato (B5) · *Codice:* `apps/lottery/deposits.py:scan_deposits`, `apps/lottery/electrum_chain.py:ElectrumChain.observe` ·
|
||||
*Test:* `tests/django/test_deposits.py`, `tests/integration/test_deposits_regtest.py`
|
||||
- **[DEP-21]** **Soglie.** Una moneta sotto `DUST_LIMIT_SATS` (294) o ancora in mempool (altezza 0) è ignorata. Le conferme sono
|
||||
`punta − altezza + 1`. La soglia è **1** per una transazione della piattaforma (uno qualunque dei suoi txid,
|
||||
[DAT-83]), **120** per una coinbase (stabilita dalla transazione grezza, accettata solo se il suo hash è il txid),
|
||||
altrimenti **`deposit_confirmations`** di `LotteryConfig` ([DAT-77]), letta a ogni giro.
|
||||
*Stato:* implementato (B5) · *Codice:* `apps/lottery/deposits.py:threshold_for`, `apps/lottery/electrum_chain.py:ElectrumChain.is_coinbase` ·
|
||||
*Test:* `tests/django/test_deposits.py::test_a_deposit_is_credited_exactly_at_its_threshold`, `test_the_threshold_is_the_configured_one`, `test_a_coinbase_needs_120`, `test_our_own_transactions_need_one`, `test_dust_and_mempool_coins_are_ignored`
|
||||
- **[DEP-22]** **Accredito verificato e idempotente.** Una moneta sopra la soglia è accreditata solo se la corroborano gli altri
|
||||
server ([ELC-14], [ELC-17]) **e** una prova merkle verificata contro un header che ha lavoro valido per il profilo di rete
|
||||
la colloca nel blocco indicato ([ELC-26]). L'accredito è un solo `Movement` di tipo `deposit` che passa da `pending` a
|
||||
`confirmed`, il `Deposit` passa a `credited` e l'audit scrive `deposit_credited`, nella stessa transazione. Una moneta già
|
||||
accreditata non si accredita mai due volte (unicità dell'outpoint, [DAT-82]). Se la verifica non riesce, l'accredito è
|
||||
rimandato al giro dopo, non perso.
|
||||
*Stato:* implementato (B5) · *Codice:* `apps/lottery/deposits.py:apply_observations` ·
|
||||
*Test:* `tests/django/test_deposits.py::test_an_unverified_deposit_is_deferred_not_lost`, `test_scanning_twice_credits_once`, `test_the_credit_is_audited`
|
||||
- **[DEP-23]** **Depositi in attesa e sparizione prima dell'accredito.** Una moneta confermata ma sotto soglia è un `Deposit`
|
||||
`detected` con un `Movement` `pending` (il giocatore la vede «in conferma», [WEB-21]). Se sparisce dall'elenco, e gli
|
||||
altri server confermano che non c'è più, il deposito diventa `orphaned` e il movimento `failed`; se ricompare torna `detected`.
|
||||
*Stato:* implementato (B5) · *Codice:* `apps/lottery/deposits.py:apply_observations` ·
|
||||
*Test:* `tests/django/test_deposits.py::test_a_waiting_deposit_shows_as_incoming`, `test_a_vanished_waiting_deposit_is_orphaned_and_can_return`
|
||||
|
||||
Reference in new issue
Block a user