From f0f881601a006de0dc1a2ce4562784d347424ad6 Mon Sep 17 00:00:00 2001 From: John Newbery Date: Tue, 11 Apr 2017 10:23:32 -0400 Subject: [PATCH] Remove SYNC_TRANSACTION_NOT_IN_BLOCK magic number. Summary: Backport core's PR10186 Test Plan: make check ./test/functional/test_runner.py Reviewers: #bitcoin_abc, matiu Reviewed By: #bitcoin_abc, matiu Subscribers: matiu, teamcity Differential Revision: https://reviews.bitcoinabc.org/D1057 --- src/wallet/wallet.cpp | 28 +++++++++++++--------------- src/wallet/wallet.h | 10 +++++++--- 2 files changed, 20 insertions(+), 18 deletions(-) diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index 3c1395bcc..4959d8798 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -1107,12 +1107,12 @@ 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. If fUpdate is true, existing transactions will be updated. + * 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 pIndex + * == nullptr, 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 * abandoned is an indication that it is not safe to be considered abandoned. @@ -1125,7 +1125,7 @@ bool CWallet::AddToWalletIfInvolvingMe(const CTransactionRef &ptx, const CTransaction &tx = *ptx; AssertLockHeld(cs_wallet); - if (posInBlock != -1) { + if (pIndex != nullptr) { for (const CTxIn &txin : tx.vin) { std::pair range = mapTxSpends.equal_range(txin.prevout); @@ -1184,8 +1184,8 @@ bool CWallet::AddToWalletIfInvolvingMe(const CTransactionRef &ptx, CWalletTx wtx(this, ptx); - // Get merkle branch if transaction was found in a block. - if (posInBlock != -1) { + // Get merkle branch if transaction was found in a block + if (pIndex != nullptr) { wtx.SetMerkleBranch(pIndex, posInBlock); } @@ -1321,12 +1321,10 @@ void CWallet::MarkConflicted(const uint256 &hashBlock, const uint256 &hashTx) { } void CWallet::SyncTransaction(const CTransactionRef &ptx, - const CBlockIndex *pindexBlockConnected, - int posInBlock) { + const CBlockIndex *pindex, int posInBlock) { const CTransaction &tx = *ptx; - if (!AddToWalletIfInvolvingMe(ptx, pindexBlockConnected, posInBlock, - true)) { + if (!AddToWalletIfInvolvingMe(ptx, pindex, posInBlock, true)) { // Not one of ours return; } @@ -1343,7 +1341,7 @@ void CWallet::SyncTransaction(const CTransactionRef &ptx, void CWallet::TransactionAddedToMempool(const CTransactionRef &ptx) { LOCK2(cs_main, cs_wallet); - SyncTransaction(ptx, nullptr, -1); + SyncTransaction(ptx); } void CWallet::BlockConnected( @@ -1359,7 +1357,7 @@ void CWallet::BlockConnected( // that the conflicted transaction was evicted. for (const CTransactionRef &ptx : vtxConflicted) { - SyncTransaction(ptx, nullptr, -1); + SyncTransaction(ptx); } for (size_t i = 0; i < pblock->vtx.size(); i++) { SyncTransaction(pblock->vtx[i], pindex, i); @@ -1370,7 +1368,7 @@ void CWallet::BlockDisconnected(const std::shared_ptr &pblock) { LOCK2(cs_main, cs_wallet); for (const CTransactionRef &ptx : pblock->vtx) { - SyncTransaction(ptx, nullptr, -1); + SyncTransaction(ptx); } } diff --git a/src/wallet/wallet.h b/src/wallet/wallet.h index ef79fcd81..8dd26a1fb 100644 --- a/src/wallet/wallet.h +++ b/src/wallet/wallet.h @@ -626,10 +626,14 @@ class CWallet final : public CCryptoKeyStore, public CValidationInterface { void SyncMetaData(std::pair); - /* Used by TransactionAddedToMemorypool/BlockConnected/Disconnected */ + /** + * 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 *pindexBlockConnected, - int posInBlock); + const CBlockIndex *pindex = nullptr, + int posInBlock = 0); /* the HD chain data model (external chain counters) */ CHDChain hdChain;