forked from bitcoin-core/gui
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit 7f8176a
committed
Merge #18204: descriptors: improve descriptor cache and cache xpubs
09e2507 Cache parent xpub inside of BIP32PubkeyProvider (Andrew Chow)
deb791c Only cache xpubs that have a hardened last step (Andrew Chow)
f76733e Cache the immediate derivation parent xpub (Andrew Chow)
58f54b6 Add DescriptorCache* read_cache and DescriptorCache* write_cache to Expand and GetPubKey (Andrew Chow)
66c2cad Rename BIP32PubkeyProvider.m_extkey to m_root_extkey (Andrew Chow)
df55d44 Track the index of the key expression in PubkeyProvider (Andrew Chow)
474ea3b Introduce DescriptorCache struct which caches xpubs (Andrew Chow)
Pull request description:
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.
ACKs for top commit:
instagibbs:
code review re-re-ACK bitcoin/bitcoin@09e2507
Sjors:
re-ACK 09e2507
Tree-SHA512: 95c8d0092274cdf115ce39f6d49dec767679abf3758d5b9e418afc308deca9dc6f67167980195bcc036cd9c09890bbbb39ec1dacffbfacdc03efd72a7e23b276File tree
Expand file treeCollapse file tree
3 files changed
+285
-91
lines changedFilter options
- src
- script
- test
Expand file treeCollapse file tree
3 files changed
+285
-91
lines changed
0 commit comments