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

Fix tracing API for Prebedrock relay #80

Merged
merged 2 commits into from
Jul 14, 2023
Merged
Changes from all commits
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
34 changes: 29 additions & 5 deletions cmd/rpcdaemon/commands/tracing.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package commands
import (
"context"
"encoding/json"
"errors"
"fmt"
"math/big"
"time"
Expand Down Expand Up @@ -72,6 +73,30 @@ func (api *PrivateDebugAPIImpl) traceBlock(ctx context.Context, blockNrOrHash rp
return fmt.Errorf("invalid arguments; block with hash %x not found", hash)
}

chainConfig, err := api.chainConfig(tx)
if err != nil {
stream.WriteNil()
return err
}

if chainConfig.IsOptimismPreBedrock(block.NumberU64()) {
if api.historicalRPCService == nil {
return rpc.ErrNoHistoricalFallback
}
var traceResult interface{}
// relay using block hash
if err := api.relayToHistoricalBackend(ctx, &traceResult, "debug_traceBlockByHash", block.Hash(), config); err != nil {
return fmt.Errorf("historical backend error: %w", err)
}
// stream out relayed response
result, err := json.Marshal(&traceResult)
if err != nil {
return err
}
stream.WriteRaw(string(result))
return nil
}

// if we've pruned this history away for this block then just return early
// to save any red herring errors
err = api.BaseAPI.checkPruneHistory(tx, block.NumberU64())
Expand All @@ -97,11 +122,6 @@ func (api *PrivateDebugAPIImpl) traceBlock(ctx context.Context, blockNrOrHash rp
if parentBlock != nil {
excessDataGas = parentBlock.ExcessDataGas()
}
chainConfig, err := api.chainConfig(tx)
if err != nil {
stream.WriteNil()
return err
}
engine := api.engine()

_, blockCtx, _, ibs, _, err := transactions.ComputeTxEnv(ctx, engine, block, chainConfig, api._blockReader, tx, 0, api.historyV3(tx))
Expand Down Expand Up @@ -298,6 +318,10 @@ func (api *PrivateDebugAPIImpl) TraceCall(ctx context.Context, args ethapi.CallA
return fmt.Errorf("get block number: %v", err)
}

if chainConfig.IsOptimismPreBedrock(blockNumber) {
return errors.New("l2geth does not have a debug_traceCall method")
}

err = api.BaseAPI.checkPruneHistory(dbtx, blockNumber)
if err != nil {
return err
Expand Down