Skip to content

Commit 32e5edc

Browse files
committed
wallet: avoid extra wtx lookup in AddToSpends
This method is only called from AddToWallet and LoadToWallet, places where we already have the wtx.
1 parent a09033e commit 32e5edc

File tree

2 files changed

+7
-10
lines changed

2 files changed

+7
-10
lines changed

src/wallet/wallet.cpp

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -663,16 +663,13 @@ void CWallet::AddToSpends(const COutPoint& outpoint, const uint256& wtxid, Walle
663663
}
664664

665665

666-
void CWallet::AddToSpends(const uint256& wtxid, WalletBatch* batch)
666+
void CWallet::AddToSpends(const CWalletTx& wtx, WalletBatch* batch)
667667
{
668-
auto it = mapWallet.find(wtxid);
669-
assert(it != mapWallet.end());
670-
const CWalletTx& thisTx = it->second;
671-
if (thisTx.IsCoinBase()) // Coinbases don't spend anything!
668+
if (wtx.IsCoinBase()) // Coinbases don't spend anything!
672669
return;
673670

674-
for (const CTxIn& txin : thisTx.tx->vin)
675-
AddToSpends(txin.prevout, wtxid, batch);
671+
for (const CTxIn& txin : wtx.tx->vin)
672+
AddToSpends(txin.prevout, wtx.GetHash(), batch);
676673
}
677674

678675
bool CWallet::EncryptWallet(const SecureString& strWalletPassphrase)
@@ -967,7 +964,7 @@ CWalletTx* CWallet::AddToWallet(CTransactionRef tx, const TxState& state, const
967964
wtx.nOrderPos = IncOrderPosNext(&batch);
968965
wtx.m_it_wtxOrdered = wtxOrdered.insert(std::make_pair(wtx.nOrderPos, &wtx));
969966
wtx.nTimeSmart = ComputeTimeSmart(wtx, rescanning_old_block);
970-
AddToSpends(hash, &batch);
967+
AddToSpends(wtx, &batch);
971968
}
972969

973970
if (!fInsertedNew)
@@ -1066,7 +1063,7 @@ bool CWallet::LoadToWallet(const uint256& hash, const UpdateWalletTxFn& fill_wtx
10661063
if (/* insertion took place */ ins.second) {
10671064
wtx.m_it_wtxOrdered = wtxOrdered.insert(std::make_pair(wtx.nOrderPos, &wtx));
10681065
}
1069-
AddToSpends(hash);
1066+
AddToSpends(wtx);
10701067
for (const CTxIn& txin : wtx.tx->vin) {
10711068
auto it = mapWallet.find(txin.prevout.hash);
10721069
if (it != mapWallet.end()) {

src/wallet/wallet.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ class CWallet final : public WalletStorage, public interfaces::Chain::Notificati
262262
typedef std::multimap<COutPoint, uint256> TxSpends;
263263
TxSpends mapTxSpends GUARDED_BY(cs_wallet);
264264
void AddToSpends(const COutPoint& outpoint, const uint256& wtxid, WalletBatch* batch = nullptr) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
265-
void AddToSpends(const uint256& wtxid, WalletBatch* batch = nullptr) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
265+
void AddToSpends(const CWalletTx& wtx, WalletBatch* batch = nullptr) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
266266

267267
/**
268268
* Add a transaction to the wallet, or update it. confirm.block_* should

0 commit comments

Comments
 (0)