feat(proxyd): avoid caching debug_getRawReceipts responses with 0 receipts
This commit is contained in:
parent
4e0100bbe9
commit
42b2f6db61
@ -128,7 +128,7 @@ type rpcCache struct {
|
|||||||
func newRPCCache(cache Cache) RPCCache {
|
func newRPCCache(cache Cache) RPCCache {
|
||||||
staticHandler := &StaticMethodHandler{cache: cache}
|
staticHandler := &StaticMethodHandler{cache: cache}
|
||||||
debugGetRawReceiptsHandler := &StaticMethodHandler{cache: cache,
|
debugGetRawReceiptsHandler := &StaticMethodHandler{cache: cache,
|
||||||
filter: func(req *RPCReq) bool {
|
filterGet: func(req *RPCReq) bool {
|
||||||
// cache only if the request is for a block hash
|
// cache only if the request is for a block hash
|
||||||
|
|
||||||
var p []rpc.BlockNumberOrHash
|
var p []rpc.BlockNumberOrHash
|
||||||
@ -141,6 +141,14 @@ func newRPCCache(cache Cache) RPCCache {
|
|||||||
}
|
}
|
||||||
return p[0].BlockHash != nil
|
return p[0].BlockHash != nil
|
||||||
},
|
},
|
||||||
|
filterPut: func(req *RPCReq, res *RPCRes) bool {
|
||||||
|
// don't cache if response contains 0 receipts
|
||||||
|
rawReceipts, ok := res.Result.([]interface{})
|
||||||
|
if !ok {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
return len(rawReceipts) > 0
|
||||||
|
},
|
||||||
}
|
}
|
||||||
handlers := map[string]RPCMethodHandler{
|
handlers := map[string]RPCMethodHandler{
|
||||||
"eth_chainId": staticHandler,
|
"eth_chainId": staticHandler,
|
||||||
|
@ -17,9 +17,10 @@ type RPCMethodHandler interface {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type StaticMethodHandler struct {
|
type StaticMethodHandler struct {
|
||||||
cache Cache
|
cache Cache
|
||||||
m sync.RWMutex
|
m sync.RWMutex
|
||||||
filter func(*RPCReq) bool
|
filterGet func(*RPCReq) bool
|
||||||
|
filterPut func(*RPCReq, *RPCRes) bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e *StaticMethodHandler) key(req *RPCReq) string {
|
func (e *StaticMethodHandler) key(req *RPCReq) string {
|
||||||
@ -34,7 +35,7 @@ func (e *StaticMethodHandler) GetRPCMethod(ctx context.Context, req *RPCReq) (*R
|
|||||||
if e.cache == nil {
|
if e.cache == nil {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
if e.filter != nil && !e.filter(req) {
|
if e.filterGet != nil && !e.filterGet(req) {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -67,7 +68,12 @@ func (e *StaticMethodHandler) PutRPCMethod(ctx context.Context, req *RPCReq, res
|
|||||||
if e.cache == nil {
|
if e.cache == nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
if e.filter != nil && !e.filter(req) {
|
// if there is a filter on get, we don't want to cache it because its irretrievable
|
||||||
|
if e.filterGet != nil && !e.filterGet(req) {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
// response filter
|
||||||
|
if e.filterPut != nil && !e.filterPut(req, res) {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -77,7 +77,7 @@ func (mh *MockedHandler) Handler(w http.ResponseWriter, req *http.Request) {
|
|||||||
for _, r := range requests {
|
for _, r := range requests {
|
||||||
method := r["method"]
|
method := r["method"]
|
||||||
block := ""
|
block := ""
|
||||||
if method == "eth_getBlockByNumber" {
|
if method == "eth_getBlockByNumber" || method == "debug_getRawReceipts" {
|
||||||
block = (r["params"].([]interface{})[0]).(string)
|
block = (r["params"].([]interface{})[0]).(string)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue
Block a user