Repository navigation
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
Open
debojyoti10CC wants to merge 2 commits into
debojyoti10CC wants to merge 2 commits into
Conversation
…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
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Explanation
eth_call(and other block-parameterised methods) with an EIP-1898 object selector, e.g.{ blockHash, requireCanonical: true }or{ blockNumber }, failed insideeth-json-rpc-middlewarebefore reaching the downstream RPC:createRetryOnEmptyMiddlewaretreated the block param as a string and calledblockRef.slice(2), throwingTypeError: blockRef.slice is not a function.createBlockCacheMiddlewarealso silently mapped object selectors to thelatestbucket.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
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 }).createRetryOnEmptyMiddlewareno longer assumes the block param is a hex string, so it avoids callingblockRef.slice(2)on objects and passes those requests to the next middleware instead of retrying via the provider.createBlockCacheMiddlewaretreats 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.