-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #166 from D8-X/track_rpc
Track rpc
- Loading branch information
Showing
5 changed files
with
83 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import { Networkish } from "@ethersproject/providers"; | ||
import { WebSocketLike } from "@ethersproject/providers/lib/websocket-provider"; | ||
import { providers } from "ethers"; | ||
import { ConnectionInfo } from "ethers/lib/utils"; | ||
|
||
export const ProvidersEthCallsStartTime = new Date(); | ||
|
||
/** | ||
* List of eth_ * method calls and their counts for all TrackedJsonRpcProvider | ||
*/ | ||
export const JsonRpcEthCalls = new Map<string, number>(); | ||
|
||
/** | ||
* List of eth_ * method calls and their counts for all TrackedWebsocketsProvider | ||
*/ | ||
export const WssEthCalls = new Map<string, number>(); | ||
|
||
export let NumJsonRpcProviders = 0; | ||
export let NumWssProviders = 0; | ||
|
||
export class TrackedWebsocketsProvider extends providers.WebSocketProvider { | ||
constructor(url: string | WebSocketLike, network?: Networkish) { | ||
super(url, network); | ||
NumWssProviders++; | ||
} | ||
|
||
send(method: string, params?: Array<any>): Promise<any> { | ||
if (!WssEthCalls.has(method)) { | ||
WssEthCalls.set(method, 0); | ||
} | ||
WssEthCalls.set(method, WssEthCalls.get(method)! + 1); | ||
|
||
return super.send(method, params); | ||
} | ||
} | ||
|
||
export class TrackedJsonRpcProvider extends providers.StaticJsonRpcProvider { | ||
constructor(url?: ConnectionInfo | string, network?: Networkish) { | ||
super(url, network); | ||
NumJsonRpcProviders++; | ||
} | ||
|
||
send(method: string, params: Array<any>): Promise<any> { | ||
if (!JsonRpcEthCalls.has(method)) { | ||
JsonRpcEthCalls.set(method, 0); | ||
} | ||
JsonRpcEthCalls.set(method, JsonRpcEthCalls.get(method)! + 1); | ||
|
||
return super.send(method, params); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters