Files
plm-lottery/docs
davideandClaude Sonnet 5.5 db24287ea5 Make the draw a commit-reveal at a fixed, confirmed, quorum-agreed height with a public proof (B-73, RND-14 … RND-20, RND-33 … RND-37, DAT-61 … DAT-66, API-25, API-45, AUD-24 … AUD-27, AUD-37, ELC-15, SEC-56, ADR-24, ADR-25)
The seed was the hash of the first block seen after the close, so a miner holding tickets
could withhold blocks until one made them win, the active Electrum server could pick which
real block was used by not announcing another (a failed corroboration even moved the draw to
the next block), and the participant order was the server-only `broadcast_at` with no
tie-break, so nobody could recompute the result.

- Open: every round gets a 32-byte `server_seed`, stored only Fernet-encrypted with the
  master-xprv key (`server_seed_enc`), with its published `server_seed_hash`;
  `draw_confirmations` is copied from round_config. The plaintext column is written only by
  the reveal.
- Entering `drawing` (one transaction, `draw_committed` audit row): participants ordered by
  bet txid, each `draw_position`, `participants_hash` (sha256 of `txid:vout:address\n`
  lines; new `bet_vout`), `draw_height = tip_at_close + 1`. A tip of 0 keeps the round
  `closing` (`draw_baseline_tip_unknown`, once per round). All persisted, so a resumed draw
  reads rather than recomputes (the `_tick` branch itself is B-81).
- `_complete_draw` / `_wait_for_draw_block` replace `_wait_for_next_block`: wait for
  `draw_confirmations` blocks from `draw_height`, then `ElectrumListener.agreed_block_hash`
  asks every server, the active one included, for the header at that exact height (valid
  work, >= 2 other answers, strict majority of all); no agreement means the same height is
  asked again and `draw_header_corroboration_failed` is written once per distinct reported
  hash. `draw_stalled` now counts from the last tip advance, or from when the quorum started
  to fail. Seed = sha256(server_seed || block_hash || participants_hash), index = seed mod n.
- The winner, the seed and the reveal (`server_seed`, `winner_drawn` payload) are written in
  one transaction; a round closing with no participants reveals too. A round opened before
  this change (no commitment) is given a secret as it enters `drawing`.
- `GET /rounds/{id}/proof` (public, 404 `round_not_found`, translated in all 7 languages) and
  the new fields on `GET /rounds/current`; `draw_confirmations` in `/admin/config` and the
  /admin form; `server_seed_hash`/`draw_height` in `/admin/rounds`, never the secret.
- Alembic d3e8b15a7c42 (plain add_column / create_index, expression indexes untouched).
- Docs: the B-73 `*Stato:*`/`*Oggi:*` lines are gone, guides and CLAUDE.md describe the new
  draw. Ambiguities resolved in api.md: the proof's participants also carry `amount_sats`
  (RND-37 lists it); `seed` is decimal in the proof and hex in the audit row, as specified.

Tests changed because the spec changed: ElectrumListener.corroborate_header (asked only the
other servers about the block the active one announced) is replaced by agreed_block_hash and
its quorum tests ported; draw_winner takes the secret and the list fingerprint; the four
_wait_for_next_block scheduler tests are replaced by _wait_for_draw_block ones (fixed height,
confirmations, same-height retry, stall clock). New: test_draw_proof.py recomputes the winner
independently from the public proof, checks the plaintext secret is nowhere in the database,
the API or the log before the reveal, and that a second pass over a `drawing` round yields
the same winner. Mutation-checked: ordering by broadcast_at, an early reveal and asking the
tip instead of the draw height each fail tests.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-10-14 16:29:09 +02:00
..

Documentazione di PLM Lottery

Questa cartella è la fonte di verità del progetto: si lavora docs-first (prima si scrive o si modifica la documentazione, poi il codice) e ogni informazione ha un solo proprietario (SSOT). Questo file è l'indice: da qui si raggiunge tutto il resto.

I tre principi

  1. Docs-first. Nessuna modifica di comportamento parte dal codice. Si modifica il requisito (o si scrive l'ADR, se è una scelta nuova), poi si implementa, poi si testa. Spec, codice e test entrano nello stesso commit.
  2. SSOT — un solo proprietario per ogni informazione. Il perché di una scelta sta in un ADR; il cosa verificabile in un requisito (PREFISSO-NN) del documento di dominio; il come nel codice; la cronologia dei difetti in storico-bug.md. Gli altri documenti rimandano all'ID, non ripetono il testo. Se due documenti dicono cose diverse, vince la specifica e si corregge l'altro.
  3. Un ADR per ogni funzionalità. Ogni funzionalità nuova inizia con un ADR in adr/ (modello: adr/TEMPLATE.md) che registra contesto, decisione, alternative scartate e conseguenze, e ne elenca i requisiti.

Dove si trova cosa

Domanda Dove
Perché è fatto così? Quali alternative sono state scartate? adr/ — indice per area e tabella funzionalità → ADR
Cosa deve fare esattamente il software? I documenti di dominio qui sotto (requisiti con ID stabile)
Quali limiti abbiamo accettato? limiti-noti.md (LIM-nn)
Che bug sono stati trovati/corretti? Quali restano aperti? storico-bug.md; i soli aperti in ../BUGS.md
In che ordine si implementano le correzioni aperte? piano-correzioni.md
Come si modifica la documentazione/il codice? processo-di-modifica.md
Come si installa, si avvia, si usa? Guide operative qui sotto

Specifica (documenti di dominio)

Punto d'ingresso narrativo: come-funziona.md.

Documento Prefisso Contenuto
registrazione-e-depositi.md REG, DEP Account, indirizzi, depositi, saldo
scommesse-e-prelievi.md BET, WDR Scommesse e prelievi
ciclo-di-vita-del-round.md RND Apertura, chiusura, estrazione, pagamento
transazioni-e-riconciliazione.md TX Ciclo di vita delle transazioni, RBF, riconciliazione
connessione-electrum.md ELC Accesso alla rete PLM e difese
architettura.md ARC Struttura del codice, processi, frontend, test
modello-dati.md DAT Tabelle, campi, stati, vincoli
api.md API Endpoint, risposte, codici di errore
sicurezza.md SEC Fiducia, chiavi, autenticazione, limiti sui tentativi
audit-log.md AUD Catalogo degli eventi di audit
operativita.md OPS Backup, riavvii, incidenti

Decisioni, limiti, storia

Documento Prefisso Contenuto
adr/ ADR Una decisione di progetto per file (53 al momento)
limiti-noti.md LIM Limiti accettati consapevolmente
storico-bug.md B-nn Tutti i bug trovati e corretti
piano-correzioni.md — Ordine di implementazione delle correzioni aperte

Guide operative (senza requisiti)

setup.md · running-the-server.md · guida-utente.md · guida-admin.md. Si aggiornano quando la specifica cambia qualcosa di visibile.

Lingua

La documentazione di docs/ è in italiano, per scelta esplicita; tutto il resto del repository (codice, commenti, commit, CLAUDE.md, BUGS.md) è in inglese.