Repository navigation
wallet: Add exportwatchonlywallet RPC to export a watchonly version of a wallet - #32489
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/32489. 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. |
dc39a64 to
30ebc97
Compare
|
🚧 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. |
211dbe3 to
9fd93da
Compare
9fd93da to
4ef9315
Compare
4ef9315 to
def9594
Compare
|
Concept ACK This might also be useful in a multisig airgapped scenario (where two private keys never go near each other). E.g. create a 2-of-2 MuSig2 wallet on your offline machine, with one hot key held by Bitcoin Core and the other a hardware wallet. Export the watch-only wallet and put it on the online machine. You can then use the hardware wallet on either the online or offline machine to co-sign. Though for that to work, the |
def9594 to
d41059b
Compare
Sjors
left a comment
There was a problem hiding this comment.
utACK eed2ac7161ecc60982a3f3f304ce93b0b58fc219
Left a bunch of comments, but I think they can wait for a followup.
| [offline]$ ./build/bin/bitcoin-cli -signet -rpcwallet="offline_wallet" listdescriptors \ | ||
| | jq -r '.descriptors' \ | ||
| >> /path/to/descriptors.json | ||
| [offline]$ ./build/bin/bitcoin-cli -signet -rpcwallet="offline_wallet" -named exportwatchonlywallet \ |
There was a problem hiding this comment.
In eed2ac7161ecc60982a3f3f304ce93b0b58fc219 doc: update offline-signing-tutorial to use exportwatchonlywallet rpc nit: could use bitcoin rpc and drop -named.
There was a problem hiding this comment.
I prefer to keep it to explicitly indicate the argument being set.
| return m_wallet_descriptor.descriptor->IsSingleType() && | ||
| m_wallet_descriptor.descriptor->IsRange() && | ||
| (HavePrivateKeys() || m_wallet_descriptor.next_index < m_wallet_descriptor.range_end); | ||
| (HavePrivateKeys() || m_wallet_descriptor.next_index < m_wallet_descriptor.range_end || m_wallet_descriptor.descriptor->CanSelfExpand()); |
There was a problem hiding this comment.
In 336042e wallet: Use Descriptor::CanSelfExpand() in CanGetAddresses(): could add a direct test, in scriptpubkeyman_tests.cpp:
BOOST_AUTO_TEST_CASE(desc_spkm_can_get_addresses_self_expand)
{
// A watch-only, unhardened, ranged descriptor can always
// derive further addresses on its own. CanGetAddresses() must therefore
// report true even when the cache is exhausted (next_index == range_end)
// and no private keys are available: self-expansion is enough.
CWallet keystore(m_node.chain.get(), "", CreateMockableWalletDatabase());
keystore.SetWalletFlag(WALLET_FLAG_DESCRIPTORS);
CExtKey extkey;
extkey.SetSeed(std::array<std::byte, 32>{});
FlatSigningProvider keys;
std::string error;
auto descs = Parse("wpkh(" + EncodeExtPubKey(extkey.Neuter()) + "/*)", keys, error, /*require_checksum=*/false);
BOOST_CHECK(!descs.empty());
// Collapsed range (range_end == next_index == 0): nothing is cached.
WalletDescriptor w_desc(std::move(descs.at(0)), /*creation_time=*/1, /*range_start=*/0, /*range_end=*/0, /*next_index=*/0);
// keypool_size=0 so the import does not top up and extend range_end.
auto spkm = DescriptorScriptPubKeyMan::CreateFromImport(keystore, w_desc, /*keypool_size=*/0, keys);
BOOST_CHECK(!spkm->HavePrivateKeys());
BOOST_CHECK(spkm->CanGetAddresses());
}There was a problem hiding this comment.
I don't think this is necessary, there are functional test which cover this.
There was a problem hiding this comment.
It does, but it's in a later commit and quite indirect.
| return m_wallet_descriptor.descriptor->IsSingleType() && | ||
| m_wallet_descriptor.descriptor->IsRange() && | ||
| (HavePrivateKeys() || m_wallet_descriptor.next_index < m_wallet_descriptor.range_end); | ||
| (HavePrivateKeys() || m_wallet_descriptor.next_index < m_wallet_descriptor.range_end || m_wallet_descriptor.descriptor->CanSelfExpand()); |
There was a problem hiding this comment.
in 336042e wallet: Use Descriptor::CanSelfExpand() in CanGetAddresses()
Just a question (maybe a stupid one 😅) the fact that next_index < range_end isn't enough to know if it can be expanded?
I guess the question in other words would be like: if it cannot be expanded will range_end != 0 in any moment?
There was a problem hiding this comment.
When next_index < range_end, we have enough information, either in the descriptor or its cache, to continue to produce scripts for the descriptor up to at least range_end. If the descriptor uses unhardened derivation, once we get to next_index == range_end, we are still able to expand the descriptor because unhardened derivation does not require private keys. However, if the descriptor does use hardened derivation, it is no longer possible to make any scripts past range_end because private keys are required.
|
wops forgot my main review comment ACK eed2ac7161ecc60982a3f3f304ce93b0b58fc219 Didn't test this time, but I did in my previous review when writing the documentation update. |
|
@achow101 do you want to address the review here, or in a follow up? |
w0xlt
left a comment
There was a problem hiding this comment.
utACK eed2ac7161ecc60982a3f3f304ce93b0b58fc219
CanSelfExpand() reports whether a descriptor can be expanded without needing any caches or private keys to be provided by the caller of Expand().
If a descriptor does not need any caches or private keys in order to expand, then CanGetAddresses() should return true for that descriptor.
If a new WalletDescriptor is provided to us with a cache, write the cache to disk as well.
When listdescriptors retrieves the descriptors from the wallet, instead of having this logic in the RPC, move it into CWallet itself. This will enable other functions to get the descriptors in an exportable form.
I think the problem is that I have no idea how I think unlocking the file before |
ExportWatchOnly produces a watchonly wallet file from a CWallet. This can be restored onto another instance of Bitcoin Core to allow that instance to watch the same descriptors, and also have all of the same initial address book and transactions.
|
Dropped the file lock, I think it's unnecessary as long as we only remove the file on failure. |
|
lgtm ACK a15bdc0 |
pablomartin4btc
left a comment
There was a problem hiding this comment.
re-ACK a15bdc0
Since my last review: addressed feedback from @Sjors and @polespinasa plus dropping the file lock from fs::path& destination in ExportWatchOnlyWallet().
Currently, if a user wants to use an airgapped setup, they need to manually create the watchonly wallet that will live on the online node by importing the public descriptors. This PR introduces
exportwatchonlywalletwhich will create a wallet file with the public descriptors to avoid exposing the specific internals to the user. Additionally, this RPC will copy any existing labels, transactions, and wallet flags. This ensures that the exported watchonly wallet is almost entirely a copy of the original wallet but without private keys.