Skip to content

Commit fa7eed5

Browse files
author
MarcoFalke
committed
doc: Clarify that vpindexToConnect is in reverse order
Also, style-fixups of touched code
1 parent fa62304 commit fa7eed5

File tree

1 file changed

+9
-11
lines changed

1 file changed

+9
-11
lines changed

src/validation.cpp

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1337,16 +1337,14 @@ static void CheckForkWarningConditions() EXCLUSIVE_LOCKS_REQUIRED(cs_main)
13371337
AssertLockHeld(cs_main);
13381338
// Before we get past initial download, we cannot reliably alert about forks
13391339
// (we assume we don't get stuck on a fork before finishing our initial sync)
1340-
if (::ChainstateActive().IsInitialBlockDownload())
1340+
if (::ChainstateActive().IsInitialBlockDownload()) {
13411341
return;
1342+
}
13421343

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)) {
13451345
LogPrintf("%s: Warning: Found invalid chain at least ~6 blocks longer than our best chain.\nChain state database corruption likely.\n", __func__);
13461346
SetfLargeWorkInvalidChainFound(true);
1347-
}
1348-
else
1349-
{
1347+
} else {
13501348
SetfLargeWorkInvalidChainFound(false);
13511349
}
13521350
}
@@ -2689,8 +2687,8 @@ bool CChainState::ActivateBestChainStep(BlockValidationState& state, const CChai
26892687
AssertLockHeld(cs_main);
26902688
AssertLockHeld(m_mempool.cs);
26912689

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);
26942692

26952693
// Disconnect active blocks which are no longer in the best chain.
26962694
bool fBlocksDisconnected = false;
@@ -2710,7 +2708,7 @@ bool CChainState::ActivateBestChainStep(BlockValidationState& state, const CChai
27102708
fBlocksDisconnected = true;
27112709
}
27122710

2713-
// Build list of new blocks to connect.
2711+
// Build list of new blocks to connect (in descending height order).
27142712
std::vector<CBlockIndex*> vpindexToConnect;
27152713
bool fContinue = true;
27162714
int nHeight = pindexFork ? pindexFork->nHeight : -1;
@@ -2720,15 +2718,15 @@ bool CChainState::ActivateBestChainStep(BlockValidationState& state, const CChai
27202718
int nTargetHeight = std::min(nHeight + 32, pindexMostWork->nHeight);
27212719
vpindexToConnect.clear();
27222720
vpindexToConnect.reserve(nTargetHeight - nHeight);
2723-
CBlockIndex *pindexIter = pindexMostWork->GetAncestor(nTargetHeight);
2721+
CBlockIndex* pindexIter = pindexMostWork->GetAncestor(nTargetHeight);
27242722
while (pindexIter && pindexIter->nHeight != nHeight) {
27252723
vpindexToConnect.push_back(pindexIter);
27262724
pindexIter = pindexIter->pprev;
27272725
}
27282726
nHeight = nTargetHeight;
27292727

27302728
// Connect new blocks.
2731-
for (CBlockIndex *pindexConnect : reverse_iterate(vpindexToConnect)) {
2729+
for (CBlockIndex* pindexConnect : reverse_iterate(vpindexToConnect)) {
27322730
if (!ConnectTip(state, chainparams, pindexConnect, pindexConnect == pindexMostWork ? pblock : std::shared_ptr<const CBlock>(), connectTrace, disconnectpool)) {
27332731
if (state.IsInvalid()) {
27342732
// The block violates a consensus rule.

0 commit comments

Comments
 (0)