From 340964b5d803a11385a8ab4de13ec7a6a839be7e Mon Sep 17 00:00:00 2001 From: manicprogrammer Date: Thu, 30 Nov 2017 10:55:18 -0500 Subject: [PATCH] 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 --- eth/api.go | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/eth/api.go b/eth/api.go index 12448a6a11..6804f79a26 100644 --- a/eth/api.go +++ b/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()) 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) @@ -498,6 +503,7 @@ func (api *PrivateDebugAPI) TraceTransaction(ctx context.Context, txHash common. return nil, err } + // Handle timeouts and RPC cancellations deadlineCtx, cancel := context.WithTimeout(ctx, timeout) go func() { @@ -518,9 +524,15 @@ func (api *PrivateDebugAPI) TraceTransaction(ctx context.Context, txHash common. } msg, context, statedb, err := api.computeTxEnv(blockHash, int(txIndex)) 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. 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()))