From bb240e290b71d4dbba7f40e6eaa364df1642297c Mon Sep 17 00:00:00 2001 From: Brannon King Date: Tue, 10 Dec 2019 22:43:07 -0700 Subject: [PATCH] fixed the txindex data --- src/txdb.cpp | 1 + src/validation.cpp | 10 ++++++---- 2 files changed, 7 insertions(+), 4 deletions(-) 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);