lightninglabs / chantools

A loose collection of tools all somehow related to lnd and Lightning Network channels.
MIT License
222 stars 32 forks source link

Feature Request: Force close from previous state #149

Closed brh28 closed 2 months ago

brh28 commented 2 months ago

I have a node that was deleted without a backup and without a seed phrase. There's one channel on that node that I have control of the peer. What I'd like to do is broadcast a previous commitment transaction from the active node. However, the forceclose command only lets you broadcast the current state.

Whether by adding an index param to the forceclose command or by some other method, is there a way of broadcasting a previous commit state from an LND node?

guggero commented 2 months ago

I've hacked this together https://github.com/lightninglabs/chantools/pull/150 quite quickly (haven't had time to properly test it yet). Will continue later today, but if you're adventurous, you can already give it a try.

guggero commented 2 months ago

Maybe don't use the --publish flag just yet to make sure it's picking the right update number and the balance is where it should be?

brh28 commented 2 months ago

Awesome, thank you. I'll play around with this today in a local regtest environment and report back any findings or questions.

To your knowledge, is there any risk of a node broadcasting a justice transaction against its own force close? Worst case scenario is I accidentally sweep funds to the side of the channel I don't have control of.

guggero commented 2 months ago

Cool. I hope the close TX that you need is still around in the new revocation database format... Just in case, don't update the running node to a new version just yet.

You said the node was fully deleted, right? So nothing running of it anymore? The only risk is if you used a watchtower with the deleted node. Then the watchtower will sweep the funds to an address controlled by the deleted node...

brh28 commented 2 months ago

Tested this locally on a regtest network (via Polar):

Command

chantools forceclose \
    --walletdb polar/july22/wallet.db \
    --channeldb polar/july22/channel.db \
    --singlechannel 6c046045443cbf11c00c3a79cc82b9d95eb4bc2479babb2657f579a24663d5ea:1 
    --updatenum 0

Output:

Error: commit at height 0 not available in channel DB

(I also tried a few other indexes with the same corresponding results)

Are there any usage issues you see? Or troubleshooting tips?

guggero commented 2 months ago

Hmm, that's what I was afraid of. A couple of versions ago (~ lnd 0.15) there was a database migration that freed up a lot of space from the channel state. I think those commitment transactions were part of that. Because for issuing retribution if your peer breaches, we don't need the full commitment TX, just the TXID and some keys. So I think that's why the data was removed...

Did you ever run with --db.prune-revocation on the still running node? If not, then maybe (just maybe) you're in luck and the data you need is still there... If not, I think the only option you have is to close at the current state and just get the current local balance...

brh28 commented 2 months ago

The test I ran above was on a newly created regtest node running locally with version lnd:0.17.4-beta. I look into whether the target node on mainnet has ever run --db.prune-revocation and will test the forceclose command against it.

Before doing so, I just want to confirm that no transaction (or any other effect) will be broadcast without the --publish flag. Is that correct?

guggero commented 2 months ago

Correct, as long as you don't specify the --publish, no request (GET or POST) or other data will leave the computer you're running the command on.

guggero commented 2 months ago

This isn't possible with the way commitment updates are stored in the channel DB currently...

brh28 commented 2 months ago

Thanks for looking into this @guggero