Skip to content

Commit c26899a

Browse files
authored
refactor!: Migrate eth-json-rpc-middleware to JsonRpcEngineV2 (#7065)
Migrates `@metamask/eth-json-rpc-middleware` to the `JsonRpcEngineV2` conventions in a total overhaul of the package. The semantics of each middleware should be the same as before. One potential behavioral difference is that request cloning within middleware now occurs with `klona` instead of `klona/full`. This is because `klona/full` copies property descriptors such that cloned requests are immutable but not frozen in the `Object.isFrozen()` sense. This is unlikely to make a difference in practice to us, since our request objects have historically been "plain" objects. As with all #6327-related work up to this point, `json-rpc-engine` received minor refactors to facilitate the use of the new abstractions _in situ_. Incidentally, all lint rule exceptions have been removed and all lint warnings and errors have been resolved for `eth-json-rpc-middleware`. Several other packages are changed to support or in consequence of the migration: - `network-controller` - The `NetworkClient` is migrated to `JsonRpcEngineV2`. - The `RpcService` now uses `Readonly<JsonRpcRequest>` internally for request objects received via its `request()` method, since the "fetch" middleware now passes it deeply frozen request objects directly. - `message-manager` and `signature-controller` - Minor changes to types in order to harmonize them with the new conventions.
1 parent be86c60 commit c26899a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+1948
-1569
lines changed

eslint-warning-thresholds.json

Lines changed: 1 addition & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -115,84 +115,6 @@
115115
"packages/eth-block-tracker/tests/withBlockTracker.ts": {
116116
"@typescript-eslint/no-explicit-any": 1
117117
},
118-
"packages/eth-json-rpc-middleware/src/block-cache.ts": {
119-
"@typescript-eslint/no-explicit-any": 1,
120-
"jsdoc/require-jsdoc": 1,
121-
"no-restricted-syntax": 1
122-
},
123-
"packages/eth-json-rpc-middleware/src/block-ref-rewrite.test.ts": {
124-
"@typescript-eslint/no-misused-promises": 3
125-
},
126-
"packages/eth-json-rpc-middleware/src/block-ref-rewrite.ts": {
127-
"jsdoc/match-description": 1
128-
},
129-
"packages/eth-json-rpc-middleware/src/block-ref.test.ts": {
130-
"jest/expect-expect": 2
131-
},
132-
"packages/eth-json-rpc-middleware/src/block-ref.ts": {
133-
"jsdoc/require-jsdoc": 1
134-
},
135-
"packages/eth-json-rpc-middleware/src/block-tracker-inspector.ts": {
136-
"jsdoc/match-description": 1,
137-
"jsdoc/require-jsdoc": 1
138-
},
139-
"packages/eth-json-rpc-middleware/src/fetch.test.ts": {
140-
"jsdoc/match-description": 1
141-
},
142-
"packages/eth-json-rpc-middleware/src/fetch.ts": {
143-
"jsdoc/match-description": 1
144-
},
145-
"packages/eth-json-rpc-middleware/src/inflight-cache.ts": {
146-
"@typescript-eslint/no-explicit-any": 1,
147-
"jsdoc/require-jsdoc": 4
148-
},
149-
"packages/eth-json-rpc-middleware/src/methods/wallet-request-execution-permissions.ts": {
150-
"jsdoc/require-jsdoc": 1
151-
},
152-
"packages/eth-json-rpc-middleware/src/methods/wallet-revoke-execution-permission.ts": {
153-
"jsdoc/require-jsdoc": 1
154-
},
155-
"packages/eth-json-rpc-middleware/src/providerAsMiddleware.ts": {
156-
"jsdoc/require-jsdoc": 1
157-
},
158-
"packages/eth-json-rpc-middleware/src/retryOnEmpty.test.ts": {
159-
"jsdoc/match-description": 3
160-
},
161-
"packages/eth-json-rpc-middleware/src/retryOnEmpty.ts": {
162-
"jsdoc/match-description": 2
163-
},
164-
"packages/eth-json-rpc-middleware/src/utils/cache.ts": {
165-
"jsdoc/match-description": 6
166-
},
167-
"packages/eth-json-rpc-middleware/src/utils/common.ts": {
168-
"jsdoc/match-description": 1
169-
},
170-
"packages/eth-json-rpc-middleware/src/utils/error.ts": {
171-
"jsdoc/require-jsdoc": 1
172-
},
173-
"packages/eth-json-rpc-middleware/src/utils/normalize.ts": {
174-
"jsdoc/match-description": 3
175-
},
176-
"packages/eth-json-rpc-middleware/src/utils/timeout.ts": {
177-
"jsdoc/match-description": 1
178-
},
179-
"packages/eth-json-rpc-middleware/src/utils/validation.ts": {
180-
"jsdoc/require-jsdoc": 4
181-
},
182-
"packages/eth-json-rpc-middleware/src/wallet.ts": {
183-
"@typescript-eslint/no-explicit-any": 2,
184-
"@typescript-eslint/prefer-nullish-coalescing": 5,
185-
"jsdoc/match-description": 3,
186-
"jsdoc/require-jsdoc": 12
187-
},
188-
"packages/eth-json-rpc-middleware/test/setupAfterEnv.ts": {
189-
"@typescript-eslint/no-explicit-any": 3,
190-
"jsdoc/match-description": 2
191-
},
192-
"packages/eth-json-rpc-middleware/test/util/helpers.ts": {
193-
"@typescript-eslint/no-explicit-any": 5,
194-
"jsdoc/match-description": 11
195-
},
196118
"packages/gas-fee-controller/src/GasFeeController.test.ts": {
197119
"import-x/namespace": 2
198120
},
@@ -219,7 +141,7 @@
219141
"jsdoc/check-tag-names": 1
220142
},
221143
"packages/message-manager/src/AbstractMessageManager.ts": {
222-
"jsdoc/check-tag-names": 25
144+
"jsdoc/check-tag-names": 23
223145
},
224146
"packages/message-manager/src/DecryptMessageManager.ts": {
225147
"jsdoc/check-tag-names": 11
@@ -236,9 +158,6 @@
236158
"packages/name-controller/src/util.ts": {
237159
"jsdoc/require-returns": 1
238160
},
239-
"packages/network-controller/src/NetworkController.ts": {
240-
"@typescript-eslint/no-misused-promises": 1
241-
},
242161
"packages/notification-services-controller/src/NotificationServicesController/NotificationServicesController.ts": {
243162
"@typescript-eslint/no-misused-promises": 1
244163
},

eslint.config.mjs

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -230,17 +230,6 @@ const config = createConfig([
230230
'@typescript-eslint/consistent-type-definitions': 'warn',
231231
},
232232
},
233-
{
234-
files: ['packages/eth-json-rpc-middleware/**/*.ts'],
235-
rules: {
236-
// TODO: Re-enable these rules or add inline ignores for warranted cases
237-
'@typescript-eslint/no-explicit-any': 'warn',
238-
'@typescript-eslint/prefer-nullish-coalescing': 'warn',
239-
'jsdoc/match-description': 'warn',
240-
'jsdoc/require-jsdoc': 'warn',
241-
'no-restricted-syntax': 'warn',
242-
},
243-
},
244233
{
245234
files: ['packages/foundryup/**/*.{js,ts}'],
246235
rules: {

packages/eth-json-rpc-middleware/CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
99

1010
### Changed
1111

12+
- **BREAKING:** Migrate to `JsonRpcEngineV2` ([#7065](https://github.com/MetaMask/core/pull/7065))
13+
- Migrates all middleware from `JsonRpcEngine` to `JsonRpcEngineV2`.
14+
- Signatures of various middleware dependencies, e.g. `processTransaction` of `createWalletMiddleware`, have changed
15+
and must be updated by consumers.
16+
- Be advised that request objects are now deeply frozen, and cannot be mutated.
17+
- To continue using this package with the legacy `JsonRpcEngine`, use the `asLegacyMiddleware` backwards compatibility function.
1218
- **BREAKING:** Use `InternalProvider` instead of `SafeEventEmitterProvider` ([#6796](https://github.com/MetaMask/core/pull/6796))
1319
- Wherever a `SafeEventEmitterProvider` was expected, an `InternalProvider` is now expected instead.
1420
- **BREAKING:** Stop retrying `undefined` results for methods that include a block tag parameter ([#7001](https://github.com/MetaMask/core/pull/7001))

packages/eth-json-rpc-middleware/jest.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ module.exports = merge(baseConfig, {
2020
// An object that configures minimum threshold enforcement for coverage results
2121
coverageThreshold: {
2222
global: {
23-
branches: 81.85,
23+
branches: 81.49,
2424
functions: 90.66,
2525
lines: 89.13,
2626
statements: 89.2,

packages/eth-json-rpc-middleware/package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@
5959
"@metamask/eth-json-rpc-provider": "^5.0.1",
6060
"@metamask/eth-sig-util": "^8.2.0",
6161
"@metamask/json-rpc-engine": "^10.1.1",
62+
"@metamask/message-manager": "^14.0.0",
6263
"@metamask/rpc-errors": "^7.0.2",
6364
"@metamask/superstruct": "^3.1.0",
6465
"@metamask/utils": "^11.8.1",
@@ -71,8 +72,10 @@
7172
"@metamask/error-reporting-service": "^3.0.0",
7273
"@metamask/network-controller": "^25.0.0",
7374
"@ts-bridge/cli": "^0.6.4",
75+
"@types/deep-freeze-strict": "^1.1.0",
7476
"@types/jest": "^27.4.1",
7577
"@types/pify": "^5.0.2",
78+
"deep-freeze-strict": "^1.1.1",
7679
"deepmerge": "^4.2.2",
7780
"jest": "^27.5.1",
7881
"tsd": "^0.31.2",

0 commit comments

Comments
 (0)