Skip to content

Commit

Permalink
Merge #12944: [wallet] ScanforWalletTransactions should mark input tx…
Browse files Browse the repository at this point in the history
…ns as dirty

Summary:
3c292cc19 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

Backport of Core PR12944
bitcoin/bitcoin#12944

Test Plan:
  make check
  test_runner.py

Reviewers: deadalnix, Fabien, jasonbcox, O1 Bitcoin ABC, #bitcoin_abc

Reviewed By: jasonbcox, O1 Bitcoin ABC, #bitcoin_abc

Differential Revision: https://reviews.bitcoinabc.org/D4674
  • Loading branch information
jonasschnelli authored and jonspock committed Oct 10, 2020
1 parent 6575d96 commit 7e8aed9
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
9 changes: 5 additions & 4 deletions src/wallet/wallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1376,10 +1376,11 @@ void CWallet::MarkConflicted(const BlockHash &hashBlock, const TxId &txid) {
}

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

if (!AddToWalletIfInvolvingMe(ptx, pindex, posInBlock, true)) {
if (!AddToWalletIfInvolvingMe(ptx, pindex, posInBlock, update_tx)) {
// Not one of ours
return;
}
Expand Down Expand Up @@ -1995,8 +1996,8 @@ CBlockIndex *CWallet::ScanForWalletTransactions(
}
for (size_t posInBlock = 0; posInBlock < block.vtx.size();
++posInBlock) {
AddToWalletIfInvolvingMe(block.vtx[posInBlock], pindex,
posInBlock, fUpdate);
SyncTransaction(block.vtx[posInBlock], pindex, posInBlock,
fUpdate);
}
} else {
ret = pindex;
Expand Down
5 changes: 3 additions & 2 deletions src/wallet/wallet.h
Original file line number Diff line number Diff line change
Expand Up @@ -754,13 +754,14 @@ class CWallet final : public CCryptoKeyStore, public CValidationInterface {
void SyncMetaData(std::pair<TxSpends::iterator, TxSpends::iterator>);

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

/* HD derive new child key (on internal or external chain) */
Expand Down

0 comments on commit 7e8aed9

Please sign in to comment.