Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[NIT-2990] Prevent calling arbtrace_* against nitro with the latest block number #2845

Merged
merged 7 commits into from
Jan 2, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 46 additions & 9 deletions execution/gethexec/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -285,14 +285,16 @@ func stateAndHeader(blockchain *core.BlockChain, block uint64) (*arbosState.Arbo
type ArbTraceForwarderAPI struct {
fallbackClientUrl string
fallbackClientTimeout time.Duration
blockchain *core.BlockChain

initialized atomic.Bool
mutex sync.Mutex
fallbackClient types.FallbackClient
}

func NewArbTraceForwarderAPI(fallbackClientUrl string, fallbackClientTimeout time.Duration) *ArbTraceForwarderAPI {
func NewArbTraceForwarderAPI(blockchain *core.BlockChain, fallbackClientUrl string, fallbackClientTimeout time.Duration) *ArbTraceForwarderAPI {
amsanghi marked this conversation as resolved.
Show resolved Hide resolved
return &ArbTraceForwarderAPI{
blockchain: blockchain,
fallbackClientUrl: fallbackClientUrl,
fallbackClientTimeout: fallbackClientTimeout,
}
Expand Down Expand Up @@ -332,16 +334,46 @@ func (api *ArbTraceForwarderAPI) forward(ctx context.Context, method string, arg
return resp, nil
}

func (api *ArbTraceForwarderAPI) Call(ctx context.Context, callArgs json.RawMessage, traceTypes json.RawMessage, blockNum json.RawMessage) (*json.RawMessage, error) {
return api.forward(ctx, "arbtrace_call", callArgs, traceTypes, blockNum)
func (api *ArbTraceForwarderAPI) ClipToPostNitroGenesis(blockNumOrHash json.RawMessage) (json.RawMessage, error) {
amsanghi marked this conversation as resolved.
Show resolved Hide resolved
var bnh rpc.BlockNumberOrHash
err := bnh.UnmarshalJSON(blockNumOrHash)
if err != nil {
return nil, err
}
blockNum, isNum := bnh.Number()
if !isNum {
return blockNumOrHash, nil
}
blockNum, _ = api.blockchain.ClipToPostNitroGenesis(blockNum)
bnh.BlockNumber = &blockNum
return json.Marshal(bnh)
}

func (api *ArbTraceForwarderAPI) CallMany(ctx context.Context, calls json.RawMessage, blockNum json.RawMessage) (*json.RawMessage, error) {
return api.forward(ctx, "arbtrace_callMany", calls, blockNum)
func (api *ArbTraceForwarderAPI) Call(ctx context.Context, callArgs json.RawMessage, traceTypes json.RawMessage, blockNumOrHash json.RawMessage) (*json.RawMessage, error) {
var err error
blockNumOrHash, err = api.ClipToPostNitroGenesis(blockNumOrHash)
if err != nil {
return nil, err
}
return api.forward(ctx, "arbtrace_call", callArgs, traceTypes, blockNumOrHash)
}

func (api *ArbTraceForwarderAPI) ReplayBlockTransactions(ctx context.Context, blockNum json.RawMessage, traceTypes json.RawMessage) (*json.RawMessage, error) {
return api.forward(ctx, "arbtrace_replayBlockTransactions", blockNum, traceTypes)
func (api *ArbTraceForwarderAPI) CallMany(ctx context.Context, calls json.RawMessage, blockNumOrHash json.RawMessage) (*json.RawMessage, error) {
var err error
blockNumOrHash, err = api.ClipToPostNitroGenesis(blockNumOrHash)
if err != nil {
return nil, err
}
return api.forward(ctx, "arbtrace_callMany", calls, blockNumOrHash)
}

func (api *ArbTraceForwarderAPI) ReplayBlockTransactions(ctx context.Context, blockNumOrHash json.RawMessage, traceTypes json.RawMessage) (*json.RawMessage, error) {
var err error
blockNumOrHash, err = api.ClipToPostNitroGenesis(blockNumOrHash)
if err != nil {
return nil, err
}
return api.forward(ctx, "arbtrace_replayBlockTransactions", blockNumOrHash, traceTypes)
}

func (api *ArbTraceForwarderAPI) ReplayTransaction(ctx context.Context, txHash json.RawMessage, traceTypes json.RawMessage) (*json.RawMessage, error) {
Expand All @@ -356,8 +388,13 @@ func (api *ArbTraceForwarderAPI) Get(ctx context.Context, txHash json.RawMessage
return api.forward(ctx, "arbtrace_get", txHash, path)
}

func (api *ArbTraceForwarderAPI) Block(ctx context.Context, blockNum json.RawMessage) (*json.RawMessage, error) {
return api.forward(ctx, "arbtrace_block", blockNum)
func (api *ArbTraceForwarderAPI) Block(ctx context.Context, blockNumOrHash json.RawMessage) (*json.RawMessage, error) {
var err error
blockNumOrHash, err = api.ClipToPostNitroGenesis(blockNumOrHash)
if err != nil {
return nil, err
}
return api.forward(ctx, "arbtrace_block", blockNumOrHash)
}

func (api *ArbTraceForwarderAPI) Filter(ctx context.Context, filter json.RawMessage) (*json.RawMessage, error) {
Expand Down
1 change: 1 addition & 0 deletions execution/gethexec/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,7 @@ func CreateExecutionNode(
Namespace: "arbtrace",
Version: "1.0",
Service: NewArbTraceForwarderAPI(
l2BlockChain,
config.RPC.ClassicRedirect,
config.RPC.ClassicRedirectTimeout,
),
Expand Down
Loading