index: Don't commit without valid m_best_block_index

Also report an error when coinstatsindex init fails.
This commit is contained in:
Martin Zumsande 2022-01-20 22:21:56 +01:00
parent 8f137e69ca
commit 0243907fae
2 changed files with 7 additions and 2 deletions

View file

@ -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;
}

View file

@ -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;