Be careful when Backing up a Lightning Wallet

The Lightning Network is a great technology which can solve Bitcoins scalability issues. It is in its early development stage so using it has some risks.

In this medium article I want to talk about backups and what you can do when your node crashes or your raspberry doesn’t boot anymore. I am running a LND node on a Raspberry Pi. I don’t have information about Eclair and C-Lightning.

I am a big believer in the Lightning Network. This article is not about spreading FUD, but about clarifying some rumours to prevent accidental loss of funds. The LND developers are working on a way to backup your LN node, but for the moment “be careful”

This article is not a guide on how to make a backup of your LN node!
This article describes what you can do in theory if you mess up, without giving you detailed instructions. I don’t dive very deep into it. I want to give you some general information about backups, but can’t help you a lot with the raspberry pi configuration itself. You probably need some other guides as well (I suggest https://github.com/Stadicus/guides/blob/master/raspibolt/README.md)
Hopefully I can give you some hints and advises on what you have to consider.
I am not an expert but just a LND user who wants to share his experience.
There might be much better solutions than the ones that I propose, but if you don’t have any clue on how to get your money after an accident, then this might help you.

This article was inspired by watching 
https://www.youtube.com/watch?v=5fMv8MpzLgQ
Here twitter user miketwenty1 explains how he lost money on the Lightning Network. Many people are unaware that the 24 word seed does not backup all of your funds.

TL;DR
LND gives you a 24 word seed when you create a node.
This seed does not backup your funds that are in Lightning Channels.
This seed does not backup your funds that return after closing Lightning Channels
If you loose access to the .lnd folder of your node, you not only risk money in channels, but also money from closed channels

If your node crashes and you can’t run LND anymore, save the “.lnd” folder somewhere, try to setup the node again (maybe reinstall LND) and paste the “.lnd” folder back.
If your raspberry doesn’t boot at all, try to remove the SD card, plug it into another device and try to retrieve the “.lnd” folder (https://sourceforge.net/projects/ext2read for windows users who run node on a pi). Now you can factory reset the raspberry, setup everything again and paste back the “.lnd” folder. This is a kind of emergency procedure.

Long version:

Most of the bitcoiners are familiar with the mnemonic seed phrase to back up your Bitcoin. If your computer, hardware wallet, phone or any other Bitcoin wallet crashes, you can use your seed phrase to recover your Bitcoin.

In the Lightning Network it is a bit more complicated.
When your LN wallet creates a channel with another node, your node will save its channel state. In this state you basically store who owns how much BTC in the channel. If you send a payment to the other node, you and your channel partner update the channel state with the latest record and sign it with their private keys (it’s more or less like this).
The current channel state itself is stored in the channel.db (“.lnd/data/graph/mainnet/channel.db”) and is independant from your 24 word seed.
If you loose access to your node (for example due to fire), then you can set up the node again with your seed, but you will not know who you created channels with and what their current state is. This means, your funds in the channels would be lost!

I recently read the false assumption that you can ask your channel partner to force close the channel. But that does not help!! The funds that return from a channel, will go to addresses which are not derived from your seed phrase. The private keys, that you need to access funds from closed channels, are stored in the wallet.db (“.lnd/data/chain/bitcoin/mainnet/wallet.db”)

Below I will list two procedures how to save your funds after accidents. One accident is, you can’t start LND anymore, the other is you can’t boot your Raspberry Pi anymore. I only describe what you have to consider and don’t go into detail. Please see it as an overview and not a complete guide!

You can’t run LND anymore but your Raspberry is still working:
1. stop LND, if it’s still running (just to be sure)
Run “lncli stop”
If you followed Stadicus guide, you should also run “sudo systemctl stop lnd.service” to make sure, that it doesn’t try to run LND again

2. copy the “.lnd” folder and save it somewhere.

3. Now you can try to get LND running again. I can’t give you instructions because I am not an expert. Maybe delete it and reinstall it. This is not topic of this guide. In step 2 you saved the “.lnd” folder somewhere save, so if you mess up, don’t worry and try again.

4. When you have your LND working again (maybe after reinstalling it) you should stop it before it syncs.
Probably you see there is a “.lnd” folder on your pi. Just delete it and replace it with the one that you saved before.

5. Run LND again and your node will have all channels and funds.

If you are running a Raspberry Pi and it doesn’t boot anymore:

I ran into this problem myself.
My raspberry just didn’t boot and I couldn’t find any information on how to restart it. I thought my money was lost, but I could recover the funds. The trick is to access the “.lnd” folder via the SD card itself.

  1. Remove the SD card from the pi and put it into your computer.
  2. Use a software that helps you retrieve the “.lnd” folder (for windows I suggest Ext2Explorer (https://sourceforge.net/projects/ext2read/)
  3. Save the “.lnd” folder somewhere on your computer.
  4. Factory reset the raspberry pi and start again with setting up a node or restore from a backup (see chapter below)
  5. Now that you have everything set up again (or installed the backup) you need to copy your “.lnd” folder (from step 2) onto your raspberry pi.
    This “.lnd” folder should have the latest channel states, so if you run LND, your node should sync again and your channels and funds should be there.

Make a backup of your Raspberry Pi

This seems a bit controversial. At the moment you can’t really make a backup of your Lightning node, but what you can do is making a backup of your whole Raspberry Pi.
The goal is to create an exact copy of your SD card and save it as a backup on a computer (or external hard drive). 
In case you mess up with your raspberry and you have to restart completely, you can just copy your backup back onto your raspberry and replace your “.lnd” folder (because the backup contains old channel states)

  1. Have your raspberry in a condition that you want to backup. This means everything is running properly and you want to return to this point if your raspberry crashes completely.
  2. Shut down the pi and remove the SD card. Plug it into the computer where the backup should be stored (In my case my windows computer)
  3. Download a program that can create an image file from SD card (for windows I suggest Win32DiskImager).
  4. Create an .img file which is basically a backup of your SD card (instructions not part of this tutorial)
  5. Now you can plug the SD card back into your pi and run your node

Restoring the backup

If your raspberry doesn’t boot and you don’t know what to do, you can try to restore the backup. Before doing this, you have to make a copy of your “.lnd” folder by retrieving it directly from the SD card (see chapter “If you are running a Raspberry Pi and it doesn’t boot anymore”)

  1. Make sure you create a fresh copy of the “.lnd” folder and save it somewhere (Don’t save it on the raspberry because we are going to overwrite it)
  2. Write your .img file (the backup of the pi) back onto your Raspberry Pi (Instructions not part of this guide)
    This will completely overwrite the SD card and sets it back to the state where it was when you created the backup.
    Obviously this will have old channel states, so we need to replace the “.lnd” folder
  3. Put your SD card into your raspberry and start it. It should hopefully boot.
    Don’t start your LND node and if you have LND autostart activated (via systemctl and services) then make sure that LND does not start.
    You still have your old “.lnd” folder on that SD card so you would risk loosing money.
    Now delete the “.lnd” folder and paste the folder from step 1.
    That “.lnd” folder will have the latest channel states.
  4. Make sure that everything is set up correctly. Check your swap file system from the Stadicus guide. Mine was completely switched off after the backup was installed, which crashed my node almost every day. Make sure that your scripts that you made executable are still executable. Scripts that I had stored on my external hard drive (the one which contains my Bitcoin Blockchain) where not marked as executable anymore.

Please understand that this guide is not very detailed. It should just give you an overview of what you could do to restore your funds. If you have hundreds of dollars stuck in your channels and your raspberry pi is destroyed (or whatever), this guide might give you some hints on how to approach this problem. If you have any question, please contact me on reddit u/Donno_ or https://twitter.com/BR_Robin

If you are in an emergency and this guide is not detailed enough, I will try to give you more information.