diff --git a/src/init.cpp b/src/init.cpp index 700fe101884f..db177217de63 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -1982,7 +1982,7 @@ bool AppInit2() #ifdef ENABLE_WALLET if (pwalletMain) { // Add wallet transactions that aren't already in a block to mapTransactions - pwalletMain->ReacceptWalletTransactions(); + pwalletMain->ReacceptWalletTransactions(/*fFirstLoad*/true); // Run a thread to flush wallet periodically threadGroup.create_thread(boost::bind(&ThreadFlushWalletDB, boost::ref(pwalletMain->strWalletFile))); diff --git a/src/wallet.cpp b/src/wallet.cpp index 6593188b3afb..66b1ddea3ac9 100644 --- a/src/wallet.cpp +++ b/src/wallet.cpp @@ -754,6 +754,7 @@ void CWallet::EraseFromWallet(const uint256& hash) LOCK(cs_wallet); if (mapWallet.erase(hash)) CWalletDB(strWalletFile).EraseTx(hash); + LogPrintf("%s: Erased wtx %s from wallet\n", __func__, hash.GetHex()); } return; } @@ -1539,9 +1540,10 @@ int CWallet::ScanForWalletTransactions(CBlockIndex* pindexStart, bool fUpdate) return ret; } -void CWallet::ReacceptWalletTransactions() +void CWallet::ReacceptWalletTransactions(bool fFirstLoad) { LOCK2(cs_main, cs_wallet); + std::set setErase; BOOST_FOREACH (PAIRTYPE(const uint256, CWalletTx) & item, mapWallet) { const uint256& wtxid = item.first; CWalletTx& wtx = item.second; @@ -1552,9 +1554,19 @@ void CWallet::ReacceptWalletTransactions() if (!wtx.IsCoinBase() && !wtx.IsCoinStake() && nDepth < 0) { // Try to add to memory pool LOCK(mempool.cs); - wtx.AcceptToMemoryPool(false); + bool fSuccess = wtx.AcceptToMemoryPool(false); + if (!fSuccess && fFirstLoad && GetTime() - wtx.GetTxTime() > 12*60*60) { + //First load of wallet, failed to accept to mempool, and older than 12 hours... not likely to ever + //make it in to mempool + setErase.emplace(wtxid); + } } } + + for (const uint256& txid : setErase) { + //todo : probably better to AbandonTransaction. Cherry-pick fd4bd5009eed5235c9afb6dc2e7e095a8bdd8c0b + EraseFromWallet(txid); + } } bool CWalletTx::InMempool() const diff --git a/src/wallet.h b/src/wallet.h index 41f17cfa23d8..f6c00fde29bd 100644 --- a/src/wallet.h +++ b/src/wallet.h @@ -474,7 +474,7 @@ class CWallet : public CCryptoKeyStore, public CValidationInterface bool AddToWalletIfInvolvingMe(const CTransaction& tx, const CBlock* pblock, bool fUpdate); void EraseFromWallet(const uint256& hash); int ScanForWalletTransactions(CBlockIndex* pindexStart, bool fUpdate = false); - void ReacceptWalletTransactions(); + void ReacceptWalletTransactions(bool fFirstLoad = false); void ResendWalletTransactions(); CAmount GetBalance() const; CAmount GetZerocoinBalance(bool fMatureOnly) const;