Add defer recovery for failed txs when tracing

This commit is contained in:
Philip Su 2024-12-11 19:02:51 -08:00
parent ad2a4cefac
commit 269b0fbc7a

View file

@ -611,12 +611,21 @@ func (api *API) traceBlock(ctx context.Context, block *types.Block, config *Trac
TxIndex: i, TxIndex: i,
TxHash: tx.Hash(), TxHash: tx.Hash(),
} }
func() {
defer func() {
if r := recover(); r != nil {
results[i] = &txTraceResult{TxHash: tx.Hash(), Error: fmt.Sprintf("panic: %v", r)}
}
}()
res, err := api.traceTx(ctx, tx, msg, txctx, blockCtx, statedb, config) res, err := api.traceTx(ctx, tx, msg, txctx, blockCtx, statedb, config)
if err != nil { if err != nil {
results[i] = &txTraceResult{TxHash: tx.Hash(), Error: err.Error()} results[i] = &txTraceResult{TxHash: tx.Hash(), Error: err.Error()}
} else { return
results[i] = &txTraceResult{TxHash: tx.Hash(), Result: res}
} }
results[i] = &txTraceResult{TxHash: tx.Hash(), Result: res}
}()
} }
return results, nil return results, nil
} }