Installing Lightning Network part 2: Here We Go Again

Ronald Mannak
Coinmonks
Published in
7 min readAug 10, 2018

--

In part 1 I installed a Lightning node on a Digital Ocean droplet. The goal was to explore the Lightning Network, and to see if it’s possible to generate passive income. Money can be made by running a Lightning node 24/7 on a server and forwarding payments from nodes to other nodes. The better connected your node is, the higher the changes payments will be routed through your node. So how did the first month go?

One month in

While other nodes have made up to 5% a week, at least for a short amount of time, I noticed I wasn’t making any money all. None. I had about 85 channels to other nodes, but not a single transaction was routed through my node.

A second issue I ran into was that I wasn’t able to connect to some other nodes. Lastly, I noticed that some channels I created were in stuck in a state, for which I opened an issue on GitHub.

So I created a second node to double check if my node was working correctly. Given that I had no problems creating and funding channels, I didn’t expect any major issues. However, it turned out my node had severe issues. It took me almost to solve (most of) the issues. It was a both exciting and frustrating journey.

The main issue I found after setting up the second node was that my two nodes were not able to connect to each other, even though they ran exactly the same software. I opened a separate GitHub issue for the connection problem.

Long story short: the Lightning ports were not set up correctly, and the Lightning software is not able to detect the issue. To make matters worse, the example setup configuration on the C-Lightning readme contained exactly the same error: The Lightning port wasn’t forwarding incoming data to the Lightning Docker container.

The good news is that I did find a much easier way to install a Lightning node using Docker Compose. I also corrected the Lightning readme and created a pull request. Here’s how to correctly set up Lightning node:

Upgrading from Part 1

If you followed the instructions in part 1 to install your Lightning node, you will need to remove the docker containers and remove the config files.

  1. Remove the existing docker containers
  2. Remove the bitcond and clightning config files
  3. Remove the convenience access scripts

You don’t need to (and don’t want to) erase the droplet, since that would force you to restore a backup, which is a difficult and risky procedure (see part 1 for details).

First, log in on your droplet.

# Log in.
$ ssh root@<droplet's ip-address> -i ~/.ssh/lightning

Next, remove the existing con

# Stop and remove the existing docker containers# 1. Find the docker container id's.
# The -a argument also lists paused containers
$ docker ps -a
# 2. Stop the containers, using the id's found in step 1.
# Repeat this step for each container.
$ docker stop <container id>
# 3. Remove the containers.
# Repeat this step for each container.
$ docker rm <container id>

Next, we’ll delete the bitcoin and lighting config files

# 1. Remove the bitcoin config file.
$ cd /scratch/bitcoin/mainnet/bitcoind
$ rm bitcoin.conf
# 2. Remove the lightning config file.
$ cd /scratch/bitcoin/mainnet/clightning
$ rm config

And delete the convenience scripts.

# 1. Remove the bitcoin convenience script.
$ rm /bin/bitcoin-cli
# 2. Remove the lightning convenience script.
$ rm /bin/lightning-cli

You’re now ready to reinstall Bitcoin and Lightning. Skip A Fresh Install chapter and continue to chapter (Re-)installing Bitcoin and Lightning.

A Fresh Install

If you didn’t install a Lightning node using the steps explained in part 1, you’ll need set up your node using the following chapter in part 1:

  • Setup Digital Ocean

Then, log in on your droplet.

# Log in.
$ ssh root@<droplet's ip-address> -i ~/.ssh/lightning

Next, we’ll create the working directories for bitcoind and clightning:

# 1. Create a working directory outside of the Docker image,
# so the working directory won't be overwritten when you
# update the Docker image with a new bitcoind version.
$ mkdir -p /scratch/bitcoin/mainnet/bitcoind
# 2. Create a working directory outside of the Docker image,
# so the working directory won't be overwritten when you
# update the Docker image with a newer C Lightning version.
$ mkdir -p /scratch/bitcoin/mainnet/clightning

(Re-)installing Bitcoin and Lightning

So there is a

  1. Set up the firewall
  2. Create Docker containers using docker-compose
  3. Create convenience access scripts

The Digital Ocean droplet comes with a firewall, called ufw. We’re going to open ports 8333 (bitcoin) and 9735 (lightning) for both incoming and outgoing traffic.

# 1. Open bitcoin port 8333.
$ sudo ufw allow 8333
# 2. Open lightning port 9735.
$ ufw allow 9735
$ ufw allow out 9735
# 3. Check the firewall status.
$ ufw status

If all is well, ufw will report something similar to the list below (plus any other ports that are open).

To                         Action      From
-- ------ ----
9735 ALLOW Anywhere
8333 ALLOW Anywhere
9735 (v6) ALLOW Anywhere (v6)
8333 (v6) ALLOW Anywhere (v6)
9735 ALLOW OUT Anywhere
8333 ALLOW OUT Anywhere
9735 (v6) ALLOW OUT Anywhere (v6)
8333 (v6) ALLOW OUT Anywhere (v6)
...

Next we’ll create the bitcoind and clightning container. Unlike part 1, we’ll use a much easier to use docker-compose script this time.

# 1. Create an empty docker-compose file in nano.
$ cd ~
$ nano docker-compose.yml
# 2. Copy and paste the docker-compose.yml code below
# and change the aliasname, rbg, and announce-addr
# 3. Save the edited file (Ctrl-X, Y, <Enter>)

The content of docker-compose.yml is shown below. Set alias to the chosen name of your node, set announce-addr to the ip-address of the droplet, and optionally set the rgb value to a color that will be used to show your node in Lightning explorers.

version: "3"
services:
bitcoind:
image: nicolasdorier/docker-bitcoin:0.16.0
container_name: bitcoind
environment:
BITCOIN_EXTRA_ARGS: |
testnet=0
whitelist=0.0.0.0/0
server=1
rpcuser=rpcuser
rpcpassword=rpcpass
expose:
- "8333"
ports:
- "0.0.0.0:8333:8333"
volumes:
- "/scratch/bitcoin/mainnet/bitcoind:/data"
clightning_bitcoin:
image: elementsproject/lightningd
container_name: lightning
command:
- --bitcoin-rpcconnect=bitcoind
- --bitcoin-rpcuser=rpcuser
- --bitcoin-rpcpassword=rpcpass
- --network=bitcoin
- --alias=
<Lightning node name>
- --rgb=FF4500
- --log-level=debug
- --announce-addr=
<droplet IP-address>:9735
environment:
EXPOSE_TCP: "true"
expose:
- "9735"
ports:
- "0.0.0.0:9735:9735"
volumes:
- "/scratch/bitcoin/mainnet/clightning:/root/.lightning"
- "/scratch/bitcoin/mainnet/bitcoind:/etc/bitcoin"
links:
- bitcoind

Note: the docker-compose.yml file is based on the example in the C-Lightning readme file. Unfortunately, the original readme file contained an error: the containers did not expose the ports. I’ve created pull request #1816 that contains a fix.

Create and run the containers by using docker-compose:

$ docker-compose up

Docker will create and run two containers. The bitcoind container should immediately beging downloading the blockchain. For a clean install, this will take hours.

Since the script will not exit, open a new terminal window or tab and log into your droplet again.

# Log in.
$ ssh root@<droplet's ip-address> -i ~/.ssh/lightning

Add a convenience script to access the bitcoind container:

# 1. Create script and edit script (see below).
$ nano /bin/bitcoin-cli
# 2. Copy and past script below# 3. Save the edited file (Ctrl-X, Y, <Enter>)# 4. Make script executable.
$ chmod +x /bin/bitcoin-cli
# 4. Confirm script is working. This command shows the wallet info.
$ bitcoin-cli getwalletinfo

In Nano (step 3 above), edit the bitcoin-cli script as follows:

#!/usr/bin/env bash
docker exec lightning bitcoin-cli -rpcuser=rpcuser -rpcpassword=rpcpass "$@"

Add a convenience script for Lightning

# 1. Create and edit script (See below).
$ nano /bin/lightning-cli
# 2. Copy and paste the script below# 3. Save the edited file (Ctrl-X, Y, <Enter>)# 2. Make script executable.
$ chmod +x /bin/lightning-cli
# 4. Confirm script is working.
$ lightning-cli getinfo

In Nano (step 2 above), edit the lightning-cli script as follows:

#!/usr/bin/env bash
docker exec lightning lightning-cli "$@"

And that’s it. Enjoy your fully functioning Lightning node!

Well, actually, not quite. You’ll see that the bitcoin-cli script doesn’t work. Since you won’t use it that often, I’m going to keep the broken script here. If you see what’s wrong, please leave a comment and I’ll update the post.

More and Better Connections

In part 1, I listed a few ways to find nodes to connect to. After I posted the article, I came across Moneni, which finds good highly connected nodes your node isn’t connected to.

Errors and Solutions

Although I solved the biggest issue of other nodes not able to connect to my node, there are still major issues I mentioned in part 1 that I haven’t been able to solve yet:

CHANNELD_AWAITING_LOCKIN and CHANNELD_SHUTTING_DOWN

Even after a month, some channels are still stuck in either awaiting lockin or shutting down state. I’ve opened an issue (issue #1776) that hasn’t received any feedback of comments yet. The bitcoins in these channels has been inaccessible for over a month.

Finally

I am going to run the server for a few weeks and will share if running a Lightning node is actually profitable at this point.

If you’re running a Lightning node, please considering creating a channel to me and funding the channel. I appreciate it!

$ lightning-cli connect 02060d0c8577cfc2a1962220a1cde4f623ca55ef80bd25e4be5a8b15fed78b11a3@178.62.237.239

Thanks

Big thanks to Ricky Kazuo Miller, Arsenie Yeremin, David Carter, Chang Li, and the C-Lightning team.

Need a Digital Ocean Account? Follow this referral link to create an account on Digital Ocean and receive $10 (I will receive $25).

If you enjoyed this article, and want to read more or show your appreciation, bitcoin is always appreciated at: 3BADHnwyuK54ZVa1dRtRj6Jj8H2BJz63Rc

--

--