From 2013b35e3ef1588547a35825dcdf73e202d135b2 Mon Sep 17 00:00:00 2001 From: Kris Nuttycombe Date: Mon, 6 Apr 2020 14:40:56 -0600 Subject: [PATCH 1/3] Remove option to load new blocks from ConnectTip --- src/main.cpp | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) 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()) From db65d92df4096f278b8a6d9a6375a52e5a1f5cc2 Mon Sep 17 00:00:00 2001 From: Kris Nuttycombe Date: Mon, 6 Apr 2020 14:48:25 -0600 Subject: [PATCH 2/3] Make condition closer to original, Fix incorrect comment. --- src/main.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 4855e29f2..7fe9aa2d7 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3213,7 +3213,6 @@ uint64_t nNotifiedSequence = 0; bool static ConnectTip(CValidationState& state, const CChainParams& chainparams, CBlockIndex* pindexNew, const CBlock* pblock) { assert(pblock && pindexNew->pprev == chainActive.Tip()); - // Read block from disk. int64_t nTime1 = GetTimeMicros(); // Apply the block atomically to the chain state. int64_t nTime2 = GetTimeMicros(); nTimeReadFromDisk += nTime2 - nTime1; @@ -3425,14 +3424,15 @@ static bool ActivateBestChainStep(CValidationState& state, const CChainParams& c // Connect new blocks. BOOST_REVERSE_FOREACH(CBlockIndex *pindexConnect, vpindexToConnect) { - const CBlock* pconnectBlock = pblock; + const CBlock* pconnectBlock; CBlock block; - if (pindexConnect != pindexMostWork) { + if (pindexConnect == pindexMostWork) { + pconnectBlock = pblock; + } else { + // read the block to be connected from disk if (!ReadBlockFromDisk(block, pindexConnect, chainparams.GetConsensus())) return AbortNode(state, "Failed to read block"); pconnectBlock = █ - } else { - pconnectBlock = pblock; } if (!ConnectTip(state, chainparams, pindexConnect, pconnectBlock)) { From 368a7c5a9d39b9d2ac1c3f15dace53ec3b7691aa Mon Sep 17 00:00:00 2001 From: Kris Nuttycombe Date: Wed, 22 Apr 2020 12:28:13 -0600 Subject: [PATCH 3/3] Ensure that we don't pass a null block pointer to ConnectTip. --- src/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index 7fe9aa2d7..df2dfd537 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3426,7 +3426,7 @@ static bool ActivateBestChainStep(CValidationState& state, const CChainParams& c BOOST_REVERSE_FOREACH(CBlockIndex *pindexConnect, vpindexToConnect) { const CBlock* pconnectBlock; CBlock block; - if (pindexConnect == pindexMostWork) { + if (pblock && pindexConnect == pindexMostWork) { pconnectBlock = pblock; } else { // read the block to be connected from disk