Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save michaltakac/a7e6a52b19dd057c95ebb1efec92afe7 to your computer and use it in GitHub Desktop.
Save michaltakac/a7e6a52b19dd057c95ebb1efec92afe7 to your computer and use it in GitHub Desktop.
updated & improved guide to installing LND, Bitcoind, on Ubuntu 16.04 Server on testnet

2018-03-18: Updating of this guide is taking a backseat to the mainnet version at

Intro

This guide is specific to getting LND and bitcoind running on ubuntu 16.04 LTS for testnet.

It does not address mainnet, or using btcd, or neutrino.

Original installation guide:

Alternative version for btcd:
https://gist.github.com/bretton/266b5a3902cd8e1a2b9776b878e5652d

Install bitcoind

Following the guide from https://bitcoin.org/en/full-node#linux-instructions

if you'd prefer to compile bitcoind yourself, please refer to
https://gist.github.com/itoonx/95aec9a3b4da01fd1fd724dffc056963

First add the repository:

sudo apt-add-repository ppa:bitcoin/bitcoin

You will be prompted for your user password. Provide it to continue, and press enter when prompted.

Run the update process:

sudo apt-get update

Then proceed with installing bitcoind as follows:

sudo apt-get install bitcoind

Setup your .bitcoin/bitcoin.conf file, there is a sample here:

https://github.com/bitcoin/bitcoin/blob/master/contrib/debian/examples/bitcoin.conf

simplest version might be as follows:

server=1
testnet=1
txindex=1
daemon=1
externalip=X.X.X.X
maxconnections=10
rpcuser=REPLACEME
rpcpassword=REPLACEME
zmqpubrawblock=tcp://127.0.0.1:28332
zmqpubrawtx=tcp://127.0.0.1:28332

Start bitcoin to initiate sync, and be sure to take a look at https://en.bitcoin.it/wiki/Running_Bitcoin

bitcoind

You can monitor the progress in the logs:

tail $HOME/.bitcoin/testnet3/debug.log

This process will take a couple of hours on testnet to complete. You can confirm you are up to date as follows:

  1. get the current testnet block count
curl -s https://testnet-api.smartbit.com.au/v1/blockchain/blocks |jq -r -c .blocks[0].height
  1. compare the result to the output of:
bitcoin-cli getblockcount
  1. alternatively, do both as a one-liner expression:
echo `bitcoin-cli getblockcount 2>&1`/`curl -s https://testnet-api.smartbit.com.au/v1/blockchain/blocks |jq -r -c .blocks[0].height 2>/dev/null`

If the output values are the same, then your bitcoind node is fully synced and you can proceed with lnd installation.

Start bitcoind automatically

To setup bitcoind to start automatically, we'll borrow the systemd setup from the following guide:

Adapted from sources

  1. First make sure bitcoind is synced, then stopped. Stop with
bitcoin-cli stop
  1. Then add & edit the systemd configuration file
sudo nano /etc/systemd/system/bitcoind.service
  1. Add in the following text, making sure to replace all instances of USERNAME with your username, or the applicable username bitcoind is being run as:
[Unit]
Description=Bitcoin daemon
After=network.target

[Service]
User=USERNAME
Group=USERNAME
Type=forking
PIDFile=/home/USERNAME/.bitcoin/bitcoind.pid
ExecStart=/usr/bin/bitcoind -conf=/home/USERNAME/.bitcoin/bitcoin.conf -pid=/home/USERNAME/.bitcoin/bitcoind.pid
KillMode=process
Restart=always
TimeoutSec=120
RestartSec=30

[Install]
WantedBy=multi-user.target
  1. Enable the systemd setup with the following commands
sudo systemctl enable bitcoind
sudo systemctl start bitcoind
  1. Check it's working properly with
systemctl status bitcoind

Bitcoind should start automatically from here on, and restart if it fails. Next we need to install Go, and LND.

Install Go

The LND install guide used to refer to golang-1.8-go, and now refers to golang-1.10-go, but Ubuntu 16.04 LTS currently has golang-1.9-go. To install the latest Go using Snap:

sudo snap install --classic go

on success you will see the result:

go 1.10 from 'mwhudson' installed

Then make a 'go' directory in your home directory

mkdir go

set the go paths, this can be done in .profile (which reads .bashrc) or directly in .bashrc. You might notice some difference between ssh sessions and local terminal sessions with .profile so for the purpose of this guide we'll use .bashrc as the results are the same for both types of session:

nano .bashrc

add to the end:

export GOPATH=$HOME/go
export PATH=$PATH:$GOROOT/bin:$GOPATH/bin

Important: the Snap install of Go will automatically set the GOROOT variable. It's no longer necessary to set this yourself, unless using apt-get install of older version of Go.

logout and log back in to reread variables, or you can type:

source .bashrc

check variables with:

go env

install dep:

go get -u github.com/golang/dep/cmd/dep

Install LND

install LND:

git clone https://github.com/lightningnetwork/lnd $GOPATH/src/github.com/lightningnetwork/lnd
cd $GOPATH/src/github.com/lightningnetwork/lnd
dep ensure
go install . ./cmd/...

(optional) run tests and check for any errors:

go install; go test -v -p 1 $(go list ./... | grep -v  '/vendor/')

Wait for bitcoind to finish syncing before continuing.

Once bitcoind has completed the sync, run lnd for first run as follows, it will take a while to catch up and sync properly. Let it finish:

lnd --bitcoin.active --bitcoin.testnet --debuglevel=debug --bitcoin.node=bitcoind --bitcoind.rpcuser=REPLACEME --bitcoind.rpcpass=REPLACEME --externalip=X.X.X.X --noencryptwallet --bitcoind.zmqpath=tcp://127.0.0.1:28332

Once sync is complete, proceed with editing config file so as to start lnd with fewer flags:

create/edit $HOME/.lnd/lnd.conf from

https://github.com/lightningnetwork/lnd/blob/master/sample-lnd.conf

simple version might be as follows:

[Application Options]
debuglevel=debug
debughtlc=true
maxpendingchannels=10
; don't encrypt wallet in testing environment, but please consider it mandatory for live
noencryptwallet=true
; replace with your external IP
externalip=YOURIP
alias=SET-YOUR-ALIAS
color=#00FF00

[Bitcoin]
bitcoin.active=1
bitcoin.testnet=1
bitcoin.node=bitcoind

[Bitcoind]
bitcoind.rpcuser=REPLACE
bitcoind.rpcpass=REPLACE
bitcoind.zmqpath=tcp://127.0.0.1:28332

[Neutrino]
; neutrino.active=1
; neutrino.connect=faucet.lightning.community

[Autopilot]
; autopilot.active=1
; The maximum number of channels that should be created.
; autopilot.maxchannels=5
; The percentage of total funds that should be committed to automatic channel
; establishment
; autopilot.allocation=0.6

thereafter you can start lnd without flags:

lnd

monitor the log file in the logs directory under $HOME/.lnd/logs/bitcoin/testnet/lnd.log

Please see Supervisor section at end, for configuration to run LND automatically

To verify things are operational, open another terminal window or session and try the following:

lncli getinfo
lncli getnetworkinfo
lncli describegraph

Setup a wallet to get testnet coins from faucet (needs a np2wkh segwit format address):

lncli newaddress np2wkh

open a testnet3 faucet:

and paste in the address you created.

After a few minutes your coins should have arrived. You can verify with:

lncli walletbalance --witness_only

Open a channel to one or more of the following nodes (via @moli), or another peer you know, or find one from https://explorer.acinq.co/#/ (which should NOT be considered an authoritative source, just a useful one, hwoever old info is retained)

Yalls.org:      039cc950286a8fa99218283d1adc2456e0d5e81be558da77dd6e85ba9a1fff5ad3@34.200.252.146:9735
Htlc.me:        02eba4a726c20c4fcc5a7291181f65dd389951b944dc48a0aec07b13d7c772de57@54.236.31.248:9735
Bitrefill:      02ca1f8792292fd2ad4001b578e962861cc1120f0140d050e87ce1d143f7179031@52.18.61.50:9735
lnd.fun:        03172377a939b21aadab64943ac82fc54a6600db48812dec9046c78abd78f5a0a2@lnd.fun:9735  
Eclair:         03933884aaf1d6b108397e5efe5c86bcf2d8ca8d2f700eda99db9214fc2712b134@endurance.acinq.co:9735
LND Faucet:     02fa77e0f4ca666f7d158c4bb6675d1436e339903a9feeeaacbd6e55021b98e7ee@159.203.125.125   
lncast.com:     027c4d2f938f5ee5184fbf0c1b3152a806243b5ec1e53cff814f439d3c18ceceec@lncast.com:9735
Slack Tipbot:   03ba998c7cfc9e48d59bf5350ebb54356b75ba9cce6a6284628eda6bf389ce452c@194.135.83.49:9735
Internet Cafe:  032d0e1611c0b8aff507703fefc3ad48f722c45a190c81de7a07141f6c92a5c9cc@86.24.91.84:9735

Open a channel by first connecting to the node, then issuing the openchannel command as follows:

lncli connect pubkey@ip:port
lncli openchannel --node_key=<pubkey> --local_amt=100000

verify pending & open channels using:

lncli pendingchannels
lncli listchannels

Supervisor setup to run the applications automatically

The are multiple ways to start things automatically.

Running bitcoind automatically can be done with systemd as outlined above, while LND can be autostarted from supervisor, or a systemd configuration too. Here's a supervisor approach:

  1. First install supervisor:
sudo apt-get install supervisor

Then add a configuration files as follows:

cd /etc/supervisor/conf.d

edit lnd.conf and add the following:

[program:lnd]
user=REPLACE-WITH-YOUR-USERNAME
command=/home/USERNAME/go/bin/lnd --configfile=/home/USERNAME/.lnd/lnd.conf
startretries=999999999999999999999999999
autostart=true
autorestart=true

reload supervisor:

sudo supervisorctl reload

You can monitor the log files by tailing them in the relevant directories in your home directory, or in /var/log/supervisor

Updating

If you do follow the updating process in the original install guide, you might need to rollback and close channels when problems.

you can use git reflog to find your prior commit, close out your channels, then roll forward and start from there.

Something like

cd $GOPATH/src/github.com/lightningnetwork/lnd
git reflog
  4559438 HEAD@{0}: pull: Fast-forward
  dd08662 HEAD@{1}: clone: from https://github.com/lightningnetwork/lnd
git revert <id>

Then once it's working again, close your channels using the help available here:

lightningnetwork/lnd#641

once confirmations done for closure, THEN proceed with upgrade process.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment