A4: round lifecycle, commit-reveal draw and simulated chain (RND-41..44, ADR-57, ADR-59)
lifecycle.tick runs the round from open to closed one write-locked step at a time, resumable from the database (an interrupted draw gives the same winner). Draw primitives move to plm_engine.draw and are shared with the old module. SimulatedChain and settle() stand in for blocks and confirmations; the worker runs both every tick and opens the first round. The round secret is stored encrypted and revealed with the winner; the proof exposes no usernames. Mutation checks confirmed the wait for in-flight bets and the txid ordering are caught by the tests. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
eded058dbb
commit
1d4b53d778
17 files changed
+978
-67
No files matched your search
@@ -1,7 +1,7 @@
|
||||
"""The background worker process (ADR-55).
|
||||
|
||||
A1 ships the process shell only: it starts, logs, stops cleanly on SIGTERM and shows up as a
|
||||
compose service. The round scheduler (A4) and the chain tasks (Phase B) plug into `tick`.
|
||||
"""The background worker process (ADR-55): runs the round lifecycle every few seconds and, on the
|
||||
simulated ledger, settles the confirmations that a real chain would bring (roadmap A4). The chain tasks
|
||||
of phase B plug into `tick` too. A step that fails is logged and retried at the next tick: the lifecycle
|
||||
keeps no state outside the database.
|
||||
"""
|
||||
|
||||
import logging
|
||||
@@ -16,7 +16,14 @@ TICK_SECONDS = 5
|
||||
|
||||
|
||||
def tick() -> None:
|
||||
"""One pass over everything the worker is responsible for. Empty until A4."""
|
||||
"""One pass over everything the worker is responsible for."""
|
||||
from django.conf import settings
|
||||
|
||||
from apps.lottery import lifecycle, simulation
|
||||
|
||||
if settings.LEDGER_BACKEND == "simulated":
|
||||
simulation.settle()
|
||||
lifecycle.tick()
|
||||
|
||||
|
||||
class Command(BaseCommand):
|
||||
@@ -32,7 +39,12 @@ class Command(BaseCommand):
|
||||
|
||||
logger.info("worker started")
|
||||
while not stop.is_set():
|
||||
tick()
|
||||
try:
|
||||
tick()
|
||||
except Exception: # a failed step leaves the round where it was; the next tick retries
|
||||
logger.exception("worker tick failed")
|
||||
if options["once"]:
|
||||
raise
|
||||
if options["once"]:
|
||||
break
|
||||
stop.wait(TICK_SECONDS)
|
||||
|
||||
Reference in new issue
Block a user