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
0ScriptPubKeyMan* CWallet::GetScriptPubKeyMan(const OutputType& type, bool internal) const
1{
2 const std::map<OutputType, ScriptPubKeyMan*>& spk_managers = internal ? m_internal_spk_managers : m_external_spk_managers;
3 std::map<OutputType, ScriptPubKeyMan*>::const_iterator it = spk_managers.find(type);
4 if (it == spk_managers.end()) {
5 WalletLogPrintf("%s scriptPubKey Manager for output type %d does not exist\n", internal ? "Internal" : "External", static_cast<int>(type));
6 return nullptr;
7 }
8 return it->second;
9}
10 auto old_spk_man_id = old_spk_man->GetID();
11 for (bool internal : {false, true}) {
12 for (OutputType t : OUTPUT_TYPES) {
13 auto active_spk_man = GetScriptPubKeyMan(t, internal);
14 if (active_spk_man && active_spk_man->GetID() == old_spk_man_id) {
15 if (internal) {
16 m_internal_spk_managers.erase(t);
17 } else {
18 m_external_spk_managers.erase(t);
19 }
20 break;
21 }
22 }
23 }