This commit is contained in:
Felipe Andrade 2023-05-15 20:20:42 -07:00
parent 7db2391624
commit 9757609d61
2 changed files with 12 additions and 14 deletions

@ -103,9 +103,6 @@ func (c *cacheWithCompression) Put(ctx context.Context, key string, value string
return c.cache.Put(ctx, key, string(encodedVal)) return c.cache.Put(ctx, key, string(encodedVal))
} }
type GetLatestBlockNumFn func(ctx context.Context) (uint64, error)
type GetLatestGasPriceFn func(ctx context.Context) (uint64, error)
type RPCCache interface { type RPCCache interface {
GetRPC(ctx context.Context, req *RPCReq) (*RPCRes, error) GetRPC(ctx context.Context, req *RPCReq) (*RPCRes, error)
PutRPC(ctx context.Context, req *RPCReq, res *RPCRes) error PutRPC(ctx context.Context, req *RPCReq, res *RPCRes) error
@ -117,16 +114,17 @@ type rpcCache struct {
} }
func newRPCCache(cache Cache) RPCCache { func newRPCCache(cache Cache) RPCCache {
staticHandler := &StaticMethodHandler{cache: cache}
handlers := map[string]RPCMethodHandler{ handlers := map[string]RPCMethodHandler{
"eth_chainId": &StaticMethodHandler{cache: cache}, "eth_chainId": staticHandler,
"net_version": &StaticMethodHandler{cache: cache}, "net_version": staticHandler,
"eth_getBlockTransactionCountByHash": &StaticMethodHandler{cache: cache}, "eth_getBlockTransactionCountByHash": staticHandler,
"eth_getUncleCountByBlockHash": &StaticMethodHandler{cache: cache}, "eth_getUncleCountByBlockHash": staticHandler,
"eth_getBlockByHash": &StaticMethodHandler{cache: cache}, "eth_getBlockByHash": staticHandler,
"eth_getTransactionByHash": &StaticMethodHandler{cache: cache}, "eth_getTransactionByHash": staticHandler,
"eth_getTransactionByBlockHashAndIndex": &StaticMethodHandler{cache: cache}, "eth_getTransactionByBlockHashAndIndex": staticHandler,
"eth_getUncleByBlockHashAndIndex": &StaticMethodHandler{cache: cache}, "eth_getUncleByBlockHashAndIndex": staticHandler,
"eth_getTransactionReceipt": &StaticMethodHandler{cache: cache}, "eth_getTransactionReceipt": staticHandler,
} }
return &rpcCache{ return &rpcCache{
cache: cache, cache: cache,
@ -149,7 +147,7 @@ func (c *rpcCache) GetRPC(ctx context.Context, req *RPCReq) (*RPCRes, error) {
} else { } else {
RecordCacheHit(req.Method) RecordCacheHit(req.Method)
} }
return res, err return res, nil
} }
func (c *rpcCache) PutRPC(ctx context.Context, req *RPCReq, res *RPCRes) error { func (c *rpcCache) PutRPC(ctx context.Context, req *RPCReq, res *RPCRes) error {

@ -67,7 +67,7 @@ func (e *StaticMethodHandler) PutRPCMethod(ctx context.Context, req *RPCReq, res
err := e.cache.Put(ctx, key, string(value)) err := e.cache.Put(ctx, key, string(value))
if err != nil { if err != nil {
log.Error("error marshalling value to put into cache", "key", key, "method", req.Method, "err", err) log.Error("error putting into cache", "key", key, "method", req.Method, "err", err)
return err return err
} }
return nil return nil