add panic catch in TraceTransaction (#41)

* add panic catch in TraceTransaction

* fix

* fix

* fix
This commit is contained in:
Jeremy Wei 2024-12-24 09:33:43 -05:00 committed by GitHub
parent aac6bf6d09
commit 21ee50facc
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -829,7 +829,13 @@ func containsTx(block *types.Block, hash common.Hash) bool {
// TraceTransaction returns the structured logs created during the execution of EVM
// and returns them as a JSON object.
func (api *API) TraceTransaction(ctx context.Context, hash common.Hash, config *TraceConfig) (interface{}, error) {
func (api *API) TraceTransaction(ctx context.Context, hash common.Hash, config *TraceConfig) (value interface{}, returnErr error) {
defer func() {
if r := recover(); r != nil {
value = nil
returnErr = fmt.Errorf("panic occurred: %v, could not trace tx: %s", r, hash.Hex())
}
}()
tx, blockHash, blockNumber, index, err := api.backend.GetTransaction(ctx, hash)
if err != nil {
return nil, err
@ -876,7 +882,13 @@ func (api *API) TraceTransaction(ctx context.Context, hash common.Hash, config *
// after executing the specified block. However, if a transaction index is provided,
// the trace will be conducted on the state after executing the specified transaction
// within the specified block.
func (api *API) TraceCall(ctx context.Context, args ethapi.TransactionArgs, blockNrOrHash rpc.BlockNumberOrHash, config *TraceCallConfig) (interface{}, error) {
func (api *API) TraceCall(ctx context.Context, args ethapi.TransactionArgs, blockNrOrHash rpc.BlockNumberOrHash, config *TraceCallConfig) (value interface{}, returnErr error) {
defer func() {
if r := recover(); r != nil {
value = nil
returnErr = fmt.Errorf("panic occurred: %v, could not trace tx: %s", r, args.ToTransaction().Hash().Hex())
}
}()
// Try to retrieve the specified block
var (
err error
@ -955,7 +967,7 @@ func (api *API) traceTx(ctx context.Context, tx *types.Transaction, message *cor
defer func() {
if r := recover(); r != nil {
value = nil
returnErr = fmt.Errorf("panic occured: %v, could not trace tx: %s", r, tx.Hash())
returnErr = fmt.Errorf("panic occurred: %v, could not trace tx: %s", r, tx.Hash())
}
}()
if config == nil {