Currently fetching a normalized descriptor requires the wallet to be unlocked as it needs the private keys to derive the last hardened xpub. This is not very user friendly as normalized descriptors shouldn’t require and don’t involve the private keys except for derivation. We solve this problem by caching the last hardened xpub (which has to be derived at some point when generating the address pool).
However the last hardened xpub was not already being cached. We only cached the immediate parent xpub and derived child keys. For example, with a descriptor derivation path of /84'/0'/0'/0/*
, the parent xpub that is cached is m/84'/0'/0'/0
, and the child keys of m/84'/0'/0'/0/i
(note that child keys would not be cached in this case). This parent xpub is not suitable for the normalized descriptor form as we want the key at m/84'/0'/0'
. So this PR adds another field to DescriptorCache
to cache the last hardened xpub so that we can use them for normalized descriptors.
Since DescriptorCache
is changing, existing descriptor wallets need to be upgraded to use this new cache. The upgrade will occur in the background either at loading time (if the wallet is not encrypted) or at unlocking time in the same manner that UpgradeKeyMetadata
operates. It will use a new wallet flag WALLET_FLAG_LAST_HARDENED_XPUB_CACHED
to indicate whether the descriptor wallet has the last hardened xpub cache.
Lastly listdescriptors
will not require the wallet to be locked and getaddressinfo
’s parent_desc
will always be output (assuming the upgrade has occurred).