*add blacklist of RPC methods to not cache

This commit is contained in:
Derrick Hammer 2023-03-29 05:31:54 -04:00
parent d14d8006ae
commit 66dc3534b2
Signed by: pcfreak30
GPG Key ID: C997C339BE476FF2
2 changed files with 17 additions and 0 deletions

View File

@ -137,6 +137,12 @@ export class RPC {
return null;
}
public deleteCachedRequest(request: RPCRequest): void {
const hash = this.hashRequest(request);
this.cache.del(hash);
}
private hashRequest(request: RPCRequest): string {
const tempRequest = {
method: request.method,

View File

@ -74,6 +74,14 @@ interface ConsensusBlockRequest {
let client: Client;
const RPC_NO_CACHE = [
"eth_call",
"eth_estimateGas",
"eth_sendRawTransaction",
"eth_getTransactionReceipt",
"eth_getTransactionCount",
];
const plugin: Plugin = {
name: "eth",
async plugin(api: PluginAPI): Promise<void> {
@ -178,6 +186,9 @@ const plugin: Plugin = {
}
let ret = provider.rpc.getCachedRequest(request);
if (RPC_NO_CACHE.includes(request.method)) {
provider.rpc.deleteCachedRequest(request);
}
// @ts-ignore
return { ...ret, id: request.id ?? ret.id };
},