|
|
@ -38,7 +38,7 @@ using namespace boost; |
|
|
|
|
|
|
|
|
|
|
|
CCriticalSection cs_main; |
|
|
|
CCriticalSection cs_main; |
|
|
|
|
|
|
|
|
|
|
|
map<uint256, CBlockIndex*> mapBlockIndex; |
|
|
|
BlockMap mapBlockIndex; |
|
|
|
CChain chainActive; |
|
|
|
CChain chainActive; |
|
|
|
int64_t nTimeBestReceived = 0; |
|
|
|
int64_t nTimeBestReceived = 0; |
|
|
|
CWaitableCriticalSection csBestBlock; |
|
|
|
CWaitableCriticalSection csBestBlock; |
|
|
@ -328,7 +328,7 @@ void ProcessBlockAvailability(NodeId nodeid) { |
|
|
|
assert(state != NULL); |
|
|
|
assert(state != NULL); |
|
|
|
|
|
|
|
|
|
|
|
if (state->hashLastUnknownBlock != 0) { |
|
|
|
if (state->hashLastUnknownBlock != 0) { |
|
|
|
map<uint256, CBlockIndex*>::iterator itOld = mapBlockIndex.find(state->hashLastUnknownBlock); |
|
|
|
BlockMap::iterator itOld = mapBlockIndex.find(state->hashLastUnknownBlock); |
|
|
|
if (itOld != mapBlockIndex.end() && itOld->second->nChainWork > 0) { |
|
|
|
if (itOld != mapBlockIndex.end() && itOld->second->nChainWork > 0) { |
|
|
|
if (state->pindexBestKnownBlock == NULL || itOld->second->nChainWork >= state->pindexBestKnownBlock->nChainWork) |
|
|
|
if (state->pindexBestKnownBlock == NULL || itOld->second->nChainWork >= state->pindexBestKnownBlock->nChainWork) |
|
|
|
state->pindexBestKnownBlock = itOld->second; |
|
|
|
state->pindexBestKnownBlock = itOld->second; |
|
|
@ -344,7 +344,7 @@ void UpdateBlockAvailability(NodeId nodeid, const uint256 &hash) { |
|
|
|
|
|
|
|
|
|
|
|
ProcessBlockAvailability(nodeid); |
|
|
|
ProcessBlockAvailability(nodeid); |
|
|
|
|
|
|
|
|
|
|
|
map<uint256, CBlockIndex*>::iterator it = mapBlockIndex.find(hash); |
|
|
|
BlockMap::iterator it = mapBlockIndex.find(hash); |
|
|
|
if (it != mapBlockIndex.end() && it->second->nChainWork > 0) { |
|
|
|
if (it != mapBlockIndex.end() && it->second->nChainWork > 0) { |
|
|
|
// An actually better block was announced.
|
|
|
|
// An actually better block was announced.
|
|
|
|
if (state->pindexBestKnownBlock == NULL || it->second->nChainWork >= state->pindexBestKnownBlock->nChainWork) |
|
|
|
if (state->pindexBestKnownBlock == NULL || it->second->nChainWork >= state->pindexBestKnownBlock->nChainWork) |
|
|
@ -434,7 +434,7 @@ CBlockLocator CChain::GetLocator(const CBlockIndex *pindex) const { |
|
|
|
CBlockIndex *CChain::FindFork(const CBlockLocator &locator) const { |
|
|
|
CBlockIndex *CChain::FindFork(const CBlockLocator &locator) const { |
|
|
|
// Find the first block the caller has in the main chain
|
|
|
|
// Find the first block the caller has in the main chain
|
|
|
|
BOOST_FOREACH(const uint256& hash, locator.vHave) { |
|
|
|
BOOST_FOREACH(const uint256& hash, locator.vHave) { |
|
|
|
std::map<uint256, CBlockIndex*>::iterator mi = mapBlockIndex.find(hash); |
|
|
|
BlockMap::iterator mi = mapBlockIndex.find(hash); |
|
|
|
if (mi != mapBlockIndex.end()) |
|
|
|
if (mi != mapBlockIndex.end()) |
|
|
|
{ |
|
|
|
{ |
|
|
|
CBlockIndex* pindex = (*mi).second; |
|
|
|
CBlockIndex* pindex = (*mi).second; |
|
|
@ -2068,7 +2068,7 @@ CBlockIndex* AddToBlockIndex(CBlockHeader& block) |
|
|
|
{ |
|
|
|
{ |
|
|
|
// Check for duplicate
|
|
|
|
// Check for duplicate
|
|
|
|
uint256 hash = block.GetHash(); |
|
|
|
uint256 hash = block.GetHash(); |
|
|
|
std::map<uint256, CBlockIndex*>::iterator it = mapBlockIndex.find(hash); |
|
|
|
BlockMap::iterator it = mapBlockIndex.find(hash); |
|
|
|
if (it != mapBlockIndex.end()) |
|
|
|
if (it != mapBlockIndex.end()) |
|
|
|
return it->second; |
|
|
|
return it->second; |
|
|
|
|
|
|
|
|
|
|
@ -2079,9 +2079,9 @@ CBlockIndex* AddToBlockIndex(CBlockHeader& block) |
|
|
|
LOCK(cs_nBlockSequenceId); |
|
|
|
LOCK(cs_nBlockSequenceId); |
|
|
|
pindexNew->nSequenceId = nBlockSequenceId++; |
|
|
|
pindexNew->nSequenceId = nBlockSequenceId++; |
|
|
|
} |
|
|
|
} |
|
|
|
map<uint256, CBlockIndex*>::iterator mi = mapBlockIndex.insert(make_pair(hash, pindexNew)).first; |
|
|
|
BlockMap::iterator mi = mapBlockIndex.insert(make_pair(hash, pindexNew)).first; |
|
|
|
pindexNew->phashBlock = &((*mi).first); |
|
|
|
pindexNew->phashBlock = &((*mi).first); |
|
|
|
map<uint256, CBlockIndex*>::iterator miPrev = mapBlockIndex.find(block.hashPrevBlock); |
|
|
|
BlockMap::iterator miPrev = mapBlockIndex.find(block.hashPrevBlock); |
|
|
|
if (miPrev != mapBlockIndex.end()) |
|
|
|
if (miPrev != mapBlockIndex.end()) |
|
|
|
{ |
|
|
|
{ |
|
|
|
pindexNew->pprev = (*miPrev).second; |
|
|
|
pindexNew->pprev = (*miPrev).second; |
|
|
@ -2294,7 +2294,7 @@ bool AcceptBlockHeader(CBlockHeader& block, CValidationState& state, CBlockIndex |
|
|
|
AssertLockHeld(cs_main); |
|
|
|
AssertLockHeld(cs_main); |
|
|
|
// Check for duplicate
|
|
|
|
// Check for duplicate
|
|
|
|
uint256 hash = block.GetHash(); |
|
|
|
uint256 hash = block.GetHash(); |
|
|
|
std::map<uint256, CBlockIndex*>::iterator miSelf = mapBlockIndex.find(hash); |
|
|
|
BlockMap::iterator miSelf = mapBlockIndex.find(hash); |
|
|
|
CBlockIndex *pindex = NULL; |
|
|
|
CBlockIndex *pindex = NULL; |
|
|
|
if (miSelf != mapBlockIndex.end()) { |
|
|
|
if (miSelf != mapBlockIndex.end()) { |
|
|
|
pindex = miSelf->second; |
|
|
|
pindex = miSelf->second; |
|
|
@ -2323,7 +2323,7 @@ bool AcceptBlockHeader(CBlockHeader& block, CValidationState& state, CBlockIndex |
|
|
|
CBlockIndex* pindexPrev = NULL; |
|
|
|
CBlockIndex* pindexPrev = NULL; |
|
|
|
int nHeight = 0; |
|
|
|
int nHeight = 0; |
|
|
|
if (hash != Params().HashGenesisBlock()) { |
|
|
|
if (hash != Params().HashGenesisBlock()) { |
|
|
|
map<uint256, CBlockIndex*>::iterator mi = mapBlockIndex.find(block.hashPrevBlock); |
|
|
|
BlockMap::iterator mi = mapBlockIndex.find(block.hashPrevBlock); |
|
|
|
if (mi == mapBlockIndex.end()) |
|
|
|
if (mi == mapBlockIndex.end()) |
|
|
|
return state.DoS(10, error("AcceptBlock() : prev block not found"), 0, "bad-prevblk"); |
|
|
|
return state.DoS(10, error("AcceptBlock() : prev block not found"), 0, "bad-prevblk"); |
|
|
|
pindexPrev = (*mi).second; |
|
|
|
pindexPrev = (*mi).second; |
|
|
@ -2517,7 +2517,7 @@ bool ProcessBlock(CValidationState &state, CNode* pfrom, CBlock* pblock, CDiskBl |
|
|
|
return error("ProcessBlock() : CheckBlock FAILED"); |
|
|
|
return error("ProcessBlock() : CheckBlock FAILED"); |
|
|
|
|
|
|
|
|
|
|
|
// If we don't already have its previous block (with full data), shunt it off to holding area until we get it
|
|
|
|
// If we don't already have its previous block (with full data), shunt it off to holding area until we get it
|
|
|
|
std::map<uint256, CBlockIndex*>::iterator it = mapBlockIndex.find(pblock->hashPrevBlock); |
|
|
|
BlockMap::iterator it = mapBlockIndex.find(pblock->hashPrevBlock); |
|
|
|
if (pblock->hashPrevBlock != 0 && (it == mapBlockIndex.end() || !(it->second->nStatus & BLOCK_HAVE_DATA))) |
|
|
|
if (pblock->hashPrevBlock != 0 && (it == mapBlockIndex.end() || !(it->second->nStatus & BLOCK_HAVE_DATA))) |
|
|
|
{ |
|
|
|
{ |
|
|
|
LogPrintf("ProcessBlock: ORPHAN BLOCK %lu, prev=%s\n", (unsigned long)mapOrphanBlocks.size(), pblock->hashPrevBlock.ToString()); |
|
|
|
LogPrintf("ProcessBlock: ORPHAN BLOCK %lu, prev=%s\n", (unsigned long)mapOrphanBlocks.size(), pblock->hashPrevBlock.ToString()); |
|
|
@ -2799,7 +2799,7 @@ CBlockIndex * InsertBlockIndex(uint256 hash) |
|
|
|
return NULL; |
|
|
|
return NULL; |
|
|
|
|
|
|
|
|
|
|
|
// Return existing
|
|
|
|
// Return existing
|
|
|
|
map<uint256, CBlockIndex*>::iterator mi = mapBlockIndex.find(hash); |
|
|
|
BlockMap::iterator mi = mapBlockIndex.find(hash); |
|
|
|
if (mi != mapBlockIndex.end()) |
|
|
|
if (mi != mapBlockIndex.end()) |
|
|
|
return (*mi).second; |
|
|
|
return (*mi).second; |
|
|
|
|
|
|
|
|
|
|
@ -2876,7 +2876,7 @@ bool static LoadBlockIndexDB() |
|
|
|
LogPrintf("LoadBlockIndexDB(): transaction index %s\n", fTxIndex ? "enabled" : "disabled"); |
|
|
|
LogPrintf("LoadBlockIndexDB(): transaction index %s\n", fTxIndex ? "enabled" : "disabled"); |
|
|
|
|
|
|
|
|
|
|
|
// Load pointer to end of best chain
|
|
|
|
// Load pointer to end of best chain
|
|
|
|
std::map<uint256, CBlockIndex*>::iterator it = mapBlockIndex.find(pcoinsTip->GetBestBlock()); |
|
|
|
BlockMap::iterator it = mapBlockIndex.find(pcoinsTip->GetBestBlock()); |
|
|
|
if (it == mapBlockIndex.end()) |
|
|
|
if (it == mapBlockIndex.end()) |
|
|
|
return true; |
|
|
|
return true; |
|
|
|
chainActive.SetTip(it->second); |
|
|
|
chainActive.SetTip(it->second); |
|
|
@ -3034,7 +3034,7 @@ void PrintBlockTree() |
|
|
|
AssertLockHeld(cs_main); |
|
|
|
AssertLockHeld(cs_main); |
|
|
|
// pre-compute tree structure
|
|
|
|
// pre-compute tree structure
|
|
|
|
map<CBlockIndex*, vector<CBlockIndex*> > mapNext; |
|
|
|
map<CBlockIndex*, vector<CBlockIndex*> > mapNext; |
|
|
|
for (map<uint256, CBlockIndex*>::iterator mi = mapBlockIndex.begin(); mi != mapBlockIndex.end(); ++mi) |
|
|
|
for (BlockMap::iterator mi = mapBlockIndex.begin(); mi != mapBlockIndex.end(); ++mi) |
|
|
|
{ |
|
|
|
{ |
|
|
|
CBlockIndex* pindex = (*mi).second; |
|
|
|
CBlockIndex* pindex = (*mi).second; |
|
|
|
mapNext[pindex->pprev].push_back(pindex); |
|
|
|
mapNext[pindex->pprev].push_back(pindex); |
|
|
@ -3280,7 +3280,7 @@ void static ProcessGetData(CNode* pfrom) |
|
|
|
if (inv.type == MSG_BLOCK || inv.type == MSG_FILTERED_BLOCK) |
|
|
|
if (inv.type == MSG_BLOCK || inv.type == MSG_FILTERED_BLOCK) |
|
|
|
{ |
|
|
|
{ |
|
|
|
bool send = false; |
|
|
|
bool send = false; |
|
|
|
map<uint256, CBlockIndex*>::iterator mi = mapBlockIndex.find(inv.hash); |
|
|
|
BlockMap::iterator mi = mapBlockIndex.find(inv.hash); |
|
|
|
if (mi != mapBlockIndex.end()) |
|
|
|
if (mi != mapBlockIndex.end()) |
|
|
|
{ |
|
|
|
{ |
|
|
|
// If the requested block is at a height below our last
|
|
|
|
// If the requested block is at a height below our last
|
|
|
@ -3711,7 +3711,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv, |
|
|
|
if (locator.IsNull()) |
|
|
|
if (locator.IsNull()) |
|
|
|
{ |
|
|
|
{ |
|
|
|
// If locator is null, return the hashStop block
|
|
|
|
// If locator is null, return the hashStop block
|
|
|
|
map<uint256, CBlockIndex*>::iterator mi = mapBlockIndex.find(hashStop); |
|
|
|
BlockMap::iterator mi = mapBlockIndex.find(hashStop); |
|
|
|
if (mi == mapBlockIndex.end()) |
|
|
|
if (mi == mapBlockIndex.end()) |
|
|
|
return true; |
|
|
|
return true; |
|
|
|
pindex = (*mi).second; |
|
|
|
pindex = (*mi).second; |
|
|
@ -4513,7 +4513,7 @@ public: |
|
|
|
CMainCleanup() {} |
|
|
|
CMainCleanup() {} |
|
|
|
~CMainCleanup() { |
|
|
|
~CMainCleanup() { |
|
|
|
// block headers
|
|
|
|
// block headers
|
|
|
|
std::map<uint256, CBlockIndex*>::iterator it1 = mapBlockIndex.begin(); |
|
|
|
BlockMap::iterator it1 = mapBlockIndex.begin(); |
|
|
|
for (; it1 != mapBlockIndex.end(); it1++) |
|
|
|
for (; it1 != mapBlockIndex.end(); it1++) |
|
|
|
delete (*it1).second; |
|
|
|
delete (*it1).second; |
|
|
|
mapBlockIndex.clear(); |
|
|
|
mapBlockIndex.clear(); |
|
|
|