From 714e4ad13d805d45210d390fae83790360f47d9a Mon Sep 17 00:00:00 2001 From: John Newbery Date: Tue, 11 Apr 2017 10:23:32 -0400 Subject: [PATCH 1/2] AddToWalletIfInvolvingMe should test pIndex, not posInBlock --- src/wallet/wallet.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index b0aa74342..d33dad281 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -957,9 +957,9 @@ bool CWallet::LoadToWallet(const CWalletTx& wtxIn) /** * Add a transaction to the wallet, or update it. pIndex and posInBlock should * be set when the transaction was known to be included in a block. When - * posInBlock = SYNC_TRANSACTION_NOT_IN_BLOCK (-1) , then wallet state is not - * updated in AddToWallet, but notifications happen and cached balances are - * marked dirty. + * pIndex == NULL, then wallet state is not updated in AddToWallet, but + * notifications happen and cached balances are marked dirty. + * * If fUpdate is true, existing transactions will be updated. * TODO: One exception to this is that the abandoned state is cleared under the * assumption that any further notification of a transaction that was considered @@ -973,7 +973,7 @@ bool CWallet::AddToWalletIfInvolvingMe(const CTransactionRef& ptx, const CBlockI { AssertLockHeld(cs_wallet); - if (posInBlock != -1) { + if (pIndex != NULL) { BOOST_FOREACH(const CTxIn& txin, tx.vin) { std::pair range = mapTxSpends.equal_range(txin.prevout); while (range.first != range.second) { @@ -993,7 +993,7 @@ bool CWallet::AddToWalletIfInvolvingMe(const CTransactionRef& ptx, const CBlockI CWalletTx wtx(this, ptx); // Get merkle branch if transaction was found in a block - if (posInBlock != -1) + if (pIndex != NULL) wtx.SetMerkleBranch(pIndex, posInBlock); return AddToWallet(wtx, false); From d0cd0bd6d99bd28ca0014a715ad2b565b3f787a4 Mon Sep 17 00:00:00 2001 From: John Newbery Date: Tue, 11 Apr 2017 10:34:30 -0400 Subject: [PATCH 2/2] Make CWallet::SyncTransactions() interface friendlier --- src/wallet/wallet.cpp | 10 +++++----- src/wallet/wallet.h | 5 +++-- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index d33dad281..d938b57b9 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -1118,10 +1118,10 @@ void CWallet::MarkConflicted(const uint256& hashBlock, const uint256& hashTx) } } -void CWallet::SyncTransaction(const CTransactionRef& ptx, const CBlockIndex *pindexBlockConnected, int posInBlock) { +void CWallet::SyncTransaction(const CTransactionRef& ptx, const CBlockIndex *pindex, int posInBlock) { const CTransaction& tx = *ptx; - if (!AddToWalletIfInvolvingMe(ptx, pindexBlockConnected, posInBlock, true)) + if (!AddToWalletIfInvolvingMe(ptx, pindex, posInBlock, true)) return; // Not one of ours // If a transaction changes 'conflicted' state, that changes the balance @@ -1136,7 +1136,7 @@ void CWallet::SyncTransaction(const CTransactionRef& ptx, const CBlockIndex *pin void CWallet::TransactionAddedToMempool(const CTransactionRef& ptx) { LOCK2(cs_main, cs_wallet); - SyncTransaction(ptx, NULL, -1); + SyncTransaction(ptx); } void CWallet::BlockConnected(const std::shared_ptr& pblock, const CBlockIndex *pindex, const std::vector& vtxConflicted) { @@ -1150,7 +1150,7 @@ void CWallet::BlockConnected(const std::shared_ptr& pblock, const // the notification that the conflicted transaction was evicted. for (const CTransactionRef& ptx : vtxConflicted) { - SyncTransaction(ptx, NULL, -1); + SyncTransaction(ptx); } for (size_t i = 0; i < pblock->vtx.size(); i++) { SyncTransaction(pblock->vtx[i], pindex, i); @@ -1161,7 +1161,7 @@ void CWallet::BlockDisconnected(const std::shared_ptr& pblock) { LOCK2(cs_main, cs_wallet); for (const CTransactionRef& ptx : pblock->vtx) { - SyncTransaction(ptx, NULL, -1); + SyncTransaction(ptx); } } diff --git a/src/wallet/wallet.h b/src/wallet/wallet.h index cf90d261a..8ebd59f8c 100644 --- a/src/wallet/wallet.h +++ b/src/wallet/wallet.h @@ -659,8 +659,9 @@ private: void SyncMetaData(std::pair); - /* Used by TransactionAddedToMemorypool/BlockConnected/Disconnected */ - void SyncTransaction(const CTransactionRef& tx, const CBlockIndex *pindexBlockConnected, int posInBlock); + /* Used by TransactionAddedToMemorypool/BlockConnected/Disconnected. + * 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 = NULL, int posInBlock = 0); /* the HD chain data model (external chain counters) */ CHDChain hdChain;