@@ -1337,16 +1337,14 @@ static void CheckForkWarningConditions() EXCLUSIVE_LOCKS_REQUIRED(cs_main)
1337
1337
AssertLockHeld (cs_main);
1338
1338
// Before we get past initial download, we cannot reliably alert about forks
1339
1339
// (we assume we don't get stuck on a fork before finishing our initial sync)
1340
- if (::ChainstateActive ().IsInitialBlockDownload ())
1340
+ if (::ChainstateActive ().IsInitialBlockDownload ()) {
1341
1341
return ;
1342
+ }
1342
1343
1343
- if (pindexBestInvalid && pindexBestInvalid->nChainWork > ::ChainActive ().Tip ()->nChainWork + (GetBlockProof (*::ChainActive ().Tip ()) * 6 ))
1344
- {
1344
+ if (pindexBestInvalid && pindexBestInvalid->nChainWork > ::ChainActive ().Tip ()->nChainWork + (GetBlockProof (*::ChainActive ().Tip ()) * 6 )) {
1345
1345
LogPrintf (" %s: Warning: Found invalid chain at least ~6 blocks longer than our best chain.\n Chain state database corruption likely.\n " , __func__);
1346
1346
SetfLargeWorkInvalidChainFound (true );
1347
- }
1348
- else
1349
- {
1347
+ } else {
1350
1348
SetfLargeWorkInvalidChainFound (false );
1351
1349
}
1352
1350
}
@@ -2689,8 +2687,8 @@ bool CChainState::ActivateBestChainStep(BlockValidationState& state, const CChai
2689
2687
AssertLockHeld (cs_main);
2690
2688
AssertLockHeld (m_mempool.cs );
2691
2689
2692
- const CBlockIndex * pindexOldTip = m_chain.Tip ();
2693
- const CBlockIndex * pindexFork = m_chain.FindFork (pindexMostWork);
2690
+ const CBlockIndex* pindexOldTip = m_chain.Tip ();
2691
+ const CBlockIndex* pindexFork = m_chain.FindFork (pindexMostWork);
2694
2692
2695
2693
// Disconnect active blocks which are no longer in the best chain.
2696
2694
bool fBlocksDisconnected = false ;
@@ -2710,7 +2708,7 @@ bool CChainState::ActivateBestChainStep(BlockValidationState& state, const CChai
2710
2708
fBlocksDisconnected = true ;
2711
2709
}
2712
2710
2713
- // Build list of new blocks to connect.
2711
+ // Build list of new blocks to connect (in descending height order) .
2714
2712
std::vector<CBlockIndex*> vpindexToConnect;
2715
2713
bool fContinue = true ;
2716
2714
int nHeight = pindexFork ? pindexFork->nHeight : -1 ;
@@ -2720,15 +2718,15 @@ bool CChainState::ActivateBestChainStep(BlockValidationState& state, const CChai
2720
2718
int nTargetHeight = std::min (nHeight + 32 , pindexMostWork->nHeight );
2721
2719
vpindexToConnect.clear ();
2722
2720
vpindexToConnect.reserve (nTargetHeight - nHeight);
2723
- CBlockIndex * pindexIter = pindexMostWork->GetAncestor (nTargetHeight);
2721
+ CBlockIndex* pindexIter = pindexMostWork->GetAncestor (nTargetHeight);
2724
2722
while (pindexIter && pindexIter->nHeight != nHeight) {
2725
2723
vpindexToConnect.push_back (pindexIter);
2726
2724
pindexIter = pindexIter->pprev ;
2727
2725
}
2728
2726
nHeight = nTargetHeight;
2729
2727
2730
2728
// Connect new blocks.
2731
- for (CBlockIndex * pindexConnect : reverse_iterate (vpindexToConnect)) {
2729
+ for (CBlockIndex* pindexConnect : reverse_iterate (vpindexToConnect)) {
2732
2730
if (!ConnectTip (state, chainparams, pindexConnect, pindexConnect == pindexMostWork ? pblock : std::shared_ptr<const CBlock>(), connectTrace, disconnectpool)) {
2733
2731
if (state.IsInvalid ()) {
2734
2732
// The block violates a consensus rule.
0 commit comments