Skip to content

Commit 0243907

Browse files
committed
index: Don't commit without valid m_best_block_index
Also report an error when coinstatsindex init fails.
1 parent 8f137e6 commit 0243907

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

src/index/base.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,11 @@ bool BaseIndex::Commit()
211211
bool BaseIndex::CommitInternal(CDBBatch& batch)
212212
{
213213
LOCK(cs_main);
214+
// Don't commit anything if we haven't indexed any block yet
215+
// (this could happen if init is interrupted).
216+
if (m_best_block_index == nullptr) {
217+
return false;
218+
}
214219
GetDB().WriteBestBlock(batch, m_chainstate->m_chain.GetLocator(m_best_block_index));
215220
return true;
216221
}

src/index/coinstatsindex.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -360,9 +360,9 @@ bool CoinStatsIndex::Init()
360360
if (pindex) {
361361
DBVal entry;
362362
if (!LookUpOne(*m_db, pindex, entry)) {
363-
return false;
363+
return error("%s: Cannot read current %s state; index may be corrupted",
364+
__func__, GetName());
364365
}
365-
366366
m_transaction_output_count = entry.transaction_output_count;
367367
m_bogo_size = entry.bogo_size;
368368
m_total_amount = entry.total_amount;

0 commit comments

Comments
 (0)