Skip to content

Commit edf4e73

Browse files
committed
wallet: Use scriptPubKey cache in IsMine
1 parent 3723233 commit edf4e73

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

src/wallet/wallet.cpp

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1571,11 +1571,22 @@ isminetype CWallet::IsMine(const CTxDestination& dest) const
15711571
isminetype CWallet::IsMine(const CScript& script) const
15721572
{
15731573
AssertLockHeld(cs_wallet);
1574-
isminetype result = ISMINE_NO;
1575-
for (const auto& spk_man_pair : m_spk_managers) {
1576-
result = std::max(result, spk_man_pair.second->IsMine(script));
1574+
1575+
// Search the cache so that IsMine is called only on the relevant SPKMs instead of on everything in m_spk_managers
1576+
const auto& it = m_cached_spks.find(script);
1577+
if (it != m_cached_spks.end()) {
1578+
isminetype res = ISMINE_NO;
1579+
for (const auto& spkm : it->second) {
1580+
res = std::max(res, spkm->IsMine(script));
1581+
}
1582+
Assume(res == ISMINE_SPENDABLE);
1583+
return res;
15771584
}
1578-
return result;
1585+
1586+
// Legacy wallet
1587+
if (IsLegacy()) return GetLegacyScriptPubKeyMan()->IsMine(script);
1588+
1589+
return ISMINE_NO;
15791590
}
15801591

15811592
bool CWallet::IsMine(const CTransaction& tx) const

0 commit comments

Comments
 (0)