Files
plm-lottery/docs/adr/ADR-51-dubbio-liberano-mai-fondi.md
T
davideandClaude Sonnet 5.5 f936d6660c Track every version of a bumped transaction and write the RBF replacement before broadcasting it (B-77, TX-12, TX-13, TX-19, TX-21, DAT-13, DAT-14, DAT-34, DAT-44, DAT-45, DAT-70, DAT-71)
The poller and the reconciler matched current_txid only. If an earlier version of
a bumped transaction confirmed it was never seen, and after 6h the row was abandoned:
a confirmed bet's participant deleted, a sent withdrawal marked failed, a paid payout
rebuilt. bump_fee also broadcast in phase 2 and persisted in phase 3 unconditionally,
so a crash or a `database is locked` in between left a transaction on the network that
the DB did not know, and an abandon or a confirmation in the meantime was overwritten.

- New table pending_transaction_txids (migration a3f5c2d9b7e1; txid unique, index on
  the owning row; existing rows backfilled with current_txid + raw and the txid their
  last bump replaced, raw_hex empty). Written with the row by place_bet,
  request_withdrawal and _trigger_payout; removed with a bet row that a verified
  refusal deletes (DAT-38).
- bump_fee in four phases: read, build and sign, commit the replacement as a candidate
  version, broadcast (verdict of B-76, fanned out when accepted; an explicit refusal
  raises RbfError and leaves the row), then switch the row over with
  `UPDATE ... WHERE status='pending' AND current_txid=<replaced>`. Zero rows matched is
  a logged conflict: nothing is overwritten and the candidate stays recorded. An
  uncertain broadcast adopts the replacement. A retry rebuilds the same candidate
  without tripping the unique txid.
- poll_once and reconcile_once look for every txid of a row. When the version found is
  not the current one, broadcast.adopt_version makes it current (raw tx included) and
  retargets spent_txid, bet_txid, withdrawals.txid and payout_txid as a bump does,
  before the confirmation handler runs. _release_inputs frees inputs claimed by any
  version of the row.
- RbfBumper takes the listener as `network`.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-10-14 14:46:43 +02:00

2.8 KiB

ADR-51 — Nel dubbio non si liberano mai i fondi

  • Stato: Accettata — implementazione da completare (B-78)
  • Area: Denaro in movimento
  • 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

Nel dubbio non si liberano mai i fondi (decisione del 2026-09-28). Una riga che sposta denaro (scommessa, prelievo, pagamento) si annulla, liberandone le monete, solo con una prova: un rifiuto esplicito della rete all'invio, oppure i suoi ingressi spesi da un'altra transazione confermata (corroborata dal quorum), oppure nessun server del quorum che conosca alcun txid della riga e una ritrasmissione dell'ultima versione a tutti i server rifiutata per ingressi mancanti o già spesi. Mai per un timeout, per l'età della riga o per il silenzio di un solo server. Si seguono tutti i txid che una riga ha avuto (ogni versione RBF): la conferma di uno qualsiasi conferma la riga. Le righe failed restano sorvegliate per 14 giorni; una conferma tardiva scrive pending_tx_resurrected e mette in pausa la lotteria (ADR-28). Regole in transazioni-e-riconciliazione.md (B-76, B-77, B-78).

  • Motivazione: liberare le monete di una transazione che poi conferma è l'errore peggiore possibile: la scommessa finisce nel montepremi senza partecipante, il prelievo parte mentre la riga dice failed, il pagamento viene ricostruito e il vincitore pagato due volte. Tutti e tre accadevano con un invio andato in timeout (B-76), con la conferma di una versione RBF precedente (B-77) o con un riavvio su un server che non aveva ancora visto la transazione (B-78).
  • Alternative scartate: abbandono a tempo (la regola precedente: 120s per building, 6 ore per pending), che trasforma un ritardo di rete in una perdita; abbandono sul parere del solo server attivo.
  • Conseguenze: una transazione ferma ma viva non si abbandona mai: la si accelera (ADR-18); un round può restare in closing o paying_out finché la rete non decide ([LIM-02], [LIM-03]). Il denaro in dubbio resta congelato e visibile, mai duplicato.

Codice: app/tx/reconcile.py:reconcile_once · app/tx/reconcile.py:_is_due · app/bets/service.py:place_bet · app/withdrawals/service.py:request_withdrawal · app/tx/confirmation.py:poll_once · app/tx/broadcast.py:bump_fee · Test: tests/unit/test_broadcast_outcome.py Stato: da implementare (B-78) · Oggi: l'abbandono avviene quando la cronologia del solo server attivo non contiene alcun txid della riga, dopo 120s per building e 6 ore per pending; le righe failed non sono più controllate.