mirror of
https://github.com/bitcoin-core/gui-qml.git
synced 2026-12-02 07:54:42 +00:00
View-only wallet import assumes native SegWit and skips the rescan #1058
Labels
No labels
Android
Bug
Build system
Design suggestion
Doc
Needs design review
Needs rebase
Stage
UX
Up for grabs
Upstream
Wallet
duplicate
enhancement
good first issue
question
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
bitcoin-core/gui-qml#1058
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Add wallet > View-only only takes a plain xpub, and the wallet it creates often can't see the funds it should watch.
The key is always wrapped as native SegWit, with the current time as the birth time:
github.com/bitcoin-core/gui-qml@6cdad53440/qml/walletqmlcontroller.cpp (L636-L639)github.com/bitcoin-core/gui-qml@6cdad53440/qml/walletqmlcontroller.cpp (L661-L663)Problems
wpkh(...). The wallet is created with no error and stays empty.ypub/zpub(upub/vpubon test networks), which many wallets export, fail with "Enter a valid extended public key (xpub)".Steps to reproduce (regtest)
hot, then pay one of its SegWit addresses:hot'slistdescriptors, copy thetpubof the active receivetr(...)descriptor and of the active receivewpkh(...)descriptor.tpub.bech32maddress ofhot, 1 BTC to a newbech32address ofhot, and mine a block.vpubinto the View-only form.Result
tpubwpkh(...)descriptors, 0 BTC, 0 transactions, even after the 2 BTC Taproot paymenttpubvpubExpected
The view-only wallet sees the same coins and history as the wallet it watches.
Suggestion
<0;1>form, and take the address type from each descriptor.ypub/upubtosh(wpkh()),zpub/vpubtowpkh()).xpub, ask for the address type instead of assuming SegWit.One more consequence of the missing rescan, at
eed1f426fcb6with Core44901d8f64cb: Receive in the new view-only wallet hands out an address the key has already used.The import adds both descriptors with the current time as the birth time and the next index at 0 (walletqmlcontroller.cpp#L671-L676). The wallet knows none of the key's history, so nothing tells Receive that the first address is used.
Steps (regtest)
src, receive 0.5 BTC on its first SegWit receive address and confirm it. (I also spent it again, so the balance is back to 0.)tpubofsrc's active receivewpkh(...)descriptor.Result
The address offered is
src's first address, the one paid in step 1, and the request is saved on it: Awaiting payment, with a QR code for that address. The payer is given an address that already has history on chain. The wallet lists no transactions at this point, so nothing on screen marks the address as used.Watching a key that already has history is the usual reason to import one, so this is the ordinary path. I only observed the first address. By source, later requests continue from the next index, which such a key has usually used as well.
Control: in an ordinary wallet I could not get a request onto a used address.
If the wallet is rescanned afterwards
This is a narrower case, because it needs the request to exist before the rescan. Running
rescanblockchainin Settings > RPC console turned the request from step 3 into Payment received, with 0.50000000 BTC as the headline amount, Requested amount 0.25000000 and no QR code. Activity links the 0.5 BTC transaction from step 1 to the request. Nobody paid this request: that payment arrived and left before the wallet was imported.Any wallet transaction paying an address marks every saved request on that address as paid, whatever the transaction's age (walletqmlmodel.cpp#L1694-L1700). The same steps with a key that has no history leave the request at Awaiting payment, and a restart without the rescan changes nothing. The amount that does not match the request is a cue, and on a real chain the linked transaction would also be older than the request.
Core's own
importdescriptorsRPC avoids this by itself: on a separate regtest chain where the key's first two receive addresses had been used, importing its receive descriptor with"timestamp": "now"rescanned, found that history, andgetnewaddressreturned an unused address. (A "now" import still rescans the last two hours, which covers a fresh regtest chain; on a real chain it would need the key's birth date.) So the rescan suggested above would avoid both problems, as long as it finishes before Receive offers an address.Tested on macOS / Qt 6.9, isolated regtest, offscreen and native, one run each. The wallet name, key, amount and message were set into their fields directly. The console command was typed and submitted through the console's Enter handler. Every other step was a click through the test bridge. The
importdescriptorscomparison was run once withbitcoin-cliand no GUI.