Snapshot the bet cost, fee address and pool cap onto the round at open, and cap the pool (B-95, RND-05, RND-06, RND-23, BET-20, BET-21, DAT-26, DAT-27, DAT-61, DAT-62, API-21, API-30, API-31, ADR-10, LIM-16)
Only the duration and the cooldown (and, since B-73, the draw confirmations) were copied onto the round when it opened. The cost of a bet and the fee address were read live, so an edit from /admin in the middle of a round gave the players of that round different stakes for the same chance and redirected the commission of the round in progress. - `rounds.bet_amount_sats`, `rounds.fee_address` and `rounds.max_round_pool_sats` are copied from round_config in the transaction that opens the round (Alembic a7d3e9f15b48: plain add_column, existing rounds backfilled with the current configuration, i.e. what they were using; the expression indexes untouched). `place_bet` charges the round's cost, `_trigger_payout` pays the round's fee address (an empty one on the row still stops the payout, as before), `GET /rounds/current` advertises the round's cost while one is active and the configured one otherwise. The minimum withdrawal and the fee rate stay live, by design (ADR-20, ADR-10). - `round_config.max_round_pool_sats` (0 = none, otherwise >= the bet cost and <= 4e15, in /admin and PUT/GET /admin/config): a bet is refused with `round_full` (params also carry `max_round_pool_sats`) once the sum of the round's participant rows, in-flight ones included, has reached the round's cap, before anything moves; the pool can exceed it by one bet at most. A cap under the bet cost is a 422 `max_round_pool_below_bet_amount`. - PUT /admin/config's payability check (RND-40) now also judges a fee-rate change against the bet cost the round in progress opened with, which can be lower than the configured one. - `error.round_full` no longer says "maximum of N players" (it also fires for the pool cap): the seven translations are generic. Ambiguity resolved: the spec said the cap is snapshotted (RND-05, BET-20, ARC) in some places and "applies immediately, also to the round in progress" in the round_config table of modello-dati; the snapshot wins, with a column on `rounds` (modello-dati/api/guide-admin brought in line). Tests changed because the spec changed: the payout fixtures seed the round's own fee address, and the old "fee address missing" payout test now empties the round's address (clearing it in the configuration mid-round must not stop the payout). New test_round_snapshot.py: the copy at open, edits reaching only the next round, every bet of a round paying the same stake whether the cost is raised or lowered meanwhile, the payout following the round's address (and surviving it being cleared in the configuration), the cap (exactly at the cap is full, in-flight bets count, no cap, a mid-round edit of the cap does not apply, the refused player's coins untouched), plus the route, the admin bounds and the two 422s, the fee-rate check against the round's own cost, and the migration backfill. Mutation-checked: charging the live cost, paying the live address, not copying the cap and `>` instead of `>=` each fail tests. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
ccd15807ed
commit
8b182ac8b6
28 files changed
+520
-121
No files matched your search
+25
-31
@@ -98,9 +98,10 @@ erDiagram
|
||||
datetime closed_at
|
||||
int duration_seconds "snapshot"
|
||||
int cooldown_seconds "snapshot"
|
||||
bigint bet_amount_sats "snapshot (da implementare)"
|
||||
string fee_address "snapshot (da implementare)"
|
||||
int draw_confirmations "snapshot (da implementare)"
|
||||
bigint bet_amount_sats "snapshot"
|
||||
string fee_address "snapshot"
|
||||
bigint max_round_pool_sats "snapshot"
|
||||
int draw_confirmations "snapshot"
|
||||
string pool_address
|
||||
string server_seed_enc "cifrato fino alla rivelazione (da implementare)"
|
||||
string server_seed "in chiaro solo dopo la rivelazione (da implementare)"
|
||||
@@ -140,9 +141,9 @@ erDiagram
|
||||
int draw_animation_seconds
|
||||
int fee_rate_sat_vb
|
||||
int rbf_timeout_seconds
|
||||
int deposit_confirmations "da implementare"
|
||||
int deposit_confirmations
|
||||
int draw_confirmations "da implementare"
|
||||
bigint max_round_pool_sats "da implementare"
|
||||
bigint max_round_pool_sats
|
||||
bool paused
|
||||
string paused_reason "da implementare"
|
||||
datetime updated_at
|
||||
@@ -426,8 +427,9 @@ restano nella tabella come storico.
|
||||
| `closed_at` | DateTime | sì | `NULL` | Chiusura delle scommesse, poi conferma del pagamento ([RND-28](ciclo-di-vita-del-round.md)) | `app/rounds/scheduler.py:RoundScheduler._tick`; `app/rounds/confirmation.py:_on_payout_confirmed` |
|
||||
| `duration_seconds` | Integer | no | `600` (anche `server_default`) | Durata di **questo** round, copiata da `round_config` all'apertura | `open_new_round_if_needed` |
|
||||
| `cooldown_seconds` | Integer | no | `30` (anche `server_default`) | Pausa dopo **questo** round, copiata da `round_config` all'apertura | `open_new_round_if_needed` |
|
||||
| `bet_amount_sats` | BigInteger | no | backfill da `round_config` nella migrazione | Costo della scommessa di **questo** round, copiato all'apertura ([DAT-61]) — *da implementare (B-95)* | `open_new_round_if_needed` |
|
||||
| `fee_address` | String(128) | no | backfill da `round_config` nella migrazione | Destinatario della commissione di **questo** round, copiato all'apertura ([DAT-61]) — *da implementare (B-95)* | `open_new_round_if_needed` |
|
||||
| `bet_amount_sats` | BigInteger | no | backfill da `round_config` nella migrazione | Costo della scommessa di **questo** round, copiato all'apertura ([DAT-61]) | `open_new_round_if_needed` |
|
||||
| `fee_address` | String(128) | no | backfill da `round_config` nella migrazione | Destinatario della commissione di **questo** round, copiato all'apertura ([DAT-61]) | `open_new_round_if_needed` |
|
||||
| `max_round_pool_sats` | BigInteger | no | `0` (`server_default`); backfill `0` | Tetto alla somma delle scommesse di **questo** round, copiato all'apertura ([DAT-61], [DAT-27]); `0` = nessun tetto | `open_new_round_if_needed` |
|
||||
| `draw_confirmations` | Integer | no | `3` (`server_default`) | Conferme richieste sul blocco di estrazione di **questo** round, copiate all'apertura ([DAT-61]) | `open_new_round_if_needed` |
|
||||
| `pool_address` | String(128) | no | `""` solo fino alla fine della transazione di apertura; backfill con l'indirizzo di riserva per i round esistenti | Indirizzo del montepremi di **questo** round ([DAT-60]) | `open_new_round_if_needed` |
|
||||
| `server_seed_enc` | Text | sì | `NULL` | Il segreto del round cifrato con Fernet, con la stessa chiave della master xprv; scritto all'apertura ([DAT-64]) | `open_new_round_if_needed` |
|
||||
@@ -560,22 +562,20 @@ restano nella tabella come storico.
|
||||
tabella con righe; il codice lo riscrive prima del commit e ogni consumatore
|
||||
rifiuta un indirizzo vuoto.
|
||||
|
||||
- **[DAT-61]** `bet_amount_sats`, `fee_address` e `draw_confirmations` di
|
||||
`rounds` sono una **copia** dei valori di `round_config` presa quando il
|
||||
- **[DAT-61]** `bet_amount_sats`, `fee_address`, `max_round_pool_sats` e
|
||||
`draw_confirmations` di `rounds` sono una **copia** dei valori di `round_config` presa quando il
|
||||
round si apre, nella stessa transazione dell'inserimento, e non cambiano
|
||||
più. Le scommesse del round costano `rounds.bet_amount_sats`, il suo
|
||||
pagamento paga la commissione a `rounds.fee_address`, la sua estrazione
|
||||
attende `rounds.draw_confirmations` conferme. La regola di dominio è in
|
||||
attende `rounds.draw_confirmations` conferme, le scommesse oltre il tetto
|
||||
`rounds.max_round_pool_sats` sono rifiutate. La regola di dominio è in
|
||||
[ciclo-di-vita-del-round.md](ciclo-di-vita-del-round.md) (B-95). La
|
||||
migrazione riempie le righe esistenti con i valori attuali di
|
||||
`round_config` ([DAT-55]).
|
||||
*Codice:* `app/rounds/service.py:open_new_round_if_needed` ·
|
||||
`app/bets/service.py:place_bet` ·
|
||||
`app/rounds/scheduler.py:RoundScheduler._trigger_payout` · *Test:* —
|
||||
*Stato:* da implementare (B-95) · *Oggi:* `draw_confirmations` è già copiato
|
||||
all'apertura (B-73); `place_bet` e `_trigger_payout`
|
||||
leggono `bet_amount_sats` e `fee_address` da `round_config` al momento
|
||||
dell'uso, quindi una modifica a metà round cambia il round in corso.
|
||||
`app/rounds/scheduler.py:RoundScheduler._trigger_payout` ·
|
||||
*Test:* `tests/unit/test_round_snapshot.py`, `tests/unit/test_rounds_service.py`, `tests/unit/test_migrations.py`
|
||||
|
||||
- **[DAT-64]** Il segreto del round sono 32 byte casuali generati con
|
||||
`secrets.token_bytes(32)`. All'inserimento del round si scrivono insieme
|
||||
@@ -748,21 +748,18 @@ Una scommessa: un utente in un round.
|
||||
moltiplicando il numero di partecipanti per il costo (B-11).
|
||||
*Codice:* `app/bets/service.py:place_bet` ·
|
||||
`app/wallet/psbt_builder.py:build_signed_transaction` ·
|
||||
`app/api/routes/rounds.py:current_round` · *Test:* `tests/unit/test_bets.py`
|
||||
*Stato:* da implementare (B-95) · *Oggi:* il costo è
|
||||
`round_config.bet_amount_sats` letto al momento della scommessa.
|
||||
`app/api/routes/rounds.py:current_round` · *Test:* `tests/unit/test_bets.py`, `tests/unit/test_round_snapshot.py`
|
||||
|
||||
- **[DAT-27]** Il numero di righe di un round, contando tutti gli stati, non
|
||||
supera `MAX_PARTICIPANTS_PER_ROUND` (400): la 401ª scommessa è rifiutata con
|
||||
`round_full` prima che si muova denaro (B-52). Con
|
||||
`round_config.max_round_pool_sats` diverso da 0 ([DAT-62]), una scommessa è
|
||||
rifiutata con `round_full` anche quando la somma dei `bet_amount_sats` del
|
||||
round, contando tutti gli stati, ha già raggiunto quel tetto; la regola di
|
||||
`rounds.max_round_pool_sats` (copiato da `round_config` all'apertura,
|
||||
[DAT-61], [DAT-62]) diverso da 0, una scommessa è rifiutata con `round_full`
|
||||
anche quando la somma dei `bet_amount_sats` del round, contando tutti gli
|
||||
stati, ha già raggiunto quel tetto; la regola di
|
||||
dominio è in [scommesse-e-prelievi.md](scommesse-e-prelievi.md) (B-95).
|
||||
*Codice:* `app/bets/service.py:place_bet` · `app/wallet/psbt_builder.py` ·
|
||||
*Test:* `tests/unit/test_bets.py`
|
||||
*Stato:* da implementare (B-95), solo per il tetto sul montepremi · *Oggi:*
|
||||
esiste solo il limite dei 400 partecipanti.
|
||||
*Test:* `tests/unit/test_bets.py`, `tests/unit/test_round_snapshot.py`
|
||||
|
||||
### `round_config`
|
||||
|
||||
@@ -772,8 +769,8 @@ senza riavviare (vedi [limiti-noti.md](limiti-noti.md)).
|
||||
| Colonna | Tipo | Default | Limiti accettati da `PUT /admin/config` | Significato | Quando ha effetto |
|
||||
|---|---|---|---|---|---|
|
||||
| `id` | Integer PK | autoincrement | — | — | — |
|
||||
| `fee_address` | String(128), non null | nessun default nel modello; la riga nasce con `""` | indirizzo PLM bech32 valido | Dove va il 30% di ogni round | Atteso: dal round **successivo**, copiato all'apertura ([DAT-61]). Oggi: subito, si legge a ogni costruzione del pagamento, quindi vale anche per il round in corso se il suo pagamento non è ancora stato costruito |
|
||||
| `bet_amount_sats` | BigInteger | `1_000_000_000` (10 PLM) | `> 0`, `≤ 100 000 PLM` | Costo della scommessa; anche il prelievo minimo | Atteso: per le scommesse dal round **successivo** ([DAT-61]), per il prelievo minimo subito. Oggi: subito, per le scommesse e i prelievi successivi; le scommesse già piazzate tengono il proprio importo ([DAT-26]) |
|
||||
| `fee_address` | String(128), non null | nessun default nel modello; la riga nasce con `""` | indirizzo PLM bech32 valido | Dove va il 30% di ogni round | Dal round **successivo**, copiato all'apertura ([DAT-61]); il round in corso paga la commissione all'indirizzo con cui si è aperto |
|
||||
| `bet_amount_sats` | BigInteger | `1_000_000_000` (10 PLM) | `> 0`, `≤ 100 000 PLM` | Costo della scommessa; anche il prelievo minimo | Per le scommesse, dal round **successivo** ([DAT-61]); per il prelievo minimo, subito ([ADR-20](adr/ADR-20-prelievo-minimo-costo-corrente-scommessa.md)). Le scommesse già piazzate tengono il proprio importo ([DAT-26]) |
|
||||
| `round_duration_seconds` | Integer | `600` | 30 s – 7 giorni | Durata del round | Dal round **successivo** ([RND-05](ciclo-di-vita-del-round.md)) |
|
||||
| `round_cooldown_seconds` | Integer | `30` | 0 s – 24 h | Pausa dopo la chiusura | Dal round **successivo**: la pausa dopo il round in corso è quella copiata alla sua apertura ([RND-05](ciclo-di-vita-del-round.md)) |
|
||||
| `draw_animation_seconds` | Integer | `20` | 0 – 600 s | Durata minima dell'animazione dell'estrazione nel frontend; non condiziona l'estrazione vera | Subito (letto da `GET /rounds/current`) |
|
||||
@@ -781,7 +778,7 @@ senza riavviare (vedi [limiti-noti.md](limiti-noti.md)).
|
||||
| `rbf_timeout_seconds` | Integer | `900` | 60 s – 7 giorni | Dopo quanto senza conferme si fa un bump RBF | Subito, anche per le transazioni già in volo (il bumper lo rilegge a ogni giro) |
|
||||
| `deposit_confirmations` | Integer | `6` | 1 – 100 | Conferme richieste per accreditare un deposito ([DAT-62]) | Subito, per gli accrediti successivi; gli output già accreditati restano |
|
||||
| `draw_confirmations` | Integer | `3` | 1 – 20 | Conferme richieste sul blocco di estrazione ([DAT-62]) | Dal round **successivo**, copiato all'apertura ([DAT-61]) |
|
||||
| `max_round_pool_sats` | BigInteger | `0` (tetto disattivato) | `0`, oppure `≥ bet_amount_sats` e `≤ 4 000 000 000 000 000` (400 × 100 000 PLM) | Tetto alla somma delle scommesse di un round ([DAT-27], [DAT-62]) — *da implementare (B-95)* | Subito, anche per il round in corso: vale per le scommesse successive |
|
||||
| `max_round_pool_sats` | BigInteger | `0` (tetto disattivato) | `0`, oppure `≥ bet_amount_sats` e `≤ 4 000 000 000 000 000` (400 × 100 000 PLM) | Tetto alla somma delle scommesse di un round ([DAT-27], [DAT-62]) | Dal round **successivo**, copiato all'apertura ([DAT-61]): un round tiene il tetto con cui si è aperto |
|
||||
| `paused` | Boolean | `False` | non modificabile da `PUT /admin/config` | Pausa della lotteria | Subito per l'apertura del round successivo; il round in corso non è toccato |
|
||||
| `paused_reason` | String(16) | `NULL` | non modificabile da `PUT /admin/config` | Perché la lotteria è in pausa ([DAT-69]) | Insieme a `paused` |
|
||||
| `updated_at` | DateTime | `utcnow`, aggiornato a ogni modifica (`onupdate`) | — | Ultima modifica della riga | ORM |
|
||||
@@ -804,8 +801,7 @@ senza riavviare (vedi [limiti-noti.md](limiti-noti.md)).
|
||||
valore uguale a quello attuale non conta come modifica.
|
||||
*Codice:* `app/api/routes/admin.py:update_config` ·
|
||||
`app/api/routes/admin.py:RoundConfigUpdate` · *Test:* `tests/unit/test_admin.py`
|
||||
*Stato:* da implementare (B-95), per l'ultima colonna ·
|
||||
*Oggi:* le colonne modificabili sono le prime nove.
|
||||
|
||||
|
||||
- **[DAT-30]** `paused` e `paused_reason` si modificano solo con
|
||||
`POST /admin/pause` e `POST /admin/resume`, che scrivono `lottery_paused` e
|
||||
@@ -827,8 +823,6 @@ senza riavviare (vedi [limiti-noti.md](limiti-noti.md)).
|
||||
aggiunge con un `server_default` temporaneo pari al predefinito ([DAT-55]).
|
||||
*Codice:* `app/db/models.py:RoundConfig` · `app/rounds/config.py:get_round_config` ·
|
||||
*Test:* `tests/unit/test_admin.py`, `tests/unit/test_migrations.py`
|
||||
*Stato:* da implementare (B-95) · *Oggi:* `max_round_pool_sats` non esiste:
|
||||
non c'è tetto.
|
||||
|
||||
- **[DAT-69]** `paused_reason` è `NULL` esattamente quando `paused` è falso;
|
||||
con `paused` vero vale uno di questi valori, e nessun altro:
|
||||
|
||||
Reference in new issue
Block a user