Backup of Lightning Labs’ lightning-app on Android.

Recently, Lightning Labs’ mobile wallets had another security feature enabled: Static channel backups. It’s quite hidden, though, and still only backs up to the phone itself. With some help and extra apps, it can be made to a full-fledged, periodic off-phone backup, though.

 

Enabling backups.

After funding the wallet – or after upgrading to a version with static channel backups – lightning-app will ask you for extra permissions to access files and  other things. This is necessary to allow it to store the channel backup, so say yes! After channels are created, you’ll have a static channel backup on the phone. I found mine in the directory “Internal Storage”/Lightning/mainnet – and the file is called channel.backup.

This is a static channel backup, meaning it will not update during the lifetime of a channel. It will, however, update when you close or open channels. A static channel backup includes enough information to restore keys for a channel and being able to ask your peer to force-close the channel. Without using a watchtower, you *will* have to trust your channel peer to be honest, here, because the backup contains nothing about the current balance. If you were using a watchtower, it will be able to catch any fraudulent force-close-transactions based on an old balance, and the fraudster will lose all his money. Game theory will over time keep people honest here, but it’s still best *not* having to restore the backup.

Getting the backup off the phone

Without getting the backup off the phone, however, your backup is not going to be worth much if you lose your phone and have to factory reset. You will also need the wallet seed to restore the backup, as it’s encrypted, so remember to keep your seed safe!

You might of course copying the file off the phone manually, or already have a backup solution in place for your phone, that you trust to backup your file system. If you want to set up automatic syncronization of the backup yourself, read on!

I have used the tool FolderSync – which enables you to run scheduled backups to a number of cloud services. It exists in a pro version, which has no ads – but the extra features in Pro is not worth it for our purpose if ads is ok for you. There probably exist other tools that provides similar features, but for me, this tools seemed good enough.

Setting up FolderSync

After installing Foldersync – and answering a few easy questions during fkrst startup – you need to go into the “Accounts” menu to create an account to the cloud provider you use. I used my own “ownCloud”, but it supports a ton of other cloud providers and remote file systems.

Having set up and tested the account setting, you need to go into the “FolderPairs” menu to create a folderpair that connects the local directory on the phone with the account you just created. Give the folderpair a meaningful name, select the account you created, select sync type “To remote folder” (you’ll not need to automatically sync back, it should not change other than on the phone), select/create a remote folder to sync to, and then pick the folder “Internal storage”/Lightning as the source directory. This has the added bonus that it will also backup a testnet channel.backup, should you have a testnet version of Lightning-app.

There’s a ton of options to tick off on the folderpair. Most of them can be left unchanged, but you need to decide what type of backup you want. If you choose “scheduled sync”, you will be able to have it backup periodically according to a schedule. If you in sync options choose “instant sync”, it will sync whenever something changes in your file system. This is probably a good idea, I have enabled it – in addition to time-based sync. Make sure you don’t tick off “delete source files after sync”, or “sync deletions”. Always let it overwrite old files.

Other than that, you have the option to limit what type of network it syncs over, whether you want to limit it to wifi only or if you want to allow a cell phone network.

Once you have finished setting it up, press “sync” and check that the files appear in the remote filesystem. And that’s it!

Restore

It is an old proverb that backup it is – it’s restore that is hard. However, this seems not to be this way on lightning-app – doing a seed restore, it finds the channel backup automatically. I presume you will need to put the directories/file in place manually should you need to do the restore on a factory reset phone or a new phone, before doing the seed restore.

My testnet channel that was restored went into “Waiting Close” mode – and from previous experience, I noticed that it could sit there for a long time. Have patience! In this case, it rather quickly transitioned to “Pending Force closing”, which means the remote node has submitted the force closing transaction. The good news is, since the remote node is the one doing the force closing, you will have your coins back in your wallet after one block.

And as any good backup/restore procedure, you should test this. Preferably on testnet!

Leave a Reply

Your email address will not be published. Required fields are marked *