MetaMask / MetaMask/metamask-extension
[Performance Issue]: PollingBlockTracker is instantiated with too high pollingInterval
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 13.2k
- Forks
- 5.6k
- Avg merge
- 2d 5h
- Merged PRs (30d)
- 451
Description
### Describe the bug
MetaMask keeps a cache of request/response in order to minimize the calls to the RPC endpoint, but its refresh interval is set too high even for the Ethereum blockchain, let alone other EVM-compatible blockchains with sub-second block creation time.
The PollingBlockTracker cache is instantiated with the default pollingInterval value that is set to 20 seconds:
https://github.com/MetaMask/metamask-extension/blob/7226357422d727cb10b42e749eb3e9b47adaaa4c/app/scripts/controllers/network/createJsonRpcClient.js#L22
https://github.com/MetaMask/eth-block-tracker/blob/c83a963aac367e9820126d7d5a544044741e0b10/src/PollingBlockTracker.ts#L45
The result is that block creations are detected much later than they actually happened, with the consequence that transaction confirmations and event logs are delayed, ruining the user experience.
For the transaction confirmation there is a workaround, it's possible to manually poll the `eth_getTransactionReceipt` function that bypass the cache and also allow MetaMask to detect a block change faster, as soon as the receipt with a more recent block number is returned. But for the event logs I haven't found a workaround yet.
It'd be very useful if the default polling interval was set to a more sane value (5 seconds?), and perhaps overridable from the MetaMask network configuration (and the related API to add a network to MM).
### Steps to reproduce
1. Connect to a network with sub-second block finality
2. Call the `eth_blockNumber` (or submit a transaction, or listen to events)
### Error messages or log output
_No response_
### Version
10.8.2
### Build type
_No response_
### Browser
Chrome, Firefox
### Operating system
Windows, MacOS, Linux
### Hardware wallet
_No response_
### Additional context
_No response_
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Read app/scripts/controllers/network/createJsonRpcClient.js at the linked construction and eth-block-tracker/src/PollingBlockTracker.ts around the default pollingInterval. Reproduce with eth_blockNumber on a sub-second network; done means the tracker interval is no longer fixed at 20 seconds and can be overridden through network configuration, reducing delayed block and event updates.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- blockchain
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100