Skip to content

perf(watcher): read a vault only when it changed or an alert of it is due - #51

Open
frontendphil wants to merge 1 commit into
mainfrom
read-on-change
Open

frontendphil wants to merge 1 commit into
mainfrom
read-on-change

Conversation

@frontendphil

Copy link
Copy Markdown
Contributor

The main fix from the RPC analysis. In production, 49 of the 77 requests a minute go to re-reading three vaults that haven't changed. Each vault with something waiting was re-read every minute: for days while a request waited, and forever when a void request was left in the queue.

When a vault is read now

A vault changes only through its contracts, and they log each change. The search in each poll now reads every log (no topic filter) of each vault's Safe, Delay, Recovery Delay, Roles modifier, Council Safe, and the other addresses that can cancel (a Council Safe that's deployed later is on the list before it exists). A vault is read when:

reason new?
one of its contracts logged something new
an alert that only time brings is due (nextAlertAt): wait over, ends soon, void, the recovery reminders 7 days and 1 day before new
an hour passed while something waits (RECHECK_MS) new: covers changes without a log
its heartbeat is due as before
it's new, has alerts left to send, or its last read failed (with backoff) as before

Known limits

  • The Delay 1.0.1 skipExpired() advances txNonce without an event, so a "Removed" alert for a request that's already void can come up to an hour late. Its "void" alert itself is on time.
  • Logs anyone can cause (ETH sent to the Safe) cost one read, at most one per poll, which is what every poll costs today.
  • When the search is behind the head (catching up after an outage), every vault with something waiting is read each poll, as before.
  • Each vault adds about 5 addresses to the search instead of 2, so one eth_getLogs covers 20 vaults instead of 50.

Tests (96 watcher tests pass, tsc and the build are clean)

  • Equivalence: one sequence runs through the single-vault watcher (reads every poll) and through --all: two withdrawals, waits ending, an execution, a queued cooldown change, a request that ends soon, becomes void and is skipped without a log, the change executed, a cancel. Both must send the same alerts at the same polls. The test fails, at the step where it matters, when the due times, the Safe's logs, or the hourly recheck are removed.
  • Unit tests for nextAlertAt (every time-based alert, and that a reminder that can no longer come doesn't keep a vault due every poll) and for watchedBy (the wallet is never watched).
  • When the search doesn't reach the head, vaults with something waiting are read every poll. That test fails without the fallback.
  • The mock chain answers eth_getLogs as a node does (one list, filtered by address, block and topics), and a new request lands in a block of its own. With the old source, all old tests pass on the new mock.
  • test:fork:alerts and test:fork:recovery-alerts (--all against the real contracts on a mainnet fork, including the time-based recovery alerts) pass locally.

Expected effect: about 77 → about 25 requests a minute (the network searches, plus hourly rechecks and reads when something happens). Each additional vault with something waiting costs almost nothing. The rpc: log line will show it.

🤖 Generated with Claude Code

… due

The network watcher read every vault in which something waited in each
poll: about 16 to 23 requests a minute each, also when nothing changed
for days, and for ever when a void request was left in the line.

A vault changes only through its contracts, and they log each change.
The search of each poll now reads every log (no topic filter) of each
vault's Safe, Delay, Recovery Delay, cancel contract, Council Safe and
the other addresses that can cancel. A vault is read when:

- one of them logged something;
- an alert that only time brings is due (nextAlertAt: a wait that ends,
  ends soon, void, the reminders before a recovery can be carried out);
- its heartbeat is due, as before;
- an hour went by while something waits in it (RECHECK_MS): the Delay
  removes void requests in skipExpired() without a log;
- it is new, has alerts left to send or could not be read, as before.

When the search did not reach the head (after an outage), every vault
in which something waits is read in each poll, as before.

The stand-in chain answers eth_getLogs as a node does now (one list,
filtered by address, block and topics), and a request lands in a block
of its own. A new test runs one sequence through a watcher that reads in
each poll and through --all, and requires the same alerts at the same
polls; it fails when the due times, the Safe's logs or the hourly read
are taken out.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@vercel

vercel Bot commented Nov 27, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
chronobox Ready Ready Preview Nov 27, 2026 2:45pm UTC
chronobox-watcher Ready Ready Preview Nov 27, 2026 2:45pm UTC

Request Review

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant