From 2a7168a46baf14a06c06e3aa8abfad400221b820 Mon Sep 17 00:00:00 2001 From: Eugene Kim Date: Mon, 9 Sep 2019 20:49:05 -0700 Subject: [PATCH] Fix nil panic if block is not found in database MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This could occur as a result of database corruption or database update race, where transaction → (blockHash, blockNum, txIndex) lookup succeeds but the body for blockHash is not (yet) in the database. --- core/rawdb/accessors_indexes.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/core/rawdb/accessors_indexes.go b/core/rawdb/accessors_indexes.go index 1757e5069..6014aec14 100644 --- a/core/rawdb/accessors_indexes.go +++ b/core/rawdb/accessors_indexes.go @@ -71,6 +71,14 @@ func ReadTransaction(db DatabaseReader, hash common.Hash) (*types.Transaction, c return nil, common.Hash{}, 0, 0 } body := ReadBody(db, blockHash, blockNumber) + if body == nil { + utils.Logger().Error(). + Uint64("number", blockNumber). + Str("hash", blockHash.Hex()). + Uint64("index", txIndex). + Msg("block Body referenced missing") + return nil, common.Hash{}, 0, 0 + } tx := body.TransactionAt(int(txIndex)) if tx == nil { utils.Logger().Error().