lightningnetwork / lnd

Lightning Network Daemon ⚡️
MIT License
7.68k stars 2.08k forks source link

BTCPay user recovery window insufficient (no seed) #2912

Closed NicolasDorier closed 5 years ago

NicolasDorier commented 5 years ago

Initially opened on https://github.com/btcpayserver/btcpayserver-docker/issues/120

This user updated from a version before 0.5.2 to 0.5.2 and lost its balance.

His logs are here.

Please advice on the procedure on LND side so he can recover/rescan.

quoting @hakonamatata

I ran btcpay-update.sh command and now my wallet balance is 0!

Channels and channelbalance seems unaffected.

version of lnd
"version": "0.5.2-beta commit=basedon-v0.5.2-beta-3-dirty",

which operating system (uname -a on *Nix)
Linux BTCPayServerVM 4.15.0-1019-azure #19-Ubuntu SMP Thu Jul 26 19:54:21 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux

Steps to reproduce
I use https://github.com/btcpayserver/btcpayserver-docker

And just ran the update command, btcpay-update.sh
Roasbeef commented 5 years ago

Seems this was related to that whole situation related to BTCPay running with pruned mode although it isn't supported combined with the forced rescan? Is the user still running with a pruned node? If BTCPay still doesn't give users their seed on start up, then I'm not sure what we can do.

NicolasDorier commented 5 years ago

We can ask them to resync the whole chain and redo a rescan. They still have all their files. Though the logs don't show that it is a problem. The logs don't appear to complains about missing blocks though

How can you force rescan?

Roasbeef commented 5 years ago

If they don't have the seed, then they can't force one normally. Instead, they may need to use this tool on their database: https://github.com/btcsuite/btcwallet/tree/master/cmd/dropwtxmgr

NicolasDorier commented 5 years ago

Ping @hakonamatata you need to:

  1. If you use luna node, resize your bitcoin volume to have like 500GB
  2. btcpay-down.sh
  3. Remove opt-save-storage-s from BTCPAYGEN_ADDITIONAL_FRAGMENTS.
  4. . btcpay-setup.sh -i
  5. Wait it fully sync
  6. Install go and run this tool https://github.com/btcsuite/btcwallet/tree/master/cmd/dropwtxmgr

Alternatively, give your BTC to the #reckd fund.

NicolasDorier commented 5 years ago

@Roasbeef or is there a way he can recover the BIP32 tpriv so he can use another tool to rescan?

Perlover commented 5 years ago
6. Install go and run this tool  https://github.com/btcsuite/btcwallet/tree/master/cmd/dropwtxmgr

May be it will help too. I used the same commands for a rescanning (a compiling the dropwtxmgr and a running).

  1. To stop lnd before

  2. To run this (i didn't it run from Docker so i don't know other paths)

    go get -u github.com/btcsuite/btcwallet/cmd/dropwtxmgr
    cp $HOME/.lnd/data/chain/bitcoin/mainnet/wallet.db $HOME/wallet.db
    dropwtxmgr --db=$HOME/.lnd/data/chain/bitcoin/mainnet/wallet.db
    1. First command - a getting and a compiling from sources
    2. The Second one - a copying wallet as backup file
    3. A dropping UTXOs in wallet file
  3. To run the lnd again.

hakonamatata commented 5 years ago

Hi, thanks for taking the time to look into this issue.

Ping @hakonamatata you need to:

1. If you use luna node, resize your bitcoin volume to have like 500GB

2. btcpay-down.sh

3. Remove `opt-save-storage-s` from `BTCPAYGEN_ADDITIONAL_FRAGMENTS`.

4. `. btcpay-setup.sh -i`

5. Wait it fully sync

6. Install go and run this tool  https://github.com/btcsuite/btcwallet/tree/master/cmd/dropwtxmgr

Alternatively, give your BTC to the #reckd fund.

Here is the config I use on my BTCPay VM in Azure. I don't use opt-save-storage-s.

root@BTCPayServerVM:/etc/profile.d# cat btcpay-env.sh

export BTCPAYGEN_OLD_PREGEN="false"
export BTCPAYGEN_CRYPTO1="btc"
export BTCPAYGEN_CRYPTO2=""
export BTCPAYGEN_CRYPTO3=""
export BTCPAYGEN_CRYPTO4=""
export BTCPAYGEN_CRYPTO5=""
export BTCPAYGEN_CRYPTO6=""
export BTCPAYGEN_CRYPTO7=""
export BTCPAYGEN_CRYPTO8=""
export BTCPAYGEN_CRYPTO9=""
export BTCPAYGEN_LIGHTNING="lnd"
export BTCPAYGEN_REVERSEPROXY="nginx"
export BTCPAYGEN_ADDITIONAL_FRAGMENTS="opt-lnd-autopilot"
export BTCPAY_DOCKER_COMPOSE="/var/lib/waagent/custom-script/download/0/btcpayserver-docker/Generated/docker-compose.generated.yml"
export BTCPAY_BASE_DIRECTORY="/var/lib/waagent/custom-script/download/0"
export BTCPAY_ENV_FILE="/var/lib/waagent/custom-script/download/0/.env"
export BTCPAY_HOST_SSHKEYFILE=""
if cat $BTCPAY_ENV_FILE &> /dev/null; then
export BTCPAY_HOST="$(cat $BTCPAY_ENV_FILE | sed -n 's/^BTCPAY_HOST=\(.*\)$/\1/p')"
export LETSENCRYPT_EMAIL="$(cat $BTCPAY_ENV_FILE | sed -n 's/^LETSENCRYPT_EMAIL=\(.*\)$/\1/p')"
export NBITCOIN_NETWORK="$(cat $BTCPAY_ENV_FILE | sed -n 's/^NBITCOIN_NETWORK=\(.*\)$/\1/p')"
export LIGHTNING_ALIAS="$(cat $BTCPAY_ENV_FILE | sed -n 's/^LIGHTNING_ALIAS=\(.*\)$/\1/p')"
export ACME_CA_URI="$(cat $BTCPAY_ENV_FILE | sed -n 's/^ACME_CA_URI=\(.*\)$/\1/p')"
export BTCPAY_SSHKEYFILE="$(cat $BTCPAY_ENV_FILE | sed -n 's/^BTCPAY_SSHKEYFILE=\(.*\)$/\1/p')"
export BTCPAY_SSHTRUSTEDFINGERPRINTS="$(cat $BTCPAY_ENV_FILE | sed -n 's/^BTCPAY_SSHTRUSTEDFINGERPRINTS=\(.*\)$/\1/p')"
fi

export COMPOSE_HTTP_TIMEOUT="180"
NicolasDorier commented 5 years ago

@hakonamatata if your node was not pruned then the issue is something else.

You can try to do what @Perlover tells you.

The wallet.db is at /var/lib/docker/volumes/generated_lnd_bitcoin_datadir/_data/data/chain/bitcoin/mainnet/wallet.db.

That said, I am wondering if the problem is not elsewhere, if your node was not pruned, then the rescan should have worked, and from your logs, it seems to have worked.

NicolasDorier commented 5 years ago

Summoning @Roasbeef here, as it seems the user did not run a pruned node.

Is there a way to expose the xpub? As I can give the user a way to scan it to see whether there is indeed money or not in his wallet.

wpaulino commented 5 years ago

@hakonamatata have you confirmed whether you should have a non-zero balance? The wallet had some bugs where it'd cause your balance to be falsely inflated, so it's possible you were just seeing that.

hakonamatata commented 5 years ago

My balance is no longer 0, it was for several days. Not sure exactly what happened.

wpaulino commented 5 years ago

From the logs I saw you had some timed out HTLCs that you swept on-chain, so that's probably it. What concerns me is that the rescan succeeded, but you still had a 0 balance. Either two things happened: there's a bug in the rescan logic (which seems unlikely given how many people have used it, but still possible) or you actually had a 0 balance.