feat: add rpcMethodName to degraded events#7954
Conversation
b71652f to
b548d8d
Compare
rpcMethodName to degraded and unavailable events
|
@metamaskbot publish-preview |
|
Preview builds have been published. See these instructions for more information about preview builds. Expand for full list of packages and versions. |
b548d8d to
497c77c
Compare
c5e4118 to
c7b7522
Compare
|
@metamaskbot publish-preview |
|
Preview builds have been published. See these instructions for more information about preview builds. Expand for full list of packages and versions. |
packages/network-controller/src/rpc-service/rpc-service.test.ts
Outdated
Show resolved
Hide resolved
packages/network-controller/src/rpc-service/rpc-service-chain.ts
Outdated
Show resolved
Hide resolved
| // Set the method name right before the callback exits so that | ||
| // it is correct when Cockatiel fires onBreak/onDegraded | ||
| // synchronously after the callback throws or returns. | ||
| this.#currentRpcMethodName = rpcMethodName; |
There was a problem hiding this comment.
I wonder if there is another way we can do this that would always guarantee the right RPC method was associated with the respective onDegraded callback.
Since Cockatiel policies have a concept of "context", I wonder if, before we call execute, we can wrap this.#policy in another policy that populates its context with the rpcMethodName so that it will automatically be available in callbacks?
I'll think about this...
There was a problem hiding this comment.
I think the way you've done this is probably best. Ideally I would like this code to be closer to onDegraded somehow, but that would probably require rearchitecting RpcService, and I'm not sure it would be worth it.
e1aae33 to
454981e
Compare
|
@metamaskbot publish-preview |
|
Preview builds have been published. See these instructions for more information about preview builds. Expand for full list of packages and versions. |
rpcMethodName to degraded and unavailable eventsrpcMethodName to degraded events
Explanation
RPC endpoint degraded events (
NetworkController:rpcEndpointDegradedand it's chain-level variant) now includerpcMethodNamein their payloads. This identifies which JSON-RPC method was being executed when the endpoint became degraded, enabling better debugging of RPC health issues.The method name is captured in
RpcServicevia#currentRpcMethodName, set in thefinallyblock of the Cockatiel policy'sexecutecallback to minimise the race window between the write and Cockatiel's synchronous event dispatch.References
Fixes: https://consensyssoftware.atlassian.net/browse/WPC-441
rpcMethodNametodegradedRPC endpoint Segment events metamask-extension#40176rpcMethodNametodegradedRPC endpoint Segment events metamask-mobile#26187Checklist
Note
Medium Risk
Introduces a breaking event/listener payload shape change and adds concurrency-sensitive tracking of the “current” RPC method, which could impact downstream consumers or edge-case event accuracy under parallel requests.
Overview
Adds
rpcMethodNametoNetworkController:rpcEndpointDegradedandNetworkController:rpcEndpointChainDegradedevent payloads so consumers can attribute slow/retry-exhausted conditions to a specific JSON-RPC method.Threads the method name from
RpcService.request()through Cockatiel’sonDegradeddispatch (via a new#currentRpcMethodName) intocreate-network-client’s degraded event publishers, updates the exportedRpcServiceRequestable.onDegradedlistener type (breaking), and expands/adjusts unit tests to assert the new field (including concurrent-request scenarios).Written by Cursor Bugbot for commit d9075b6. This will update automatically on new commits. Configure here.