Support For Arbitrary Number (1+) of Keychains#318
Support For Arbitrary Number (1+) of Keychains#318thunderbiscuit wants to merge 14 commits intobitcoindevkit:masterfrom
Conversation
7059451 to
0df1a2a
Compare
|
The next few commits:
|
524d4df to
6c50f00
Compare
There was a problem hiding this comment.
Quick review on 6c50f00: given your commit message I thought you were adding the Wallet::new constructor here, but the commit only contains the addition of the KeyRing to the Wallet type. Mind you this might be enough for this commit. Feel free to add a new commit with the constructor, or add it to this commit; whatever you think works best.
Also note that fa984e6 and 6c50f00 don't compile because of
impl AsRef<bdk_chain::tx_graph::TxGraph<ConfirmationBlockTime>> for Wallet {
fn as_ref(&self) -> &bdk_chain::tx_graph::TxGraph<ConfirmationBlockTime> {
self.keychain_tx_graph.graph()
}
}on line 2638 of wallet/mod.rs. You could comment it out with the rest to ensure everything builds.
wallet/src/wallet/changeset.rs
Outdated
| pub keyring: keyring::changeset::ChangeSet<K>, | ||
| /// Changes to the [`LocalChain`](local_chain::LocalChain). | ||
| pub local_chain: local_chain::ChangeSet, | ||
| pub chain: local_chain::ChangeSet, |
There was a problem hiding this comment.
I'm not sure if the renaming of this field is intentional and I don't have an opinion on whether it's a good idea or not yet, but it probably belongs in a different PR.
There was a problem hiding this comment.
I did the rename since the corresponding field in Wallet is so. reverted the rename in 588121b.
7c976e1 to
588121b
Compare
|
I am so sorry 😢 . I completely messed dividing the commits into two. Things should be fixed now! |
|
This one now needs a big ol' rebase @110CodingP. |
dfdcd83 to
4a3486e
Compare
|
Wow! this one was HUGE! For the first few commits I did something like |
|
Adding an example like this fails: // Simple KeyRing, allowing us to build a standard 2-descriptor wallet.
let external_descriptor: &str = "tr(tpubD6NzVbkrYhZ4WyC5VZLuSJQ14uwfUbus7oAFurAFkZA5N3groeQqtW65m8pG1TT1arPpfWu9RbBsc5rSBncrX2d84BAwJJHQfaRjnMCQwuT/86h/1h/0h/0/*)";
let internal_descriptor: &str = "tr(tpubD6NzVbkrYhZ4WyC5VZLuSJQ14uwfUbus7oAFurAFkZA5N3groeQqtW65m8pG1TT1arPpfWu9RbBsc5rSBncrX2d84BAwJJHQfaRjnMCQwuT/86h/1h/0h/1/*)";
let mut keyring: KeyRing<KeychainKind> = KeyRing::new(Network::Regtest, KeychainKind::External, external_descriptor);
keyring.add_descriptor(KeychainKind::Internal, internal_descriptor, false);
let mut wallet = Wallet::new(keyring);With a stacktrace containing: thread 'main' panicked at /Users/user/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/miniscript-12.3.5/src/descriptor/key.rs:687:14:
The key should not contain any wildcards at this pointAfter a bit of poking around I found that this is coming from the descriptor_id() method called inside insert_descriptor(): pub fn insert_descriptor(
&mut self,
keychain: K,
descriptor: Descriptor<DescriptorPublicKey>,
) -> Result<bool, InsertDescriptorError<K>> {
let did = descriptor.descriptor_id();I don't have time to finish the investigation today, but just pointing it out. I'm not sure yet why this worked well in the multi-keychain-wallet crate and not here, nor why the code for the constructor is so different than the other previous constructors like |
|
This almost scared me for a moment 😅 ! Using descriptors with unhardened paths seems to work. |
|
Total facepalm. Sorry @110CodingP! Ok so I simplified the example a little bit just to keep a really neat version of how to build a wallet as close as you can from the 2.0 approach. |
4403cdb to
16d6f8c
Compare
af0e9eb to
4177147
Compare
Completes first 2 of the Todos? |
for e33e007 : Also ig |
|
Also is |
57ba434 to
ba0a282
Compare
|
Thanks for providing design feedback @evanlinjin! Lots of food for thoughts. I'll bring those up at the next dev call(s), and maybe with some of our users I know are intending to use the multi-keychain feature. Here are some of my early thoughts on this: Default Keychains
All of this to say I am cautiously open to removing the default keychain from this PR at the moment, barring any veto from other team members or things I haven't thought of. Wallet/MultiKeychainWalletOk this is an interesting one... thanks for laying it out this way I don't think I had understood you correctly when you first spoke of this a few months back on a dev call. I see the idea behind the layers. At first glance however, this to me feels like more maintainership burden than is worth (because the 2 keychain wallet and the multi keychain wallet are so similar), but this is just a gut feeling, and of course I'm not the one who bears this burden the most. Will discuss over the next dev calls. We can lay down the new code that allows the |
ba0a282 to
5ce40ec
Compare
30de2ec to
db47943
Compare
115060d to
916bc1b
Compare
bdbad0b to
3d6a95a
Compare
3fe0ed5 to
5fb3a4a
Compare
5fb3a4a to
3fe0ed5
Compare
84adb7b to
e3ac74d
Compare
Added #![allow(unused)] to circumvent clippy errors. Removed policy module and related code as policy is anyway being phased out in 3.0. Co-authored-by: thunderbiscuit <thunderbiscuit@protonmail.com> Co-authored-by: valued mammal <valuedmammal@protonmail.com>
Added `keyring::ChangeSet`. The `add_descriptor` function returns a `KeyRing::Changeset` since this would eventually be required when we introducing APIs to add descriptors to `Wallet.keyring`. Also implemented `FromSql` and `ToSql` for `KeychainKind`. Also modified `DescriptorError` and added `KeyRingError` since information of whether a keychain/desc is already assigned should be with the wallet and thus belongs to its error types. Co-authored-by: thunderbiscuit <thunderbiscuit@protonmail.com> Co-authored-by: valued mammal <valuedmammal@protonmail.com>
Modified the `Wallet::ChangeSet` accordingly. Modified AddressInfo, add reveal_next_address Also added default version for address APIs. Modified Update to take in a generic Also modified `balance` method to incorporate `CanonicalView` and a more flexible `trust_predicate` which fixes incorrect trusted balance calculation by the `Wallet`. Modified `CreateParams` to incorporate the changes. Modified `persist_test_utils` to incorporate the new `Wallet`. Note: `persist_keychains` and `persist_keychain` are two separate tests keeping in mind that some users may not use > 1 keychain. Among all tests only `persist_keychains` assumes multiple keychains. Co-authored-by: thunderbiscuit <thunderbiscuit@protonmail.com> Co-authored-by: valued mammal <valuedmammal@protonmail.com>
Also fixed original examples. Co-authored-by: codingp110 <codingp110@gmail.com> Co-authored-by: valued mammal <valuedmammal@protonmail.com>
Co-authored-by: codingp110 <codingp110@gmail.com> Co-authored-by: valued mammal <valuedmammal@protonmail.com>
Description
This PR allows the
Wallettype to track any number of keychains. It is a breaking change.Related Issues: #188, #227
Related PRs: #230, #226
Exploratory Crate: multi-keychain-wallet
Follow along the todos and PR development on this HackMD file.
Commits
Walletdependent code.KeyRingand related types.Walletto levergage theKeyRing.Todos
Search for the following pattern to find Todos in the codebase:
// TODO PR #318: We should fix this because...Changelog notice
TODO