Close the smaller state inconsistencies (B-96, BET-02, BET-07, WDR-01, WDR-15, TX-16, TX-18, TX-27, TX-29, DEP-15, DEP-16, AUD-30, AUD-46, DAT-22)
- bet/withdrawal routes read listener.client after taking the user lock - a reduced full-balance withdrawal is checked against the minimum again - a bet covered only by pending balance answers balance_pending_confirmation - a recovered bet/withdrawal/payout writes bet_placed/withdrawal_sent/payout_sent - an abandoned payout clears winner/fee/reserve amounts with payout_txid - the reconciler pings SSE only for rows it changed - closing_stalled every 30 minutes past the deadline; closing_waiting_since on /rounds/current - one refresh per user at a time; a failed refresh no longer ends the Electrum session Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
24e5fc3d8b
commit
9520c80dcf
23 files changed
+445
-151
No files matched your search
@@ -47,6 +47,9 @@ _PAYOUT_RETRY_INTERVAL_SECONDS = 60
|
||||
# corroboration failure. These only make an already-long wait *observable*, they
|
||||
# never cut it short.
|
||||
_DRAW_PROGRESS_LOG_INTERVAL_SECONDS = 60
|
||||
# B-96 (TX-29, AUD-46): how long past its deadline a round may sit in `closing` on an in-flight bet before
|
||||
# `closing_stalled` is written, and how often it repeats. The wait itself has no limit (ADR-51).
|
||||
CLOSING_STALL_THRESHOLD_SECONDS = 1800
|
||||
_DRAW_STALL_THRESHOLD_SECONDS = 360 # a few multiples of PLM's 120s block time
|
||||
|
||||
|
||||
@@ -143,10 +146,50 @@ class RoundScheduler:
|
||||
)
|
||||
)
|
||||
if pending_count:
|
||||
await self._note_closing_stall(round_id, deadline)
|
||||
return # wait for in-flight bets to confirm before closing; stays "closing"
|
||||
|
||||
await self._close_and_draw(round_id)
|
||||
|
||||
async def _note_closing_stall(self, round_id: int, deadline: datetime) -> None:
|
||||
"""B-96 (TX-29, AUD-46): the wait in `closing` is unbounded by design, so it is made
|
||||
visible — one `closing_stalled` row per CLOSING_STALL_THRESHOLD_SECONDS once the round has
|
||||
been past its deadline for that long. The latest row is the clock of the next one (read
|
||||
from the log, not from memory, so a restart neither repeats nor anticipates it)."""
|
||||
now = datetime.now(timezone.utc)
|
||||
seconds_past = (now - deadline).total_seconds()
|
||||
if seconds_past < CLOSING_STALL_THRESHOLD_SECONDS:
|
||||
return
|
||||
async with self._session_factory() as session:
|
||||
last = await session.scalar(
|
||||
select(AuditLog.created_at)
|
||||
.where(AuditLog.event_type == "closing_stalled", AuditLog.round_id == round_id)
|
||||
.order_by(AuditLog.id.desc())
|
||||
.limit(1)
|
||||
)
|
||||
if last is not None and now < last.replace(tzinfo=timezone.utc) + timedelta(
|
||||
seconds=CLOSING_STALL_THRESHOLD_SECONDS
|
||||
):
|
||||
return
|
||||
txids = list(
|
||||
await session.scalars(
|
||||
select(RoundParticipant.bet_txid)
|
||||
.where(
|
||||
RoundParticipant.round_id == round_id,
|
||||
RoundParticipant.status.in_(("building", "broadcast")),
|
||||
)
|
||||
.order_by(RoundParticipant.id)
|
||||
)
|
||||
)
|
||||
await write_audit_log(
|
||||
session,
|
||||
"closing_stalled",
|
||||
{"in_flight": len(txids), "txids": txids, "seconds_past_deadline": int(seconds_past)},
|
||||
round_id=round_id,
|
||||
)
|
||||
await session.commit()
|
||||
logger.warning("round %s has waited %ss past its deadline for %s in-flight bet(s)", round_id, int(seconds_past), len(txids))
|
||||
|
||||
async def _close_and_draw(self, round_id: int) -> None:
|
||||
"""Close a `closing` round once nothing is in flight: either close it (no confirmed
|
||||
participant) or commit to the draw — fix the participant list, its fingerprint and the
|
||||
|
||||
Reference in new issue
Block a user