proxyd/fix: eth2 block tags {safe, finalized} should be valid tag values and avoid cache

This commit is contained in:
Felipe Andrade 2023-05-08 19:59:17 -07:00
parent 6302eddef8
commit cc9f6022de
2 changed files with 50 additions and 10 deletions

@ -73,12 +73,48 @@ func TestRPCCacheImmutableRPCs(t *testing.T) {
Params: []byte(`["earliest", false]`), Params: []byte(`["earliest", false]`),
ID: ID, ID: ID,
}, },
res: &RPCRes{ res: nil,
name: "eth_getBlockByNumber earliest",
},
{
req: &RPCReq{
JSONRPC: "2.0", JSONRPC: "2.0",
Result: `{"difficulty": "0x1", "number": "0x1"}`, Method: "eth_getBlockByNumber",
Params: []byte(`["safe", false]`),
ID: ID, ID: ID,
}, },
name: "eth_getBlockByNumber earliest", res: nil,
name: "eth_getBlockByNumber safe",
},
{
req: &RPCReq{
JSONRPC: "2.0",
Method: "eth_getBlockByNumber",
Params: []byte(`["finalized", false]`),
ID: ID,
},
res: nil,
name: "eth_getBlockByNumber finalized",
},
{
req: &RPCReq{
JSONRPC: "2.0",
Method: "eth_getBlockByNumber",
Params: []byte(`["pending", false]`),
ID: ID,
},
res: nil,
name: "eth_getBlockByNumber pending",
},
{
req: &RPCReq{
JSONRPC: "2.0",
Method: "eth_getBlockByNumber",
Params: []byte(`["latest", false]`),
ID: ID,
},
res: nil,
name: "eth_getBlockByNumber latest",
}, },
{ {
req: &RPCReq{ req: &RPCReq{
@ -101,11 +137,7 @@ func TestRPCCacheImmutableRPCs(t *testing.T) {
Params: []byte(`["earliest", "0x2", false]`), Params: []byte(`["earliest", "0x2", false]`),
ID: ID, ID: ID,
}, },
res: &RPCRes{ res: nil,
JSONRPC: "2.0",
Result: `[{"number": "0x1"}, {"number": "0x2"}]`,
ID: ID,
},
name: "eth_getBlockRange earliest", name: "eth_getBlockRange earliest",
}, },
} }

@ -271,7 +271,11 @@ func (e *EthGasPriceMethodHandler) PutRPCMethod(context.Context, *RPCReq, *RPCRe
} }
func isBlockDependentParam(s string) bool { func isBlockDependentParam(s string) bool {
return s == "latest" || s == "pending" return s == "earliest" ||
s == "latest" ||
s == "pending" ||
s == "finalized" ||
s == "safe"
} }
func decodeGetBlockByNumberParams(params json.RawMessage) (string, bool, error) { func decodeGetBlockByNumberParams(params json.RawMessage) (string, bool, error) {
@ -355,7 +359,11 @@ func decodeEthCallParams(req *RPCReq) (*ethCallParams, string, error) {
} }
func validBlockInput(input string) bool { func validBlockInput(input string) bool {
if input == "earliest" || input == "pending" || input == "latest" { if input == "earliest" ||
input == "latest" ||
input == "pending" ||
input == "finalized" ||
input == "safe" {
return true return true
} }
_, err := decodeBlockInput(input) _, err := decodeBlockInput(input)