Engine

Watcher

A second, independent program that rebuilds every proposed holder draw from the chain and cancels one that does not match.

Codeengine/src/watcher/ (index.ts, watcher.ts)
Runs asIts own process, dist/watcher.mjs
Pollevery WATCHER_POLL_SECONDS (20 s)
NeedsAn Elysium RPC. No database, no API, nothing from the engine
TodayNot running. It watches a deployed PrizePoolV2, and none is deployed

The PrizePool already refuses a round whose randomness is not drand's, and it picks the winners itself. The one thing it takes on trust is the table of weights: who held how much, for how long. The watcher rebuilds that table for every proposed round and compares it with the one on chain. If they differ, it cancels the round before its veto window ends, and the pot stays in the pool for the next round.

See Holder draws for how a round and its table are defined.

Why it is separate

The watcher exists to catch what goes wrong with the engine: a bug, a stolen draw key, or an RPC that lies. So it shares nothing with the engine but the chain.

EngineWatcher
Hostits owna different one
RPC providerELYSIUM_RPC_URLa different provider
KeyDRAW_KEY (proposes)GUARDIAN_KEY (cancels)
StatePostgresin memory only

It uses the same code to rebuild a round (engine/src/draws/round.ts), but in its own run, on its own machine, through its own RPC.

Danger

Never put GUARDIAN_KEY on the engine's host. One machine holding both keys can propose a wrong round and has the only key that would cancel it.

What it checks

Every poll it reads the PrizePool's pendingRounds. For each round it has not checked yet:

  1. Reads the round from the contract: pot, winners, root, total weight and randomness. The randomness on chain was already verified by the contract against drand's public key.
  2. Rebuilds the round from the token's transfers, with that pot and that randomness.
  3. Compares the result with what was proposed.
It findsIt does
The same root, the same total weight and the same winnersNotes the round as verified. Nothing is sent
A different root or total weightCalls veto(roundId) and raises an alert. The pot stays in the pool
Winners that are not the ones its own table and the randomness giveThe same
A round that should not have been drawn at all (fewer than three eligible wallets)The same
It cannot read the chainKeeps retrying while there is time, with a warning. See below
A wrong round, but it has no guardian key, or its veto failedRaises an alert naming the round, so a guardian can call veto by hand. It tries again every poll

A round it could not check

Not being able to check a round is not the same as the round being wrong. While more than a fifth of the veto window is left (and at least 60 s), the watcher warns and retries on the next poll. Inside that last stretch:

WATCHER_VETO_UNVERIFIEDWhat happens
true (default)It vetoes the round. The pot waits for the next one
falseIt raises an alert (…is about to be paid WITHOUT having been checked) and lets the round be paid

A false veto is harmless (the pot rolls over) but noisy. If the watcher cancels a round you believe was honest, compare npm run draw on both machines for that round before anything else.

Settings

Settings are in engine/watcher.env.example.

VariableDefaultWhat it does
MOTION_TOKENrequiredThe token whose holders are drawn
PRIZE_POOL_ADDRESSrequiredThe PrizePoolV2 to watch
FEE_SPLITTER_ADDRESSunsetAs the engine has it. This contract never wins
SWAP_ADAPTER_ADDRESSunsetAs the engine has it. This contract never wins
DRAW_EXCLUDEemptyExactly as the engine has it
ELYSIUM_RPC_URLthe public endpointA different provider from the engine's. Several may be listed, comma-separated
GUARDIAN_KEYunsetA wallet holding the PrizePool's GUARDIAN_ROLE, with a little HYPE for gas. Without it the watcher checks and alerts but cannot cancel
ALERT_WEBHOOK_URLunsetWhere alarms go: a Slack or Discord incoming webhook, or any URL that accepts a JSON POST
WATCHER_VETO_UNVERIFIEDtrueCancel a round that could not be checked by the time its veto window is nearly over
WATCHER_POLL_SECONDS20How often it looks (5 to 600)
PORTunsetIf set, serves /health

Warning

MOTION_TOKEN, PRIZE_POOL_ADDRESS, FEE_SPLITTER_ADDRESS, SWAP_ADAPTER_ADDRESS and DRAW_EXCLUDE must match the engine's. Otherwise the two build different tables and the watcher cancels honest rounds.

The round length and the veto window are not settings: the watcher reads roundSeconds and vetoDelay from the PrizePool at start. If the veto window is shorter than six polls, it logs a warning that a wrong round may be paid before it is seen.

Running it

In engine/:

bash
cp watcher.env.example .env.watcher   # MOTION_TOKEN and PRIZE_POOL_ADDRESS at minimum
npm run watcher                       # build + run, reads .env.watcher

In production, build once and start the bundled file. The settings come from the host's environment, and GUARDIAN_KEY from its secret store:

bash
npm run build
npm run start:watcher                 # node dist/watcher.mjs

An invalid configuration stops it with Watcher configuration is invalid: and the failing keys. A token with no HYPE-paired pool on Ascend stops it too.

At start it checks its key and says what it can do, in the log and as an alert (Watcher started: …):

Start-up lineMeaning
guardian 0x… can cancel a wrong roundThe key holds GUARDIAN_ROLE
watching only: no GUARDIAN_KEY…Wrong rounds are reported but cannot be cancelled
watching only: 0x… does not hold the PrizePool's guardian role yet…The admin grants the role with grantRole

Tip

Before real draws start, check that the start-up alert has arrived where a person will see it.

Health and alerts

With PORT set, GET /health answers:

json
{ "ok": true, "canVeto": true, "verified": 12, "vetoed": [], "unresolved": [], "lastTickAt": "2026-12-03T10:15:20.000Z" }
FieldMeaning
okfalse, with HTTP 503, when the last completed poll is older than 5 poll intervals
canVetoThe key holds the guardian role
verifiedHow many rounds it has verified
vetoedThe round ids it cancelled
unresolvedRounds it wanted to cancel but could not, or let through unchecked

The watcher sends its alerts to ALERT_WEBHOOK_URL with the same limits as the engine's (see Risk controls): the same alert at most once in 30 minutes, at most 12 a minute.

AlertLevel
Watcher started: …info
Draw round N could not be checked yet; retryingwarning
Draw round N was cancelled by the watcher: …error
Draw round N is WRONG and was NOT cancelled: this watcher has no guardian key…error
Draw round N is WRONG and the watcher's veto FAILED…error
Draw round N is about to be paid WITHOUT having been checkederror
The watcher cannot read the chain: draws are not being checked (after 3 failed polls in a row)error

The watcher keeps what it has checked in memory. After a restart it checks every pending round again.

What a stolen guardian key can do

The guardian role can do two things on the PrizePool: cancel a pending round with veto, and pause the pool (only the admin can unpause it).

So a thief can stop draws from being paid: each cancelled round's pot stays in the pool. A thief cannot propose a round, pay one, choose a winner or move any money.