Merge pull request #5786 from ethereum-optimism/bugfix/safe-finalized-tags

proxyd: Pass through finalized and safe tags
This commit is contained in:
OptimismBot 2023-05-25 15:32:55 -04:00 committed by GitHub
commit 95895d6090
2 changed files with 40 additions and 0 deletions

@ -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
}

@ -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{