wallet: avoid extra wtx lookup in AddToSpends

This method is only called from AddToWallet and LoadToWallet,
places where we already have the wtx.
This commit is contained in:
furszy committed 2022-06-20 14:21:57 -03:00
1 parent a09033e22c
commit 32e5edc0f4
2 files changed
+7 -10

No files matched your search

+6 -9
View File
@@ -663,16 +663,13 @@ void CWallet::AddToSpends(const COutPoint& outpoint, const uint256& wtxid, Walle
} }
void CWallet::AddToSpends(const uint256& wtxid, WalletBatch* batch) void CWallet::AddToSpends(const CWalletTx& wtx, WalletBatch* batch)
{ {
auto it = mapWallet.find(wtxid); if (wtx.IsCoinBase()) // Coinbases don't spend anything!
assert(it != mapWallet.end());
const CWalletTx& thisTx = it->second;
if (thisTx.IsCoinBase()) // Coinbases don't spend anything!
return; return;
for (const CTxIn& txin : thisTx.tx->vin) for (const CTxIn& txin : wtx.tx->vin)
AddToSpends(txin.prevout, wtxid, batch); AddToSpends(txin.prevout, wtx.GetHash(), batch);
} }
bool CWallet::EncryptWallet(const SecureString& strWalletPassphrase) bool CWallet::EncryptWallet(const SecureString& strWalletPassphrase)
@@ -967,7 +964,7 @@ CWalletTx* CWallet::AddToWallet(CTransactionRef tx, const TxState& state, const
wtx.nOrderPos = IncOrderPosNext(&batch); wtx.nOrderPos = IncOrderPosNext(&batch);
wtx.m_it_wtxOrdered = wtxOrdered.insert(std::make_pair(wtx.nOrderPos, &wtx)); wtx.m_it_wtxOrdered = wtxOrdered.insert(std::make_pair(wtx.nOrderPos, &wtx));
wtx.nTimeSmart = ComputeTimeSmart(wtx, rescanning_old_block); wtx.nTimeSmart = ComputeTimeSmart(wtx, rescanning_old_block);
AddToSpends(hash, &batch); AddToSpends(wtx, &batch);
} }
if (!fInsertedNew) if (!fInsertedNew)
@@ -1066,7 +1063,7 @@ bool CWallet::LoadToWallet(const uint256& hash, const UpdateWalletTxFn& fill_wtx
if (/* insertion took place */ ins.second) { if (/* insertion took place */ ins.second) {
wtx.m_it_wtxOrdered = wtxOrdered.insert(std::make_pair(wtx.nOrderPos, &wtx)); wtx.m_it_wtxOrdered = wtxOrdered.insert(std::make_pair(wtx.nOrderPos, &wtx));
} }
AddToSpends(hash); AddToSpends(wtx);
for (const CTxIn& txin : wtx.tx->vin) { for (const CTxIn& txin : wtx.tx->vin) {
auto it = mapWallet.find(txin.prevout.hash); auto it = mapWallet.find(txin.prevout.hash);
if (it != mapWallet.end()) { if (it != mapWallet.end()) {
+1 -1
View File
@@ -262,7 +262,7 @@ private:
typedef std::multimap<COutPoint, uint256> TxSpends; typedef std::multimap<COutPoint, uint256> TxSpends;
TxSpends mapTxSpends GUARDED_BY(cs_wallet); TxSpends mapTxSpends GUARDED_BY(cs_wallet);
void AddToSpends(const COutPoint& outpoint, const uint256& wtxid, WalletBatch* batch = nullptr) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet); void AddToSpends(const COutPoint& outpoint, const uint256& wtxid, WalletBatch* batch = nullptr) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
void AddToSpends(const uint256& wtxid, WalletBatch* batch = nullptr) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet); void AddToSpends(const CWalletTx& wtx, WalletBatch* batch = nullptr) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
/** /**
* Add a transaction to the wallet, or update it. confirm.block_* should * Add a transaction to the wallet, or update it. confirm.block_* should