From 1839ec74da9d87be39e7332c151beece91767c24 Mon Sep 17 00:00:00 2001 From: random-zebra Date: Tue, 7 Jul 2020 12:34:54 +0200 Subject: [PATCH] [BUG] fix detection of wallet conflicts in CWallet::AddToWallet Check for explicit wallet conflicts when fFromLoadWallet (from bitcoin/bitcoin@9ac63d6d3056600c1b784da0e6b98f679fa98b6e, wrongly backported in #970) --- src/wallet/wallet.cpp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index 01422378d4dc..58fad6a942d4 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -780,6 +780,14 @@ bool CWallet::AddToWallet(const CWalletTx& wtxIn, bool fFromLoadWallet, CWalletD wtx.BindWallet(this); wtxOrdered.insert(std::make_pair(wtx.nOrderPos, TxPair(&wtx, (CAccountingEntry*)0))); AddToSpends(hash); + for (const CTxIn& txin : wtx.vin) { + if (mapWallet.count(txin.prevout.hash)) { + CWalletTx& prevtx = mapWallet[txin.prevout.hash]; + if (prevtx.nIndex == -1 && !prevtx.hashUnset()) { + MarkConflicted(prevtx.hashBlock, wtx.GetHash()); + } + } + } } else { LOCK(cs_wallet); // Inserts only if not already there, returns tx inserted or tx found @@ -793,14 +801,6 @@ bool CWallet::AddToWallet(const CWalletTx& wtxIn, bool fFromLoadWallet, CWalletD wtxOrdered.insert(std::make_pair(wtx.nOrderPos, TxPair(&wtx, (CAccountingEntry*)0))); wtx.UpdateTimeSmart(); AddToSpends(hash); - for (const CTxIn& txin : wtx.vin) { - if (mapWallet.count(txin.prevout.hash)) { - CWalletTx& prevtx = mapWallet[txin.prevout.hash]; - if (prevtx.nIndex == -1 && !prevtx.hashUnset()) { - MarkConflicted(prevtx.hashBlock, wtx.GetHash()); - } - } - } } bool fUpdated = false;