diff --git a/cmd/rpcdaemon/commands/tracing.go b/cmd/rpcdaemon/commands/tracing.go index c43fcc8c48d..3901e6676dd 100644 --- a/cmd/rpcdaemon/commands/tracing.go +++ b/cmd/rpcdaemon/commands/tracing.go @@ -3,6 +3,7 @@ package commands import ( "context" "encoding/json" + "errors" "fmt" "math/big" "time" @@ -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()) @@ -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)) @@ -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