Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wallet: remove GetScriptPubKeyMan spam #21880

Closed

Conversation

klementtan
Copy link
Contributor

@klementtan klementtan commented May 7, 2021

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;
                }
            }
        }

@DrahtBot
Copy link
Contributor

DrahtBot commented May 7, 2021

The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

Conflicts

Reviewers, this pull request conflicts with the following ones:

If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.

@fanquake
Copy link
Member

fanquake commented May 8, 2021

@S3RK You might be interested in this.

@S3RK
Copy link
Contributor

S3RK commented May 10, 2021

Updating descriptors by removing SPKmanager from the map and creating a new one has been shown to be problematic — see #19651. I'd suggest to review #19651 as it removes the code it question altogether and it had one ACK already.

@achow101
Copy link
Member

Agree with @S3RK that we should focus on #19651 which removes this code and replaces it with proper updating that also happens to not call GetScriptPubKeyMan a bunch.

@fanquake
Copy link
Member

Going to close this in favour of #19651. @klementtan would you like to review that PR instead?

@fanquake fanquake closed this May 10, 2021
@klementtan
Copy link
Contributor Author

Agreed. #19651 is a better solution than this. Will take a look at it.

@bitcoin bitcoin deleted a comment from tyson12346 May 11, 2021
@bitcoin bitcoin deleted a comment from tyson12346 May 11, 2021
@bitcoin bitcoin locked and limited conversation to collaborators May 11, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

GetScriptPubKeyMan spamming the logs with irrelevant message
7 participants