From 2c38386484cdb507c4687caceb37e0b963e33594 Mon Sep 17 00:00:00 2001 From: historia <[not public]> Date: Fri, 18 Sep 2026 21:50:17 -0400 Subject: fix: make slot payout and stake resolution one durable save --- internal/game/casino.go | 27 +++++++++++---------------- 1 file changed, 11 insertions(+), 16 deletions(-) (limited to 'internal/game/casino.go') diff --git a/internal/game/casino.go b/internal/game/casino.go index f6592ac..c52e5eb 100644 --- a/internal/game/casino.go +++ b/internal/game/casino.go @@ -23,7 +23,7 @@ type casinoWallet struct { // Wager debits the stake and records it in PendingWagers in the SAME atomic // character save. The entry stays until the round resolves: a settlement -// removes the stakes it returns (PayStakeCover) or consumes them +// removes the stakes it returns (PayCredits) or consumes them // (ResolveStake/ResolveStakes), and startup refunds anything still listed // (see recoverPendingWagers). A failed save reverts the in-memory debit and // ledger entry, so a player is never charged for a stake that is not durable. @@ -72,20 +72,15 @@ func (w casinoWallet) Wager(amount int) (casino.Wager, error) { return casino.Wager{Total: amount, Chips: chips, Credits: credits, ID: pending.ID}, nil } -// PayCredits applies winnings that do not return a stake (a slot spin's -// payout: the stake was consumed by playing the round and is resolved -// separately). The credit and the save are the commit point; a failed save -// reverts the credit and reports persistence failure so the caller does not -// announce a win that is not durable. -func (w casinoWallet) PayCredits(amount int) error { - return w.payCredits(amount, nil) -} - -// PayStakeCover applies a settlement whose amount INCLUDES the return of the -// listed stake wager IDs (a table hand pays its stake back inside the -// payout). The credit and the removal of those stakes happen in ONE atomic -// save, so a crash can never pay the payout AND refund the returned stake. -func (w casinoWallet) PayStakeCover(amount int, stakeIDs []string) error { +// PayCredits banks a payout durably and, in the SAME save, resolves the +// listed stakes. stakeIDs may be empty for a payout that returns no stake (a +// free-spin bank already refunded by RefundOutstanding). A table settlement +// passes the hand's stake IDs so the credit and the stake return are one +// atomic step; a slot win passes its triggering stake for the same reason. +// Either way a crash can never pay the payout AND refund the same stake. A +// failed save reverts both the credit and the ledger and reports persistence +// failure, so the caller never announces a win that is not durable. +func (w casinoWallet) PayCredits(amount int, stakeIDs ...string) error { return w.payCredits(amount, stakeIDs) } @@ -129,7 +124,7 @@ func (w casinoWallet) ResolveStakes() { // ResolveStake consumes ONE pending stake by wallet handle: its hand lost or // was paid by a cover, so it must never be refunded. A settlement that -// already removed it (PayStakeCover) makes this a no-op, so no redundant +// already removed it (PayCredits) makes this a no-op, so no redundant // save is paid. func (w casinoWallet) ResolveStake(stakeID string) { if stakeID == "" || !removePendingWager(w.p, stakeID) { -- cgit v1.2.3