Improves the descriptor cache by changing it from a std::vector<unsigned char>
to a newly introduced DescriptorCache
class. Instead of serializing pubkeys and whatever else we would want to cache in a way that may not be backwards compatible, we instead create a DescriptorCache
object and populate it. This object contains only an xpub cache. Since the only PubkeyProvider
that used the cache is the BIP32PubkeyProvider
we just have it store the xpubs instead of the pubkeys. This allows us to have both the parent xpub and the child xpubs in the same container. The map is keyed by KeyOriginInfo
.
Sine we are caching CExtPubKey
s in DescriptorCache
, BIP32PubKeyProviders
can use the cached parent xpubs to derive the children if unhardened derivation is used in the last step. This also means that we can still derive the keys for a BIP32PubkeyProvider
that has hardened derivation steps. When combined with descriptor wallets, this should allow us to be able to import a descriptor with an xprv
and hardened steps and still be able to derive from it. In that sense, this is an alternative to #18163
To test that this works, the tests have been updated to do an additional Expand
at the i + 1
position. This expansion is not cached. We then do an ExpandFromCache
at i + 1
and use the cache that was produced by the expansion at i
. This way, we won’t have the child xpubs for i + 1
but we will have the parent xpubs. So this checks whether the parent xpubs are being stored and can be used to derive the child keys. Descriptors that have a hardened last step are skipped for this part of the test because that will always require private keys.