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.
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
- Compiling and running a node
- Becoming a hub
- Paying for services
- Shopping for goods
- 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
$ 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: Leaving directory '/home/ubuntu/bitcoin-0.16.1'
make: 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.
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.
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 github.com/golang/dep/cmd/dep
$ dep version
$ dep version
version : devel
And then install
go get -d github.com/lightningnetwork/lnd && \
cd $GOPATH/src/github.com/lightningnetwork/lnd && \
make && \
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.
loadConfig: either --bitcoin.mainnet, or bitcoin.testnet, bitcoin.simnet, or bitcoin.regtest must be specified
Perhaps the sample config was outdated. I add
lnd.conf in the
[Bitcoin] section and try again.
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): nYour 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...!!!YOU MUST WRITE DOWN THIS SEED TO BE ABLE TO RESTORE THE WALLET!!!---------------BEGIN LND CIPHER SEED---------------
---------------END LND CIPHER SEED-----------------!!!YOU MUST WRITE DOWN THIS SEED TO BE ABLE TO RESTORE THE WALLET!!!lnd successfully initialized!
lnd it has noticed the wallet creation and began syncing with
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 126.96.36.199 closed by remote host.
lnd is catching up from block
410,000. I expect this to be quick.
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.
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.
autopilot.active=1 to the
[Autopilot] section of
Next I will need some funds. I’m quite sure this is done by with
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.USAGE:
lncli newaddress address-typeCATEGORY:
WalletDESCRIPTION: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
$ lncli newaddress np2wkh
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
Follow me on Medium and Twitter for more reviews.