Skip to content

refactor!: Replace SafeEventEmitterProvider with InternalProvider#6796

Merged
rekmarks merged 14 commits intomainfrom
rekm/internal-provider
Oct 31, 2025
Merged

refactor!: Replace SafeEventEmitterProvider with InternalProvider#6796
rekmarks merged 14 commits intomainfrom
rekm/internal-provider

Conversation

@rekmarks
Copy link
Copy Markdown
Member

@rekmarks rekmarks commented Oct 7, 2025

Explanation

As of #6328 SafeEventEmitterProvider no longer used the EventEmitter API, making its name misleading. Consequently, this PR renames it to InternalProvider and stops extending SafeEventEmitter. This new name better reflects its use as an internal-only provider that does not conform to any particular standard.

SafeEventEmitterProvider is still exported as a deprecated alias of InternalProvider in order to circumvent build failures due to repo-external packages that use this alias. Once we have updated external packages to use InternalProvider instead, the old alias can be removed.

References

Closes #6594

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, highlighting breaking changes as necessary
  • I've prepared draft pull requests for clients and consumer packages to resolve any breaking changes

Note

Renames and replaces SafeEventEmitterProvider with InternalProvider across packages, updates proxies and types, adds a deprecated alias, and adjusts tests/changelogs accordingly.

  • Provider (eth-json-rpc-provider):
    • Add InternalProvider (no longer extends SafeEventEmitter); update providerFromEngine/providerFromMiddleware to return it.
    • Export SafeEventEmitterProvider as a deprecated alias; update tests/exports; drop @metamask/safe-event-emitter dep.
  • Middleware (eth-json-rpc-middleware):
    • Change provider types to InternalProvider in block-ref, retryOnEmpty, and providerAsMiddleware.
  • Block Tracker (eth-block-tracker):
    • Expect InternalProvider in PollingBlockTracker and tests; update CHANGELOG (BREAKING).
  • Network Controller:
    • Switch provider type to InternalProvider across types/clients.
    • Use createSwappableProxy for provider proxies; keep createEventEmitterProxy for block tracker; adjust handlers/comments and tests.
  • Selected Network Controller:
    • Use createSwappableProxy for provider proxy; align with InternalProvider; update tests.
  • Tests/Utilities:
    • Update FakeProvider/FakeBlockTracker and various tests to InternalProvider.
  • Changelogs:
    • Note BREAKING change across affected packages.
  • Misc:
    • Update ESLint thresholds and snapshots; lockfile changes reflect dependency removal.

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

@rekmarks rekmarks changed the title refactor!: refactorSafeEventEmitterProvider -> InternalProvider refactor!: Replace SafeEventEmitterProvider with InternalProvider Oct 7, 2025
@rekmarks rekmarks marked this pull request as ready for review October 7, 2025 20:59
@rekmarks rekmarks requested review from a team as code owners October 7, 2025 20:59
Copy link
Copy Markdown
Contributor

@mcmire mcmire left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think there's one thing with the proxies that we may want to adjust, but the rest looks good. Thank you for removing the lint warnings as well!

Can you:

  • generate preview builds
  • make a new branch on Extension, upgrade network-controller to the preview build, push the PR, and wait for CI to pass
  • build the extension locally, open the test dapp, and make sure you can still make network requests on different chains
  • do the same thing for mobile

Let me know if you want to tag team this, I have a bit of time now.

cursor[bot]

This comment was marked as outdated.

@rekmarks
Copy link
Copy Markdown
Member Author

rekmarks commented Oct 7, 2025

@metamaskbot publish-preview

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Oct 7, 2025

Preview builds have been published. See these instructions for more information about preview builds.

Expand for full list of packages and versions.
{
  "@metamask-previews/account-tree-controller": "1.4.0-preview-622f3f09",
  "@metamask-previews/accounts-controller": "33.1.0-preview-622f3f09",
  "@metamask-previews/address-book-controller": "6.1.1-preview-622f3f09",
  "@metamask-previews/announcement-controller": "7.0.3-preview-622f3f09",
  "@metamask-previews/app-metadata-controller": "1.0.0-preview-622f3f09",
  "@metamask-previews/approval-controller": "7.1.3-preview-622f3f09",
  "@metamask-previews/assets-controllers": "78.0.0-preview-622f3f09",
  "@metamask-previews/base-controller": "8.4.0-preview-622f3f09",
  "@metamask-previews/bridge-controller": "48.0.0-preview-622f3f09",
  "@metamask-previews/bridge-status-controller": "48.0.0-preview-622f3f09",
  "@metamask-previews/build-utils": "3.0.3-preview-622f3f09",
  "@metamask-previews/chain-agnostic-permission": "1.1.1-preview-622f3f09",
  "@metamask-previews/composable-controller": "11.0.0-preview-622f3f09",
  "@metamask-previews/controller-utils": "11.14.0-preview-622f3f09",
  "@metamask-previews/delegation-controller": "0.7.0-preview-622f3f09",
  "@metamask-previews/earn-controller": "8.0.0-preview-622f3f09",
  "@metamask-previews/eip-5792-middleware": "1.2.0-preview-622f3f09",
  "@metamask-previews/eip1193-permission-middleware": "1.0.0-preview-622f3f09",
  "@metamask-previews/ens-controller": "17.0.1-preview-622f3f09",
  "@metamask-previews/error-reporting-service": "2.2.0-preview-622f3f09",
  "@metamask-previews/eth-json-rpc-provider": "5.0.0-preview-622f3f09",
  "@metamask-previews/foundryup": "1.0.1-preview-622f3f09",
  "@metamask-previews/gas-fee-controller": "24.0.0-preview-622f3f09",
  "@metamask-previews/gator-permissions-controller": "0.2.0-preview-622f3f09",
  "@metamask-previews/json-rpc-engine": "10.1.0-preview-622f3f09",
  "@metamask-previews/json-rpc-middleware-stream": "8.0.7-preview-622f3f09",
  "@metamask-previews/keyring-controller": "23.1.0-preview-622f3f09",
  "@metamask-previews/logging-controller": "6.0.4-preview-622f3f09",
  "@metamask-previews/message-manager": "13.0.0-preview-622f3f09",
  "@metamask-previews/messenger": "0.3.0-preview-622f3f09",
  "@metamask-previews/multichain-account-service": "1.6.0-preview-622f3f09",
  "@metamask-previews/multichain-api-middleware": "1.2.0-preview-622f3f09",
  "@metamask-previews/multichain-network-controller": "1.0.0-preview-622f3f09",
  "@metamask-previews/multichain-transactions-controller": "5.0.0-preview-622f3f09",
  "@metamask-previews/name-controller": "8.0.3-preview-622f3f09",
  "@metamask-previews/network-controller": "24.2.0-preview-622f3f09",
  "@metamask-previews/network-enablement-controller": "2.1.0-preview-622f3f09",
  "@metamask-previews/notification-services-controller": "18.2.0-preview-622f3f09",
  "@metamask-previews/permission-controller": "11.0.6-preview-622f3f09",
  "@metamask-previews/permission-log-controller": "4.0.0-preview-622f3f09",
  "@metamask-previews/phishing-controller": "14.1.0-preview-622f3f09",
  "@metamask-previews/polling-controller": "14.0.0-preview-622f3f09",
  "@metamask-previews/preferences-controller": "20.0.1-preview-622f3f09",
  "@metamask-previews/profile-sync-controller": "25.1.0-preview-622f3f09",
  "@metamask-previews/rate-limit-controller": "6.0.3-preview-622f3f09",
  "@metamask-previews/remote-feature-flag-controller": "1.7.0-preview-622f3f09",
  "@metamask-previews/sample-controllers": "2.0.0-preview-622f3f09",
  "@metamask-previews/seedless-onboarding-controller": "4.0.0-preview-622f3f09",
  "@metamask-previews/selected-network-controller": "24.0.0-preview-622f3f09",
  "@metamask-previews/shield-controller": "0.2.0-preview-622f3f09",
  "@metamask-previews/signature-controller": "34.0.0-preview-622f3f09",
  "@metamask-previews/subscription-controller": "1.0.0-preview-622f3f09",
  "@metamask-previews/token-search-discovery-controller": "3.3.0-preview-622f3f09",
  "@metamask-previews/transaction-controller": "60.6.0-preview-622f3f09",
  "@metamask-previews/user-operation-controller": "39.0.0-preview-622f3f09"
}

@rekmarks
Copy link
Copy Markdown
Member Author

rekmarks commented Oct 7, 2025

cc: @mcmire

@mcmire

This comment was marked as outdated.

@rekmarks

This comment was marked as outdated.

@rekmarks rekmarks marked this pull request as draft October 8, 2025 16:17
@rekmarks rekmarks force-pushed the rekm/internal-provider branch 2 times, most recently from c48651b to 2caa429 Compare October 28, 2025 17:39
@rekmarks rekmarks force-pushed the rekm/internal-provider branch from 2caa429 to f0dbedf Compare October 29, 2025 20:39
@rekmarks rekmarks requested a review from mcmire October 29, 2025 20:40
@rekmarks rekmarks marked this pull request as ready for review October 29, 2025 20:40
* @deprecated Use {@link InternalProvider} instead.
*/
type SafeEventEmitterProvider = InternalProvider;
const SafeEventEmitterProvider = InternalProvider;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the reasoning for keeping the alias around if we are removing it everywhere?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Builds / tests fail because something monorepo-external uses SafeEventEmitterProvider and removing it completely blows up. My suspicion is that all library uses of it need to be removed, then we can delete the deprecated alias completely.


this.messenger.registerActionHandler(
// TODO: Either fix this lint violation or explain why it's necessary to ignore.
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are all of these no longer required? 🤔

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My suspicion is that they weren't required prior to this PR, and the manner in which I linted the package (yarn eslint --fix packages/... from root) removed a bunch of unused disable directives.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When these lint violations appeared, at the time we were using an older version of the typescript-eslint packages. When we upgraded, they went away.

Copy link
Copy Markdown
Contributor

@mcmire mcmire left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

import { type JsonRpcRequest, type Json } from '@metamask/utils';
import { BrowserProvider } from 'ethers';
import { promisify } from 'util';
// eslint-disable-next-line import-x/namespace
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ugh, I'm not sure why we have this lint rule, it doesn't make sense to me. Oh well...


this.messenger.registerActionHandler(
// TODO: Either fix this lint violation or explain why it's necessary to ignore.
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When these lint violations appeared, at the time we were using an older version of the typescript-eslint packages. When we upgraded, they went away.

@rekmarks rekmarks enabled auto-merge (squash) October 31, 2025 18:17
@rekmarks rekmarks disabled auto-merge October 31, 2025 18:17
@rekmarks rekmarks enabled auto-merge (squash) October 31, 2025 18:19
@rekmarks rekmarks disabled auto-merge October 31, 2025 19:07
@rekmarks
Copy link
Copy Markdown
Member Author

I am bypassing rules to merge this without a review from @MetaMask/confirmations. Their review requirement was triggered by changes to packages/transaction-controller, but the only thing we did was rename the type of a property in a test mock.

@rekmarks rekmarks merged commit b3b0638 into main Oct 31, 2025
260 checks passed
@rekmarks rekmarks deleted the rekm/internal-provider branch October 31, 2025 19:09
github-merge-queue bot pushed a commit to MetaMask/metamask-extension that referenced this pull request Mar 23, 2026
## **Description**

Bump the following packages:

### `@metamask/chain-agnostic-permission` `^1.3.0` → `^1.4.0`

[Changelog](https://github.com/MetaMask/core/blob/main/packages/chain-agnostic-permission/CHANGELOG.md#140)
- **Added:** `Bip122AccountChangedNotifications` property in
`KnownSessionProperties` enum
([#7537](MetaMask/core#7537))
- **Changed:** Remove `@metamask/network-controller` dependency
([#7561](MetaMask/core#7561))
- **Changed:** Dependency bumps (`@metamask/utils`,
`@metamask/controller-utils`, `@metamask/permission-controller`)

### `@metamask/multichain-api-middleware` `^1.2.5` → `^1.2.7`

[Changelog](https://github.com/MetaMask/core/blob/main/packages/multichain-api-middleware/CHANGELOG.md#127)
- **v1.2.7:** Dependency bumps (`network-controller` ^30.0.0,
`json-rpc-engine`, `multichain-transactions-controller`,
`controller-utils`)
- **v1.2.6 Fixed:** `wallet_revokeSession` to handle cases where
`params` is not provided
([#7551](MetaMask/core#7551))
- **v1.2.6 Changed:** Dependency bumps (`json-rpc-engine`, `utils`,
`network-controller`, `controller-utils`, `permission-controller`,
`chain-agnostic-permission`)

### `@metamask/ppom-validator` `0.39.0` → `0.39.1`

[Changelog](https://github.com/MetaMask/ppom-validator/blob/main/CHANGELOG.md#0391)
- **Changed:** Move `@metamask/network-controller` from peer to direct
dependency and bump ^25.0.0 → ^30.0.0
([#254](MetaMask/ppom-validator#254))
- **Changed:** Bump `@metamask/utils` from `^9.2.1` to `^11.0.0`
([#254](MetaMask/ppom-validator#254))

### `@metamask/selected-network-controller` `^25.0.0` → `^26.0.3`

[Changelog](https://github.com/MetaMask/core/blob/main/packages/selected-network-controller/CHANGELOG.md#2600)
- **v26.0.0 BREAKING:** Use `InternalProvider` instead of
`SafeEventEmitterProvider`
([#6796](MetaMask/core#6796))
- **v26.0.0 BREAKING:** Bump `@metamask/network-controller` from ^25.0.0
to ^26.0.0 ([#7202](MetaMask/core#7202))
- **v26.0.1:** Move peer dependencies to direct dependencies
(`network-controller`, `permission-controller`)
([#7209](MetaMask/core#7209))
- **v26.0.2–v26.0.3:** Dependency bumps (`network-controller` to
^30.0.0, `json-rpc-engine`)

No code changes required — breaking changes are internal to the packages
and don't affect extension usage. All dependency versions are already
compatible.

## **Changelog**

CHANGELOG entry: null

## **Related issues**

Fixes: N/A

## **Manual testing steps**

1. Build the extension and verify it runs correctly
2. Confirm no type errors are introduced

## **Screenshots/Recordings**

N/A — dependency-only changes

## **Pre-merge author checklist**

- [x] 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).
- [x] 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]
> **Medium Risk**
> Dependency-only update, but it upgrades core
networking/permission-related packages (e.g.,
`@metamask/selected-network-controller` and transitive
`@metamask/network-controller`/RPC middleware), which can subtly affect
session/network behavior at runtime.
> 
> **Overview**
> Bumps several MetaMask core dependencies:
`@metamask/chain-agnostic-permission` to `^1.4.0`,
`@metamask/multichain-api-middleware` to `^1.2.7`,
`@metamask/ppom-validator` to `0.39.1`, and
`@metamask/selected-network-controller` to `^26.0.3`.
> 
> Updates `yarn.lock` accordingly, including transitive shifts such as
`@metamask/network-controller` moving to `^30.0.0` in dependent packages
and related RPC middleware/util version bumps.
> 
> <sup>Written by [Cursor
Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit
133258b. This will update automatically
on new commits. Configure
[here](https://cursor.com/dashboard?tab=bugbot).</sup>
<!-- /CURSOR_SUMMARY -->
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.

SafeEventEmitterProvider should reflect that it is no longer a SafeEventEmitter

5 participants