Skip to content

test(fork): hint the creation block, so the fork never searches the whole chain - #47

Merged
frontendphil merged 2 commits into
mainfrom
fork-tests-faster
Nov 27, 2026
Merged

frontendphil merged 2 commits into
mainfrom
fork-tests-faster

Conversation

@frontendphil

@frontendphil frontendphil commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

The fork job takes about 2½ minutes on a good day. On #46, test:fork alone took 5m25s.

Why it was slow

I put a logging proxy between anvil and the Tenderly gateway. Most of the upstream time went to eth_getLogs from block 0x0:

suite wall whole-chain eth_getLogs
test:fork 65s 10 calls, 52s
test:fork:guardian 39s 6 calls, 28s
test:fork:deposit 22s 3 calls, 13s
test:fork:alerts 9s 1 call, 5s

Without a block hint, inspect() reads the Roles modifier's logs from block 0. Anvil forwards the part before the fork block upstream, and the gateway then searches all of mainnet for an address that exists only on the fork. That takes 3–8s per new Chronobox, and much longer when the public gateway is slow.

The change (tests only, no app code)

  • test/fork-hints.ts: a BlockHints that says "made after the current head". Each fork suite takes it before its snapshot and passes it to every inspect call that had no hint.
  • A wrong hint cannot hide a history: when the hinted read finds no setup event, the app reads again from block 0 (verifyCancelPermission). fork.ts still checks that path with its hint that is too late.
  • Step 9b makes the app read from block 0 on purpose: without logs it searches the deploy block, and with a hint that is too late it reads again from block 0. These were the pauses after 9a. madeAfter() answers the part before the fork for that one Roles modifier itself (no code, no logs), because the test made it on the fork. The app sends the same requests, and 9b now also asserts that it read from the remembered block and then from block 0x0.
  • Step 10a (the other pause) only needs chainId: 1 on its hints, not get: () => null, so it uses the fork's hint.
  • No chainId on the hint, so no passed history is cached between reads. Every inspect still verifies the full history.

Result, locally, each suite from a cold fork, with no eth_getLogs left going upstream: test:fork 65s → 16s, guardian 39s → 12s, deposit 22s → 10s, alerts 9s → 6s. That's 135s → 44s overall. The recovery suites (not in CI) pass too.

🤖 Generated with Claude Code

…hole chain

Without a block hint, inspect() reads the logs of a Roles modifier from
block 0. On a fork, anvil forwards the part before the fork block to the
forked RPC, which then searches the whole of mainnet for an address that
exists only on the fork: 3 to 8 seconds for each new Chronobox, and much
more when the public gateway is slow (test:fork took 5m25s on #46).

The fork tests now pass a hint: everything they make comes after the head
at their start. A wrong hint cannot hide a history (the app reads again
from block 0 when the start is missing), and fork.ts still checks that
fallback with a hint that is too late.

Locally, from a cold fork: test:fork 65s -> 18s, guardian 39s -> 12s,
deposit 22s -> 10s, alerts 9s -> 6s.

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 11:57am UTC
chronobox-watcher Ready Ready Preview Nov 27, 2026 11:57am UTC

Request Review

The two pauses in test:fork were the reads from block 0 that stayed on
purpose:

- 9b: without logs, the app searches the deploy block with eth_getCode
  at old blocks (21 upstream requests), and a hint that is too late makes
  it read the history again from block 0 (one whole-chain search).
- 10a: its hints returned null, though the step only needs a chainId.

10a now uses the fork's hint. 9b reads through madeAfter(): for the Roles
modifier that the test made on the fork, it answers the part before the
fork itself (no code, no logs) instead of anvil asking the forked RPC.
The app sends the same requests, and 9b now also checks that the history
was read from the remembered block and then from block 0.

test:fork from a cold fork: 18s -> 16s, and no eth_getLogs goes upstream.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@frontendphil
frontendphil merged commit f18b268 into main Nov 27, 2026
7 checks passed
@frontendphil
frontendphil deleted the fork-tests-faster branch November 27, 2026 11:59
frontendphil added a commit that referenced this pull request Nov 27, 2026
test:fork:recovery and test:fork:recovery-alerts ran only by hand. With
the block hints of #47 they take about 10 s each, so CI runs them after
the other fork suites, on the same fork. All six passed in that order
locally.

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
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