getAlby / hub

Alby Hub - Your own lightning node connected to every app. Run anywhere. Become self-sovereign.
https://albyhub.com
Apache License 2.0
105 stars 21 forks source link

Enable closing all LDK channels using SCBs #53

Open rolznz opened 5 months ago

rolznz commented 5 months ago

In a worst case scenario where a user deletes their hub and only has a backup, it would be great for them to recover funds from their open channels by requesting the counterparty to close them. Since the user does not have the channel state backed up (it needs to be backed up after every payment, currently we only do backups when the user opens a new channel)

In https://github.com/getAlby/hub/pull/693 we implemented all the restoration code, except we'd like to instead move it into a small isolated console app built specifically for this purpose, so that we do not need to maintain it in Alby Hub.

How the static channel backups work: when a new channel is opened we save a channel backup locally and also save an encrypted version to the Alby Account if the user has connected their Alby Account. But for testing this feature, we can simply use the local static backup file that is saved as this is not encrypted.

The app should be written in Rust and initialize a LDK node (using LDK-node) and accept a seed entered/pasted in, as well as a static channels backup JSON file (or paste the JSON content as text). It should restore the monitors just as the above PR does, and then start the node and force close all the channels before running the sync and continue as normal.

It should periodically check the onchain balance and report it to the user, and also show pending onchain balances. (see https://github.com/getAlby/hub/blob/master/lnclient/ldk/ldk.go#L1024).

Once there are no more pending balances from channel closures, the user should be able to exit the program. They can then open Sparrow wallet with their seed phrase to send the funds onchain, or import their seed into Alby Hub (note: this is currently an issue because by default we only watch the first onchain address and the user would need to generate more to see their funds).

To generate the backup, start Alby Hub with Mutinynet configuration (see the README), then use the mutinynet faucet to topup your node and open an outbound channel to the faucet (it's the default option when going to the "increase spending balance" option). Ideally after the channel becomes active, you should do one outgoing payment (You can send some sats to the Faucet lightning address, also listed in the faucet which you can pay from the Alby Hub wallet page). This will ensure that the channel SCB is out of date (but can still be used to request the channels to be force closed and recover the funds).

Wait for the channel to open (3 confirmations) and you should see a non-empty SCB json file saved to WORK_DIR/ldk/static_channel_backups. Go to settings -> backup to write down your seed phrase.

Once the basic restoration is working, we could improve the tool to also support accepting the Alby encrypted backups (requires the user's passphrase to decrypt as the encryption key is the user's seed encrypted by their passphrase)

This Rust app should be executable on Linux, Windows and Mac.

Finally, we can then remove the changes in Alby Hub to decrease the complexity of the LDK implementation.

bumi commented 5 months ago

Maybe this can be a different backup/recover app? (to keep this one small and simple)

rolznz commented 3 months ago

From @reneaaron

Let's say we add this option in the advanced setup and a user would upload their SCB. The node would ask peers to FC channels and then initialize with the same seed (so in max. 2 weeks you should see the balances of closed channels turning up in you savings balance?)

I like this flow because for the user it is more convenient, and we also do not need to build and package another app to do this

rolznz commented 2 months ago

Backend part was done in https://github.com/getAlby/hub/pull/693 - but there is no UI yet.

We possibly can move this code to a separate tool to reduce complexity of maintaining this in Alby Hub.