From 10b8b8e32af76dee6f4061e959f1f3b5748b683e Mon Sep 17 00:00:00 2001 From: Felipe Andrade Date: Fri, 19 May 2023 16:13:03 -0700 Subject: [PATCH] fix(proxyd): avoid caching tx hash based methods, since the response may change with a reorg --- proxyd/proxyd/cache.go | 2 - proxyd/proxyd/cache_test.go | 42 ------------------- .../proxyd/integration_tests/caching_test.go | 24 +++++------ 3 files changed, 12 insertions(+), 56 deletions(-) diff --git a/proxyd/proxyd/cache.go b/proxyd/proxyd/cache.go index 4f978c5..9684b75 100644 --- a/proxyd/proxyd/cache.go +++ b/proxyd/proxyd/cache.go @@ -130,10 +130,8 @@ func newRPCCache(cache Cache) RPCCache { "eth_getBlockTransactionCountByHash": staticHandler, "eth_getUncleCountByBlockHash": staticHandler, "eth_getBlockByHash": staticHandler, - "eth_getTransactionByHash": staticHandler, "eth_getTransactionByBlockHashAndIndex": staticHandler, "eth_getUncleByBlockHashAndIndex": staticHandler, - "eth_getTransactionReceipt": staticHandler, } return &rpcCache{ cache: cache, diff --git a/proxyd/proxyd/cache_test.go b/proxyd/proxyd/cache_test.go index 0deb0e3..727cdc7 100644 --- a/proxyd/proxyd/cache_test.go +++ b/proxyd/proxyd/cache_test.go @@ -87,34 +87,6 @@ func TestRPCCacheImmutableRPCs(t *testing.T) { }, name: "eth_getBlockByHash", }, - { - req: &RPCReq{ - JSONRPC: "2.0", - Method: "eth_getTransactionByHash", - Params: mustMarshalJSON([]string{"0x88df016429689c079f3b2f6ad39fa052532c56795b733da78a91ebe6a713944b"}), - ID: ID, - }, - res: &RPCRes{ - JSONRPC: "2.0", - Result: `{"eth_getTransactionByHash":"!"}`, - ID: ID, - }, - name: "eth_getTransactionByHash", - }, - { - req: &RPCReq{ - JSONRPC: "2.0", - Method: "eth_getTransactionByBlockHashAndIndex", - Params: mustMarshalJSON([]string{"0xe670ec64341771606e55d6b4ca35a1a6b75ee3d5145a99d05921026d1527331", "0x55"}), - ID: ID, - }, - res: &RPCRes{ - JSONRPC: "2.0", - Result: `{"eth_getTransactionByBlockHashAndIndex":"!"}`, - ID: ID, - }, - name: "eth_getTransactionByBlockHashAndIndex", - }, { req: &RPCReq{ JSONRPC: "2.0", @@ -129,20 +101,6 @@ func TestRPCCacheImmutableRPCs(t *testing.T) { }, name: "eth_getUncleByBlockHashAndIndex", }, - { - req: &RPCReq{ - JSONRPC: "2.0", - Method: "eth_getTransactionReceipt", - Params: mustMarshalJSON([]string{"0x85d995eba9763907fdf35cd2034144dd9d53ce32cbec21349d4b12823c6860c5"}), - ID: ID, - }, - res: &RPCRes{ - JSONRPC: "2.0", - Result: `{"eth_getTransactionReceipt":"!"}`, - ID: ID, - }, - name: "eth_getTransactionReceipt", - }, } for _, rpc := range rpcs { diff --git a/proxyd/proxyd/integration_tests/caching_test.go b/proxyd/proxyd/integration_tests/caching_test.go index a69ec4f..e4a64d9 100644 --- a/proxyd/proxyd/integration_tests/caching_test.go +++ b/proxyd/proxyd/integration_tests/caching_test.go @@ -77,12 +77,6 @@ func TestCaching(t *testing.T) { "{\"jsonrpc\": \"2.0\", \"result\": \"eth_getBlockByHash\", \"id\": 999}", 1, }, - { - "eth_getTransactionByHash", - []interface{}{"0x88df016429689c079f3b2f6ad39fa052532c56795b733da78a91ebe6a713944b"}, - "{\"jsonrpc\": \"2.0\", \"result\": \"eth_getTransactionByHash\", \"id\": 999}", - 1, - }, { "eth_getTransactionByBlockHashAndIndex", []interface{}{"0xe670ec64341771606e55d6b4ca35a1a6b75ee3d5145a99d05921026d1527331", "0x55"}, @@ -95,12 +89,6 @@ func TestCaching(t *testing.T) { "{\"jsonrpc\": \"2.0\", \"result\": \"eth_getUncleByBlockHashAndIndex\", \"id\": 999}", 1, }, - { - "eth_getTransactionReceipt", - []interface{}{"0x85d995eba9763907fdf35cd2034144dd9d53ce32cbec21349d4b12823c6860c5"}, - "{\"jsonrpc\": \"2.0\", \"result\": \"eth_getTransactionReceipt\", \"id\": 999}", - 1, - }, /* not cacheable */ { "eth_getBlockByNumber", @@ -111,6 +99,18 @@ func TestCaching(t *testing.T) { "{\"jsonrpc\": \"2.0\", \"result\": \"eth_getBlockByNumber\", \"id\": 999}", 2, }, + { + "eth_getTransactionReceipt", + []interface{}{"0x85d995eba9763907fdf35cd2034144dd9d53ce32cbec21349d4b12823c6860c5"}, + "{\"jsonrpc\": \"2.0\", \"result\": \"eth_getTransactionReceipt\", \"id\": 999}", + 2, + }, + { + "eth_getTransactionByHash", + []interface{}{"0x88df016429689c079f3b2f6ad39fa052532c56795b733da78a91ebe6a713944b"}, + "{\"jsonrpc\": \"2.0\", \"result\": \"eth_getTransactionByHash\", \"id\": 999}", + 2, + }, { "eth_call", []interface{}{