Abandon a transaction only on proof, and keep watching failed rows (B-78, TX-15, TX-17, TX-23, TX-26, ELC-28, DAT-33, DAT-36, DAT-69, DAT-72, AUD-11, AUD-12, AUD-31, AUD-39, API-32)

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>
This commit is contained in:
davideandClaude Sonnet 5.5 committed 2026-10-14 15:07:09 +02:00
1 parent f936d6660c
commit a4b160e240
29 files changed
+1280 -201

No files matched your search

+11 -22
View File
@@ -327,23 +327,14 @@ riserva di [TX-11] serve proprio a dargli un'uscita da ridurre.
alcuno, e anche in quel caso l'assenza da sola non basta ad abbandonarla
([TX-17]). Un **errore di rete** non porta a nulla: la riga resta com'è
fino al giro successivo.
*Codice:* `app/tx/reconcile.py:reconcile_once`, `app/electrum/listener.py:ElectrumListener._corroborate_majority` ·
*Test:* `tests/unit/test_reconcile.py`, `tests/unit/test_tx_versions.py`
*Stato:* da implementare (B-78) · *Oggi:* si interroga solo il server
attivo, e un txid assente dalla sua cronologia è
trattato come "sconosciuto alla rete": dopo un riavvio su un server diverso
una riga `building` viene abbandonata dopo 120s anche se la transazione è
nella mempool degli altri nodi (che la tengono fino a 336 ore con le
impostazioni predefinite di Bitcoin Core, contro le 6 ore di tolleranza).
*Codice:* `app/tx/reconcile.py:reconcile_once`, `app/electrum/listener.py:ElectrumListener.get_histories` ·
*Test:* `tests/unit/test_reconcile_proof.py`, `tests/unit/test_reconcile.py`, `tests/unit/test_tx_versions.py`
- **[TX-26]** Prima di scrivere un esito, il riconciliatore rilegge la riga
nella propria transazione del database ([TX-28]) e non fa nulla se il suo
stato **o il suo `current_txid`** non sono più quelli che aveva quando ha
interrogato la rete (una conferma o un RBF avvenuti nel frattempo).
*Codice:* `app/tx/reconcile.py:reconcile_once` ·
*Test:* —
*Stato:* da implementare (B-78) · *Oggi:* ricontrolla solo lo stato, quindi
può abbandonare una riga appena sostituita dall'RBF sulla base del txid
precedente.
*Test:* `tests/unit/test_reconcile_proof.py`
- **[TX-16]** **Presente in rete**: una riga `building` viene promossa a
`pending` (e partecipante o prelievo da `building` a `broadcast`), con un
evento `pending_tx_recovered` e l'evento che l'invio riuscito avrebbe
@@ -377,11 +368,8 @@ riserva di [TX-11] serve proprio a dargli un'uscita da ridurre.
il partecipante viene rimosso, o il prelievo segnato `failed` senza txid; il
saldo dell'utente viene ricalcolato; si scrive `pending_tx_abandoned` (con
il numero di monete liberate) e si invia una notifica SSE.
*Codice:* `app/tx/reconcile.py:_abandon`, `app/tx/reconcile.py:_release_inputs`, `app/tx/reconcile.py:reconcile_once` ·
*Test:* `tests/unit/test_reconcile.py`
*Stato:* da implementare (B-78) · *Oggi:* basta che la cronologia del
server attivo non contenga `current_txid` (motivo `not found on chain`),
senza reinvio e senza guardare gli ingressi.
*Codice:* `app/tx/reconcile.py:_abandon`, `app/tx/reconcile.py:_release_inputs`, `app/tx/reconcile.py:reconcile_once`, `app/electrum/listener.py:ElectrumListener.confirmed_spender`, `app/electrum/listener.py:ElectrumListener.rebroadcast_everywhere` ·
*Test:* `tests/unit/test_reconcile_proof.py`, `tests/unit/test_reconcile.py`
- **[TX-23]** **Le righe `failed` restano sorvegliate** per 14 giorni dal
passaggio a `failed` (`failed_at`, [modello-dati.md](modello-dati.md)
(B-78)): a ogni giro il riconciliatore cerca i loro txid come in [TX-15].
@@ -391,11 +379,12 @@ riserva di [TX-11] serve proprio a dargli un'uscita da ridurre.
lotteria viene messa in pausa (`paused_reason = 'resurrected_tx'`) perché
l'operatore rimetta in ordine partecipante, prelievo o pagamento; il
riconciliatore non corregge da solo le righe collegate.
*Codice:* `app/tx/reconcile.py:reconcile_once` ·
*Test:* —
*Stato:* da implementare (B-78) · *Oggi:* una riga `failed` non viene più
guardata: se la transazione conferma dopo l'abbandono, nessuno se ne
accorge.
*Codice:* `app/tx/reconcile.py:reconcile_once`, `app/tx/reconcile.py:_resurrect`, `app/rounds/pause.py:pause_automatically` ·
*Test:* `tests/unit/test_reconcile_proof.py`, `tests/unit/test_pause_reason.py`
*Stato:* da implementare (B-83), per la conferma con prova merkle · *Oggi:*
la conferma di una riga `failed` è quella dei server **altri dall'attivo**:
una maggioranza stretta di essi (almeno il minimo del quorum) elenca uno
dei suoi txid in un blocco, senza prova merkle ([TX-22]).
- **[TX-27]** Il riconciliatore invia una notifica SSE solo per le righe di
cui ha cambiato qualcosa (promozione, abbandono, riallineamento del txid),
non per ogni riga esaminata.