diff --git a/src/main.cpp b/src/main.cpp index 85914e54e..4855e29f2 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3212,15 +3212,9 @@ uint64_t nNotifiedSequence = 0; */ bool static ConnectTip(CValidationState& state, const CChainParams& chainparams, CBlockIndex* pindexNew, const CBlock* pblock) { - assert(pindexNew->pprev == chainActive.Tip()); + assert(pblock && pindexNew->pprev == chainActive.Tip()); // Read block from disk. int64_t nTime1 = GetTimeMicros(); - CBlock block; - if (!pblock) { - if (!ReadBlockFromDisk(block, pindexNew, chainparams.GetConsensus())) - return AbortNode(state, "Failed to read block"); - pblock = █ - } // Apply the block atomically to the chain state. int64_t nTime2 = GetTimeMicros(); nTimeReadFromDisk += nTime2 - nTime1; int64_t nTime3; @@ -3431,7 +3425,17 @@ static bool ActivateBestChainStep(CValidationState& state, const CChainParams& c // Connect new blocks. BOOST_REVERSE_FOREACH(CBlockIndex *pindexConnect, vpindexToConnect) { - if (!ConnectTip(state, chainparams, pindexConnect, pindexConnect == pindexMostWork ? pblock : NULL)) { + const CBlock* pconnectBlock = pblock; + CBlock block; + if (pindexConnect != pindexMostWork) { + if (!ReadBlockFromDisk(block, pindexConnect, chainparams.GetConsensus())) + return AbortNode(state, "Failed to read block"); + pconnectBlock = █ + } else { + pconnectBlock = pblock; + } + + if (!ConnectTip(state, chainparams, pindexConnect, pconnectBlock)) { if (state.IsInvalid()) { // The block violates a consensus rule. if (!state.CorruptionPossible())