Rename setBlockIndexValid to setBlockIndexCandidates

This commit is contained in:
Pieter Wuille 2014-10-06 08:31:33 +02:00
parent 1af838b339
commit e17bd58392
1 changed files with 15 additions and 15 deletions

View File

@ -99,7 +99,7 @@ namespace {
// The set of all CBlockIndex entries with BLOCK_VALID_TRANSACTIONS or better that are at least // The set of all CBlockIndex entries with BLOCK_VALID_TRANSACTIONS or better that are at least
// as good as our current tip. Entries may be failed, though. // as good as our current tip. Entries may be failed, though.
set<CBlockIndex*, CBlockIndexWorkComparator> setBlockIndexValid; set<CBlockIndex*, CBlockIndexWorkComparator> setBlockIndexCandidates;
// Number of nodes with fSyncStarted. // Number of nodes with fSyncStarted.
int nSyncStarted = 0; int nSyncStarted = 0;
// All pairs A->B, where A (or one if its ancestors) misses transactions, but B has transactions. // All pairs A->B, where A (or one if its ancestors) misses transactions, but B has transactions.
@ -1318,7 +1318,7 @@ void static InvalidBlockFound(CBlockIndex *pindex, const CValidationState &state
if (!state.CorruptionPossible()) { if (!state.CorruptionPossible()) {
pindex->nStatus |= BLOCK_FAILED_VALID; pindex->nStatus |= BLOCK_FAILED_VALID;
pblocktree->WriteBlockIndex(CDiskBlockIndex(pindex)); pblocktree->WriteBlockIndex(CDiskBlockIndex(pindex));
setBlockIndexValid.erase(pindex); setBlockIndexCandidates.erase(pindex);
InvalidChainFound(pindex); InvalidChainFound(pindex);
} }
} }
@ -1918,8 +1918,8 @@ static CBlockIndex* FindMostWorkChain() {
// Find the best candidate header. // Find the best candidate header.
{ {
std::set<CBlockIndex*, CBlockIndexWorkComparator>::reverse_iterator it = setBlockIndexValid.rbegin(); std::set<CBlockIndex*, CBlockIndexWorkComparator>::reverse_iterator it = setBlockIndexCandidates.rbegin();
if (it == setBlockIndexValid.rend()) if (it == setBlockIndexCandidates.rend())
return NULL; return NULL;
pindexNew = *it; pindexNew = *it;
} }
@ -1938,10 +1938,10 @@ static CBlockIndex* FindMostWorkChain() {
CBlockIndex *pindexFailed = pindexNew; CBlockIndex *pindexFailed = pindexNew;
while (pindexTest != pindexFailed) { while (pindexTest != pindexFailed) {
pindexFailed->nStatus |= BLOCK_FAILED_CHILD; pindexFailed->nStatus |= BLOCK_FAILED_CHILD;
setBlockIndexValid.erase(pindexFailed); setBlockIndexCandidates.erase(pindexFailed);
pindexFailed = pindexFailed->pprev; pindexFailed = pindexFailed->pprev;
} }
setBlockIndexValid.erase(pindexTest); setBlockIndexCandidates.erase(pindexTest);
fInvalidAncestor = true; fInvalidAncestor = true;
break; break;
} }
@ -1990,15 +1990,15 @@ static bool ActivateBestChainStep(CValidationState &state, CBlockIndex *pindexMo
return false; return false;
} }
} else { } else {
// Delete all entries in setBlockIndexValid that are worse than our new current block. // Delete all entries in setBlockIndexCandidates that are worse than our new current block.
// Note that we can't delete the current block itself, as we may need to return to it later in case a // Note that we can't delete the current block itself, as we may need to return to it later in case a
// reorganization to a better block fails. // reorganization to a better block fails.
std::set<CBlockIndex*, CBlockIndexWorkComparator>::iterator it = setBlockIndexValid.begin(); std::set<CBlockIndex*, CBlockIndexWorkComparator>::iterator it = setBlockIndexCandidates.begin();
while (setBlockIndexValid.value_comp()(*it, chainActive.Tip())) { while (setBlockIndexCandidates.value_comp()(*it, chainActive.Tip())) {
setBlockIndexValid.erase(it++); setBlockIndexCandidates.erase(it++);
} }
// Either the current tip or a successor of it we're working towards is left in setBlockIndexValid. // Either the current tip or a successor of it we're working towards is left in setBlockIndexCandidates.
assert(!setBlockIndexValid.empty()); assert(!setBlockIndexCandidates.empty());
if (!pindexOldTip || chainActive.Tip()->nChainWork > pindexOldTip->nChainWork) { if (!pindexOldTip || chainActive.Tip()->nChainWork > pindexOldTip->nChainWork) {
// We're in a better position than we were. Return temporarily to release the lock. // We're in a better position than we were. Return temporarily to release the lock.
break; break;
@ -2123,7 +2123,7 @@ bool ReceivedBlockTransactions(const CBlock &block, CValidationState& state, CBl
CBlockIndex *pindex = queue.front(); CBlockIndex *pindex = queue.front();
queue.pop_front(); queue.pop_front();
pindex->nChainTx = (pindex->pprev ? pindex->pprev->nChainTx : 0) + pindex->nTx; pindex->nChainTx = (pindex->pprev ? pindex->pprev->nChainTx : 0) + pindex->nTx;
setBlockIndexValid.insert(pindex); setBlockIndexCandidates.insert(pindex);
std::pair<std::multimap<CBlockIndex*, CBlockIndex*>::iterator, std::multimap<CBlockIndex*, CBlockIndex*>::iterator> range = mapBlocksUnlinked.equal_range(pindex); std::pair<std::multimap<CBlockIndex*, CBlockIndex*>::iterator, std::multimap<CBlockIndex*, CBlockIndex*>::iterator> range = mapBlocksUnlinked.equal_range(pindex);
while (range.first != range.second) { while (range.first != range.second) {
std::multimap<CBlockIndex*, CBlockIndex*>::iterator it = range.first; std::multimap<CBlockIndex*, CBlockIndex*>::iterator it = range.first;
@ -2803,7 +2803,7 @@ bool static LoadBlockIndexDB()
} }
} }
if (pindex->IsValid(BLOCK_VALID_TRANSACTIONS) && (pindex->nChainTx || pindex->pprev == NULL)) if (pindex->IsValid(BLOCK_VALID_TRANSACTIONS) && (pindex->nChainTx || pindex->pprev == NULL))
setBlockIndexValid.insert(pindex); setBlockIndexCandidates.insert(pindex);
if (pindex->nStatus & BLOCK_FAILED_MASK && (!pindexBestInvalid || pindex->nChainWork > pindexBestInvalid->nChainWork)) if (pindex->nStatus & BLOCK_FAILED_MASK && (!pindexBestInvalid || pindex->nChainWork > pindexBestInvalid->nChainWork))
pindexBestInvalid = pindex; pindexBestInvalid = pindex;
if (pindex->pprev) if (pindex->pprev)
@ -2947,7 +2947,7 @@ bool CVerifyDB::VerifyDB(CCoinsView *coinsview, int nCheckLevel, int nCheckDepth
void UnloadBlockIndex() void UnloadBlockIndex()
{ {
mapBlockIndex.clear(); mapBlockIndex.clear();
setBlockIndexValid.clear(); setBlockIndexCandidates.clear();
chainActive.SetTip(NULL); chainActive.SetTip(NULL);
pindexBestInvalid = NULL; pindexBestInvalid = NULL;
} }