Getting ready for ⚡️Lightning⚡️ on Bitcoin Mainnet

Stadicus
6 min readFeb 2, 2018

--

This page is no longer maintained. Please check out the latest and enhanced version of this guide on Github:

Updated Guide for Bitcoin Mainnet!
https://github.com/Stadicus/guides/blob/master/raspibolt/README.md

Lightning Networks is very new and not production ready. It is currently tested on Bitcoin Testnet, and for good reason. However, as Lightning promises to ail a lot of the current scaling pains, and even to extend Bitcoin’s usefulness with increased privacy and instant confirmation, the community is very, very, VERY eager to get it running on Bitcoin Mainnet.

Impressive progress with hundreds of Lightning nodes on mainnet

Not to everybody’s delight, as people could lose money and developers lose time by becoming customer-support representatives.

This guide builds on my previous guide and assumes the following procedure:

  1. Setting up your Lightning node on testnet using the
    Beginner’s Guide to ️⚡Lightning️⚡ on a Raspberry Pi
  2. This guide: prepare everything for mainnet, so that the switch will be quick and straight forward.
  3. Once a stable Lightning node is officially released for mainnet: Full Throttle Ahead!

Note: There are still some issues with Eclair node on the Raspberry Pi, potentially due to the limited memory. I am running and testing all implementations (LND, c-lightning, Eclair) at the moment and depending on which implementation is ready for mainnet, maybe a switch to a different project is needed. They all run on the Bitcoin Core node, however, so a switch is no big deal.

It will not yet provide directions on how to run Lightning on mainnet.

1) Downloading the Bitcoin blockchain

The size of the blockchain will be the main bottleneck when switching to mainnet. Currently, the Lightning node runs on top of the testnet blockchain, which is 15 GB. The mainet blockchain, however, is 200 GB. It’s less the time to download the data, but to validate everything since Satoshi’s genesis block, and build the whole transaction index, that would bring our Pi with its tiny memory down.

This is why the Bitcoin blockchain needs to be preloaded to the external hard disk on a regular computer. Fortunately, the Bitcoin Core software runs on most operating systems, and behaves exactly alike. I will show you how to prepare the data on a Windows machine, but this will also work on Mac and Linux.

Download and verify Bitcoin Core

Download the Bitcoin Core installer from bitcoin.org/download and store it on the external hard disk.

To check the authenticity of the program, we again check its checksum with the checksums provided and signed by Wladimir van der Laan. We already downloaded the reference checksums and checked the signature, thus we just need to get the checksum of the new windows installer.

Note: in Windows, I’ll preface all commands you need to enter with > , so with the command > cd bitcoin , just enter “cd bitcoin” and hit enter.

Open a Windows command prompt (Win+R, enter “cmd”, hit enter), navigate to the external drive (look up the drive letter in Windows Explorer) and create the new directory “bitcoin_mainnet” (the directory “bitcoin_testnet” should already exist from the previous guide). Then calculate the checksum.

> G:
> mkdir bitcoin_mainnet
> dir
> certutil -hashfile bitcoin-0.15.1-win64-setup.exe sha256

Compare this checksum with the reference data on the Pi. This file and its signature has already been verified in the previous guide. The checksum and release version must match.

$ grep bitcoin /home/pi/download/SHA256SUMS.asc

Installing Bitcoin Core

Install Bitcoin Core using the default settings and start the program. Now you can choose the data directory: set this to the new “bitcoin_mainnet” folder on the external hard disk.

Bitcoin Core opens and starts immediately syncing the blockchain. Unfortunately, we need to set one additional setting in the “bitcoin.conf” file, otherwise the whole blockchain will be useless.

Using the menu, open “Settings” / “Options” and click the button “Open Configuration File”. Enter the following line:

txindex=1

Save and close the text file, quit Bitcoin Core using “File” / “Exit” and restart the program. The program will start syncing again.

Performance considerations

The sync will take a long time, depending on your external hard drive. There are two main resources that can speed things up:

  1. Memory for indexing
    If your computer has a lot of memory, you can increase the database in-memory cache by adding the following line (with megabytes of memory to use, adjusted to your computer) into the “bitcoin.conf” file
    dbcache=6000
  2. Speed of your external hard disk
    Indexing creates heavy read/write traffic to your hard disk. If you have enough space on your internal hard disk, it might be quicker to use you regular drive and then copy the whole directory to the external hard disk when finished.

Back to the Pi

Once the Bitcoin blockchain is synced and verified, you can exit Bitcoin Core, eject the hard disk from Windows Explorer and reattach it to your Pi. Do not change anything else yet.

2) Hardening your Pi (even more)

Login with SSH keys

One of the best options to secure the SSH login is to completely disable the password login and require a SSH key certificate. Only someone with physical possession of the private key can login.

The following external guide explains, how to set up the “SSH Keys Authentication” login. Depending on your operating system, you might want to use a different guide.

Now that we can log in using our SSH certificate (please check this first!), we disable the regular password login.
$ sudo nano /etc/ssh/sshd_config

Set the parameters “ChallengeResponseAuthentication” and “PasswordAuthentication” to “no”, save (Ctrl-O) and exit (Ctrl-X).

Now, we restart the SSH daemon. Try to log in with a new SSH session without private key. Your login attempt should be denied.
$ sudo systemctl restart sshd.service

⚠️ If you lose your private key file, you can no longer login using SSH. You then need to attach the Pi to a monitor and keyboard to gain access again.

3) Ressource management

On mainnet, I expect more load on the Pi, especially once everything is synced fully. To monitor running processes, CPU load and memory usage, you can use “htop”:
$ htop

The current load on Testnet is very small

4) Various

Public availability

Make sure that your Bitcoin node is publicly available by running the following command:
$ curl -sL https://bitnodes.earn.com/api/v1/nodes/me-18333/

The answer should be: {“success”:true}. Otherwise, check your port forwarding options.

Some bling for your command prompt

Do you like a nice command prompt? Here are some (very, very optional) suggestions:

Bash auto-completion

If you enter a command and hit the Tab key, the command line tries to complete the command, directory or filename for you. This is very handy but does not work automatically for options of bitcoin-cli or eclair-cli.

Install bash completion

$ wget https://raw.githubusercontent.com/bitcoin/bitcoin/master/contrib/bitcoin-cli.bash-completion

$ wget https://raw.githubusercontent.com/lightningnetwork/lnd/master/contrib/lncli.bash-completion

$ sudo cp *.bash-completion /etc/bash_completion.d/

Next steps

I will update this guide regarding additional steps necessary.

--

--

Stadicus

Co-founder of Shift Crypto, makers of BitBox hardware wallets. @Stadicus3000 on Twitter.