`_tick` skipped `drawing`: the wait for the draw block lived only inside the `_close_and_draw` call that entered it, so any exception (a locked database writing an audit row, a malformed header) or a restart left the round in `drawing` for ever with the pool inside and no new round able to open. Since B-73 everything the draw needs is committed on entering `drawing` (encrypted secret, ordered list with `draw_position`, `participants_hash`, `draw_height`, `draw_confirmations`), so `_tick` now calls `_complete_draw` for a round in `drawing`. `_complete_draw` rereads that state, is idempotent (a round no longer `drawing`, or with a winner, is left alone; the winner write is re-checked under BEGIN IMMEDIATE) and runs inside the single scheduler loop, so the inline call from `_close_and_draw` and the tick can never run concurrently. Tests (test_draw_proof.py): an exception in the quorum query, then a tick, completes with the same height, list, fingerprint and the winner the public proof recomputes; a brand-new scheduler (restart) resumes and a second tick draws and triggers nothing again; a failure in the very transaction that stores the winner leaves no winner and no revealed secret, and the next tick completes. Mutation-checked: without the `_tick` branch all three fail. Docs: the B-81 `*Stato:*`/`*Oggi:*` lines are gone (RND-01, RND-15, RND-36, ARC-27, OPS-09, ADR-12, ADR-25), OPS-13 no longer prescribes the manual `closing` workaround, LIM-01 is struck, storico-bug.md and BUGS.md updated. No existing test changed. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
35 lines
2.5 KiB
Markdown
35 lines
2.5 KiB
Markdown
# ADR-25 — Il blocco di estrazione è fissato per altezza, è successivo alla chiusura, e si usa solo quando è confermato e corroborato
|
|
|
|
- **Stato:** Accettata
|
|
- **Area:** Round ed estrazione
|
|
- **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
|
|
|
|
**Il blocco di estrazione è fissato per altezza, è successivo
|
|
alla chiusura, e si usa solo quando è confermato e corroborato.**
|
|
All'ingresso in `drawing` si salva `draw_height = tip_at_close + 1`, che non
|
|
cambia più. Si attende che quel blocco abbia `draw_confirmations` conferme
|
|
(3 per default, fotografato all'apertura, [ADR-10](ADR-10-parametri-round-fotografati-all-apertura.md)), poi si chiede a tutti i
|
|
server l'header *a quell'altezza*: serve l'accordo del quorum ([ADR-07](ADR-07-ogni-decisione-sposta-denaro-base-risposta.md)); in
|
|
caso di disaccordo si attende e si richiede la stessa altezza, mai un blocco
|
|
diverso. L'attesa non ha timeout (l'entropia dipende davvero da un blocco
|
|
futuro) ma è osservabile (`draw_stalled`, `draw_waiting_since`) e
|
|
riprendibile: `draw_height`, `participants_hash` e la posizione di ogni
|
|
partecipante sono salvati, e lo scheduler riprende un round in `drawing`
|
|
dopo un errore o un riavvio con lo stesso esito. Un'altezza `0` alla
|
|
chiusura significa «sconosciuta»: la prima altezza appresa fa da base.
|
|
- *Motivazione:* un hash già pubblico mentre le scommesse erano aperte
|
|
renderebbe il vincitore prevedibile (B-63); un header fabbricato
|
|
sceglierebbe il vincitore (B-28); un'altezza non fissata lascia al server
|
|
attivo la scelta di quale blocco reale usare, e passare a «un blocco
|
|
ulteriore» dopo una corroborazione fallita gli dà un secondo tentativo
|
|
(B-73). Le conferme sul blocco di estrazione evitano che una
|
|
riorganizzazione cambi il seme dopo l'estrazione. Uno stato tenuto solo in
|
|
memoria bloccava il round in `drawing` a ogni eccezione (B-81).
|
|
- *Alternative scartate:* timeout sull'attesa con ripiego su un altro blocco
|
|
(riaprirebbe la scelta del blocco).
|
|
|
|
*Codice:* `app/rounds/scheduler.py:RoundScheduler._wait_for_draw_block` · `app/rounds/scheduler.py:RoundScheduler._close_and_draw` · `app/rounds/scheduler.py:RoundScheduler._tick` ·
|
|
*Test:* `tests/unit/test_scheduler.py::test_a_block_relayer_cannot_choose_the_block_that_seeds_the_draw`, `tests/unit/test_scheduler.py::test_a_disagreement_asks_the_same_height_again_and_is_audited_once_per_hash`
|