Browse Source

fix wrongly erasing of indextx with checklevel==3

miguelfreitas
Miguel Freitas 11 years ago
parent
commit
ad712d5006
  1. 23
      src/main.cpp
  2. 2
      src/main.h

23
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()); assert(pindex == view.GetBestBlock());
if (pfClean)
*pfClean = false;
bool fClean = true;
CBlockUndo blockUndo; CBlockUndo blockUndo;
CDiskBlockPos pos = pindex->GetUndoPos(); CDiskBlockPos pos = pindex->GetUndoPos();
if (pos.IsNull()) 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--) { for (int i = block.vtx.size() - 1; i >= 1; i--) {
const CTransaction &tx = block.vtx[i]; const CTransaction &tx = block.vtx[i];
if( !pblocktree->EraseTxIndex(tx.GetUsernameHash()) ) { if( !fJustCheck )
fClean = fClean && error("DisconnectBlock() : error erasing txIndex"); pblocktree->EraseTxIndex(tx.GetUsernameHash());
}
} }
// move best block pointer to prevout block // move best block pointer to prevout block
view.SetBestBlock(pindex->pprev); view.SetBestBlock(pindex->pprev);
if (pfClean) { return true;
*pfClean = fClean;
return true;
} else {
return fClean;
}
} }
void static FlushBlockFile(bool fFinalize = false) void static FlushBlockFile(bool fFinalize = false)
@ -1171,7 +1160,7 @@ bool SetBestChain(CValidationState &state, CBlockIndex* pindexNew)
if (!ReadBlockFromDisk(block, pindex)) if (!ReadBlockFromDisk(block, pindex))
return state.Abort(_("Failed to read block")); return state.Abort(_("Failed to read block"));
int64 nStart = GetTimeMicros(); 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()); return error("SetBestBlock() : DisconnectBlock %s failed", pindex->GetBlockHash().ToString().c_str());
if (fBenchmark) if (fBenchmark)
printf("- Disconnect: %.2fms\n", (GetTimeMicros() - nStart) * 0.001); 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 // 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) { if (nCheckLevel >= 3 && pindex == pindexState && (coins.GetCacheSize() + pcoinsTip->GetCacheSize()) <= 2*nCoinCacheSize + 32000) {
bool fClean = true; 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()); return error("VerifyDB() : *** irrecoverable inconsistency in block data at %d, hash=%s", pindex->nHeight, pindex->GetBlockHash().ToString().c_str());
pindexState = pindex->pprev; pindexState = pindex->pprev;
if (!fClean) { if (!fClean) {

2
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 * 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 * 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. */ * 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 // 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); bool ConnectBlock(CBlock& block, CValidationState& state, CBlockIndex* pindex, CCoinsViewCache& coins, bool fJustCheck = false);

Loading…
Cancel
Save