Skip to content

Commit 619cd29

Browse files
committed
Merge #12944: [wallet] ScanforWalletTransactions should mark input txns as dirty
3c292cc ScanforWalletTransactions should mark input txns as dirty (Gregory Sanders) Pull request description: I'm hitting a corner case in my mainnet wallet where I load a restore a wallet, call `rescanblockchain` from RPC, and it's "double counting" an output I've sent to myself since currently it never marks input transactions as dirty. This is fixed by a restart of the wallet. Note that this only happens with keys with birthdate *after* the blocks containing the spent funds which gets scanned on startup, so it's hard to test without a set seed function. Tree-SHA512: ee1fa152bb054b57ab4c734e355df10d241181e0372c81d583be61678fffbabe5ae60b09b05dc1bbbcfb4838df9d8538791d4c1d80a09b84d78ad2f50dcb0a61
2 parents 2ea7eb6 + 3c292cc commit 619cd29

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

src/wallet/wallet.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1227,10 +1227,10 @@ void CWallet::MarkConflicted(const uint256& hashBlock, const uint256& hashTx)
12271227
}
12281228
}
12291229

1230-
void CWallet::SyncTransaction(const CTransactionRef& ptx, const CBlockIndex *pindex, int posInBlock) {
1230+
void CWallet::SyncTransaction(const CTransactionRef& ptx, const CBlockIndex *pindex, int posInBlock, bool update_tx) {
12311231
const CTransaction& tx = *ptx;
12321232

1233-
if (!AddToWalletIfInvolvingMe(ptx, pindex, posInBlock, true))
1233+
if (!AddToWalletIfInvolvingMe(ptx, pindex, posInBlock, update_tx))
12341234
return; // Not one of ours
12351235

12361236
// If a transaction changes 'conflicted' state, that changes the balance
@@ -1758,7 +1758,7 @@ CBlockIndex* CWallet::ScanForWalletTransactions(CBlockIndex* pindexStart, CBlock
17581758
break;
17591759
}
17601760
for (size_t posInBlock = 0; posInBlock < block.vtx.size(); ++posInBlock) {
1761-
AddToWalletIfInvolvingMe(block.vtx[posInBlock], pindex, posInBlock, fUpdate);
1761+
SyncTransaction(block.vtx[posInBlock], pindex, posInBlock, fUpdate);
17621762
}
17631763
} else {
17641764
ret = pindex;

src/wallet/wallet.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -708,9 +708,9 @@ class CWallet final : public CCryptoKeyStore, public CValidationInterface
708708

709709
void SyncMetaData(std::pair<TxSpends::iterator, TxSpends::iterator>);
710710

711-
/* Used by TransactionAddedToMemorypool/BlockConnected/Disconnected.
711+
/* Used by TransactionAddedToMemorypool/BlockConnected/Disconnected/ScanForWalletTransactions.
712712
* Should be called with pindexBlock and posInBlock if this is for a transaction that is included in a block. */
713-
void SyncTransaction(const CTransactionRef& tx, const CBlockIndex *pindex = nullptr, int posInBlock = 0) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
713+
void SyncTransaction(const CTransactionRef& tx, const CBlockIndex *pindex = nullptr, int posInBlock = 0, bool update_tx = true) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
714714

715715
/* the HD chain data model (external chain counters) */
716716
CHDChain hdChain;

0 commit comments

Comments
 (0)