From ad712d5006f6cba79040578b3d003bcc5bf8e106 Mon Sep 17 00:00:00 2001 From: Miguel Freitas Date: Thu, 25 Jul 2013 10:43:06 -0300 Subject: [PATCH] fix wrongly erasing of indextx with checklevel==3 --- src/main.cpp | 23 ++++++----------------- src/main.h | 2 +- 2 files changed, 7 insertions(+), 18 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 1baba2a9..d98c2b3c 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -978,15 +978,10 @@ void UpdateTime(CBlockHeader& block, const CBlockIndex* pindexPrev) -bool DisconnectBlock(CBlock& block, CValidationState& state, CBlockIndex* pindex, CCoinsViewCache& view, bool* pfClean) +bool DisconnectBlock(CBlock& block, CValidationState& state, CBlockIndex* pindex, CCoinsViewCache& view, bool fJustCheck) { assert(pindex == view.GetBestBlock()); - if (pfClean) - *pfClean = false; - - bool fClean = true; - CBlockUndo blockUndo; CDiskBlockPos pos = pindex->GetUndoPos(); if (pos.IsNull()) @@ -1002,20 +997,14 @@ bool DisconnectBlock(CBlock& block, CValidationState& state, CBlockIndex* pindex for (int i = block.vtx.size() - 1; i >= 1; i--) { const CTransaction &tx = block.vtx[i]; - if( !pblocktree->EraseTxIndex(tx.GetUsernameHash()) ) { - fClean = fClean && error("DisconnectBlock() : error erasing txIndex"); - } + if( !fJustCheck ) + pblocktree->EraseTxIndex(tx.GetUsernameHash()); } // move best block pointer to prevout block view.SetBestBlock(pindex->pprev); - if (pfClean) { - *pfClean = fClean; - return true; - } else { - return fClean; - } + return true; } void static FlushBlockFile(bool fFinalize = false) @@ -1171,7 +1160,7 @@ bool SetBestChain(CValidationState &state, CBlockIndex* pindexNew) if (!ReadBlockFromDisk(block, pindex)) return state.Abort(_("Failed to read block")); int64 nStart = GetTimeMicros(); - if (!DisconnectBlock(block, state, pindex, view)) + if (!DisconnectBlock(block, state, pindex, view, false)) return error("SetBestBlock() : DisconnectBlock %s failed", pindex->GetBlockHash().ToString().c_str()); if (fBenchmark) printf("- Disconnect: %.2fms\n", (GetTimeMicros() - nStart) * 0.001); @@ -2017,7 +2006,7 @@ bool VerifyDB(int nCheckLevel, int nCheckDepth) // check level 3: check for inconsistencies during memory-only disconnect of tip blocks if (nCheckLevel >= 3 && pindex == pindexState && (coins.GetCacheSize() + pcoinsTip->GetCacheSize()) <= 2*nCoinCacheSize + 32000) { bool fClean = true; - if (!DisconnectBlock(block, state, pindex, coins, &fClean)) + if (!DisconnectBlock(block, state, pindex, coins, nCheckLevel < 4)) return error("VerifyDB() : *** irrecoverable inconsistency in block data at %d, hash=%s", pindex->nHeight, pindex->GetBlockHash().ToString().c_str()); pindexState = pindex->pprev; if (!fClean) { diff --git a/src/main.h b/src/main.h index 25aefbc3..e7dbfcd5 100644 --- a/src/main.h +++ b/src/main.h @@ -515,7 +515,7 @@ bool ReadBlockFromDisk(CBlock& block, const CBlockIndex* pindex); * In case pfClean is provided, operation will try to be tolerant about errors, and *pfClean * will be true if no problems were found. Otherwise, the return value will be false in case * of problems. Note that in any case, coins may be modified. */ -bool DisconnectBlock(CBlock& block, CValidationState& state, CBlockIndex* pindex, CCoinsViewCache& coins, bool* pfClean = NULL); +bool DisconnectBlock(CBlock& block, CValidationState& state, CBlockIndex* pindex, CCoinsViewCache& coins, bool fJustCheck = false); // Apply the effects of this block (with given index) on the UTXO set represented by coins bool ConnectBlock(CBlock& block, CValidationState& state, CBlockIndex* pindex, CCoinsViewCache& coins, bool fJustCheck = false);