From b76ca3dc43dce40ca09b462803cb558f2c2e7249 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Fri, 7 Dec 2018 00:38:13 +0800 Subject: [PATCH] Try wallet fix here --- src/main.cpp | 24 ++++++++++++++++++++++-- src/wallet/walletdb.cpp | 9 ++++++--- 2 files changed, 28 insertions(+), 5 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 7668f7f87..912ab7cf8 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3835,15 +3835,16 @@ bool static DisconnectTip(CValidationState &state, bool fBare = false) { assert(pcoinsTip->GetSaplingAnchorAt(pcoinsTip->GetBestAnchor(SAPLING), newSaplingTree)); // Let wallets know transactions went from 1-confirmed to // 0-confirmed or conflicted: + std::vector TxToRemove; for (int i = 0; i < block.vtx.size(); i++) { CTransaction &tx = block.vtx[i]; //if ((i == (block.vtx.size() - 1)) && ((ASSETCHAINS_LWMAPOS && block.IsVerusPOSBlock()) || (ASSETCHAINS_STAKED != 0 && (komodo_isPoS((CBlock *)&block) != 0)))) if ((i == (block.vtx.size() - 1)) && (ASSETCHAINS_STAKED != 0 && (komodo_isPoS((CBlock *)&block) != 0))) { - //EraseFromWallets(tx.GetHash()); #ifdef ENABLE_WALLET - pwalletMain->EraseFromWallet(tx.GetHash()); + TxToRemove.push_back(tx.GetHash()); + //pwalletMain->EraseFromWallet(tx.GetHash()); #endif } else @@ -3851,6 +3852,25 @@ bool static DisconnectTip(CValidationState &state, bool fBare = false) { SyncWithWallets(tx, NULL); } } + if ( ASSETCHAINS_STAKED != 0 ) // If Staked chain, scan wallet for orphaned txs and delete them. + { + LOCK2(cs_main, pwalletMain->cs_wallet); + for (map::iterator it = pwalletMain->mapWallet.begin(); it != pwalletMain->mapWallet.end(); ++it) + { + CTransaction tx; + uint256 hashBlock; + if (!GetTransaction((*it).first,tx,hashBlock,true)) + { + fprintf(stderr, "TX Does Not Exist: %s\n",(*it).first.ToString().c_str()); + TxToRemove.push_back((*it).first); + } + } + BOOST_FOREACH (uint256& hash, TxToRemove) + { + pwalletMain->EraseFromWallet(hash); + fprintf(stderr, "Erased %s from wallet.\n",hash.ToString().c_str()); + } + } // Update cached incremental witnesses GetMainSignals().ChainTip(pindexDelete, &block, newSproutTree, newSaplingTree, false); return true; diff --git a/src/wallet/walletdb.cpp b/src/wallet/walletdb.cpp index 41c0de4b2..52c815ce2 100644 --- a/src/wallet/walletdb.cpp +++ b/src/wallet/walletdb.cpp @@ -867,6 +867,8 @@ static bool IsKeyType(string strType) strType == "mkey" || strType == "ckey"); } +extern uint64_t ASSETCHAINS_STAKED; + DBErrors CWalletDB::LoadWallet(CWallet* pwallet) { pwallet->vchDefaultKey = CPubKey(); @@ -918,8 +920,9 @@ DBErrors CWalletDB::LoadWallet(CWallet* pwallet) { // Leave other errors alone, if we try to fix them we might make things worse. fNoncriticalErrors = true; // ... but do warn the user there is something wrong. - if (strType == "tx") - // Rescan if there is a bad transaction record: + if (strType == "tx" && ASSETCHAINS_STAKED == 0 ) + // Rescan if there is a bad transaction record.. + // But dont on staked chains! SoftSetBoolArg("-rescan", true); } } @@ -967,7 +970,7 @@ DBErrors CWalletDB::LoadWallet(CWallet* pwallet) if (wss.fAnyUnordered) result = ReorderTransactions(pwallet); - + return result; }