Skip to content

Commit faa18ca

Browse files
author
MarcoFalke
committed
wallet: Erase wtxOrderd wtx pointer on removeprunedfunds
1 parent 3d3d8ae commit faa18ca

File tree

2 files changed

+13
-7
lines changed

2 files changed

+13
-7
lines changed

src/wallet/wallet.cpp

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -923,11 +923,10 @@ bool CWallet::AddToWallet(const CWalletTx& wtxIn, bool fFlushOnClose)
923923
CWalletTx& wtx = (*ret.first).second;
924924
wtx.BindWallet(this);
925925
bool fInsertedNew = ret.second;
926-
if (fInsertedNew)
927-
{
926+
if (fInsertedNew) {
928927
wtx.nTimeReceived = GetAdjustedTime();
929928
wtx.nOrderPos = IncOrderPosNext(&batch);
930-
wtxOrdered.insert(std::make_pair(wtx.nOrderPos, TxPair(&wtx, nullptr)));
929+
wtx.m_it_wtxOrdered = wtxOrdered.insert(std::make_pair(wtx.nOrderPos, TxPair(&wtx, nullptr)));
931930
wtx.nTimeSmart = ComputeTimeSmart(wtx);
932931
AddToSpends(hash);
933932
}
@@ -998,9 +997,12 @@ bool CWallet::AddToWallet(const CWalletTx& wtxIn, bool fFlushOnClose)
998997
bool CWallet::LoadToWallet(const CWalletTx& wtxIn)
999998
{
1000999
uint256 hash = wtxIn.GetHash();
1001-
CWalletTx& wtx = mapWallet.emplace(hash, wtxIn).first->second;
1000+
const auto& ins = mapWallet.emplace(hash, wtxIn);
1001+
CWalletTx& wtx = ins.first->second;
10021002
wtx.BindWallet(this);
1003-
wtxOrdered.insert(std::make_pair(wtx.nOrderPos, TxPair(&wtx, nullptr)));
1003+
if (/* insertion took place */ ins.second) {
1004+
wtx.m_it_wtxOrdered = wtxOrdered.insert(std::make_pair(wtx.nOrderPos, TxPair(&wtx, nullptr)));
1005+
}
10041006
AddToSpends(hash);
10051007
for (const CTxIn& txin : wtx.tx->vin) {
10061008
auto it = mapWallet.find(txin.prevout.hash);
@@ -3206,8 +3208,11 @@ DBErrors CWallet::ZapSelectTx(std::vector<uint256>& vHashIn, std::vector<uint256
32063208
{
32073209
AssertLockHeld(cs_wallet); // mapWallet
32083210
DBErrors nZapSelectTxRet = WalletBatch(*database,"cr+").ZapSelectTx(vHashIn, vHashOut);
3209-
for (uint256 hash : vHashOut)
3210-
mapWallet.erase(hash);
3211+
for (uint256 hash : vHashOut) {
3212+
const auto& it = mapWallet.find(hash);
3213+
wtxOrdered.erase(it->second.m_it_wtxOrdered);
3214+
mapWallet.erase(it);
3215+
}
32113216

32123217
if (nZapSelectTxRet == DBErrors::NEED_REWRITE)
32133218
{

src/wallet/wallet.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,7 @@ class CWalletTx : public CMerkleTx
339339
char fFromMe;
340340
std::string strFromAccount;
341341
int64_t nOrderPos; //!< position in ordered transaction list
342+
std::multimap<int64_t, std::pair<CWalletTx*, CAccountingEntry*>>::const_iterator m_it_wtxOrdered;
342343

343344
// memory only
344345
mutable bool fDebitCached;

0 commit comments

Comments
 (0)