mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-17 09:23:48 +00:00
eth: Make debug api trace errors more user friendly
add error type evaluation for errors that may return a MissingNodeError and return more friendly message for ethereum/go-ethereum#15500
This commit is contained in:
parent
3d378688e1
commit
340964b5d8
1 changed files with 14 additions and 2 deletions
16
eth/api.go
16
eth/api.go
|
|
@ -452,7 +452,12 @@ func (api *PrivateDebugAPI) traceBlock(block *types.Block, logConfig *vm.LogConf
|
||||||
}
|
}
|
||||||
statedb, err := blockchain.StateAt(blockchain.GetBlock(block.ParentHash(), block.NumberU64()-1).Root())
|
statedb, err := blockchain.StateAt(blockchain.GetBlock(block.ParentHash(), block.NumberU64()-1).Root())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, structLogger.StructLogs(), err
|
switch err.(type) {
|
||||||
|
case *trie.MissingNodeError:
|
||||||
|
return false, structLogger.StructLogs(), fmt.Errorf("required historical state unavailable")
|
||||||
|
default:
|
||||||
|
return false, structLogger.StructLogs(), err
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
receipts, _, usedGas, err := processor.Process(block, statedb, config)
|
receipts, _, usedGas, err := processor.Process(block, statedb, config)
|
||||||
|
|
@ -498,6 +503,7 @@ func (api *PrivateDebugAPI) TraceTransaction(ctx context.Context, txHash common.
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Handle timeouts and RPC cancellations
|
// Handle timeouts and RPC cancellations
|
||||||
deadlineCtx, cancel := context.WithTimeout(ctx, timeout)
|
deadlineCtx, cancel := context.WithTimeout(ctx, timeout)
|
||||||
go func() {
|
go func() {
|
||||||
|
|
@ -518,9 +524,15 @@ func (api *PrivateDebugAPI) TraceTransaction(ctx context.Context, txHash common.
|
||||||
}
|
}
|
||||||
msg, context, statedb, err := api.computeTxEnv(blockHash, int(txIndex))
|
msg, context, statedb, err := api.computeTxEnv(blockHash, int(txIndex))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
switch err.(type) {
|
||||||
|
case *trie.MissingNodeError:
|
||||||
|
return nil, fmt.Errorf("required historical state unavailable")
|
||||||
|
default:
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Run the transaction with tracing enabled.
|
// Run the transaction with tracing enabled.
|
||||||
vmenv := vm.NewEVM(context, statedb, api.config, vm.Config{Debug: true, Tracer: tracer})
|
vmenv := vm.NewEVM(context, statedb, api.config, vm.Config{Debug: true, Tracer: tracer})
|
||||||
ret, gas, failed, err := core.ApplyMessage(vmenv, msg, new(core.GasPool).AddGas(tx.Gas()))
|
ret, gas, failed, err := core.ApplyMessage(vmenv, msg, new(core.GasPool).AddGas(tx.Gas()))
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue