Skip to content

fix(eth-json-rpc-middleware): pass EIP-1898 object block selectors through block-cache and retry-on-empty - #11729

Open
debojyoti10CC wants to merge 2 commits into
MetaMask:mainfrom
debojyoti10CC:fix/eip1898-block-selector
Open

debojyoti10CC wants to merge 2 commits into
MetaMask:mainfrom
debojyoti10CC:fix/eip1898-block-selector

Conversation

@debojyoti10CC

@debojyoti10CC debojyoti10CC commented Nov 24, 2026 •

Copy link
Copy Markdown

Explanation

eth_call (and other block-parameterised methods) with an EIP-1898 object selector, e.g. { blockHash, requireCanonical: true } or { blockNumber }, failed inside eth-json-rpc-middleware before reaching the downstream RPC: createRetryOnEmptyMiddleware treated the block param as a string and called blockRef.slice(2), throwing TypeError: blockRef.slice is not a function. createBlockCacheMiddleware also silently mapped object selectors to the latest bucket.

Both middlewares now skip non-string block selectors and call next(), so the selector reaches downstream unchanged and is never cached or retried here.

Tests: added regression tests for both middlewares (blockHash+requireCanonical and blockNumber selectors). Before the fix, 4 tests fail (TypeError: blockRef.slice is not a function); after, the package suite passes (20 files, 459 tests, no type errors).

References

Fixes #11219

Checklist

  • I've updated the test suite for new or updated code as appropriate
  • I've updated documentation (JSDoc, Markdown, etc.) for new or updated code as appropriate
  • I've communicated my changes to consumers by updating changelogs for packages I've changed

Note

Low Risk
Targeted guardrails in caching/retry middleware with regression tests; behavior for string block tags is unchanged.

Overview
Fixes RPC failures when block-parameterised methods (e.g. eth_call) use EIP-1898 object block selectors ({ blockHash, requireCanonical } or { blockNumber }).

createRetryOnEmptyMiddleware no longer assumes the block param is a hex string, so it avoids calling blockRef.slice(2) on objects and passes those requests to the next middleware instead of retrying via the provider.

createBlockCacheMiddleware treats non-string block tags as non-cacheable, so object selectors are not folded into the "latest" cache bucket and are forwarded unchanged.

Regression tests cover both middlewares; the unreleased changelog documents the fix (Fixes #11219).

Reviewed by Cursor Bugbot for commit fd9b01e. Bugbot is set up for automated code reviews on this repo. Configure here.

…rough block-cache and retry-on-empty

retryOnEmpty called blockRef.slice() on the block parameter, which throws for EIP-1898 selectors such as { blockHash } or { blockNumber }. block-cache also mapped such selectors onto the 'latest' cache bucket. Both middlewares now skip object selectors and forward the request unchanged.

Fixes MetaMask#11219
@debojyoti10CC
debojyoti10CC requested a review from a team as a code owner November 24, 2026 04:27

This branch has not been deployed

No deployments
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.

EIP-1898 object selectors fail before downstream RPC in eth-json-rpc-middleware 26.0.0

1 participant