wallet: Use scriptPubKey cache in GetScriptPubKeyMans

This commit is contained in:
Ava Chow 2024-02-02 14:17:02 -05:00
parent edf4e73a16
commit b410f68791

View file

@ -3436,12 +3436,18 @@ ScriptPubKeyMan* CWallet::GetScriptPubKeyMan(const OutputType& type, bool intern
std::set<ScriptPubKeyMan*> CWallet::GetScriptPubKeyMans(const CScript& script) const std::set<ScriptPubKeyMan*> CWallet::GetScriptPubKeyMans(const CScript& script) const
{ {
std::set<ScriptPubKeyMan*> spk_mans; std::set<ScriptPubKeyMan*> spk_mans;
SignatureData sigdata;
for (const auto& spk_man_pair : m_spk_managers) { // Search the cache for relevant SPKMs instead of iterating m_spk_managers
if (spk_man_pair.second->CanProvide(script, sigdata)) { const auto& it = m_cached_spks.find(script);
spk_mans.insert(spk_man_pair.second.get()); if (it != m_cached_spks.end()) {
} spk_mans.insert(it->second.begin(), it->second.end());
} }
SignatureData sigdata;
Assume(std::all_of(spk_mans.begin(), spk_mans.end(), [&script, &sigdata](ScriptPubKeyMan* spkm) { return spkm->CanProvide(script, sigdata); }));
// Legacy wallet
if (IsLegacy() && GetLegacyScriptPubKeyMan()->CanProvide(script, sigdata)) spk_mans.insert(GetLegacyScriptPubKeyMan());
return spk_mans; return spk_mans;
} }