partial bitcoin#24117: make indices robust against init aborts

excludes:
- bfcd60f5d505334230013de4115483b22a7898ee
This commit is contained in:
Kittywhiskers Van Gogh 2022-01-20 22:21:56 +01:00 committed by PastaPastaPasta
parent 4e9d9a69e8
commit 123cf8d2c7
2 changed files with 7 additions and 1 deletions

View File

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

View File

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