Skip to content

Commit

Permalink
Merge pull request #80 from testinprod-io/pcw109550/relay-debug-trace…
Browse files Browse the repository at this point in the history
…-api

Fix tracing API for Prebedrock relay
  • Loading branch information
pcw109550 authored Jul 14, 2023
2 parents 651f397 + afc6e2b commit 0d527b6
Showing 1 changed file with 29 additions and 5 deletions.
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

0 comments on commit 0d527b6

Please sign in to comment.