Repository navigation
wallet: Add importdescriptors interface - #34861
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/34861. ReviewsSee the guideline and AI policy 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 typos and grammar issues:
2026-09-14 18:21:43 |
a3582a2 to
5e9dab4
Compare
Why can a GUI not use the RPC interface? |
Sorry, a GUI can. I ment Bitcoin Core GUI needs it because it doesn't use RPC. |
|
Concept ACK We'll eventually want a way to import descriptors in the GUI, and moving this code out of Let's update the PR description to make it clear this isn't an IPC change. Until #10102 |
|
Concept ACK Makes sense to move this into the wallet interface, but this does indeed have nothing to do with ipc for now. |
|
Updated the title and description to avoid confusion |
|
Thanks for the clarification, Concept ACK. |
|
Approach ACK |
5e9dab4 to
b88462d
Compare
|
Concept ACK, this refactor is a nice win for maintainability, and makes adding importdescriptors to the GUI and/or to an IPC interface or any other interface trivial. I could be mistaken as I haven't tried yet to make this change myself, but I think that the RPC code should consume the interface you are adding, because it deduplicates code and increases confidence that the interface added in this PR (which in the current branch is untested) works correctly since we reuse all of our functional tests on it. If that's not feasible, the interface commit should probably be held off until the PR that introduces its consumer in the GUI. |
That is not how RPCs access the wallet, and making RPCs access the wallet through this interface is a pretty significant change that is massively outside of the scope of this PR. It would also mean that a bunch of things use the interface, while other things access I think the layout of the commits could be changed to make this easier to review. In general, making a new function that is mostly a copy of another function that will end up replacing the other function makes review more difficult as it does not allow git to show reviewers where things are moved. It also runs the risk of things that are added to the original function not making it into the copy when the PR is rebased, although this is less likely to be an issue for this PR. Since the difference between the 2 functions is primarily in the data types, I would suggest having a first commit that separates |
|
Added a helper function to minimize the size of the main functions: This function cal also be used by other RPCs who rely on WalletErrorCodes. It avoid having duplicated switch cases around the codebase. |
|
Force pushed to apply some comments by Sjors and David.
Giving all this a prettier and cleaner RPC interface :) |
|
Force pushed to address some nits :) |
|
re-ACK d1036b8 |
|
ACK d1036b8 |
There was a problem hiding this comment.
ACK d1036b8
A few things I noticed, none of them blocking:
In 89becfe the range checks were also added to ImportDescriptor(), so all callers get them. Two checks are still only in the RPC: negative timestamps and the "*" label, so importDescriptors() accepts both. Could they also be checked in imports.cpp? The RPC check for the timestamp can stay, so the RPC still returns a top-level error.
nit: the title and message of f50d56b say ProcessDescriptorImport returns ImportDescriptorResult, but that type does not exist in that commit (or anywhere in the PR). The returned type is ImportResult. However, I prefer ImportDescriptorResult.
|
Can you rebase and take the nits? |
Timestamp 0 is allowed and it does not seem a reason to have a minimum timestamp > 0 other than some carried value from legacy wallet. Lowering simplifies importdescriptors because, before this change, if a timestamp 0 was set by the user it would be overwritten by the minimum timestamp, but error messages should still report timestamp 0. Negative timestamps are now invalid and throw.
ImportDescriptorRquest will replace the UniValue-based interface of ProcessDescriptorImport(), which will allow to extract the functionality to other interfaces such as the GUI, etc, in a subsequent commit.
…ptorImport Adds a new function ProcessUniValueDescriptor that translates from UniValue to ImportDescriptorRequest. Refactors ProcessDescriptorImport to work with ImportDescriptorRequest objects instead of UniValue. Refactors RPCMethod importdescriptors() to use ProcessUniValueDescriptor. The commit introduces a small behavior change to make label handling more consistent. Previously, an unset label on a descriptor that cannot have a label would eventually be converted to an empty string. However, if the user explicitly set the label to an empty string, the importdescriptors RPC call would fail because the descriptor does not support labels. This inconsistency does not make sense, since an empty string (or null) effectively means that no label was set. With this change, null labels and empty strings are treated as valid and are considered equivalent to having no label at all.
ImportError struct will substitute the UniValue based response of ProcessDescriptorImport in a subsequent commit. This will allow other interfaces such as the GUI to consume those function. Added an extra constructors that will be useful in following commits. Also add new error codes to the WalletError codes enum, this is necessary in order to propagate error codes to the new interfaces and to translate errors to the rpc wallet error codes.
Helper function to translate from WalletErrorCode to RPC error codes.
…orResult Make ProcessDescriptorImport return a ImportDescriptorResult object instead of a UniValue. This commit gets rid of a try-catch that generates a big diff of identation changes, it is recommended to review it with --ignore-space-change
…ocessDescriptorsImport Rename ProcessDescriptorImport() to ImportDescriptor(). ImportDescriptor() takes a single descriptor request and imports it into the wallet. Add ProcessDescriptorsImport() (descriptors in plural) to handle wallet locking and rescanning over a vector of ImportDescriptorRequest items. It is also in charge of collecting all responses of imports from ImportDescriptor. This allows a next commit to extract ImportDescriptor() and ProcessDescriptorsImport() out of the RPC code so they can be used by other future interfaces.
….cpp Extract ImportDescriptor() and ProcessDescriptorsImport() out of backup.cpp and move them into imports.cpp so other future interfaces can use them without needing to know about RPC code. The commit can be reviewed with the --color-moved=dimmed-zebra option for an easier review.
|
Rebased on top of master and addressed the pending nits :) |
Co-authored-by: w0xlt <[email protected]> ProcessUniValueDescriptor() checks for the descriptor range correctness, but since a future commit adds an interface to import descriptors, those checks must be extracted from RPC code. This commit adds a helper function to check ranges in descriptors and checks for the range inside ImportDescriptor(). ProcessUniValueDescriptor keeps also the check as other RPC calls other than importdescriptors also needs to check for ranges. This introduces a double check on the RPC path, but the cost of it is minimal and can be accepted.
|
🚧 At least one of the CI tasks failed. HintsTry to run the tests locally, according to the documentation. However, a CI failure may still
Leave a comment here, if you need help tracking down a confusing failure. |
|
re-ACK 2c249db |
| if ((high >> 31) != 0) { | ||
| return util::Unexpected<std::string>("End of range is too high"); | ||
| } | ||
| if (high >= low + 1000000) { |
There was a problem hiding this comment.
low + 1000000 can overflow before the low > high check below.
For example, a range of [INT64_MAX, 0] reaches this expression and invokes signed-integer overflow, which is undefined behavior. Previously, ParseRange() rejected low > high before performing this arithmetic.
Could the reversed-range check be moved above this one, followed by high - low >= 1000000? The subtraction is safe after establishing 0 <= low <= high.
It would also be useful to add {std::numeric_limits<int64_t>::max(), 0} to reject_invalid_descriptor_ranges.
A possible implementation would be:
if (low > high) {
return util::Unexpectedstd::string(
"Range specified as [begin,end] must not have begin after end");
}
if (high - low >= 1000000) {
return util::Unexpectedstd::string("Range is too large");
}
Wouldn't call this a blocker, just wanted to call it out.
There was a problem hiding this comment.
Thanks Rob 🔺
Unless maintainers ask me to fix this I will leave at is, because there is a PR already fixing overflows in descriptors ranges. See #35989.
And also because the user must intentionally trigger this.
If that PR gets closed I am happy to open a follow-up PR fixing all this overflows.
This PR adds an interface for importing descriptors.
The motivation behind this is that currently, importing descriptors is only possible via RPC. Bitcoin Core GUI doesn't use the RPC interface so it cannot offer descriptor import functionality, which is needed to support more complex wallet setups such as multisig.
This PR also adds a refactor by moving the
importdescriptorslogic from the RPC layer intoCWallet::ImportDescriptor, making it reusable by both the RPC and this new interface.The main changes are:
CWallet::ImportDescriptor()containing the core import logic, previously embedded in the RPCProcessDescriptorImportfunction.wallet::ImportDescriptorResult, a new result struct that carries success status, error message, warnings, and aFailureReasonenum. The RPC layer usesFailureReasonto map results back to the appropriate JSON-RPC error codes, keeping RPC concerns out ofCWallet.ProcessDescriptorImportinrpc/backup.cppto delegate toCWallet::ImportDescriptor.interfaces::Wallet::importDescriptors()as a new interface method, allowing the GUI to import descriptors without going through RPC.I have a GUI menu here: polespinasa#7 so it can be tested. I will open a PR against the main GUI repo, once this gets merged.