Track parent->child relations for blocks
Allows to cheaply find all possible children of a block.
This commit is contained in:
parent
04a51c9ef4
commit
2bf6eb1c7c
@ -68,6 +68,7 @@
|
|||||||
CCriticalSection cs_main;
|
CCriticalSection cs_main;
|
||||||
|
|
||||||
BlockMap mapBlockIndex;
|
BlockMap mapBlockIndex;
|
||||||
|
PrevBlockMap mapPrevBlockIndex;
|
||||||
CChain chainActive;
|
CChain chainActive;
|
||||||
CBlockIndex *pindexBestHeader = NULL;
|
CBlockIndex *pindexBestHeader = NULL;
|
||||||
CWaitableCriticalSection csBestBlock;
|
CWaitableCriticalSection csBestBlock;
|
||||||
@ -3042,6 +3043,11 @@ CBlockIndex* AddToBlockIndex(const CBlockHeader& block)
|
|||||||
|
|
||||||
setDirtyBlockIndex.insert(pindexNew);
|
setDirtyBlockIndex.insert(pindexNew);
|
||||||
|
|
||||||
|
// track prevBlockHash -> pindex (multimap)
|
||||||
|
if (pindexNew->pprev) {
|
||||||
|
mapPrevBlockIndex.emplace(pindexNew->pprev->GetBlockHash(), pindexNew);
|
||||||
|
}
|
||||||
|
|
||||||
return pindexNew;
|
return pindexNew;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -3827,6 +3833,11 @@ bool static LoadBlockIndexDB(const CChainParams& chainparams)
|
|||||||
{
|
{
|
||||||
CBlockIndex* pindex = item.second;
|
CBlockIndex* pindex = item.second;
|
||||||
vSortedByHeight.push_back(std::make_pair(pindex->nHeight, pindex));
|
vSortedByHeight.push_back(std::make_pair(pindex->nHeight, pindex));
|
||||||
|
|
||||||
|
// build mapPrevBlockIndex
|
||||||
|
if (pindex->pprev) {
|
||||||
|
mapPrevBlockIndex.emplace(pindex->pprev->GetBlockHash(), pindex);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
sort(vSortedByHeight.begin(), vSortedByHeight.end());
|
sort(vSortedByHeight.begin(), vSortedByHeight.end());
|
||||||
BOOST_FOREACH(const PAIRTYPE(int, CBlockIndex*)& item, vSortedByHeight)
|
BOOST_FOREACH(const PAIRTYPE(int, CBlockIndex*)& item, vSortedByHeight)
|
||||||
|
@ -157,7 +157,9 @@ extern CScript COINBASE_FLAGS;
|
|||||||
extern CCriticalSection cs_main;
|
extern CCriticalSection cs_main;
|
||||||
extern CTxMemPool mempool;
|
extern CTxMemPool mempool;
|
||||||
typedef boost::unordered_map<uint256, CBlockIndex*, BlockHasher> BlockMap;
|
typedef boost::unordered_map<uint256, CBlockIndex*, BlockHasher> BlockMap;
|
||||||
|
typedef std::unordered_multimap<uint256, CBlockIndex*, BlockHasher> PrevBlockMap;
|
||||||
extern BlockMap mapBlockIndex;
|
extern BlockMap mapBlockIndex;
|
||||||
|
extern PrevBlockMap mapPrevBlockIndex;
|
||||||
extern uint64_t nLastBlockTx;
|
extern uint64_t nLastBlockTx;
|
||||||
extern uint64_t nLastBlockSize;
|
extern uint64_t nLastBlockSize;
|
||||||
extern const std::string strMessageMagic;
|
extern const std::string strMessageMagic;
|
||||||
|
Loading…
Reference in New Issue
Block a user