Anonymous
Dec 22, 2017

Pending Earnings

Payout Failed :( Try again?

Ride the Lightning: How to use the Lightning Network on the Bitcoin Mainnet

However, actual Lightning Network usage has been a bit thin on the ground. The peer-to-peer protocol has been specced out, and implementations such as c-lightning, lnd, and lit have been written, but users and network nodes are scarce.

This post will explain how to ignore the "do not use these with real money!" warnings and deploy a Lightning Network node on the Bitcoin mainnet.

Step 0: Get Docker For this writeup, I'm using Docker to run all the relevant software, because building things from source is hard and I'm lazy. If you have a recent Ubuntu machine and have Docker already set up, you should be good. Otherwise:

install Docker

sudo apt install docker

Add yourself to the Docker group for sudo-less Docker commands

sudo usermod -aG docker $USER

Make sure to log out and in again for group membership to refresh!

Step 1: Get Bitcoin I already happened to have a Docker-based Bitcoin full node set up, but you probably don't. To set one up, first make a directory for where you want your Bitcoin config and blockchain data to live. I keep mine on a special scratch mount:

sudo mkdir -p /scratch/bitcoin/mainnet/bitcoind Then, start up one of the excellent Bitcoin builds provided by @amacneil:

docker run --rm --name bitcoind_mainnet -v /scratch/bitcoin/mainnet/bitcoind:/data -p 8333:8333 -p 9735:9735 amacneil/bitcoin:latest This command, on the first run, will automatically download the Bitcoin image. On subsequent runs, it will use the local image. We needed to mount our config and chain data storage directory with -v, and expose ports 8333 (used by Bitcoin's peer-to-peer network) and 9735 (used by the Lightning Network's peer-to-peer network) on the host. (We're later going to be dumping the Lightning node into the same virtual network host as the Bitcoin node, so we have to forward the Lightning port now.)

At this point, you might want to set up port forwards on your router for these ports, and punch any necessary holes in your firewall.

Add some Security By default, the running bitcoind is listening on port 8332 with no IP whitelist, a username of bitcoin, and a password of password. The only security comes from Docker not exposing port 8332 to the outside world. If this makes you feel nervous, edit /scratch/bitcoin/mainnet/bitcoind/bitcoin.conf and set a real rpcpassword and some safe file permissions, and then stop your bitcoind (with a Ctrl+C in the window running the command, or a docker stop bitcoind_mainnet in another terminal) and restart it.

Wrap bitcoin-cli Bitcoin Core's bitcoind comes with a useful bitcoin-cli tool. I use this script, saved as bitcoin-cli on my $PATH, to give me CLI access to my Dockerized Bitcoin node:

#!/usr/bin/env bash docker run --rm --network container:bitcoind_mainnet -v /scratch/bitcoin/mainnet/bitcoind:/data amacneil/bitcoin:latest bitcoin-cli "[email protected]" This runs another Docker container from the same amacneil/bitcoin:latest image, but drops it into the network namespace of the running bitcoind_mainnet container, so they share the same localhost and the RPC client can talk to the RPC server. It also exposes the same data directory, so that the client can read the RPC password if one is set. It forwards all the scripts arguments to the containerized bitcoin-cli, so that it will do whatever you told it to do.

Once that script is saved somewhere and marked executable, try it out with something like bitcoin-cli getinfo. You should get a nice informative response like:

{ "version": 140200, "protocolversion": 70015, "walletversion": 130000, "balance": 0.00000000, "blocks": 483425, "timeoffset": 0, "connections": 8, "proxy": "", "difficulty": 888171856257.3206, "testnet": false, "keypoololdest": 1503625917, "keypoolsize": 100, "paytxfee": 0.00000000, "relayfee": 0.00001000, "errors": "" } If you see something like that, your Dockerized bitcoind is working correctly, and you can move on to...

Step 2: Get Lightning Since I was already running bitcoind, when I went looking for a Lightning node I wanted one that supported bitcoind as a backend. Since lnd and lit only support the Go-based btcd and rely on its own particular RPC calls and interfaces that bitcoind doesn't have, my only real option was c-lightning's lightningd. I'm not sure that c-lightning is the Right Choice in general for a Lightning node, since lnd seems to be getting more attention, but it works with the software stack I have and is written in a language I speak, so it's what I chose.

First, we need to make a directory for the Lightning Network state files. This holds your node's database of its open payment channels, as well as the filesystem socket that the user interface uses to communicate with the node's backend.

sudo mkdir -p /scratch/bitcoin/mainnet/clightning Then, you can run this super long command to download and run lightningd:


Article Payment

Y'alls Peer