@@ -2811,10 +2811,9 @@ static void PruneBlockIndexCandidates() {
2811
2811
* Try to make some progress towards making pindexMostWork the active block.
2812
2812
* pblock is either NULL or a pointer to a CBlock corresponding to pindexMostWork.
2813
2813
*/
2814
- static bool ActivateBestChainStep (CValidationState& state, const CChainParams& chainparams, CBlockIndex* pindexMostWork, const CBlock* pblock)
2814
+ static bool ActivateBestChainStep (CValidationState& state, const CChainParams& chainparams, CBlockIndex* pindexMostWork, const CBlock* pblock, bool & fInvalidFound )
2815
2815
{
2816
2816
AssertLockHeld (cs_main);
2817
- bool fInvalidFound = false ;
2818
2817
const CBlockIndex *pindexOldTip = chainActive.Tip ();
2819
2818
const CBlockIndex *pindexFork = chainActive.FindFork (pindexMostWork);
2820
2819
@@ -2902,15 +2901,22 @@ bool ActivateBestChain(CValidationState &state, const CChainParams& chainparams,
2902
2901
{
2903
2902
LOCK (cs_main);
2904
2903
CBlockIndex *pindexOldTip = chainActive.Tip ();
2905
- pindexMostWork = FindMostWorkChain ();
2904
+ if (pindexMostWork == NULL ) {
2905
+ pindexMostWork = FindMostWorkChain ();
2906
+ }
2906
2907
2907
2908
// Whether we have anything to do at all.
2908
2909
if (pindexMostWork == NULL || pindexMostWork == chainActive.Tip ())
2909
2910
return true ;
2910
2911
2911
- if (!ActivateBestChainStep (state, chainparams, pindexMostWork, pblock && pblock->GetHash () == pindexMostWork->GetBlockHash () ? pblock : NULL ))
2912
+ bool fInvalidFound = false ;
2913
+ if (!ActivateBestChainStep (state, chainparams, pindexMostWork, pblock && pblock->GetHash () == pindexMostWork->GetBlockHash () ? pblock : NULL , fInvalidFound ))
2912
2914
return false ;
2913
2915
2916
+ if (fInvalidFound ) {
2917
+ // Wipe cache, we may need another branch now.
2918
+ pindexMostWork = NULL ;
2919
+ }
2914
2920
pindexNewTip = chainActive.Tip ();
2915
2921
pindexFork = chainActive.FindFork (pindexOldTip);
2916
2922
fInitialDownload = IsInitialBlockDownload ();
0 commit comments