diff --git a/proxyd/proxyd/rewriter.go b/proxyd/proxyd/rewriter.go index 35d78df..ab13a05 100644 --- a/proxyd/proxyd/rewriter.go +++ b/proxyd/proxyd/rewriter.go @@ -159,6 +159,13 @@ func rewriteTagMap(rctx RewriteContext, m map[string]interface{}, key string) (b } func rewriteTag(rctx RewriteContext, current string) (string, bool, error) { + // If a tag is the safe or finalized block number, don't rewrite it. + // We have a custom check here because the rpc.BlockNumberOrHash type + // doesn't support these custom tags yet. + if current == "safe" || current == "finalized" { + return current, false, nil + } + jv, err := json.Marshal(current) if err != nil { return "", false, err @@ -177,5 +184,6 @@ func rewriteTag(rctx RewriteContext, current string) (string, bool, error) { return "", false, ErrRewriteBlockOutOfRange } } + return current, false, nil } diff --git a/proxyd/proxyd/rewriter_test.go b/proxyd/proxyd/rewriter_test.go index ed5e6a7..5b23c84 100644 --- a/proxyd/proxyd/rewriter_test.go +++ b/proxyd/proxyd/rewriter_test.go @@ -308,6 +308,38 @@ func TestRewriteRequest(t *testing.T) { require.Equal(t, hexutil.Uint64(100).String(), p[0]) }, }, + { + name: "eth_getBlockByNumber finalized", + args: args{ + rctx: RewriteContext{latest: hexutil.Uint64(100)}, + req: &RPCReq{Method: "eth_getBlockByNumber", Params: mustMarshalJSON([]string{"finalized"})}, + res: nil, + }, + expected: RewriteNone, + check: func(t *testing.T, args args) { + var p []string + err := json.Unmarshal(args.req.Params, &p) + require.Nil(t, err) + require.Equal(t, 1, len(p)) + require.Equal(t, "finalized", p[0]) + }, + }, + { + name: "eth_getBlockByNumber safe", + args: args{ + rctx: RewriteContext{latest: hexutil.Uint64(100)}, + req: &RPCReq{Method: "eth_getBlockByNumber", Params: mustMarshalJSON([]string{"safe"})}, + res: nil, + }, + expected: RewriteNone, + check: func(t *testing.T, args args) { + var p []string + err := json.Unmarshal(args.req.Params, &p) + require.Nil(t, err) + require.Equal(t, 1, len(p)) + require.Equal(t, "safe", p[0]) + }, + }, { name: "eth_getBlockByNumber within range", args: args{