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

fix: clear cached block after blockResetTimeout when updating the block while polling is not running#348

Merged
jiexi merged 10 commits intomainfrom
jl/clear-cached-block-with-timeout-after-update
Oct 14, 2025
Merged

fix: clear cached block after blockResetTimeout when updating the block while polling is not running#348
jiexi merged 10 commits intomainfrom
jl/clear-cached-block-with-timeout-after-update

Conversation

@jiexi
Copy link
Copy Markdown
Member

@jiexi jiexi commented Oct 14, 2025

Clears the cached block after blockResetTimeout duration when polling is not running and an update is triggered via checkForLatestBlock or getLatestBlock


Note

Clears the cached block after blockResetDuration when getLatestBlock/checkForLatestBlock run while the tracker is not polling, with corresponding tests and changelog updates.

  • Block Tracker behavior:
    • PollingBlockTracker._updateLatestBlock() now schedules a cache reset via _setupBlockResetTimeout() when _isRunning is false, clearing getCurrentBlock() after blockResetDuration.
  • Tests (src/PollingBlockTracker.test.ts):
    • Add/adjust cases to verify a reset timer is started when not running and not started when running for both getLatestBlock() and checkForLatestBlock().
    • Refine useCache: false scenarios to respect pollingInterval timing and cached state.
    • Update various expectations and names around timers, destruction, and listener removal.
  • Docs:
    • CHANGELOG.md: Add Fixed entry describing the new cache-clear behavior when not polling.

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

@jiexi jiexi requested a review from a team as a code owner October 14, 2025 17:40
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 cd5c134 into main Oct 14, 2025
15 checks passed
@jiexi jiexi deleted the jl/clear-cached-block-with-timeout-after-update branch October 14, 2025 18:07
github-merge-queue bot pushed a commit to MetaMask/metamask-extension that referenced this pull request Oct 15, 2025
<!--
Please submit this PR as a draft initially.
Do not mark it as "Ready for review" until the template has been
completely filled out, and PR status checks have passed at least once.
-->

## **Description**

Resolves `@metamask/eth-block-tracker` to `12.2.1` to fix a bug.

See changelog.

[![Open in GitHub
Codespaces](https://github.com/codespaces/badge.svg)](https://codespaces.new/MetaMask/metamask-extension/pull/36869?quickstart=1)

## **Changelog**


CHANGELOG entry: Fixed a bug where the block number returned by the EVM
provider would get stuck and fail to update in certain scenarios

## **Related issues**

See: MetaMask/eth-block-tracker#348
Fixes: https://consensyssoftware.atlassian.net/browse/NWNT-615

## **Manual testing steps**

1. Navigate to a dApp website (e.g., Etherscan, OpenSea)
1. Connect MetaMask wallet to the site
1. Note which network is connected to the website (shown in the "Manage
permissions" area)
1. Click the network selector dropdown in the activity section (below
the main balance area)
1. Select a DIFFERENT network than the one connected to the website
1. Open browser console
1. Run: `Number(await window.ethereum.request({method:
"eth_blockNumber"}))`
1. Wait 1-2 minutes
1. Run the same command again
1. Observe that the block number changed
1. Wait 1-2 minutes
1. Run the same command again
1. Observe that the block number changed

## **Screenshots/Recordings**

<!-- If applicable, add screenshots and/or recordings to visualize the
before and after of your change. -->

### **Before**



https://github.com/user-attachments/assets/c44a9b00-9d74-4274-9cf0-f6c9be3539ed



### **After**



https://github.com/user-attachments/assets/6a2630c9-7f56-425a-806e-eeeaa1700611



## **Pre-merge author checklist**

- [ ] I've followed [MetaMask Contributor
Docs](https://github.com/MetaMask/contributor-docs) and [MetaMask
Extension Coding
Standards](https://github.com/MetaMask/metamask-extension/blob/main/.github/guidelines/CODING_GUIDELINES.md).
- [ ] I've completed the PR template to the best of my ability
- [ ] I’ve included tests if applicable
- [ ] I’ve documented my code using [JSDoc](https://jsdoc.app/) format
if applicable
- [ ] I’ve applied the right labels on the PR (see [labeling
guidelines](https://github.com/MetaMask/metamask-extension/blob/main/.github/guidelines/LABELING_GUIDELINES.md)).
Not required for external contributors.

## **Pre-merge reviewer checklist**

- [ ] I've manually tested the PR (e.g. pull and build branch, run the
app, test code being changed).
- [ ] I confirm that this PR addresses all acceptance criteria described
in the ticket it closes and includes the necessary testing evidence such
as recordings and or screenshots.

<!-- CURSOR_SUMMARY -->
---

> [!NOTE]
> Updates @metamask/eth-block-tracker to 12.2.1 and aligns
@metamask/eth-json-rpc-provider to ^5.0.0.
> 
> - **Dependencies**:
>   - Update `@metamask/eth-block-tracker` to `12.2.1`.
>   - Align `@metamask/eth-json-rpc-provider` to `^5.0.0`.
> 
> <sup>Written by [Cursor
Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit
64156b8. This will update automatically
on new commits. Configure
[here](https://cursor.com/dashboard?tab=bugbot).</sup>
<!-- /CURSOR_SUMMARY -->
runway-github bot added a commit to MetaMask/metamask-extension that referenced this pull request Oct 15, 2025
<!--
Please submit this PR as a draft initially.
Do not mark it as "Ready for review" until the template has been
completely filled out, and PR status checks have passed at least once.
-->

## **Description**

Resolves `@metamask/eth-block-tracker` to `12.2.1` to fix a bug.

See changelog.

[![Open in GitHub
Codespaces](https://github.com/codespaces/badge.svg)](https://codespaces.new/MetaMask/metamask-extension/pull/36869?quickstart=1)

## **Changelog**


CHANGELOG entry: Fixed a bug where the block number returned by the EVM
provider would get stuck and fail to update in certain scenarios

## **Related issues**

See: MetaMask/eth-block-tracker#348
Fixes: https://consensyssoftware.atlassian.net/browse/NWNT-615

## **Manual testing steps**

1. Navigate to a dApp website (e.g., Etherscan, OpenSea)
1. Connect MetaMask wallet to the site
1. Note which network is connected to the website (shown in the "Manage
permissions" area)
1. Click the network selector dropdown in the activity section (below
the main balance area)
1. Select a DIFFERENT network than the one connected to the website
1. Open browser console
1. Run: `Number(await window.ethereum.request({method:
"eth_blockNumber"}))`
1. Wait 1-2 minutes
1. Run the same command again
1. Observe that the block number changed
1. Wait 1-2 minutes
1. Run the same command again
1. Observe that the block number changed

## **Screenshots/Recordings**

<!-- If applicable, add screenshots and/or recordings to visualize the
before and after of your change. -->

### **Before**



https://github.com/user-attachments/assets/c44a9b00-9d74-4274-9cf0-f6c9be3539ed



### **After**



https://github.com/user-attachments/assets/6a2630c9-7f56-425a-806e-eeeaa1700611



## **Pre-merge author checklist**

- [ ] I've followed [MetaMask Contributor
Docs](https://github.com/MetaMask/contributor-docs) and [MetaMask
Extension Coding
Standards](https://github.com/MetaMask/metamask-extension/blob/main/.github/guidelines/CODING_GUIDELINES.md).
- [ ] I've completed the PR template to the best of my ability
- [ ] I’ve included tests if applicable
- [ ] I’ve documented my code using [JSDoc](https://jsdoc.app/) format
if applicable
- [ ] I’ve applied the right labels on the PR (see [labeling
guidelines](https://github.com/MetaMask/metamask-extension/blob/main/.github/guidelines/LABELING_GUIDELINES.md)).
Not required for external contributors.

## **Pre-merge reviewer checklist**

- [ ] I've manually tested the PR (e.g. pull and build branch, run the
app, test code being changed).
- [ ] I confirm that this PR addresses all acceptance criteria described
in the ticket it closes and includes the necessary testing evidence such
as recordings and or screenshots.

<!-- CURSOR_SUMMARY -->
---

> [!NOTE]
> Updates @metamask/eth-block-tracker to 12.2.1 and aligns
@metamask/eth-json-rpc-provider to ^5.0.0.
> 
> - **Dependencies**:
>   - Update `@metamask/eth-block-tracker` to `12.2.1`.
>   - Align `@metamask/eth-json-rpc-provider` to `^5.0.0`.
> 
> <sup>Written by [Cursor
Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit
64156b8. This will update automatically
on new commits. Configure
[here](https://cursor.com/dashboard?tab=bugbot).</sup>
<!-- /CURSOR_SUMMARY -->
runway-github bot added a commit to MetaMask/metamask-extension that referenced this pull request Oct 15, 2025
<!--
Please submit this PR as a draft initially.
Do not mark it as "Ready for review" until the template has been
completely filled out, and PR status checks have passed at least once.
-->

## **Description**

Resolves `@metamask/eth-block-tracker` to `12.2.1` to fix a bug.

See changelog.

[![Open in GitHub
Codespaces](https://github.com/codespaces/badge.svg)](https://codespaces.new/MetaMask/metamask-extension/pull/36869?quickstart=1)

## **Changelog**

CHANGELOG entry: Fixed a bug where the block number returned by the EVM
provider would get stuck and fail to update in certain scenarios

## **Related issues**

See: MetaMask/eth-block-tracker#348
Fixes: https://consensyssoftware.atlassian.net/browse/NWNT-615

## **Manual testing steps**

1. Navigate to a dApp website (e.g., Etherscan, OpenSea)
1. Connect MetaMask wallet to the site
1. Note which network is connected to the website (shown in the "Manage
permissions" area)
1. Click the network selector dropdown in the activity section (below
the main balance area)
1. Select a DIFFERENT network than the one connected to the website
1. Open browser console
1. Run: `Number(await window.ethereum.request({method:
"eth_blockNumber"}))`
1. Wait 1-2 minutes
1. Run the same command again
1. Observe that the block number changed
1. Wait 1-2 minutes
1. Run the same command again
1. Observe that the block number changed

## **Screenshots/Recordings**

<!-- If applicable, add screenshots and/or recordings to visualize the
before and after of your change. -->

### **Before**

https://github.com/user-attachments/assets/c44a9b00-9d74-4274-9cf0-f6c9be3539ed

### **After**

https://github.com/user-attachments/assets/6a2630c9-7f56-425a-806e-eeeaa1700611

## **Pre-merge author checklist**

- [ ] I've followed [MetaMask Contributor
Docs](https://github.com/MetaMask/contributor-docs) and [MetaMask
Extension Coding
Standards](https://github.com/MetaMask/metamask-extension/blob/main/.github/guidelines/CODING_GUIDELINES.md).
- [ ] I've completed the PR template to the best of my ability
- [ ] I’ve included tests if applicable
- [ ] I’ve documented my code using [JSDoc](https://jsdoc.app/) format
if applicable
- [ ] I’ve applied the right labels on the PR (see [labeling
guidelines](https://github.com/MetaMask/metamask-extension/blob/main/.github/guidelines/LABELING_GUIDELINES.md)).
Not required for external contributors.

## **Pre-merge reviewer checklist**

- [ ] I've manually tested the PR (e.g. pull and build branch, run the
app, test code being changed).
- [ ] I confirm that this PR addresses all acceptance criteria described
in the ticket it closes and includes the necessary testing evidence such
as recordings and or screenshots.

<!-- CURSOR_SUMMARY -->
---

> [!NOTE]
> Updates @metamask/eth-block-tracker to 12.2.1 and aligns
@metamask/eth-json-rpc-provider to ^5.0.0.
>
> - **Dependencies**:
>   - Update `@metamask/eth-block-tracker` to `12.2.1`.
>   - Align `@metamask/eth-json-rpc-provider` to `^5.0.0`.
>
> <sup>Written by [Cursor
Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit
64156b8. This will update automatically
on new commits. Configure
[here](https://cursor.com/dashboard?tab=bugbot).</sup>
<!-- /CURSOR_SUMMARY -->
runway-github bot pushed a commit to MetaMask/metamask-extension that referenced this pull request Oct 15, 2025
…ker` to `12.2.1` (#36869)

<!--
Please submit this PR as a draft initially.
Do not mark it as "Ready for review" until the template has been
completely filled out, and PR status checks have passed at least once.
-->

## **Description**

Resolves `@metamask/eth-block-tracker` to `12.2.1` to fix a bug.

See changelog.

[![Open in GitHub
Codespaces](https://github.com/codespaces/badge.svg)](https://codespaces.new/MetaMask/metamask-extension/pull/36869?quickstart=1)

## **Changelog**


CHANGELOG entry: Fixed a bug where the block number returned by the EVM
provider would get stuck and fail to update in certain scenarios

## **Related issues**

See: MetaMask/eth-block-tracker#348
Fixes: https://consensyssoftware.atlassian.net/browse/NWNT-615

## **Manual testing steps**

1. Navigate to a dApp website (e.g., Etherscan, OpenSea)
1. Connect MetaMask wallet to the site
1. Note which network is connected to the website (shown in the "Manage
permissions" area)
1. Click the network selector dropdown in the activity section (below
the main balance area)
1. Select a DIFFERENT network than the one connected to the website
1. Open browser console
1. Run: `Number(await window.ethereum.request({method:
"eth_blockNumber"}))`
1. Wait 1-2 minutes
1. Run the same command again
1. Observe that the block number changed
1. Wait 1-2 minutes
1. Run the same command again
1. Observe that the block number changed

## **Screenshots/Recordings**

<!-- If applicable, add screenshots and/or recordings to visualize the
before and after of your change. -->

### **Before**



https://github.com/user-attachments/assets/c44a9b00-9d74-4274-9cf0-f6c9be3539ed



### **After**



https://github.com/user-attachments/assets/6a2630c9-7f56-425a-806e-eeeaa1700611



## **Pre-merge author checklist**

- [ ] I've followed [MetaMask Contributor
Docs](https://github.com/MetaMask/contributor-docs) and [MetaMask
Extension Coding
Standards](https://github.com/MetaMask/metamask-extension/blob/main/.github/guidelines/CODING_GUIDELINES.md).
- [ ] I've completed the PR template to the best of my ability
- [ ] I’ve included tests if applicable
- [ ] I’ve documented my code using [JSDoc](https://jsdoc.app/) format
if applicable
- [ ] I’ve applied the right labels on the PR (see [labeling
guidelines](https://github.com/MetaMask/metamask-extension/blob/main/.github/guidelines/LABELING_GUIDELINES.md)).
Not required for external contributors.

## **Pre-merge reviewer checklist**

- [ ] I've manually tested the PR (e.g. pull and build branch, run the
app, test code being changed).
- [ ] I confirm that this PR addresses all acceptance criteria described
in the ticket it closes and includes the necessary testing evidence such
as recordings and or screenshots.

<!-- CURSOR_SUMMARY -->
---

> [!NOTE]
> Updates @metamask/eth-block-tracker to 12.2.1 and aligns
@metamask/eth-json-rpc-provider to ^5.0.0.
> 
> - **Dependencies**:
>   - Update `@metamask/eth-block-tracker` to `12.2.1`.
>   - Align `@metamask/eth-json-rpc-provider` to `^5.0.0`.
> 
> <sup>Written by [Cursor
Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit
64156b8. This will update automatically
on new commits. Configure
[here](https://cursor.com/dashboard?tab=bugbot).</sup>
<!-- /CURSOR_SUMMARY -->
gauthierpetetin added a commit to MetaMask/metamask-extension that referenced this pull request Oct 15, 2025
…ker` to `12.2.1` (#36903)

- chore: Resolve `@metamask/eth-block-tracker` to `12.2.1` (#36869)

<!--
Please submit this PR as a draft initially.
Do not mark it as "Ready for review" until the template has been
completely filled out, and PR status checks have passed at least once.
-->

## **Description**

Resolves `@metamask/eth-block-tracker` to `12.2.1` to fix a bug.

See changelog.

[![Open in GitHub

Codespaces](https://github.com/codespaces/badge.svg)](https://codespaces.new/MetaMask/metamask-extension/pull/36869?quickstart=1)

## **Changelog**


CHANGELOG entry: Fixed a bug where the block number returned by the EVM
provider would get stuck and fail to update in certain scenarios

## **Related issues**

See: MetaMask/eth-block-tracker#348
Fixes: https://consensyssoftware.atlassian.net/browse/NWNT-615

## **Manual testing steps**

1. Navigate to a dApp website (e.g., Etherscan, OpenSea)
1. Connect MetaMask wallet to the site
1. Note which network is connected to the website (shown in the "Manage
permissions" area)
1. Click the network selector dropdown in the activity section (below
the main balance area)
1. Select a DIFFERENT network than the one connected to the website
1. Open browser console
1. Run: `Number(await window.ethereum.request({method:
"eth_blockNumber"}))`
1. Wait 1-2 minutes
1. Run the same command again
1. Observe that the block number changed
1. Wait 1-2 minutes
1. Run the same command again
1. Observe that the block number changed

## **Screenshots/Recordings**

<!-- If applicable, add screenshots and/or recordings to visualize the
before and after of your change. -->

### **Before**




https://github.com/user-attachments/assets/c44a9b00-9d74-4274-9cf0-f6c9be3539ed



### **After**




https://github.com/user-attachments/assets/6a2630c9-7f56-425a-806e-eeeaa1700611



## **Pre-merge author checklist**

- [ ] I've followed [MetaMask Contributor
Docs](https://github.com/MetaMask/contributor-docs) and [MetaMask
Extension Coding

Standards](https://github.com/MetaMask/metamask-extension/blob/main/.github/guidelines/CODING_GUIDELINES.md).
- [ ] I've completed the PR template to the best of my ability
- [ ] I’ve included tests if applicable
- [ ] I’ve documented my code using [JSDoc](https://jsdoc.app/) format
if applicable
- [ ] I’ve applied the right labels on the PR (see [labeling

guidelines](https://github.com/MetaMask/metamask-extension/blob/main/.github/guidelines/LABELING_GUIDELINES.md)).
Not required for external contributors.

## **Pre-merge reviewer checklist**

- [ ] I've manually tested the PR (e.g. pull and build branch, run the
app, test code being changed).
- [ ] I confirm that this PR addresses all acceptance criteria described
in the ticket it closes and includes the necessary testing evidence such
as recordings and or screenshots.

<!-- CURSOR_SUMMARY -->
---

> [!NOTE]
> Bumps `@metamask/eth-block-tracker` to 12.2.1 (with
`@metamask/eth-json-rpc-provider` -> ^5.0.0) and updates attribution.
> 
> - **Dependencies**:
>   - Bump `@metamask/eth-block-tracker` to `12.2.1` in `yarn.lock`.
> - Update transitive dep `@metamask/eth-json-rpc-provider` to `^5.0.0`.
> - **Attribution**:
> - Update `attribution.txt` to reflect `@metamask/eth-block-tracker`
`12.2.1`.
> 
> <sup>Written by [Cursor
Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit
ce58db4. This will update automatically
on new commits. Configure
[here](https://cursor.com/dashboard?tab=bugbot).</sup>
<!-- /CURSOR_SUMMARY -->


[3e55943](3e55943)

---------

Co-authored-by: jiexi <jiexiluan@gmail.com>
Co-authored-by: MetaMask Bot <metamaskbot@users.noreply.github.com>
Co-authored-by: Gauthier Petetin <gauthierpetetin@hotmail.com>
Gudahtt added a commit to MetaMask/metamask-mobile that referenced this pull request Oct 16, 2025
`@metamask/eth-block-tracker` had a bug where a block could be cached
indefinitely if the block tracker was not actively polling. This was
fixed in version 12.2.1.

Details: MetaMask/eth-block-tracker#348

Dependencies that use the block tracker have been updated to ensure
we're only using the version with this fix.
github-merge-queue bot pushed a commit to MetaMask/metamask-mobile that referenced this pull request Oct 16, 2025
## **Description**

`@metamask/eth-block-tracker` had a bug where a block could be cached
indefinitely if the block tracker was not actively polling. This was
fixed in version 12.2.1.

Details: MetaMask/eth-block-tracker#348

Dependencies that use the block tracker have been updated to ensure
we're only using the version with this fix.

I'm not aware of any end-user impact here, but this cache problem was
exposed in some in-progress work.

## **Changelog**

CHANGELOG entry: null

## **Related issues**

MetaMask/eth-block-tracker#348

## **Manual testing steps**

N/A

## **Screenshots/Recordings**

N/A

## **Pre-merge author checklist**

- [x] I’ve followed [MetaMask Contributor
Docs](https://github.com/MetaMask/contributor-docs) and [MetaMask Mobile
Coding
Standards](https://github.com/MetaMask/metamask-mobile/blob/main/.github/guidelines/CODING_GUIDELINES.md).
- [x] I've completed the PR template to the best of my ability
- [x] I’ve included tests if applicable
- [x] I’ve documented my code using [JSDoc](https://jsdoc.app/) format
if applicable
- [x] I’ve applied the right labels on the PR (see [labeling
guidelines](https://github.com/MetaMask/metamask-mobile/blob/main/.github/guidelines/LABELING_GUIDELINES.md)).
Not required for external contributors.

## **Pre-merge reviewer checklist**

- [ ] I've manually tested the PR (e.g. pull and build branch, run the
app, test code being changed).
- [ ] I confirm that this PR addresses all acceptance criteria described
in the ticket it closes and includes the necessary testing evidence such
as recordings and or screenshots.

<!-- CURSOR_SUMMARY -->
---

> [!NOTE]
> Updates key MetaMask dependencies across the network/JSON-RPC stack,
including `eth-block-tracker@12.2.1`, `eth-json-rpc-middleware@19.0.1`,
and `network-controller@24.2.2`.
> 
> - **Dependencies**:
>   - **Network/JSON-RPC stack updates**:
>     - `@metamask/eth-block-tracker` → `12.2.1` (transitive)
>     - `@metamask/eth-json-rpc-middleware` → `^19.0.1`
>     - `@metamask/eth-json-rpc-provider` → `^5.0.1`
>     - `@metamask/eth-json-rpc-infura` → `^10.3.0`
>     - `@metamask/json-rpc-engine` → `^10.1.1`
>     - `@metamask/network-controller` → `^24.2.2`
>     - `@metamask/eip-5792-middleware` → `^1.2.3`
>     - `@metamask/transaction-controller` → `^60.7.0`
> 
> <sup>Written by [Cursor
Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit
839459d. 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