@@ -62,8 +62,9 @@ CBlockIndex* BlockManager::AddToBlockIndex(const CBlockHeader& block)
62
62
// Check for duplicate
63
63
uint256 hash = block.GetHash ();
64
64
BlockMap::iterator it = m_block_index.find (hash);
65
- if (it != m_block_index.end ())
65
+ if (it != m_block_index.end ()) {
66
66
return it->second ;
67
+ }
67
68
68
69
// Construct new block index object
69
70
CBlockIndex* pindexNew = new CBlockIndex (block);
@@ -74,8 +75,7 @@ CBlockIndex* BlockManager::AddToBlockIndex(const CBlockHeader& block)
74
75
BlockMap::iterator mi = m_block_index.insert (std::make_pair (hash, pindexNew)).first ;
75
76
pindexNew->phashBlock = &((*mi).first );
76
77
BlockMap::iterator miPrev = m_block_index.find (block.hashPrevBlock );
77
- if (miPrev != m_block_index.end ())
78
- {
78
+ if (miPrev != m_block_index.end ()) {
79
79
pindexNew->pprev = (*miPrev).second ;
80
80
pindexNew->nHeight = pindexNew->pprev ->nHeight + 1 ;
81
81
pindexNew->BuildSkip ();
@@ -112,7 +112,7 @@ void BlockManager::PruneOneBlockFile(const int fileNumber)
112
112
// m_blocks_unlinked or setBlockIndexCandidates.
113
113
auto range = m_blocks_unlinked.equal_range (pindex->pprev );
114
114
while (range.first != range.second ) {
115
- std::multimap<CBlockIndex *, CBlockIndex *>::iterator _it = range.first ;
115
+ std::multimap<CBlockIndex*, CBlockIndex*>::iterator _it = range.first ;
116
116
range.first ++;
117
117
if (_it->second == pindex) {
118
118
m_blocks_unlinked.erase (_it);
@@ -207,17 +207,19 @@ void BlockManager::FindFilesToPrune(std::set<int>& setFilesToPrune, uint64_t nPr
207
207
nLastBlockWeCanPrune, count);
208
208
}
209
209
210
- CBlockIndex * BlockManager::InsertBlockIndex (const uint256& hash)
210
+ CBlockIndex* BlockManager::InsertBlockIndex (const uint256& hash)
211
211
{
212
212
AssertLockHeld (cs_main);
213
213
214
- if (hash.IsNull ())
214
+ if (hash.IsNull ()) {
215
215
return nullptr ;
216
+ }
216
217
217
218
// Return existing
218
219
BlockMap::iterator mi = m_block_index.find (hash);
219
- if (mi != m_block_index.end ())
220
+ if (mi != m_block_index.end ()) {
220
221
return (*mi).second ;
222
+ }
221
223
222
224
// Create new
223
225
CBlockIndex* pindexNew = new CBlockIndex ();
@@ -236,10 +238,9 @@ bool BlockManager::LoadBlockIndex(
236
238
}
237
239
238
240
// Calculate nChainWork
239
- std::vector<std::pair<int , CBlockIndex*> > vSortedByHeight;
241
+ std::vector<std::pair<int , CBlockIndex*>> vSortedByHeight;
240
242
vSortedByHeight.reserve (m_block_index.size ());
241
- for (const std::pair<const uint256, CBlockIndex*>& item : m_block_index)
242
- {
243
+ for (const std::pair<const uint256, CBlockIndex*>& item : m_block_index) {
243
244
CBlockIndex* pindex = item.second ;
244
245
vSortedByHeight.push_back (std::make_pair (pindex->nHeight , pindex));
245
246
}
@@ -265,8 +266,7 @@ bool BlockManager::LoadBlockIndex(
265
266
}
266
267
}
267
268
268
- for (const std::pair<int , CBlockIndex*>& item : vSortedByHeight)
269
- {
269
+ for (const std::pair<int , CBlockIndex*>& item : vSortedByHeight) {
270
270
if (ShutdownRequested ()) return false ;
271
271
CBlockIndex* pindex = item.second ;
272
272
pindex->nChainWork = (pindex->pprev ? pindex->pprev ->nChainWork : 0 ) + GetBlockProof (*pindex);
@@ -329,16 +329,18 @@ bool BlockManager::LoadBlockIndex(
329
329
if (pindex->nStatus & BLOCK_FAILED_MASK && (!chainman.m_best_invalid || pindex->nChainWork > chainman.m_best_invalid ->nChainWork )) {
330
330
chainman.m_best_invalid = pindex;
331
331
}
332
- if (pindex->pprev )
332
+ if (pindex->pprev ) {
333
333
pindex->BuildSkip ();
334
+ }
334
335
if (pindex->IsValid (BLOCK_VALID_TREE) && (pindexBestHeader == nullptr || CBlockIndexWorkComparator ()(pindexBestHeader, pindex)))
335
336
pindexBestHeader = pindex;
336
337
}
337
338
338
339
return true ;
339
340
}
340
341
341
- void BlockManager::Unload () {
342
+ void BlockManager::Unload ()
343
+ {
342
344
m_blocks_unlinked.clear ();
343
345
344
346
for (const BlockMap::value_type& entry : m_block_index) {
@@ -380,8 +382,7 @@ bool BlockManager::LoadBlockIndexDB(ChainstateManager& chainman)
380
382
setBlkDataFiles.insert (pindex->nFile );
381
383
}
382
384
}
383
- for (std::set<int >::iterator it = setBlkDataFiles.begin (); it != setBlkDataFiles.end (); it++)
384
- {
385
+ for (std::set<int >::iterator it = setBlkDataFiles.begin (); it != setBlkDataFiles.end (); it++) {
385
386
FlatFilePos pos (*it, 0 );
386
387
if (CAutoFile (OpenBlockFile (pos, true ), SER_DISK, CLIENT_VERSION).IsNull ()) {
387
388
return false ;
@@ -390,13 +391,14 @@ bool BlockManager::LoadBlockIndexDB(ChainstateManager& chainman)
390
391
391
392
// Check whether we have ever pruned block & undo files
392
393
m_block_tree_db->ReadFlag (" prunedblockfiles" , fHavePruned );
393
- if (fHavePruned )
394
+ if (fHavePruned ) {
394
395
LogPrintf (" LoadBlockIndexDB(): Block files have previously been pruned\n " );
396
+ }
395
397
396
398
// Check whether we need to continue reindexing
397
399
bool fReindexing = false ;
398
400
m_block_tree_db->ReadReindexing (fReindexing );
399
- if (fReindexing ) fReindex = true ;
401
+ if (fReindexing ) fReindex = true ;
400
402
401
403
return true ;
402
404
}
@@ -405,8 +407,7 @@ CBlockIndex* BlockManager::GetLastCheckpoint(const CCheckpointData& data)
405
407
{
406
408
const MapCheckpoints& checkpoints = data.mapCheckpoints ;
407
409
408
- for (const MapCheckpoints::value_type& i : reverse_iterate (checkpoints))
409
- {
410
+ for (const MapCheckpoints::value_type& i : reverse_iterate (checkpoints)) {
410
411
const uint256& hash = i.second ;
411
412
CBlockIndex* pindex = LookupBlockIndex (hash);
412
413
if (pindex) {
0 commit comments