From b7990707430f880d2e4151e186bef4ee21125b4e Mon Sep 17 00:00:00 2001 From: Matt Corallo Date: Wed, 20 Jan 2021 17:22:26 -0300 Subject: [PATCH] Take a CTransactionRef in AddToWalletIfInvolvingMe to avoid a copy --- src/wallet/wallet.cpp | 10 +++++----- src/wallet/wallet.h | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index 977d243b55ce4..976cf1365efcd 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -1060,8 +1060,9 @@ void CWallet::AddExternalNotesDataToTx(CWalletTx& wtx) const * Abandoned state should probably be more carefully tracked via different * posInBlock signals or by checking mempool presence when necessary. */ -bool CWallet::AddToWalletIfInvolvingMe(const CTransaction& tx, const uint256& blockHash, int posInBlock, bool fUpdate) +bool CWallet::AddToWalletIfInvolvingMe(const CTransactionRef& ptx, const uint256& blockHash, int posInBlock, bool fUpdate) { + const CTransaction& tx = *ptx; { AssertLockHeld(cs_wallet); @@ -1242,15 +1243,14 @@ void CWallet::MarkConflicted(const uint256& hashBlock, const uint256& hashTx) void CWallet::SyncTransaction(const CTransactionRef& ptx, const CBlockIndex *pindexBlockConnected, int posInBlock) { - const CTransaction& tx = *ptx; - if (!AddToWalletIfInvolvingMe(tx, + if (!AddToWalletIfInvolvingMe(ptx, (pindexBlockConnected) ? pindexBlockConnected->GetBlockHash() : uint256(), posInBlock, true)) { return; // Not one of ours } - MarkAffectedTransactionsDirty(tx); + MarkAffectedTransactionsDirty(*ptx); } void CWallet::TransactionAddedToMempool(const CTransactionRef& ptx) @@ -1747,7 +1747,7 @@ int CWallet::ScanForWalletTransactions(CBlockIndex* pindexStart, bool fUpdate, b int posInBlock; for (posInBlock = 0; posInBlock < (int)block.vtx.size(); posInBlock++) { const auto& tx = block.vtx[posInBlock]; - if (AddToWalletIfInvolvingMe(*tx, pindex->GetBlockHash(), posInBlock, fUpdate)) { + if (AddToWalletIfInvolvingMe(tx, pindex->GetBlockHash(), posInBlock, fUpdate)) { myTxHashes.push_back(tx->GetHash()); ret++; } diff --git a/src/wallet/wallet.h b/src/wallet/wallet.h index 200f10ffb0095..4e5788493ffec 100644 --- a/src/wallet/wallet.h +++ b/src/wallet/wallet.h @@ -604,7 +604,7 @@ class CWallet : public CCryptoKeyStore, public CValidationInterface void TransactionAddedToMempool(const CTransactionRef& tx) override; void BlockConnected(const std::shared_ptr& pblock, const CBlockIndex *pindex, const std::vector& vtxConflicted) override; void BlockDisconnected(const std::shared_ptr& pblock) override; - bool AddToWalletIfInvolvingMe(const CTransaction& tx, const uint256& blockHash, int posInBlock, bool fUpdate); + bool AddToWalletIfInvolvingMe(const CTransactionRef& tx, const uint256& blockHash, int posInBlock, bool fUpdate); void EraseFromWallet(const uint256& hash); /**