HomePhabricator

[backport#17373] wallet: Various fixes and cleanup to keypool handling in…

Description

[backport#17373] wallet: Various fixes and cleanup to keypool handling in LegacyScriptPubKeyMan and CWallet

Summary:
886f1731bec4393dd342403ac34069a3a4f95eea Key pool: Fix omitted pre-split count in GetKeyPoolSize (Andrew Chow)
386a994b853bc5b3a2ed0d812673465b8ffa4849 Key pool: Change ReturnDestination interface to take address instead of key (Andrew Chow)
ba41aa4969169cd73d6b4f57444ed7d8d875de10 Key pool: Move LearnRelated and GetDestination calls (Andrew Chow)
65833a74076cddf986037c6eb3b29a9b9dbe31c5 Add OutputType and CPubKey parameters to KeepDestination (Andrew Chow)
9fcf8ce7ae02bf170b9bf0c2887fd709d752cbf7 Rename Keep/ReturnKey to Keep/ReturnDestination and remove the wrapper (Andrew Chow)
596f6460f9fd8273665c8754ccd673d93a4f25f0 Key pool: Move CanGetAddresses call (Andrew Chow)

Pull request description:

  • The pwallet->CanGetAddresses() call in ReserveDestination::GetReservedDestination to LegacyScriptPubKeyMan::GetReservedDestination so that the sanity check results in a failure when a ScriptPubKeyMan individually cannot get a destination, not when any of the ScriptPubKeyMans can't.
  • ScriptPubKeyMan::GetReservedDestination is changed to return the destination so that future ScriptPubKeyMans can return destinations constructed in other ways. This is implemented for LegacyScriptPubKeyMan by moving key-to-destination code from CWallet to LegacyScriptPubKeyMan
  • In order for ScriptPubKeyMan to be generic and work with future ScriptPubKeyMans, ScriptPubKeyMan::ReturnDestination is changed to take a CTxDestination instead of a CPubKey. Since LegacyScriptPubKeyMan still deals with keys internally, a new map m_reserved_key_to_index is added in order to track the keypool indexes that have been reserved.
  • A bug is fixed in how the total keypool size is calculated as it was omitting set_pre_split_keypool which is a bug.

    Split from #17261

Depends on D7690

Backport of Core PR17373

Test Plan:

ninja check check-functional

Reviewers: #bitcoin_abc, deadalnix

Reviewed By: #bitcoin_abc, deadalnix

Differential Revision: https://reviews.bitcoinabc.org/D7697

Details

Provenance
fanquake <fanquake@gmail.com>Authored on Dec 6 2019, 18:37
majcostaCommitted on Oct 1 2020, 13:32
majcostaPushed on Oct 1 2020, 13:32
Reviewer
Restricted Project
Differential Revision
D7697: [backport#17373] wallet: Various fixes and cleanup to keypool handling in LegacyScriptPubKeyMan and CWallet
Parents
rABC61d4ae5b7551: [backport#17237 2/2] wallet: LearnRelatedScripts only if KeepDestination
Branches
Unknown
Tags
Unknown