From 0243907faee0aa6af09974131d9a46a7f9c3ef38 Mon Sep 17 00:00:00 2001 From: Martin Zumsande Date: Thu, 20 Jan 2022 22:21:56 +0100 Subject: index: Don't commit without valid m_best_block_index Also report an error when coinstatsindex init fails. --- src/index/base.cpp | 5 +++++ src/index/coinstatsindex.cpp | 4 ++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/index/base.cpp b/src/index/base.cpp index 2e3d500cd1..8fe30f8960 100644 --- a/src/index/base.cpp +++ b/src/index/base.cpp @@ -211,6 +211,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 ef247dc119..7d4860b20b 100644 --- a/src/index/coinstatsindex.cpp +++ b/src/index/coinstatsindex.cpp @@ -360,9 +360,9 @@ 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; m_bogo_size = entry.bogo_size; m_total_amount = entry.total_amount; -- cgit v1.2.3 From bfcd60f5d505334230013de4115483b22a7898ee Mon Sep 17 00:00:00 2001 From: Martin Zumsande Date: Thu, 20 Jan 2022 22:23:55 +0100 Subject: test: activate all index types in feature_init.py --- test/functional/feature_init.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/test/functional/feature_init.py b/test/functional/feature_init.py index dbd71a8b2d..d0cb1e10e2 100755 --- a/test/functional/feature_init.py +++ b/test/functional/feature_init.py @@ -64,6 +64,8 @@ class InitStressTest(BitcoinTestFramework): 'addcon thread start', 'loadblk thread start', 'txindex thread start', + 'block filter index thread start', + 'coinstatsindex thread start', 'msghand thread start', 'net thread start', 'addcon thread start', @@ -74,7 +76,7 @@ class InitStressTest(BitcoinTestFramework): for terminate_line in lines_to_terminate_after: self.log.info(f"Starting node and will exit after line '{terminate_line}'") with node.wait_for_debug_log([terminate_line], ignore_case=True): - node.start(extra_args=['-txindex=1']) + node.start(extra_args=['-txindex=1', '-blockfilterindex=1', '-coinstatsindex=1']) self.log.debug("Terminating node after terminate line was found") sigterm_node() @@ -109,7 +111,7 @@ class InitStressTest(BitcoinTestFramework): # investigate doing this later. node.assert_start_raises_init_error( - extra_args=['-txindex=1'], + extra_args=['-txindex=1', '-blockfilterindex=1', '-coinstatsindex=1'], expected_msg=err_fragment, match=ErrorMatch.PARTIAL_REGEX, ) -- cgit v1.2.3