Skip to content

Commit

Permalink
Fetch header correctly (including snapshots) for debug_traceCall, fix… (
Browse files Browse the repository at this point in the history
#6273)

… formatting when error

Fixes #5365

Co-authored-by: Alexey Sharp <alexeysharp@Alexeys-iMac.local>
  • Loading branch information
AlexeyAkhunov and Alexey Sharp authored Dec 10, 2022
1 parent f512c88 commit 983f417
Showing 1 changed file with 10 additions and 11 deletions.
21 changes: 10 additions & 11 deletions cmd/rpcdaemon/commands/tracing.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,38 +199,37 @@ func (api *PrivateDebugAPIImpl) TraceTransaction(ctx context.Context, hash commo
func (api *PrivateDebugAPIImpl) TraceCall(ctx context.Context, args ethapi.CallArgs, blockNrOrHash rpc.BlockNumberOrHash, config *tracers.TraceConfig, stream *jsoniter.Stream) error {
dbtx, err := api.db.BeginRo(ctx)
if err != nil {
stream.WriteNil()
return err
return fmt.Errorf("create ro transaction: %v", err)
}
defer dbtx.Rollback()

chainConfig, err := api.chainConfig(dbtx)
if err != nil {
stream.WriteNil()
return err
return fmt.Errorf("read chain config: %v", err)
}
engine := api.engine()

blockNumber, hash, _, err := rpchelper.GetBlockNumber(blockNrOrHash, dbtx, api.filters)
if err != nil {
stream.WriteNil()
return err
return fmt.Errorf("get block number: %v", err)
}

stateReader, err := rpchelper.CreateStateReader(ctx, dbtx, blockNrOrHash, 0, api.filters, api.stateCache, api.historyV3(dbtx), api._agg)
if err != nil {
return err
return fmt.Errorf("create state reader: %v", err)
}
header, err := api._blockReader.Header(context.Background(), dbtx, hash, blockNumber)
if err != nil {
return fmt.Errorf("could not fetch header %d(%x): %v", blockNumber, hash, err)
}
header := rawdb.ReadHeader(dbtx, hash, blockNumber)
if header == nil {
stream.WriteNil()
return fmt.Errorf("block %d(%x) not found", blockNumber, hash)
}
ibs := state.New(stateReader)

if config != nil && config.StateOverrides != nil {
if err := config.StateOverrides.Override(ibs); err != nil {
return err
return fmt.Errorf("override state: %v", err)
}
}

Expand All @@ -244,7 +243,7 @@ func (api *PrivateDebugAPIImpl) TraceCall(ctx context.Context, args ethapi.CallA
}
msg, err := args.ToMessage(api.GasCap, baseFee)
if err != nil {
return err
return fmt.Errorf("convert args to msg: %v", err)
}

blockCtx := transactions.NewEVMBlockContext(engine, header, blockNrOrHash.RequireCanonical, dbtx, api._blockReader)
Expand Down

0 comments on commit 983f417

Please sign in to comment.