Skip to content

Commit 145d5be

Browse files
committed
Introduce BlockMap type for mapBlockIndex
1 parent a0dbe43 commit 145d5be

File tree

9 files changed

+27
-26
lines changed

9 files changed

+27
-26
lines changed

src/checkpoints.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ namespace Checkpoints {
156156
BOOST_REVERSE_FOREACH(const MapCheckpoints::value_type& i, checkpoints)
157157
{
158158
const uint256& hash = i.second;
159-
std::map<uint256, CBlockIndex*>::const_iterator t = mapBlockIndex.find(hash);
159+
BlockMap::const_iterator t = mapBlockIndex.find(hash);
160160
if (t != mapBlockIndex.end())
161161
return t->second;
162162
}

src/init.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1031,7 +1031,7 @@ bool AppInit2(boost::thread_group& threadGroup)
10311031
{
10321032
string strMatch = mapArgs["-printblock"];
10331033
int nFound = 0;
1034-
for (map<uint256, CBlockIndex*>::iterator mi = mapBlockIndex.begin(); mi != mapBlockIndex.end(); ++mi)
1034+
for (BlockMap::iterator mi = mapBlockIndex.begin(); mi != mapBlockIndex.end(); ++mi)
10351035
{
10361036
uint256 hash = (*mi).first;
10371037
if (boost::algorithm::starts_with(hash.ToString(), strMatch))

src/main.cpp

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ using namespace boost;
3838

3939
CCriticalSection cs_main;
4040

41-
map<uint256, CBlockIndex*> mapBlockIndex;
41+
BlockMap mapBlockIndex;
4242
CChain chainActive;
4343
int64_t nTimeBestReceived = 0;
4444
CWaitableCriticalSection csBestBlock;
@@ -328,7 +328,7 @@ void ProcessBlockAvailability(NodeId nodeid) {
328328
assert(state != NULL);
329329

330330
if (state->hashLastUnknownBlock != 0) {
331-
map<uint256, CBlockIndex*>::iterator itOld = mapBlockIndex.find(state->hashLastUnknownBlock);
331+
BlockMap::iterator itOld = mapBlockIndex.find(state->hashLastUnknownBlock);
332332
if (itOld != mapBlockIndex.end() && itOld->second->nChainWork > 0) {
333333
if (state->pindexBestKnownBlock == NULL || itOld->second->nChainWork >= state->pindexBestKnownBlock->nChainWork)
334334
state->pindexBestKnownBlock = itOld->second;
@@ -344,7 +344,7 @@ void UpdateBlockAvailability(NodeId nodeid, const uint256 &hash) {
344344

345345
ProcessBlockAvailability(nodeid);
346346

347-
map<uint256, CBlockIndex*>::iterator it = mapBlockIndex.find(hash);
347+
BlockMap::iterator it = mapBlockIndex.find(hash);
348348
if (it != mapBlockIndex.end() && it->second->nChainWork > 0) {
349349
// An actually better block was announced.
350350
if (state->pindexBestKnownBlock == NULL || it->second->nChainWork >= state->pindexBestKnownBlock->nChainWork)
@@ -434,7 +434,7 @@ CBlockLocator CChain::GetLocator(const CBlockIndex *pindex) const {
434434
CBlockIndex *CChain::FindFork(const CBlockLocator &locator) const {
435435
// Find the first block the caller has in the main chain
436436
BOOST_FOREACH(const uint256& hash, locator.vHave) {
437-
std::map<uint256, CBlockIndex*>::iterator mi = mapBlockIndex.find(hash);
437+
BlockMap::iterator mi = mapBlockIndex.find(hash);
438438
if (mi != mapBlockIndex.end())
439439
{
440440
CBlockIndex* pindex = (*mi).second;
@@ -2068,7 +2068,7 @@ CBlockIndex* AddToBlockIndex(CBlockHeader& block)
20682068
{
20692069
// Check for duplicate
20702070
uint256 hash = block.GetHash();
2071-
std::map<uint256, CBlockIndex*>::iterator it = mapBlockIndex.find(hash);
2071+
BlockMap::iterator it = mapBlockIndex.find(hash);
20722072
if (it != mapBlockIndex.end())
20732073
return it->second;
20742074

@@ -2079,9 +2079,9 @@ CBlockIndex* AddToBlockIndex(CBlockHeader& block)
20792079
LOCK(cs_nBlockSequenceId);
20802080
pindexNew->nSequenceId = nBlockSequenceId++;
20812081
}
2082-
map<uint256, CBlockIndex*>::iterator mi = mapBlockIndex.insert(make_pair(hash, pindexNew)).first;
2082+
BlockMap::iterator mi = mapBlockIndex.insert(make_pair(hash, pindexNew)).first;
20832083
pindexNew->phashBlock = &((*mi).first);
2084-
map<uint256, CBlockIndex*>::iterator miPrev = mapBlockIndex.find(block.hashPrevBlock);
2084+
BlockMap::iterator miPrev = mapBlockIndex.find(block.hashPrevBlock);
20852085
if (miPrev != mapBlockIndex.end())
20862086
{
20872087
pindexNew->pprev = (*miPrev).second;
@@ -2294,7 +2294,7 @@ bool AcceptBlockHeader(CBlockHeader& block, CValidationState& state, CBlockIndex
22942294
AssertLockHeld(cs_main);
22952295
// Check for duplicate
22962296
uint256 hash = block.GetHash();
2297-
std::map<uint256, CBlockIndex*>::iterator miSelf = mapBlockIndex.find(hash);
2297+
BlockMap::iterator miSelf = mapBlockIndex.find(hash);
22982298
CBlockIndex *pindex = NULL;
22992299
if (miSelf != mapBlockIndex.end()) {
23002300
pindex = miSelf->second;
@@ -2323,7 +2323,7 @@ bool AcceptBlockHeader(CBlockHeader& block, CValidationState& state, CBlockIndex
23232323
CBlockIndex* pindexPrev = NULL;
23242324
int nHeight = 0;
23252325
if (hash != Params().HashGenesisBlock()) {
2326-
map<uint256, CBlockIndex*>::iterator mi = mapBlockIndex.find(block.hashPrevBlock);
2326+
BlockMap::iterator mi = mapBlockIndex.find(block.hashPrevBlock);
23272327
if (mi == mapBlockIndex.end())
23282328
return state.DoS(10, error("AcceptBlock() : prev block not found"), 0, "bad-prevblk");
23292329
pindexPrev = (*mi).second;
@@ -2517,7 +2517,7 @@ bool ProcessBlock(CValidationState &state, CNode* pfrom, CBlock* pblock, CDiskBl
25172517
return error("ProcessBlock() : CheckBlock FAILED");
25182518

25192519
// If we don't already have its previous block (with full data), shunt it off to holding area until we get it
2520-
std::map<uint256, CBlockIndex*>::iterator it = mapBlockIndex.find(pblock->hashPrevBlock);
2520+
BlockMap::iterator it = mapBlockIndex.find(pblock->hashPrevBlock);
25212521
if (pblock->hashPrevBlock != 0 && (it == mapBlockIndex.end() || !(it->second->nStatus & BLOCK_HAVE_DATA)))
25222522
{
25232523
LogPrintf("ProcessBlock: ORPHAN BLOCK %lu, prev=%s\n", (unsigned long)mapOrphanBlocks.size(), pblock->hashPrevBlock.ToString());
@@ -2799,7 +2799,7 @@ CBlockIndex * InsertBlockIndex(uint256 hash)
27992799
return NULL;
28002800

28012801
// Return existing
2802-
map<uint256, CBlockIndex*>::iterator mi = mapBlockIndex.find(hash);
2802+
BlockMap::iterator mi = mapBlockIndex.find(hash);
28032803
if (mi != mapBlockIndex.end())
28042804
return (*mi).second;
28052805

@@ -2876,7 +2876,7 @@ bool static LoadBlockIndexDB()
28762876
LogPrintf("LoadBlockIndexDB(): transaction index %s\n", fTxIndex ? "enabled" : "disabled");
28772877

28782878
// Load pointer to end of best chain
2879-
std::map<uint256, CBlockIndex*>::iterator it = mapBlockIndex.find(pcoinsTip->GetBestBlock());
2879+
BlockMap::iterator it = mapBlockIndex.find(pcoinsTip->GetBestBlock());
28802880
if (it == mapBlockIndex.end())
28812881
return true;
28822882
chainActive.SetTip(it->second);
@@ -3034,7 +3034,7 @@ void PrintBlockTree()
30343034
AssertLockHeld(cs_main);
30353035
// pre-compute tree structure
30363036
map<CBlockIndex*, vector<CBlockIndex*> > mapNext;
3037-
for (map<uint256, CBlockIndex*>::iterator mi = mapBlockIndex.begin(); mi != mapBlockIndex.end(); ++mi)
3037+
for (BlockMap::iterator mi = mapBlockIndex.begin(); mi != mapBlockIndex.end(); ++mi)
30383038
{
30393039
CBlockIndex* pindex = (*mi).second;
30403040
mapNext[pindex->pprev].push_back(pindex);
@@ -3280,7 +3280,7 @@ void static ProcessGetData(CNode* pfrom)
32803280
if (inv.type == MSG_BLOCK || inv.type == MSG_FILTERED_BLOCK)
32813281
{
32823282
bool send = false;
3283-
map<uint256, CBlockIndex*>::iterator mi = mapBlockIndex.find(inv.hash);
3283+
BlockMap::iterator mi = mapBlockIndex.find(inv.hash);
32843284
if (mi != mapBlockIndex.end())
32853285
{
32863286
// If the requested block is at a height below our last
@@ -3711,7 +3711,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
37113711
if (locator.IsNull())
37123712
{
37133713
// If locator is null, return the hashStop block
3714-
map<uint256, CBlockIndex*>::iterator mi = mapBlockIndex.find(hashStop);
3714+
BlockMap::iterator mi = mapBlockIndex.find(hashStop);
37153715
if (mi == mapBlockIndex.end())
37163716
return true;
37173717
pindex = (*mi).second;
@@ -4513,7 +4513,7 @@ class CMainCleanup
45134513
CMainCleanup() {}
45144514
~CMainCleanup() {
45154515
// block headers
4516-
std::map<uint256, CBlockIndex*>::iterator it1 = mapBlockIndex.begin();
4516+
BlockMap::iterator it1 = mapBlockIndex.begin();
45174517
for (; it1 != mapBlockIndex.end(); it1++)
45184518
delete (*it1).second;
45194519
mapBlockIndex.clear();

src/main.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,8 @@ static const unsigned char REJECT_CHECKPOINT = 0x43;
8585
extern CScript COINBASE_FLAGS;
8686
extern CCriticalSection cs_main;
8787
extern CTxMemPool mempool;
88-
extern std::map<uint256, CBlockIndex*> mapBlockIndex;
88+
typedef std::map<uint256, CBlockIndex*> BlockMap;
89+
extern BlockMap mapBlockIndex;
8990
extern uint64_t nLastBlockTx;
9091
extern uint64_t nLastBlockSize;
9192
extern const std::string strMessageMagic;

src/qt/transactionrecord.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ void TransactionRecord::updateStatus(const CWalletTx &wtx)
170170

171171
// Find the block the tx is in
172172
CBlockIndex* pindex = NULL;
173-
std::map<uint256, CBlockIndex*>::iterator mi = mapBlockIndex.find(wtx.hashBlock);
173+
BlockMap::iterator mi = mapBlockIndex.find(wtx.hashBlock);
174174
if (mi != mapBlockIndex.end())
175175
pindex = (*mi).second;
176176

src/rpcblockchain.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,7 @@ Value gettxout(const Array& params, bool fHelp)
392392
if (n<0 || (unsigned int)n>=coins.vout.size() || coins.vout[n].IsNull())
393393
return Value::null;
394394

395-
std::map<uint256, CBlockIndex*>::iterator it = mapBlockIndex.find(pcoinsTip->GetBestBlock());
395+
BlockMap::iterator it = mapBlockIndex.find(pcoinsTip->GetBestBlock());
396396
CBlockIndex *pindex = it->second;
397397
ret.push_back(Pair("bestblock", pindex->GetBlockHash().GetHex()));
398398
if ((unsigned int)coins.nHeight == MEMPOOL_HEIGHT)

src/rpcrawtransaction.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ void TxToJSON(const CTransaction& tx, const uint256 hashBlock, Object& entry)
8888

8989
if (hashBlock != 0) {
9090
entry.push_back(Pair("blockhash", hashBlock.GetHex()));
91-
map<uint256, CBlockIndex*>::iterator mi = mapBlockIndex.find(hashBlock);
91+
BlockMap::iterator mi = mapBlockIndex.find(hashBlock);
9292
if (mi != mapBlockIndex.end() && (*mi).second) {
9393
CBlockIndex* pindex = (*mi).second;
9494
if (chainActive.Contains(pindex)) {

src/rpcwallet.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1447,7 +1447,7 @@ Value listsinceblock(const Array& params, bool fHelp)
14471447
uint256 blockId = 0;
14481448

14491449
blockId.SetHex(params[0].get_str());
1450-
std::map<uint256, CBlockIndex*>::iterator it = mapBlockIndex.find(blockId);
1450+
BlockMap::iterator it = mapBlockIndex.find(blockId);
14511451
if (it != mapBlockIndex.end())
14521452
pindex = it->second;
14531453
}

src/wallet.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2113,7 +2113,7 @@ void CWallet::GetKeyBirthTimes(std::map<CKeyID, int64_t> &mapKeyBirth) const {
21132113
for (std::map<uint256, CWalletTx>::const_iterator it = mapWallet.begin(); it != mapWallet.end(); it++) {
21142114
// iterate over all wallet transactions...
21152115
const CWalletTx &wtx = (*it).second;
2116-
std::map<uint256, CBlockIndex*>::const_iterator blit = mapBlockIndex.find(wtx.hashBlock);
2116+
BlockMap::const_iterator blit = mapBlockIndex.find(wtx.hashBlock);
21172117
if (blit != mapBlockIndex.end() && chainActive.Contains(blit->second)) {
21182118
// ... which are already in a block
21192119
int nHeight = blit->second->nHeight;
@@ -2233,7 +2233,7 @@ int CMerkleTx::SetMerkleBranch(const CBlock* pblock)
22332233
}
22342234

22352235
// Is the tx in a block that's in the main chain
2236-
map<uint256, CBlockIndex*>::iterator mi = mapBlockIndex.find(hashBlock);
2236+
BlockMap::iterator mi = mapBlockIndex.find(hashBlock);
22372237
if (mi == mapBlockIndex.end())
22382238
return 0;
22392239
CBlockIndex* pindex = (*mi).second;
@@ -2250,7 +2250,7 @@ int CMerkleTx::GetDepthInMainChainINTERNAL(CBlockIndex* &pindexRet) const
22502250
AssertLockHeld(cs_main);
22512251

22522252
// Find the block it claims to be in
2253-
map<uint256, CBlockIndex*>::iterator mi = mapBlockIndex.find(hashBlock);
2253+
BlockMap::iterator mi = mapBlockIndex.find(hashBlock);
22542254
if (mi == mapBlockIndex.end())
22552255
return 0;
22562256
CBlockIndex* pindex = (*mi).second;

0 commit comments

Comments
 (0)