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>
24 lines
1.5 KiB
Markdown
24 lines
1.5 KiB
Markdown
# ADR-31 — Tutto ciò che spende denaro si scrive prima di inviarlo
|
|
|
|
- **Stato:** Accettata
|
|
- **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
|
|
|
|
**Tutto ciò che spende denaro si scrive prima di inviarlo** (stato
|
|
`building`, monete già segnate come spese) e si risolve contro la catena
|
|
dopo; nessuna sessione del database resta aperta durante una chiamata di
|
|
rete. Vale anche per le sostituzioni RBF: la nuova versione si salva come
|
|
candidata prima dell'invio (B-77). Solo un **rifiuto esplicito** della rete
|
|
annulla tutto e risponde **502**; un invio dall'esito incerto (timeout,
|
|
connessione caduta dopo la scrittura) lascia la riga `building` al
|
|
riconciliatore e risponde **202** ([ADR-51](ADR-51-dubbio-liberano-mai-fondi.md)).
|
|
- *Motivazione:* un crash fra invio e salvataggio lasciava monete spese in
|
|
catena senza traccia (B-08, B-25). Dettagli in
|
|
[transazioni-e-riconciliazione.md](../transazioni-e-riconciliazione.md).
|
|
|
|
*Codice:* `app/bets/service.py:place_bet` · `app/withdrawals/service.py:request_withdrawal` · `app/rounds/scheduler.py:RoundScheduler._trigger_payout` · `app/tx/broadcast.py:bump_fee` · `app/tx/reconcile.py:reconcile_once` ·
|
|
*Test:* `tests/unit/test_bets.py::test_bet_is_persisted_before_it_is_broadcast`, `tests/unit/test_broadcast_outcome.py`, `tests/unit/test_scheduler.py::test_trigger_payout_persists_before_broadcasting`, `tests/unit/test_reconcile.py`
|
|
|