Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)));
Expand Down
16 changes: 14 additions & 2 deletions src/wallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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<uint256> setErase;
BOOST_FOREACH (PAIRTYPE(const uint256, CWalletTx) & item, mapWallet) {
const uint256& wtxid = item.first;
CWalletTx& wtx = item.second;
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/wallet.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down