Skip to content
This repository was archived by the owner on Oct 16, 2025. It is now read-only.

fix: ensure middleware uses latest block number#416

Merged
jiexi merged 11 commits intomainfrom
jl/bump-eth-block-tracker-getLatestBlock-cache-fix
Oct 9, 2025
Merged

fix: ensure middleware uses latest block number#416
jiexi merged 11 commits intomainfrom
jl/bump-eth-block-tracker-getLatestBlock-cache-fix

Conversation

@jiexi
Copy link
Copy Markdown
Member

@jiexi jiexi commented Oct 8, 2025

Sets useCache: false option for PollingBlockTracker.getLatestBlock() to ensure that an up-to-date block number is retrieved. Previously it was possible to only get out-of-date block numbers if the PollingBlockTracker was no longer polling

See: https://github.com/MetaMask/eth-block-tracker/pull/340/files
See: https://consensyssoftware.atlassian.net/browse/NWNT-615


Note

Update middleware to call blockTracker.getLatestBlock({ useCache: false }) and bump deps to @metamask/eth-block-tracker@^12.2.0 and @metamask/eth-json-rpc-provider@^5.0.0.

  • Middleware:
    • Use blockTracker.getLatestBlock({ useCache: false }) in src/block-cache.ts, src/block-ref-rewrite.ts, src/block-ref.ts, and src/retryOnEmpty.ts to ensure fresh block numbers.
  • Dependencies:
    • Bump @metamask/eth-block-tracker to ^12.2.0 and @metamask/eth-json-rpc-provider to ^5.0.0 (and related transitive updates in yarn.lock).
  • Changelog:
    • Document dependency bumps and latest-block behavior; note removal of ethersProviderAsMiddleware.

Written by Cursor Bugbot for commit 6bc0146. This will update automatically on new commits. Configure here.

@jiexi jiexi requested a review from a team as a code owner October 8, 2025 20:11
CHANGELOG.md Outdated
### Changed

- Bump `@metamask/eth-block-tracker` from `^12.0.0` to `^12.2.0` ([#404](https://github.com/MetaMask/eth-json-rpc-middleware/pull/413))
- Change all `PollingBlockTracker.getLatestBlock()` calls to include `useCache: true` ([#416](https://github.com/MetaMask/eth-json-rpc-middleware/pull/416))
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Is this meant to be indented under the bump entry?

Suggested change
- Change all `PollingBlockTracker.getLatestBlock()` calls to include `useCache: true` ([#416](https://github.com/MetaMask/eth-json-rpc-middleware/pull/416))
- Change all `PollingBlockTracker.getLatestBlock()` calls to include `useCache: true` ([#416](https://github.com/MetaMask/eth-json-rpc-middleware/pull/416))

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.

yeah, but we make it a root level item if you don't think there's value making a sub item

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.

also i think the links for the changelogs are wrong. #404 vs link to 413

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Good catch, I can fix that change entry mistake separately.

I was thinking this should be a top-level entry because it's not really related to the dependency bump

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.

unindented and moved to the bottom of the changes c939a8c

Copy link
Copy Markdown
Member

@Gudahtt Gudahtt left a comment

Choose a reason for hiding this comment

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

LGTM!

@jiexi jiexi merged commit 65e0b97 into main Oct 9, 2025
20 checks passed
@jiexi jiexi deleted the jl/bump-eth-block-tracker-getLatestBlock-cache-fix branch October 9, 2025 20:32
jiexi added a commit that referenced this pull request Oct 15, 2025
Gudahtt pushed a commit that referenced this pull request Oct 15, 2025
This reverts commit 65e0b97.

<!--
Thanks for your contribution! Take a moment to answer these questions so
that reviewers have the information they need to properly understand
your changes:

* What is the current state of things and why does it need to change?
* What is the solution your changes offer and how does it work?

Are there any issues or other links reviewers should consult to
understand this pull request better? For instance:

* Fixes #12345
* See: #67890
-->

<!-- CURSOR_SUMMARY -->
---

> [!NOTE]
> Remove `useCache: false` from `PollingBlockTracker.getLatestBlock()`
calls across middlewares; update changelog and raise Jest coverage
thresholds.
> 
> - **Middleware**:
> - Remove `useCache: false` from `PollingBlockTracker.getLatestBlock()`
in `src/block-cache.ts`, `src/block-ref-rewrite.ts`, `src/block-ref.ts`,
and `src/retryOnEmpty.ts`.
> - **Changelog**:
> - Add Unreleased “Fixed” note about preventing request delays and
reverting `#416`.
> - **Testing**:
> - Increase Jest global coverage thresholds (`branches`, `functions`,
`lines`, `statements`).
> 
> <sup>Written by [Cursor
Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit
2edc83d. This will update automatically
on new commits. Configure
[here](https://cursor.com/dashboard?tab=bugbot).</sup>
<!-- /CURSOR_SUMMARY -->
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants