-
Notifications
You must be signed in to change notification settings - Fork 38.6k
wallet: addhdkey RPC to add just keys to wallets via new unused(KEY) descriptor
#29136
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
|
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. Code Coverage & BenchmarksFor details see: https://corecheck.dev/bitcoin/bitcoin/pulls/29136. ReviewsSee the guideline for information on the review process.
If your review is incorrectly listed, please copy-paste ConflictsReviewers, this pull request conflicts with the following ones:
If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first. LLM Linter (✨ experimental)Possible places where named args for integral literals may be used (e.g.
2026-01-05 |
|
This is great, amazed you could implement this so quickly! I was thinking about the void(KEY) idea more today, and think it would be good to make 3 tweaks: 1 - rename "void(KEY)" to "unused(KEY)" I think these changes would help make these descriptors easier to understand and also enhance backwards compatibility, because IIUC wallets containing unknown descriptor types can't be opened by older software. Also keeping redundant descriptors in the wallet that were only temporarily needed is confusing. If making these tweaks isn't possible or is not a good idea. I still think probably we should rename void(KEY) to data(KEY) or something like that. I think while "void" makes a certain amount of sense as programming jargon, it's not really a familiar term and doesn't describe the purpose of these descriptors, which is just to hold an inert piece of data, and not be used for generating or matching scriptpubkeys. I also have a number of ideas to improve the RPC interface for generating keys and descriptors, and will try to post them soon. (EDIT: now posted #29130 (comment)). But this seems like a very good start and very functional. |
5338f09 to
18c2d9a
Compare
18c2d9a to
3e6a00d
Compare
Done these. I've also added a further restriction that unused() cannot be import to a wallet without private keys. It isn't useful in such wallets so I think it makes sense to disallow their import.
Still working and thinking on this. However we've generally held to the policy of not deleting any records from the wallet since that could result in private keys being accidentally deleted. The only exception to that was adding encryption. |
42f1fc8 to
22c8984
Compare
Oh, I didn't know that but it makes sense. One approach you could take would just be to delete the descriptor from memory without actually deleting it from the database, and ignore it the next time the wallet is loaded. But a drawback of this would be that once Another approach that might be acceptable could be to add a Or maybe just decide in this case that it is ok to delete a record after verifying all the information it contains is present in other records. Would also want to think about it more, though. |
8ee55e4 to
439734e
Compare
|
re-ACK 439734e (you can drop "Based on" from the PR description) |
rkrux
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ACK 439734e
Thanks for incorporating suggestions; TIL about the for-else pattern in Python.
git range-diff 6100108...439734e| if len(x["descriptors"]) == 1 and x["descriptors"][0]["desc"].startswith("unused("): | ||
| break | ||
| else: | ||
| assert False, "Did not find HD key with no descriptors" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In 71b4900 "wallet: Add addhdkey RPC"
Nit if retouched:
- assert False, "Did not find HD key with no descriptors"
+ assert False, "Did not find any HD key with unused descriptor" | for (auto& pubkey : keys) { | ||
| if (pubkey->IsRange()) { | ||
| error = "unused(): key cannot be ranged"; | ||
| return {}; | ||
| } | ||
| ret.emplace_back(std::make_unique<UnusedDescriptor>(std::move(pubkey))); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah right! Fine to keep it as-is in the parsing flow.
Via addhdkey RPC though, I don't suppose there is a way to get multipath keys added? (as only one hdkey can be generated or imported)
|
Needs rebase. |
Doesn't seem like it does? |
|
I guess not. Just tried a merge with current master, which builds fine and tests pass. |
439734e to
6928cad
Compare
|
re-utACK 6928cad Just a rebase. |
rkrux
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
re-ACK 6928cad
The range diff looks fine to me - there are few function moving changes here and there that are due to rebase I suppose.
git range-diff 439734e...6928cad
fjahr
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Concept ACK
Looks already pretty good to me.
unused() descriptors do not have scriptPubKeys. Instead, the wallet uses them to store keys without having any scripts to watch for.
6928cad to
23f5529
Compare
It is sometimes useful for the wallet to have keys that it can sign with but are not (initially) involved in any scripts, e.g. for setting up a multisig. Ryanofsky suggested A
unused(KEY)descriptor which allows for a key to be specified, but produces no scripts. These can be imported into the wallet, and subsequently retrieved withgethdkeys. Additionally,listdescriptorswill output these descriptors so that they can be easily backed up.In order to make it easier for people to add HD keys to their wallet, and to generate a new one if they want to rotate their descriptors, an
addhdkeyRPC is also added. Without arguments, it will generate a new HD key and add it to the wallet via aunused(KEY)descriptor. If provided a private key, it will construct the descriptor and add it to the wallet.See also: #26728 (comment)
Based on #29130 as
gethdkeysis useful for testing this.