Bitcoin Lightning Network #1: Can I compile and run a node?

Lightning Network is a layer-two scaling solution for Bitcoin. What’s it like being a Lightning Network user nearly 3 years after its whitepaper was released? Andreas finds out.

Today I’ll be reviewing the Bitcoin Lightning Network, a layer-two/off-chain payment system and scaling solution for Bitcoin. This is the first time I’m using any Lightning Network software and look forward to trying the technology for myself.

TL;DR: Installing and configuring lnd is quick and easy. The autopilot feature automatically establishes and funds payment channels to make future payment routing faster and cheaper.

The Lightning Whitepaper was written by Joseph Poon and Thaddeus Dryja in January, 2016. There are multiple implementations of the protocol standard, including lnd and c-lightning.

Lightning Network is already adapted for use with Litecoin. Cross-chain atomic swaps have been possible and documented since 2013 using the Tier Nolan protocol, but was never adopted by the mainstream.

I have split this review of the Bitcoin Lightning Network into multiple parts for better readability. Subscribe to the newsletter and I’ll tell you when I publish the next part.

Parts of the review

  1. Compiling and running a node
  2. Becoming a hub
  3. Paying for services
  4. Shopping for goods
  5. Final thoughts

Installing the Lightning Network Daemon

Setting up the Amazon EC2 instance

I know for sure that I’ll need to run a Bitcoin full-node. To stay on the safe side I’ll use the latest stable version of Bitcoin Core, the most popular Bitcoin reference software.

I can’t use my laptop for the full node. It would take too long sync, is not always on, and changes IP address frequently. I start a machine on Amazon AWS in the Oregon region.

Ubuntu 16.04 is a popular Linux version and compatible with most coins.

I select the c5.large instance type. It comes with 2 CPU cores, 4 GB RAM, and a 10 Gbit Internet connection.

I need to fit the entire blockchain on the hard drive.

There’s overhead in storing the Bitcoin blockchain on a hard drive. Especially if I need to enable transaction indexing. I’ll go with 500 GB to be sure. I choose the maximum disk performance available to improve sync time.

I open up the Bitcoin peer-to-peer port from the outside to improve connectivity.

I recall reading Lighting Network requires nodes to have fixed IP addresses. I assign one.

I connect to the machine over SSH and make sure its Ubuntu installation is updated.

While the machine upgrades I read the Lightning Network documentation. It seems it can run with either Bitcoin Core or btcd as the backend. I have more experience with Bitcoin Core.

I noticed comments about having to run with transaction indexing, txindex=1, as I suspected. ZeroMQ (zmq) is also required. ZeroMQ is a way for programs running on the same computer to notify each other of events, such as new transactions and blocks.

Compiling Bitcoin Core from source

I download Bitcoin Core v0.16.1.

$ wget

And extract.

$ tar zxvf v0.16.1.tar.gz
$ cd bitcoin-0.16.1/

The required dependencies of Bitcoin Core seem quite straight forward.

I run everything in one command.

sudo apt-get install -y build-essential libtool \
autotools-dev automake pkg-config \
libssl-dev libevent-dev bsdmainutils \
python3 libboost-system-dev \
libboost-filesystem-dev libboost-chrono-dev \
libboost-program-options-dev libboost-test-dev \
libboost-thread-dev && \
sudo apt-get install -y software-properties-common && \
sudo add-apt-repository ppa:bitcoin/bitcoin && \
sudo apt-get update && \
sudo apt-get install -y libdb4.8-dev libdb4.8++-dev && \
sudo apt-get install -y libzmq3-dev

Installing dependencies took only three minutes.

I compile Bitcoin Core.

make[2]: Leaving directory '/home/ubuntu/bitcoin-0.16.1'
make[1]: Leaving directory '/home/ubuntu/bitcoin-0.16.1'
~/bitcoin-0.16.1$ bitcoind --version
Bitcoin Core Daemon version v0.16.1.0-gdac5d68fc6cf
Copyright (C) 2009-2018 The Bitcoin Core developers

I edit the config.

$ vim ~/.bitcoin/bitcoin.conf

While waiting for Bitcoin Core to compile I peek at the lnd documentation. I add the required ZeroMQ settings.

Don’t worry. I changed the password.

I start bitcoind. Syncing will take hours or days. The most recent block is 530533. I run the command watch bitcoin-cli getnetworkinfo in another tab to monitor the sync progress.

Bitcoin Core is now syncing.

I look at the documentation for lnd, the Lightning Network Daemon. It’s written in Go. Programs written in Go are mostly easy to install.

I install go and the package manager dep according to the docs.

$ sudo apt-get install -y golang-1.10-go
$ sudo ln -s /usr/lib/go-1.10/bin/go /usr/local/bin/go
go version
go version go1.10 linux/amd64
$ echo 'export GOPATH=~/gocode' >> ~/.bashrc
$ echo 'export PATH=$PATH:$GOPATH/bin' >> ~/.bashrc
$ source ~/.bashrc
$ go get -u
$ dep version
$ dep version
version : devel

And then install lnd.

go get -d && \
cd $GOPATH/src/ && \
make && \
make install

Compilation takes less than five minutes.

$ lnd --version
lnd version 0.4.2-beta commit=a0b2fadea35fa4642daf4e9f56e6ecfe31d22ce1

I look in the lnd docs for config file examples.

vim ~/.lnd/lnd.conf

I start lnd.

$ lnd
loadConfig: either --bitcoin.mainnet, or bitcoin.testnet, bitcoin.simnet, or bitcoin.regtest must be specified

Perhaps the sample config was outdated. I add bitcoin.mainnet=1 to lnd.conf in the [Bitcoin] section and try again.

$ lnd
loadConfig: debug-htlc mode cannot be used on bitcoin mainnet

I remove the option and try again.

I try the lncli create command.

ubuntu@ip-172-31-33-128:~$ lncli create
Input wallet password:
Confirm wallet password:
Do you have an existing cipher seed mnemonic you want to use? (Enter y/n): n
Your cipher seed can optionally be encrypted.
Input your passphrase you wish to encrypt it (or press enter to proceed without a cipher seed passphrase):
Generating fresh cipher seed...
---------------BEGIN LND CIPHER SEED---------------
1. xxxxxxxx
5. xxxxxxxx
9. xxxxxxxx
13. xxxxxxxx
17. xxxxxxxx
21. xxxxxxxx
---------------END LND CIPHER SEED-----------------
lnd successfully initialized!

Back in lnd it has noticed the wallet creation and began syncing with bitcoind.

Downloading and syncing the Bitcoin blockchain will take some time. I’ll continue tomorrow.

I check back the next day. bitcoind has finished syncing.

But the Lightning Network Daemon has crashed.

The terminal has also crashed. I restart the system and try again. If the machine runs out of memory again I will either switch to an instance with more RAM or add a swapfile.

~ ssh andreas-tries-lightning-network sudo shutdown -r now
Connection to closed by remote host.

After restarting lnd is catching up from block 410,000. I expect this to be quick.

I looked up the memory issue and found that other users are experiencing it as well.

There’s too much output from lnd. I change the config to reduce debug level. I also comment out the max channels setting which was copy pasted from an example.

[Application Options]

Writers critical of Lightning Network claim the probability of finding routes between two random nodes is very low for amounts over $10. I suspect this is because they are choosing random nodes and not peering properly.

There are a few settings relating to autopilot, a feature that automatically opens channels. I’ll try that first.

I add to the [Autopilot] section of lnd.conf.

Next I will need some funds. I’m quite sure this is done by with lncli.

The newaddress looks like what I need.

$ lncli newaddress
[lncli] invalid address type , support address type are: p2wkh and np2wkh

I guess that p2wkh is pay-to-witness-key-hash. I don’t know what the n in front means.

$ lncli newaddress --help
lncli newaddress - Generates a new address.
lncli newaddress address-type
Generate a wallet new address. Address-types has to be one of:
- p2wkh: Pay to witness key hash
- np2wkh: Pay to nested witness key hash

I still don’t know which one to use. I’ll try np2wkh.

$ lncli newaddress np2wkh
"address": "3CkeGETi1N85NSTJ9GFn87dAN34tHYZzQn"

I send some BTC to my Lightning Node to see what happens.

I check back several hours later. Has enabling autopilot has worked?

My Lightning Network node has started opening channels!

Compiling, installing, and running Lightning Network Daemon, lnd, was straight forward. I look forward to using payment channels for sending and receiving bitcoin.

In part two I’ll try to become a super connected Lightning Network hub. Maybe I can even make money by routing payments? Subscribe to the newsletter below to find out.

See you back here for part two, blockchainers!

About The Author

Andreas Brekken is the CEO of and has been obsessed with cryptocurrency since 2011. He was the CTO/co-founder of and later worked as an engineer with

Follow me on Medium and Twitter for more reviews.