lightningnetwork / lnd

Lightning Network Daemon ⚡️
MIT License
7.65k stars 2.07k forks source link

[bug]: Walletbalance of default account is 0, after import of external xpub #8109

Closed feelancer21 closed 6 months ago

feelancer21 commented 11 months ago

Your environment

lnd 0.16.4 bitcond 25.0 (pruned)

Steps to reproduce

I imported an external xpub with

lncli wallet accounts import --address_type p2tr --master_key_fingerprint fingerprint xpub name

lncli walletbalance shows a balance of 0 for both accounts. But lncli listunspent is still listing the correct utxos

Roasbeef commented 11 months ago

We don't rescan on import yet, so that's working as expected.

feelancer21 commented 11 months ago

Yes, but I get a 0 for both accounts (default and the new one).

And I cannot sweep the utxos of the default account now

[lncli] rpc error: code = Unknown desc = insufficient input to create sweep tx: input_sum=0 BTC, output_sum=0.00000106 BTC

Edit: My bictoind backend is a pruned node.

guggero commented 11 months ago

I think you need to use the lncli walletbalance --acctoun=imported flag. By default walletbalance only shows the balance of the "default" account (which is the internal wallet).

ziggie1984 commented 11 months ago

I did a basic test(regtest):

2 nodes, importing the default p2tr xpub into the other node. Although the imported xpub had funds on it, they are not shown on the other node, even after a rescan. So there seems to be a problem recognizing these new addresses from the pubkey ? Will try to find the problem ...

guggero commented 11 months ago

When you say rescan, what type of rescan do you mean?

ziggie1984 commented 11 months ago

lnd --reset-wallet-transactions

guggero commented 11 months ago

lnd --reset-wallet-transactions

Hmm, okay. I would've expected that to pick up the imported accounts too. But who knows, maybe they are explicitly excluded for some reason (the wallet code needs a lot of work...).

feelancer21 commented 11 months ago

I think you need to use the lncli walletbalance --acctoun=imported flag. By default walletbalance only shows the balance of the "default" account (which is the internal wallet).

The problem is, that also my default account has a balance of 0 since the import.

    "total_balance": "0",
    "confirmed_balance": "0",
    "unconfirmed_balance": "0",
    "locked_balance": "0",
    "reserved_balance_anchor_chan": "100000",

Seems that the import of the external account has destroyed some information. Because it is not possible to send the existing utxos of the default account at the moment.

Maybe it is edge case, when the backend is a pruned bitcoind node.

I think I have to switch to a full node and start a rescan.

ziggie1984 commented 11 months ago

So tested with several scenarios, current master but even 16.04 works fine and shows the default wallet balance, although I have imported several xpubs. So could not reproduce the issue, especially you said that your lncli listunspent cmd worked perfectly fine, but the lncli walletbalance showed an amount of 0 (they use almost the same backend call). So not reproducible for now. Let us know if this happens again after your rescan.

guggero commented 6 months ago

Closing in favor of https://github.com/lightningnetwork/lnd/issues/8593.