reconcile_once abandoned a row when the *active* server's history lacked its txid:
after 120s for `building` (which a restart onto a different server makes likely),
after 6h for `pending`, and all at once after a forward clock jump. It re-checked the
status but not the txid, so it raced the bumper, and a `failed` row was never looked at
again.
- The reconciler asks every server (ElectrumListener.get_histories, active + others) for
the history of the row's address and looks for every txid of the row. Present on any
server -> promoted (adopting the version found). Absent is only "no server of the
quorum knows it" and needs the active server plus the quorum minimum of the others to
have answered; even then nothing is released without proof:
(a) an input spent in a block by a transaction that is none of the row's versions,
agreed by a strict majority of a quorum of the other servers (confirmed_spender), or
(b) a rebroadcast of the latest raw tx to every server (rebroadcast_everywhere)
refused by all of them, explicitly, for missing/spent inputs.
Accepted or "already known" by any server means alive; a fee refusal is not proof
(`building` -> `pending` for the bumper, `pending` untouched); too few answers or
anything else leaves the row alone. failure_reason names the proof.
- The write re-reads status *and* current_txid under begin_immediate (TX-26).
- pending_transactions.failed_at (set by _abandon and _release_failed_withdrawal) starts
a 14-day watch: a failed row that a majority of the other servers (at least the quorum
minimum) list in a block becomes `confirmed`, writes pending_tx_resurrected once and
pauses the lottery with paused_reason `resurrected_tx`; linked rows are not corrected.
The confirmation is by quorum of histories for now; merkle proofs come with B-83.
- round_config.paused_reason (migration b7d2e41c9a05, with the failed_at one): `operator`
from POST /admin/pause (which accepts an optional `note` and never overwrites an
automatic reason), cleared by resume, which logs the reason it lifted; exposed on
/admin/config and GET /rounds/current. rounds/pause.py:pause_automatically is the
system's way in.
- PendingTransactionReconciler takes the listener as `network`; with none it can promote
but never abandon.
Tests changed because the spec changed: the three reconciler tests that expect an
abandonment (and the one in test_tx_versions) now supply a network that proves the
transaction is gone.
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
40 lines
2.6 KiB
Markdown
40 lines
2.6 KiB
Markdown
# ADR-51 — Nel dubbio non si liberano mai i fondi
|
|
|
|
- **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
|
|
|
|
**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](ADR-28-pausa-manutenzione-ferma-round-successivo.md)). Regole in
|
|
[transazioni-e-riconciliazione.md](../transazioni-e-riconciliazione.md#riconciliazione)
|
|
(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](ADR-18-l-accelerazione-rbf-paga-chi-riceve.md)); 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`, `tests/unit/test_tx_versions.py`, `tests/unit/test_reconcile_proof.py`
|