From 123cf8d2c71610e9e03e38fe73c8f5fd960cfa2c Mon Sep 17 00:00:00 2001 From: Kittywhiskers Van Gogh <63189531+kittywhiskers@users.noreply.github.com> Date: Thu, 20 Jan 2022 22:21:56 +0100 Subject: [PATCH] partial bitcoin#24117: make indices robust against init aborts excludes: - bfcd60f5d505334230013de4115483b22a7898ee --- src/index/base.cpp | 5 +++++ src/index/coinstatsindex.cpp | 3 ++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/index/base.cpp b/src/index/base.cpp index 082c46e6a6..2b586e704d 100644 --- a/src/index/base.cpp +++ b/src/index/base.cpp @@ -203,6 +203,11 @@ bool BaseIndex::Commit() bool BaseIndex::CommitInternal(CDBBatch& batch) { LOCK(cs_main); + // Don't commit anything if we haven't indexed any block yet + // (this could happen if init is interrupted). + if (m_best_block_index == nullptr) { + return false; + } GetDB().WriteBestBlock(batch, m_chainstate->m_chain.GetLocator(m_best_block_index)); return true; } diff --git a/src/index/coinstatsindex.cpp b/src/index/coinstatsindex.cpp index 6cab21297a..5fa2fc5bc9 100644 --- a/src/index/coinstatsindex.cpp +++ b/src/index/coinstatsindex.cpp @@ -355,7 +355,8 @@ bool CoinStatsIndex::Init() if (pindex) { DBVal entry; if (!LookUpOne(*m_db, pindex, entry)) { - return false; + return error("%s: Cannot read current %s state; index may be corrupted", + __func__, GetName()); } m_transaction_output_count = entry.transaction_output_count;