Skip to content

Commit ed82e71

Browse files
author
MarcoFalke
committed
wallet: Erase wtxOrderd wtx pointer on removeprunedfunds
Github-Pull: #13437 Rebased-From: faa18ca
1 parent e15e3a9 commit ed82e71

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
@@ -913,11 +913,10 @@ bool CWallet::AddToWallet(const CWalletTx& wtxIn, bool fFlushOnClose)
913913
CWalletTx& wtx = (*ret.first).second;
914914
wtx.BindWallet(this);
915915
bool fInsertedNew = ret.second;
916-
if (fInsertedNew)
917-
{
916+
if (fInsertedNew) {
918917
wtx.nTimeReceived = GetAdjustedTime();
919918
wtx.nOrderPos = IncOrderPosNext(&walletdb);
920-
wtxOrdered.insert(std::make_pair(wtx.nOrderPos, TxPair(&wtx, nullptr)));
919+
wtx.m_it_wtxOrdered = wtxOrdered.insert(std::make_pair(wtx.nOrderPos, TxPair(&wtx, nullptr)));
921920
wtx.nTimeSmart = ComputeTimeSmart(wtx);
922921
AddToSpends(hash);
923922
}
@@ -987,9 +986,12 @@ bool CWallet::AddToWallet(const CWalletTx& wtxIn, bool fFlushOnClose)
987986
bool CWallet::LoadToWallet(const CWalletTx& wtxIn)
988987
{
989988
uint256 hash = wtxIn.GetHash();
990-
CWalletTx& wtx = mapWallet.emplace(hash, wtxIn).first->second;
989+
const auto& ins = mapWallet.emplace(hash, wtxIn);
990+
CWalletTx& wtx = ins.first->second;
991991
wtx.BindWallet(this);
992-
wtxOrdered.insert(std::make_pair(wtx.nOrderPos, TxPair(&wtx, nullptr)));
992+
if (/* insertion took place */ ins.second) {
993+
wtx.m_it_wtxOrdered = wtxOrdered.insert(std::make_pair(wtx.nOrderPos, TxPair(&wtx, nullptr)));
994+
}
993995
AddToSpends(hash);
994996
for (const CTxIn& txin : wtx.tx->vin) {
995997
auto it = mapWallet.find(txin.prevout.hash);
@@ -3123,8 +3125,11 @@ DBErrors CWallet::ZapSelectTx(std::vector<uint256>& vHashIn, std::vector<uint256
31233125
{
31243126
AssertLockHeld(cs_wallet); // mapWallet
31253127
DBErrors nZapSelectTxRet = CWalletDB(*dbw,"cr+").ZapSelectTx(vHashIn, vHashOut);
3126-
for (uint256 hash : vHashOut)
3127-
mapWallet.erase(hash);
3128+
for (uint256 hash : vHashOut) {
3129+
const auto& it = mapWallet.find(hash);
3130+
wtxOrdered.erase(it->second.m_it_wtxOrdered);
3131+
mapWallet.erase(it);
3132+
}
31283133

31293134
if (nZapSelectTxRet == DB_NEED_REWRITE)
31303135
{

src/wallet/wallet.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,7 @@ class CWalletTx : public CMerkleTx
327327
char fFromMe;
328328
std::string strFromAccount;
329329
int64_t nOrderPos; //!< position in ordered transaction list
330+
std::multimap<int64_t, std::pair<CWalletTx*, CAccountingEntry*>>::const_iterator m_it_wtxOrdered;
330331

331332
// memory only
332333
mutable bool fDebitCached;

0 commit comments

Comments
 (0)