A user could bet and then double-spend the 1-conference deposit that funded the bet with a private chain: the bet left the chain but its participant stayed `confirmed`, and the payout failed "insufficient pool UTXOs" for ever with everyone else's money stuck. Coinbase outputs were also credited at 1 confirmation (maturity is 120). Deposits - `round_config.deposit_confirmations` (default 6, 1-100, editable from /admin) is the threshold for a deposit; an output of a platform transaction (any txid of a pending_transactions row, RBF versions included) keeps 1; a coinbase output needs 120, recognised from the raw transaction, which must hash to the txid (`is_coinbase`, cached). `read_deposit_policy` / `classify_new_deposits` run between the read and the write, so no session is open across the lookup. - The quorum must also place the coin deep enough on our own tip (ELC-17). - Confirmed outputs short of their threshold are pending deposits (memory only, replaced at every refresh): shown in `pending_balance_sats` / `has_pending` (also for DEP-13's withdrawal message), never spendable. No scripthash notification announces a maturing deposit, so each new block refreshes only the users that have one, one task per user (DEP-09 now says so). Payout - `_trigger_payout` verifies the round's confirmed participants' bet outputs with the other servers (`verify_pool_outpoints`: strict majority of >= 2 answers per outpoint, a mempool-only coin or a tie gives no verdict) and builds from exactly those outpoints (RND-22), never from whatever else sits at the address. No quorum: `payout_failed`, `pool verification unavailable`, nothing changes. Bets that are gone become `reorged_out`, one `participant_reorged_out` row each, `pool_amount_sats` rewritten (only downward) in the same transaction, and the 70/30 split is computed on what is left. - Winner's own bet gone: nothing is built; `rounds.payout_blocked_at` (Alembic f2c64a8d1e93, with `deposit_confirmations`, plain add_column) is set, `payout_blocked` and the pause with `paused_reason = 'payout_blocked'` are written in one transaction; `POST /admin/resume` clears the mark and the next attempt verifies again. /admin/rounds returns it. - Rounds opened before B-80 (pool = the shared reserve address) keep the old active-server `listunspent` choice, since that address holds no single round's bets. Ambiguities resolved: the winner's row stays `confirmed` while held (AUD-45 says every participant whose bet is gone becomes `reorged_out`, but OPS-30/DAT-68 need the verification to repeat after the resume, which only a `confirmed` row allows); `/`'s deposit hint no longer says "1 confirmation" (7 languages, same keys); guides updated. Tests changed because the spec changed: listener tests that credited height-100 coins at tip 0 now set a tip past every threshold; the payout fixtures seed confirmed participants (the new source of the inputs) instead of an active-server `listunspent`, FakeNetwork answers the verification, and test_round_pool_address asserts the quorum is asked about the round's address. New: thresholds at exactly 6/5, configured value, coinbase at 119/120 and a mismatching or missing raw tx, platform outputs at 1, dust, quorum height, waiting-deposit display and disappearance, block-triggered refresh, resume, verification verdicts, gone bets excluded with the split recomputed, winner gone held and paused, held payouts untouched until the resume, re-verification after it, no quorum, a payout with 1 and with 400 participants against reserve+fee+dust, admin config bounds and migration. Mutation-checked: threshold 1, ignored coinbase, no height bound, no verification and no winner hold each fail tests. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
47 lines
2.9 KiB
Markdown
47 lines
2.9 KiB
Markdown
# ADR-52 — Le riorganizzazioni della catena si contengono invece di ignorarle
|
|
|
|
- **Stato:** Accettata
|
|
- **Area:** Conferme e fiducia nella rete
|
|
- **Fonte di verità per:** la scelta di progetto descritta qui sotto; i requisiti (`PREFISSO-NN`) che la attuano stanno nei documenti di dominio, indicati nelle *Conseguenze*.
|
|
|
|
## Decisione
|
|
|
|
**Le riorganizzazioni della catena si contengono invece di
|
|
ignorarle** (decisione del 2026-09-28). Tre misure:
|
|
- *si rilevano*: il listener tiene gli ultimi 10 header e segue una
|
|
biforcazione fino al punto comune; ogni riorganizzazione scrive
|
|
`chain_reorg_detected` con profondità e altezze. Una biforcazione che non
|
|
trova il punto comune entro 10 header è trattata come un header non
|
|
valido (fine della sessione e rotazione, [ADR-26](ADR-26-validazione-degli-header-concatenata-senza-ricalcolo.md));
|
|
- *si fermano quelle profonde*: una profondità ≥ 2 mette in pausa la
|
|
lotteria (`paused_reason = 'reorg'`, [ADR-28](ADR-28-pausa-manutenzione-ferma-round-successivo.md)) finché l'operatore non la
|
|
riprende;
|
|
- *si paga solo ciò che è in catena*: prima di costruire un pagamento le
|
|
monete dell'indirizzo del round si verificano con il quorum; i
|
|
partecipanti la cui scommessa non c'è più diventano `reorged_out` e la
|
|
ripartizione 70/30 si calcola su ciò che resta. Se manca la scommessa del
|
|
vincitore, il pagamento è trattenuto (`payout_blocked`) e la lotteria va in
|
|
pausa.
|
|
|
|
Regole in [connessione-electrum.md](../connessione-electrum.md#4-header-validati-non-creduti)
|
|
e [ciclo-di-vita-del-round.md](../ciclo-di-vita-del-round.md#4--pagamento)
|
|
(B-82, B-85).
|
|
- *Motivazione:* la regola precedente («1 conferma, nessun rollback»)
|
|
presupponeva riorganizzazioni rare e innocue. Con la potenza di PLM in
|
|
affitto una riorganizzazione è un attacco possibile, e senza queste misure
|
|
una sola scommessa sparita rende il round impagabile per sempre (B-82),
|
|
mentre una riorganizzazione di un blocco, normale in qualunque catena,
|
|
veniva scambiata per un server ostile (B-74).
|
|
- *Alternative scartate:* ignorare le riorganizzazioni (la regola
|
|
precedente); un rollback completo (ricalcolare saldi già spesi e ripetere
|
|
estrazioni già rivelate non è sempre possibile e sposterebbe denaro senza
|
|
l'operatore); pausa anche per profondità 1 (una riorganizzazione di un
|
|
blocco è frequente e non tocca i depositi a 6 conferme, [ADR-06](ADR-06-depositi-richiedono-deposit-confirmations-conferme-6.md)).
|
|
- *Conseguenze:* un attacco al 51% resta possibile; queste misure lo
|
|
rendono visibile, fanno sì che non blocchi la lotteria in modo
|
|
irrecuperabile e limitano il danno a ciò che l'attaccante ha rimosso
|
|
([LIM-24]).
|
|
|
|
*Codice:* `app/electrum/listener.py:ElectrumListener._record_reorg` · `app/rounds/scheduler.py:RoundScheduler._trigger_payout` · `app/rounds/service.py:open_new_round_if_needed` ·
|
|
*Test:* `tests/unit/test_electrum_listener.py`, `tests/unit/test_pool_verification.py`
|