Skip to content

Commit

Permalink
Add message popup when db corrupt. Make ReindexAccumulators() use ref…
Browse files Browse the repository at this point in the history
… list.

Github-Merge: PIVX-Project#405
Rebased-From: 43af66b
  • Loading branch information
presstab authored and meyer9 committed Feb 15, 2018
1 parent 610c370 commit bcd6d12
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 19 deletions.
4 changes: 3 additions & 1 deletion src/init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1339,8 +1339,10 @@ bool AppInit2(boost::thread_group& threadGroup)
LoadSporksFromDB();

uiInterface.InitMessage(_("Loading block index..."));
if (!LoadBlockIndex()) {
string strBlockIndexError = "";
if (!LoadBlockIndex(strBlockIndexError)) {
strLoadError = _("Error loading block database");
strLoadError = strprintf("%s : %s", strLoadError, strBlockIndexError);
break;
}

Expand Down
20 changes: 13 additions & 7 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2971,7 +2971,7 @@ bool RecalculatePHRSupply(int nHeightStart)
return true;
}

bool ReindexAccumulators(list<uint256> listMissingCheckpoints, string& strError)
bool ReindexAccumulators(list<uint256>& listMissingCheckpoints, string& strError)
{
// Phore: recalculate Accumulator Checkpoints that failed to database properly
if (!listMissingCheckpoints.empty() && chainActive.Height() >= Params().Zerocoin_StartHeight()) {
Expand Down Expand Up @@ -4897,7 +4897,7 @@ CBlockIndex* InsertBlockIndex(uint256 hash)
return pindexNew;
}

bool static LoadBlockIndexDB()
bool static LoadBlockIndexDB(string& strError)
{
if (!pblocktree->LoadBlockIndexGuts())
return false;
Expand Down Expand Up @@ -4982,8 +4982,8 @@ bool static LoadBlockIndexDB()
//the block index database.

if (!mapBlockIndex.count(pcoinsTip->GetBestBlock())) {
uiInterface.ThreadSafeMessageBox("Transaction database does not match the block database. Restart using -reindex.", "", CClientUIInterface::MSG_ERROR);
abort();
strError = "The wallet has been not been closed gracefully, causing the transaction database to be out of sync with the block database";
return false;
}
LogPrintf("%s : pcoinstip synced to block height %d, block index height %d\n", __func__, mapBlockIndex[pcoinsTip->GetBestBlock()]->nHeight, vSortedByHeight.size());

Expand All @@ -4999,10 +4999,15 @@ bool static LoadBlockIndexDB()
}
}

// Start at the last block that was successfully added to the txdb (pcoinsTip) and manually add all transactions that occurred for each block up until
// the best known block from the block index db.
CCoinsViewCache view(pcoinsTip);
while (nSortedPos < vSortedByHeight.size()) {
CBlock block;
assert(ReadBlockFromDisk(block, pindex));
if (!ReadBlockFromDisk(block, pindex)) {
strError = "The wallet has been not been closed gracefully and has caused corruption of blocks stored to disk. Data directory is in an unusable state";
return false;
}

vector<CTxUndo> vtxundo;
vtxundo.reserve(block.vtx.size() - 1);
Expand All @@ -5022,6 +5027,7 @@ bool static LoadBlockIndexDB()
pindex = vSortedByHeight[++nSortedPos].second;
}

// Save the updates to disk
if (!view.Flush() || !pcoinsTip->Flush())
LogPrintf("%s : failed to flush view\n", __func__);

Expand Down Expand Up @@ -5155,10 +5161,10 @@ void UnloadBlockIndex()
pindexBestInvalid = NULL;
}

bool LoadBlockIndex()
bool LoadBlockIndex(string& strError)
{
// Load block index from databases
if (!fReindex && !LoadBlockIndexDB())
if (!fReindex && !LoadBlockIndexDB(strError))
return false;
return true;
}
Expand Down
22 changes: 11 additions & 11 deletions src/main.h
Original file line number Diff line number Diff line change
Expand Up @@ -182,11 +182,11 @@ void RegisterNodeSignals(CNodeSignals& nodeSignals);
/** Unregister a network node */
void UnregisterNodeSignals(CNodeSignals& nodeSignals);

/**
/**
* Process an incoming block. This only returns after the best known valid
* block is made active. Note that it does not, however, guarantee that the
* specific block passed to it has been checked for validity!
*
*
* @param[out] state This may be set to an Error state if any error occurred processing it, including during validation/connection/etc of otherwise unrelated blocks during reorganisation; or it may be set to an Invalid state if pblock is itself invalid (but this is not guaranteed even when the block is checked). If you want to *possibly* get feedback on whether pblock is valid, you must also install a CValidationInterface - this will have its BlockChecked method called whenever *any* block completes validation.
* @param[in] pfrom The node which we are receiving the block from; it is added to mapBlockSource and may be penalised if the block is invalid.
* @param[in] pblock The block we want to process.
Expand All @@ -207,7 +207,7 @@ bool LoadExternalBlockFile(FILE* fileIn, CDiskBlockPos* dbp = NULL);
/** Initialize a new block tree database + block data on disk */
bool InitBlockIndex();
/** Load the block tree and coins database from disk */
bool LoadBlockIndex();
bool LoadBlockIndex(std::string& strError);
/** Unload database information */
void UnloadBlockIndex();
/** See whether the protocol update is enforced for connected nodes */
Expand Down Expand Up @@ -354,7 +354,7 @@ bool MoneyRange(CAmount nValueOut);
/**
* Check transaction inputs, and make sure any
* pay-to-script-hash transactions are evaluating IsStandard scripts
*
*
* Why bother? To avoid denial-of-service attacks; an attacker
* can submit a standard HASH... OP_EQUAL transaction,
* which will get accepted into blocks. The redemption
Expand All @@ -363,14 +363,14 @@ bool MoneyRange(CAmount nValueOut);
* DUP CHECKSIG DROP ... repeated 100 times... OP_1
*/

/**
/**
* Check for standard transaction types
* @param[in] mapInputs Map of previous transactions that have outputs we're spending
* @return True if all inputs (scriptSigs) use only standard transaction forms
*/
bool AreInputsStandard(const CTransaction& tx, const CCoinsViewCache& mapInputs);

/**
/**
* Count ECDSA signature operations the old-fashioned (pre-0.6) way
* @return number of sigops this transaction's outputs will produce when spent
* @see CTransaction::FetchInputs
Expand All @@ -379,7 +379,7 @@ unsigned int GetLegacySigOpCount(const CTransaction& tx);

/**
* Count ECDSA signature operations in pay-to-script-hash inputs.
*
*
* @param[in] mapInputs Map of previous transactions that have outputs we're spending
* @return maximum number of sigops required to validate this transaction's inputs
* @see CTransaction::FetchInputs
Expand Down Expand Up @@ -419,8 +419,8 @@ void PopulateInvalidOutPointMap();
bool ValidOutPoint(const COutPoint out, int nHeight);
void RecalculateZPHRSpent();
void RecalculateZPHRMinted();
bool RecalculatePHRSupply(int nHeightStart);
bool ReindexAccumulators(list<uint256> listMissingCheckpoints, string& strError);
bool RecalculatePIVSupply(int nHeightStart);
bool ReindexAccumulators(list<uint256>& listMissingCheckpoints, string& strError);


/**
Expand Down Expand Up @@ -458,9 +458,9 @@ class CBlockUndo
};


/**
/**
* Closure representing one script verification
* Note that this stores references to the spending transaction
* Note that this stores references to the spending transaction
*/
class CScriptCheck
{
Expand Down

0 comments on commit bcd6d12

Please sign in to comment.