Skip to content

Commit 48d705f

Browse files
presstabWarrows
authored andcommitted
Remove stale wallet transactions on initial load.
1 parent 12985ae commit 48d705f

File tree

3 files changed

+10
-5
lines changed

3 files changed

+10
-5
lines changed

src/init.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2015,7 +2015,7 @@ bool AppInit2()
20152015
#ifdef ENABLE_WALLET
20162016
if (pwalletMain) {
20172017
// Add wallet transactions that aren't already in a block to mapTransactions
2018-
pwalletMain->ReacceptWalletTransactions();
2018+
pwalletMain->ReacceptWalletTransactions(/*fFirstLoad*/true);
20192019

20202020
// Run a thread to flush wallet periodically
20212021
threadGroup.create_thread(boost::bind(&ThreadFlushWalletDB, boost::ref(pwalletMain->strWalletFile)));

src/wallet/wallet.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -927,6 +927,7 @@ void CWallet::EraseFromWallet(const uint256& hash)
927927
LOCK(cs_wallet);
928928
if (mapWallet.erase(hash))
929929
CWalletDB(strWalletFile).EraseTx(hash);
930+
LogPrintf("%s: Erased wtx %s from wallet\n", __func__, hash.GetHex());
930931
}
931932
return;
932933
}
@@ -1508,7 +1509,7 @@ int CWallet::ScanForWalletTransactions(CBlockIndex* pindexStart, bool fUpdate, b
15081509
return ret;
15091510
}
15101511

1511-
void CWallet::ReacceptWalletTransactions()
1512+
void CWallet::ReacceptWalletTransactions(bool fFirstLoad)
15121513
{
15131514
LOCK2(cs_main, cs_wallet);
15141515
std::map<int64_t, CWalletTx*> mapSorted;
@@ -1520,7 +1521,6 @@ void CWallet::ReacceptWalletTransactions()
15201521
assert(wtx.GetHash() == wtxid);
15211522

15221523
int nDepth = wtx.GetDepthInMainChain();
1523-
15241524
if (!wtx.IsCoinBase() && !wtx.IsCoinStake() && nDepth == 0 && !wtx.isAbandoned()) {
15251525
mapSorted.insert(std::make_pair(wtx.nOrderPos, &wtx));
15261526
}
@@ -1532,7 +1532,12 @@ void CWallet::ReacceptWalletTransactions()
15321532
CWalletTx& wtx = *(item.second);
15331533

15341534
LOCK(mempool.cs);
1535-
wtx.AcceptToMemoryPool(false);
1535+
bool fSuccess = wtx.AcceptToMemoryPool(false);
1536+
if (!fSuccess && fFirstLoad && GetTime() - wtx.GetTxTime() > 12*60*60) {
1537+
//First load of wallet, failed to accept to mempool, and older than 12 hours... not likely to ever
1538+
//make it in to mempool
1539+
AbandonTransaction(wtx.GetHash());
1540+
}
15361541
}
15371542
}
15381543

src/wallet/wallet.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -426,7 +426,7 @@ class CWallet : public CCryptoKeyStore, public CValidationInterface
426426
bool AddToWalletIfInvolvingMe(const CTransaction& tx, const CBlock* pblock, bool fUpdate);
427427
void EraseFromWallet(const uint256& hash);
428428
int ScanForWalletTransactions(CBlockIndex* pindexStart, bool fUpdate = false, bool fromStartup = false);
429-
void ReacceptWalletTransactions();
429+
void ReacceptWalletTransactions(bool fFirstLoad = false);
430430
void ResendWalletTransactions();
431431
CAmount GetBalance() const;
432432
CAmount GetZerocoinBalance(bool fMatureOnly) const;

0 commit comments

Comments
 (0)