A reorganisation was neither recorded nor acted upon, and a competing header at the tip's own height was ignored for as long as the tip stood, leaving the listener on an orphan. - A header at the height we hold with a different hash is followed through the same fork-point search as any other reorg (ELC-09) instead of being ignored; it still has to bring valid work and a connected chain. - ElectrumListener._record_reorg writes `chain_reorg_detected` (depth, fork height, old and new tip height and hash) before the window moves, so a failed write ends the session and the next server's announcement of the same fork is recorded then. Depth 1 is a transaction of its own; depth >= 2 also pauses the lottery with paused_reason 'reorg' and writes `lottery_paused` in the same transaction (begin_immediate first). - Docs: ELC-09/22/23/24, AUD-03/11/38, DAT-30/69, OPS-30, RND-04, ADR-26/52 lose their B-85 "da implementare" lines. Tests changed because the spec changed: test_apply_header_ignores_a_competing_header_at_ the_current_tip_height encoded the B-64 behaviour that ELC-09 now reverses; it is replaced by test_a_competing_header_at_the_tip_height_is_a_reorg_to_follow and the depth tests. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
36 lines
2.7 KiB
Markdown
36 lines
2.7 KiB
Markdown
# ADR-26 — Validazione degli header concatenata, senza ricalcolo della difficoltà
|
|
|
|
- **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
|
|
|
|
**Validazione degli header concatenata, senza ricalcolo della
|
|
difficoltà.** Un header deve dichiarare un bersaglio non più facile del
|
|
limite di rete (`powLimit`, `0x00000000ffff…`), rispettare quel bersaglio e
|
|
concatenarsi alla catena che teniamo: su un avanzamento di più blocchi si
|
|
scaricano gli header intermedi e si verifica tutta la catena. Il listener
|
|
tiene gli ultimi 10 header; un header che non si concatena alla punta ma a
|
|
uno di essi è una riorganizzazione da seguire ([ADR-52](ADR-52-riorganizzazioni-catena-contengono-invece-ignorarle.md)), non un server
|
|
ostile. Un header senza `hex` è ignorato senza chiudere la sessione. Regole
|
|
in [connessione-electrum.md](../connessione-electrum.md#4-header-validati-non-creduti)
|
|
(B-74, B-85).
|
|
- *Motivazione:* il controllo «rispetta il bersaglio che dichiara», da solo,
|
|
**non è una difesa**: il bersaglio lo sceglie chi produce l'header, e con
|
|
`bits=0x207fffff` un header passa senza lavoro. Un salto di più blocchi non
|
|
collegato alla punta permetteva di fissare un'altezza enorme, che non
|
|
regredisce mai, e congelare ogni estrazione (B-74). Trattare ogni
|
|
riorganizzazione di un blocco come un server ostile chiudeva la sessione
|
|
su tutti i server fino al blocco successivo.
|
|
- *Alternative scartate:* validazione completa della catena con le regole di
|
|
ricalcolo della difficoltà di PLM (fuori scopo: servirebbe la storia delle
|
|
difficoltà, e il commit-reveal di [ADR-24](ADR-24-l-estrazione-commit-reveal-fra-server.md) toglie a un header fabbricato il
|
|
potere di scegliere il vincitore).
|
|
- *Conseguenze:* un header a difficoltà minima costa ancora poco lavoro
|
|
([LIM-14]); a fermare una catena fabbricata sono la concatenazione, il
|
|
quorum ([ADR-07](ADR-07-ogni-decisione-sposta-denaro-base-risposta.md)) e il fatto che il seme dipende anche da `server_seed`.
|
|
|
|
*Codice:* `app/electrum/listener.py:ElectrumListener._apply_header` · `app/rounds/draw.py:header_meets_its_own_target` ·
|
|
*Test:* `tests/unit/test_electrum_listener.py::test_a_multi_block_jump_is_validated_by_fetching_the_headers_in_between`, `tests/unit/test_electrum_listener.py::test_a_fork_is_walked_back_and_followed_instead_of_ending_the_session`, `tests/unit/test_electrum_listener.py::test_a_competing_header_at_the_tip_height_is_a_reorg_to_follow`, `tests/unit/test_draw.py::test_a_header_below_the_pow_limit_is_rejected_even_if_it_meets_its_own_target`
|