From 66dc3534b2899c31c23d4ddd80f877845d7d4497 Mon Sep 17 00:00:00 2001 From: Derrick Hammer Date: Wed, 29 Mar 2023 05:31:54 -0400 Subject: [PATCH] *add blacklist of RPC methods to not cache --- src/client/rpc/rpc.ts | 6 ++++++ src/index.ts | 11 +++++++++++ 2 files changed, 17 insertions(+) diff --git a/src/client/rpc/rpc.ts b/src/client/rpc/rpc.ts index f8e12a0..fbec543 100644 --- a/src/client/rpc/rpc.ts +++ b/src/client/rpc/rpc.ts @@ -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, diff --git a/src/index.ts b/src/index.ts index 8b11804..f654ae0 100644 --- a/src/index.ts +++ b/src/index.ts @@ -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 { @@ -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 }; },