Engine
Watcher
A second, independent program that rebuilds every proposed holder draw from the chain and cancels one that does not match.
| Code | engine/src/watcher/ (index.ts, watcher.ts) |
| Runs as | Its own process, dist/watcher.mjs |
| Poll | every WATCHER_POLL_SECONDS (20 s) |
| Needs | An Elysium RPC. No database, no API, nothing from the engine |
| Today | Not 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.
| Engine | Watcher | |
|---|---|---|
| Host | its own | a different one |
| RPC provider | ELYSIUM_RPC_URL | a different provider |
| Key | DRAW_KEY (proposes) | GUARDIAN_KEY (cancels) |
| State | Postgres | in 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:
- 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.
- Rebuilds the round from the token's transfers, with that pot and that randomness.
- Compares the result with what was proposed.
| It finds | It does |
|---|---|
| The same root, the same total weight and the same winners | Notes the round as verified. Nothing is sent |
| A different root or total weight | Calls veto(roundId) and raises an alert. The pot stays in the pool |
| Winners that are not the ones its own table and the randomness give | The same |
| A round that should not have been drawn at all (fewer than three eligible wallets) | The same |
| It cannot read the chain | Keeps retrying while there is time, with a warning. See below |
| A wrong round, but it has no guardian key, or its veto failed | Raises 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_UNVERIFIED | What happens |
|---|---|
true (default) | It vetoes the round. The pot waits for the next one |
false | It 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.
| Variable | Default | What it does |
|---|---|---|
MOTION_TOKEN | required | The token whose holders are drawn |
PRIZE_POOL_ADDRESS | required | The PrizePoolV2 to watch |
FEE_SPLITTER_ADDRESS | unset | As the engine has it. This contract never wins |
SWAP_ADAPTER_ADDRESS | unset | As the engine has it. This contract never wins |
DRAW_EXCLUDE | empty | Exactly as the engine has it |
ELYSIUM_RPC_URL | the public endpoint | A different provider from the engine's. Several may be listed, comma-separated |
GUARDIAN_KEY | unset | A 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_URL | unset | Where alarms go: a Slack or Discord incoming webhook, or any URL that accepts a JSON POST |
WATCHER_VETO_UNVERIFIED | true | Cancel a round that could not be checked by the time its veto window is nearly over |
WATCHER_POLL_SECONDS | 20 | How often it looks (5 to 600) |
PORT | unset | If 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/:
cp watcher.env.example .env.watcher # MOTION_TOKEN and PRIZE_POOL_ADDRESS at minimum
npm run watcher # build + run, reads .env.watcherIn production, build once and start the bundled file. The settings come from the host's environment, and GUARDIAN_KEY from its secret store:
npm run build
npm run start:watcher # node dist/watcher.mjsAn 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 line | Meaning |
|---|---|
| guardian 0x… can cancel a wrong round | The 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:
{ "ok": true, "canVeto": true, "verified": 12, "vetoed": [], "unresolved": [], "lastTickAt": "2026-12-03T10:15:20.000Z" }| Field | Meaning |
|---|---|
ok | false, with HTTP 503, when the last completed poll is older than 5 poll intervals |
canVeto | The key holds the guardian role |
verified | How many rounds it has verified |
vetoed | The round ids it cancelled |
unresolved | Rounds 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.
| Alert | Level |
|---|---|
| Watcher started: … | info |
| Draw round N could not be checked yet; retrying | warning |
| 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 checked | error |
| 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.