diff --git a/src/txdb.cpp b/src/txdb.cpp index 9abacfb5a..9746bf84a 100644 --- a/src/txdb.cpp +++ b/src/txdb.cpp @@ -372,6 +372,7 @@ bool CBlockTreeDB::LoadBlockIndexGuts(const Consensus::Params& consensusParams, } bool CBlockTreeDB::WriteTxIndex(const std::vector> &list) { + if (list.empty()) return true; db << "begin"; auto query = db << "INSERT OR REPLACE INTO tx_to_block VALUES(?,?,?,?)"; for (auto& kvp: list) { diff --git a/src/validation.cpp b/src/validation.cpp index 8f431db5b..6c1de96c0 100644 --- a/src/validation.cpp +++ b/src/validation.cpp @@ -2088,10 +2088,12 @@ bool CChainState::ConnectBlock(const CBlock& block, CValidationState& state, CBl if (fJustCheck) return true; - if (pindex->pprev != nullptr && - !WriteUndoDataForBlock(blockundo, state, pindex, chainparams) && - !pblocktree->WriteTxIndex(vPos)) - return false; + if (pindex->pprev != nullptr) { + if (!WriteUndoDataForBlock(blockundo, state, pindex, chainparams)) + return error("Unable to write to the Undo data block"); + if (!pblocktree->WriteTxIndex(vPos)) + return error("Unable to write to the TX Index"); + } if (!pindex->IsValid(BLOCK_VALID_SCRIPTS)) { pindex->RaiseValidity(BLOCK_VALID_SCRIPTS);