From f6f2603373fcbf192d90b7d7a448aec0e9a724d5 Mon Sep 17 00:00:00 2001 From: miketout Date: Tue, 13 Sep 2022 00:57:36 -0700 Subject: [PATCH] Workaround bridgekeeper issue --- src/main.cpp | 8 ++++++-- src/pbaas/notarization.cpp | 22 ++++++++++++++++++++-- 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 4e9b526d5..fb6d5c3e9 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -5384,7 +5384,7 @@ static bool ActivateBestChainStep(CValidationState& state, const CChainParams& c { CBlockIndex *tipindex; fprintf(stderr,">>>>>>>>>>> rewind start ht.%d -> KOMODO_REWIND.%d\n",chainActive.LastTip()->GetHeight(),KOMODO_REWIND); - while ( KOMODO_REWIND > 0 && (tipindex= chainActive.LastTip()) != 0 && tipindex->GetHeight() > KOMODO_REWIND ) + while ( KOMODO_REWIND > 0 && (tipindex = chainActive.LastTip()) != 0 && tipindex->GetHeight() > KOMODO_REWIND ) { fBlocksDisconnected = true; fprintf(stderr,"%d ",(int32_t)tipindex->GetHeight()); @@ -5396,7 +5396,11 @@ static bool ActivateBestChainStep(CValidationState& state, const CChainParams& c sleep(20); fprintf(stderr,"resuming normal operations\n"); KOMODO_REWIND = 0; - //return(true); + if (pindexMostWork->GetHeight() > chainActive.Height()) + { + pindexMostWork = pindexMostWork->GetAncestor(chainActive.Height()); + } + pindexFork = chainActive.FindFork(pindexMostWork); } // Build list of new blocks to connect. std::vector vpindexToConnect; diff --git a/src/pbaas/notarization.cpp b/src/pbaas/notarization.cpp index 8b4ad5b41..9bb8472be 100644 --- a/src/pbaas/notarization.cpp +++ b/src/pbaas/notarization.cpp @@ -3682,10 +3682,28 @@ bool CPBaaSNotarization::ConfirmOrRejectNotarizations(CWallet *pWallet, bool retVal = false; int firstNotarizationIndex = -1; + LogPrint("notarization", "%s: proofRootArr: %s\n", __func__, proofRootArr.write().c_str()); + + // we seem to be getting an extra element at times + // TODO: HARDENING - fix this in bridgekeeper + if (proofRootArr.size() > bestFork.size()) + { + UniValue tempArr(UniValue::VARR); + for (int i = 0; i < bestFork.size(); i++) + { + tempArr.push_back(proofRootArr[i]); + } + } + // look from the latest notarization that may qualify - for (int i = proofRootArr.size() - 1; i >= 0; i--) + for (int i = (proofRootArr.size() - 1); i >= 0; i--) { - int idx = bestFork[uni_get_int(proofRootArr[i])]; + int idx = uni_get_int(proofRootArr[i]); + if (idx >= bestFork.size()) + { + continue; + } + idx = bestFork[idx]; auto proofIt = cnd.vtx[idx].second.proofRoots.find(ASSETCHAINS_CHAINID);