diff options
Diffstat (limited to '')
| -rw-r--r-- | docs/GAMES.md | 28 | ||||
| -rw-r--r-- | docs/TESTING.md | 10 |
2 files changed, 38 insertions, 0 deletions
diff --git a/docs/GAMES.md b/docs/GAMES.md index 844d1b0..2b8adf5 100644 --- a/docs/GAMES.md +++ b/docs/GAMES.md | |||
| @@ -137,6 +137,34 @@ plays ( | |||
| 137 | The balance update and the `plays` insert happen in one transaction | 137 | The balance update and the `plays` insert happen in one transaction |
| 138 | (`database::apply_play`). | 138 | (`database::apply_play`). |
| 139 | 139 | ||
| 140 | ### Reserved bets and restarts | ||
| 141 | |||
| 142 | Blackjack and crash reserve the bet before the round can settle. The debit and | ||
| 143 | a `pending_plays` row are written in one transaction | ||
| 144 | (`database::reserve_play`); settling deletes that row and writes the `plays` | ||
| 145 | audit row in the same transaction. | ||
| 146 | |||
| 147 | ``` | ||
| 148 | pending_plays ( | ||
| 149 | session_id TEXT PRIMARY KEY, | ||
| 150 | username TEXT NOT NULL, | ||
| 151 | game_type TEXT NOT NULL, | ||
| 152 | bet_amount INTEGER NOT NULL, | ||
| 153 | details TEXT NOT NULL DEFAULT '{}', | ||
| 154 | created_at DATETIME DEFAULT CURRENT_TIMESTAMP | ||
| 155 | ) | ||
| 156 | ``` | ||
| 157 | |||
| 158 | If the server dies with a round in flight, the reservation survives the process. | ||
| 159 | The next startup calls `recover_orphaned_reservations` before the listener | ||
| 160 | accepts connections, and each leftover is settled as a **forfeit**: the bet is | ||
| 161 | not refunded, and the audit row gets `winnings = 0`, | ||
| 162 | `details.result = "abandoned"`, `details.reason = "server_restart"`. | ||
| 163 | |||
| 164 | The sweep runs once per process, never per connection. A per-connection sweep | ||
| 165 | would settle another player's live hand, and only one server process may own a | ||
| 166 | database. | ||
| 167 | |||
| 140 | ## Wire protocol | 168 | ## Wire protocol |
| 141 | 169 | ||
| 142 | Slots keeps its original exchange: | 170 | Slots keeps its original exchange: |
diff --git a/docs/TESTING.md b/docs/TESTING.md index 3c7fa61..60bc4ac 100644 --- a/docs/TESTING.md +++ b/docs/TESTING.md | |||
| @@ -111,6 +111,16 @@ Use an 80-column terminal because several output lines are width-sensitive. | |||
| 111 | 7. Confirm the crash point is absent from the `CRASH_START` line (it must only | 111 | 7. Confirm the crash point is absent from the `CRASH_START` line (it must only |
| 112 | appear once the round is over). | 112 | appear once the round is over). |
| 113 | 113 | ||
| 114 | ## Manual restart check | ||
| 115 | |||
| 116 | 1. Start a blackjack hand (or a crash round) and confirm `pending_plays` has one | ||
| 117 | row while the round is live. | ||
| 118 | 2. `kill -9` the server, then start it again on the same database. The log must | ||
| 119 | say `Settled 1 orphaned reservation(s) as abandoned after a restart`. | ||
| 120 | 3. Confirm the balance did not change, `pending_plays` is empty, and `plays` has | ||
| 121 | one row with `winnings = 0`, `details.result = "abandoned"` and | ||
| 122 | `details.reason = "server_restart"`. | ||
| 123 | |||
| 114 | ## Manual server checks | 124 | ## Manual server checks |
| 115 | 125 | ||
| 116 | - Register, log out, log in again (bcrypt path). | 126 | - Register, log out, log in again (bcrypt path). |
