Skip to content

fix: limit default watchBlocks catch-up to 100 blocks - #5381

Merged
jxom merged 2 commits into
mainfrom
jxom/watch-blocks-catch-up-cap
Nov 2, 2026
Merged

jxom merged 2 commits into
mainfrom
jxom/watch-blocks-catch-up-cap

Conversation

@jxom

@jxom jxom commented Nov 2, 2026

Copy link
Copy Markdown
Member

Limits the default emitMissed catch-up in watchBlocks to 100 blocks. After a longer gap, such as a device waking from sleep, it emits only the latest block. An explicit emitMissed: true still emits every block.

Follows #5380, which turned emitMissed on by default on fast chains. On Arbitrum, one hour of sleep queued about 14,400 getBlock calls before the latest block.

@vercel

vercel Bot commented Nov 2, 2026 •

Copy link
Copy Markdown

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

Project Deployment Actions Updated
viem Ready Ready Preview Nov 2, 2026 8:11pm UTC

Request Review

@changeset-bot

changeset-bot Bot commented Nov 2, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: d0743d9

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
viem Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 2, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-02T20:06:52.866905Z d0743d9 New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 017ecb6324

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

pollingInterval > blockTime / 2)
// The default catches up at most 100 blocks, so a long gap, such as a
// device waking from sleep, skips to the latest block.
const maxMissed = emitMissed_ === undefined ? 100 : Number.POSITIVE_INFINITY

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Include the catch-up cap in the observer key

When one watcher relies on the default emitMissed value and another explicitly sets emitMissed: true on the same client, both compute emitMissed === true and therefore share the same observer ID. Because observe runs only the first watcher's polling function, the explicit watcher can incorrectly inherit the 100-block cap, or the default watcher can inherit unlimited catch-up, depending on registration order. Include maxMissed or the explicit/default distinction in the observer key so these different behaviors cannot be deduplicated.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in d0743d9: maxMissed is now part of the observer key, with a test that runs a default watcher beside an explicit emitMissed: true one.

@github-actions

github-actions Bot commented Nov 2, 2026 •

Copy link
Copy Markdown
Contributor

Published viem@0.0.0-pr-5381-d0743d9 under the pr-5381 dist-tag, which follows this pull request until it closes.

pnpm add viem@pr-5381
pnpm add viem@0.0.0-pr-5381-d0743d9

@jxom
jxom merged commit 5d11346 into main Nov 2, 2026
37 of 41 checks passed
@jxom
jxom deleted the jxom/watch-blocks-catch-up-cap branch November 2, 2026 20:18
This was referenced Nov 2, 2026

This branch was successfully deployed

1 active deployment
Preview — d0743d98 Deployed Nov 2, 2026 by vercel[bot]
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