fixes: #21716
Problem:
In AddWalletDescriptor we iterate through every combination of internal/external and OutputType. For each combination we call GetScriptPubKeyMan and when the combination is invalid we would log a warning scriptPubKey Manager for output type and thus causing the spam in the logs.
My approach
Since there is only one ScriptPubKeyMan that has the same id as old_spk_man_id, we would instead iterate through both the map and erase the ScriptPubKeyMan once we find it.
The code that causes the spam: src/wallet/wallet.cpp
ScriptPubKeyMan* CWallet::GetScriptPubKeyMan(const OutputType& type, bool internal) const
{
const std::map<OutputType, ScriptPubKeyMan*>& spk_managers = internal ? m_internal_spk_managers : m_external_spk_managers;
std::map<OutputType, ScriptPubKeyMan*>::const_iterator it = spk_managers.find(type);
if (it == spk_managers.end()) {
WalletLogPrintf("%s scriptPubKey Manager for output type %d does not exist\n", internal ? "Internal" : "External", static_cast<int>(type));
return nullptr;
}
return it->second;
}
auto old_spk_man_id = old_spk_man->GetID();
for (bool internal : {false, true}) {
for (OutputType t : OUTPUT_TYPES) {
auto active_spk_man = GetScriptPubKeyMan(t, internal);
if (active_spk_man && active_spk_man->GetID() == old_spk_man_id) {
if (internal) {
m_internal_spk_managers.erase(t);
} else {
m_external_spk_managers.erase(t);
}
break;
}
}
}