MetaMask / MetaMask/core

[eth-json-rpc-middleware] Response cache needs to be invalidated when `chainId` changes

Open
#6,875 1 comment 0 reactions 0 assignees View on GitHub
team-wallet-framework wf-bugs
Dominant language
TypeScript
Stars
413
Forks
308
Avg merge
1d 4h
Merged PRs (30d)
253

Description

If I use MetaMask through WalletConnect, then when I change the network in the wallet, the `chainId` is correctly updated in the provider, as is the RPC URL, but `eth-json-rpc-middleware` continues to return values from the old `chainId`, e.g. the result of `getCode` still refers to code deployed on the old network, not the new one that was just switched to.

`eth_getCode` is marked for caching as `perma`:

https://github.com/MetaMask/eth-json-rpc-middleware/blob/main/src/utils/cache.ts#L81

The cache does not check whether `chainId` has changed when evaluating whether the cache should be used.

https://github.com/MetaMask/eth-json-rpc-middleware/blob/main/src/block-cache.ts

The cache needs to be invalidated when `chainId` changes, otherwise stale values will be returned.

Contributor guide

No contributing guide indexed for this repository

Research direction

Start with src/utils/cache.ts and src/block-cache.ts, then trace how cached eth_getCode responses are selected when the provider changes network. Add regression coverage for switching chainId and verify that results from the previous network are not reused; run the eth-json-rpc-middleware package tests to confirm the cache behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
api
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.