This will be the first in a short series of Lightning Network articles
While bitcoin has proven a robust and secure store of value, and the protocol a proven method of handling trustless transactions, it is not designed to handle millions of transactions a second with very low fees. For that a Layer 2 protocol is needed, that builds on the bitcoin network. This was first mooted by Satoshi Nakamoto in 2009 but there was no firm proposal. Over the following years various other ideas were put forward until, in 2015, Poon and Dryja released “The Bitcoin Lightning Network” paper.
During the following years the Lightning Network was developed in testing mode on the bitcoin testnet until, in March 2018, the first transactions were made on the mainnet. In the years since then it has been slowly, steadily growing.
There are many articles about the Lightning Network, Binance have a good overview.
I find the Lightning Network to be one of the most fascinating ideas around and what better way to educate myself than to run a Bitcoin/Lightning Node myself.
In one sense, running a Lightning node is pretty straightforward. A basic Linux installation, the bitcoind server and the lnd server, a lot of disk space and you’re good to go. But to be useful it needs to be on 24/7 and reachable by the internet at large. So my old laptop is not the best option and an online VPS would be expensive in disk space. However, it is an ideal project for a little Raspberry Pi with an extra hard disk.
There are plenty of projects out there based on the Raspberry Pi (other micros are available) and the two most interesting are the Raspbiblitz and the Raspibolt. You can also get a fully rigged and ready to go option like the Lightning in a box.
I went with Raspiblitz and I went ahead and ordered the Raspiblitz v1.4 from Fulmo. With the blockchain already installed. Pay in BTC and get 15% discount! Just after I ordered it, the COVID-19 event happened, supply chains with China were disrupted, shortage of parts etc. But after a few weeks wait, it showed up!
It’s a small kit of parts with no instructions, but it was also pretty self evident what went where and it’s at this point you need to head over to the documentation and follow the instructions. I’m not going to reiterate what they have there as it is very thorough and at the end you will have a fully functional bitcoin node and lightning node. Note that the hard disk needs to plug in to USB3 (blue).
Just a couple of observations:
- Read the documentation!
- Be patient.
- RTFM again while you are waiting…
- You will need four passwords and a machine name, write them down, you’ll need them.
The passwords should not contain unusual characters, spaces or single/double quotes.
Although I had the blockchain already setup it needs to update and check transactions. And if you are used to working on a laptop with quadcore helium cooled 128Gb power, then a Raspberry Pi is going to be sloooow. Even doing a reboot will take time… it needs to shut down the bitcoind and lnd processes tidily and then restart them and check integrity etc. It’s easy to think it has got locked up and this is my most common mistake, to assume things were stuck. Learn to follow the log files (
/mnt/hdd/lnd/logs/bitcoin/mainnet/lnd.log) and make use of
The basic setup and running of the Raspiblitz is straightforward, especially given the excellent documentation from
rootzoll on the github pages. But there are a few areas of knowledge that I wasn’t sure about. Like, where to go now… :)
Although there is a web interface to the Lightning wallet (RTL), it’s still worth taking the time to play around with the CLI to get a feeling for the wide range of commands that are available. See Lightning API for full details,
Now we’ve got the
Lightning part of
Lightning Network taken care of, it’s time to look in to the
Network aspect of the system. A network needs peers to connect to, so that is the next thing to do. First we need a portal to the outside world.
There are three ways of getting connected to the wider Lightning network. Through your office/home router, on a VPN tunnel to a full time internet server, or through the Tor network. I didn’t need the anonymity and privacy of the Tor network, nor the added complexity, so didn’t go that route. I did try setting up a VPN tunnel to a DigitalOcean server which partly worked, but I spent all day trying to allow packets back to the Raspiblitz without success. So I dropped that and went with opening the correct ports on my office router and using a free DNS redirector and a custom domain.
Give your Raspiblitz a fixed IP address on your local network (edit
/etc/dhcpcd.conf), then go into the local network router to open up ports 8333, 9735, 10009 and 8080 for that IP. 8333 is for bitcoind, the others are for the lightning daemon. I used the DynamicDNS provider
https://freedns.afraid.org. You can make a free account and it just works.
After running for a few weeks I was prodding around inside the RP and realized it was an debian apt system. I typed
sudo apt update and, lo, there were 30 or so updates. So I automatically did
sudo apt upgrade. DO NOT DO THIS! Bad things happen!
There is a clear, well documented upgrade path in the manual and it’s important to follow that. After messing up the system with the above foobar, I had to download the SD image, burn it on the SD card and reboot/reload the system. You’ll need to setup the passwords again and possibly allow a little time to resync the blockchains.
In May 2020 there was an update to the system (v1.4 to v1.5) so I was well prepared for that and the upgrade went reasonably smoothly.
In both cases above there were some glitches in the process, probably from my mucking about. 😰 see Addendum below for more info.