2017-08-03 03:52:37 +02:00
# Installation
2017-01-06 01:35:09 +01:00
2017-08-03 03:52:37 +02:00
### Preliminaries
2017-08-24 23:09:18 +02:00
In order to work with [`lnd` ](https://github.com/lightningnetwork/lnd ), the
following build dependencies are required:
2018-05-15 00:59:10 +02:00
2017-08-03 03:52:37 +02:00
* **Go:** `lnd` is written in Go. To install, run one of the following commands:
2017-08-24 23:09:18 +02:00
2018-05-15 00:59:10 +02:00
2018-08-25 03:27:53 +02:00
**Note** : The minimum version of Go supported is Go 1.10. We recommend that
2018-02-20 02:44:01 +01:00
users use the latest version of Go, which at the time of writing is
2018-08-25 03:27:53 +02:00
[`1.11` ](https://blog.golang.org/go1.11 ).
2017-08-24 23:09:18 +02:00
2018-05-15 00:59:10 +02:00
2017-08-24 23:09:18 +02:00
On Linux:
```
2018-08-25 03:27:53 +02:00
sudo apt-get install golang-1.11-go
2017-08-03 03:52:37 +02:00
```
2018-04-20 01:06:39 +02:00
> Note that golang-1.10-go puts binaries in /usr/lib/go-1.10/bin. If you want them on your PATH, you need to make that change yourself. Alternatively, you can run:
```
sudo ln -s /usr/lib/go-1.10/bin/go /usr/local/bin/go
```
2017-04-01 16:03:34 +02:00
2018-04-28 15:47:46 +02:00
On Mac OS X:
2017-08-24 23:09:18 +02:00
```
2017-08-03 03:52:37 +02:00
brew install go
```
2017-08-24 23:09:18 +02:00
2018-04-28 15:47:46 +02:00
On FreeBSD:
```
pkg install go
```
2017-08-24 23:09:18 +02:00
Alternatively, one can download the pre-compiled binaries hosted on the
[golang download page ](https://golang.org/dl/ ). If one seeks to install
from source, then more detailed installation instructions can be found
2018-05-15 00:59:10 +02:00
[here ](http://golang.org/doc/install ).
2017-08-03 03:52:37 +02:00
At this point, you should set your `$GOPATH` environment variable, which
represents the path to your workspace. By default, `$GOPATH` is set to
2017-12-03 03:59:11 +01:00
`~/go` . You will also need to add `$GOPATH/bin` to your `PATH` . This ensures
2017-08-09 07:30:51 +02:00
that your shell will be able to detect the binaries you install.
2017-08-03 03:52:37 +02:00
```bash
2017-08-24 23:09:18 +02:00
export GOPATH=~/gocode
2017-08-03 03:52:37 +02:00
export PATH=$PATH:$GOPATH/bin
```
2017-08-24 23:09:18 +02:00
We recommend placing the above in your .bashrc or in a setup script so that
you can avoid typing this every time you open a new terminal window.
2017-08-03 03:52:37 +02:00
2018-03-04 19:43:56 +01:00
* **dep:** This project uses `dep` to manage dependencies as well
2018-03-30 08:49:46 +02:00
as to provide *reproducible builds* .
2018-05-15 00:59:10 +02:00
2018-03-30 08:49:46 +02:00
**Note** : `dep` is automatically installed via the `make` . To fetch `dep`
manually, use the following command (assumes you already have Go properly
installed):
2017-08-03 03:52:37 +02:00
```
2018-03-04 19:43:56 +01:00
go get -u github.com/golang/dep/cmd/dep
2017-08-03 03:52:37 +02:00
```
2017-08-23 06:01:20 +02:00
### Installing lnd
2017-08-03 03:52:37 +02:00
With the preliminary steps completed, to install `lnd` , `lncli` , and all
related dependencies run the following commands:
2017-01-06 01:35:09 +01:00
```
2018-03-30 08:49:46 +02:00
go get -d github.com/lightningnetwork/lnd
2017-08-03 03:52:37 +02:00
cd $GOPATH/src/github.com/lightningnetwork/lnd
2018-03-30 08:49:46 +02:00
make & & make install
2017-01-06 01:35:09 +01:00
```
2018-06-30 01:48:31 +02:00
For Windows WSL users, make will need to be referenced directly via /usr/bin/make/, or alternatively by wrapping quotation marks around make, like so:
```
/usr/bin/make & & /usr/bin/make install
"make" & & "make" install
```
2018-04-28 15:47:46 +02:00
On FreeBSD, use gmake instead of make.
2018-05-04 01:27:09 +02:00
Alternatively, if one doesn't wish to use `make` , then the `go` commands can be
used directly:
```
dep ensure -v
2018-05-15 00:56:36 +02:00
go install -v ./...
2018-07-11 04:03:06 +02:00
```
2018-05-04 01:27:09 +02:00
2017-08-03 03:52:37 +02:00
**Updating**
2017-04-01 16:03:34 +02:00
2018-03-04 19:43:56 +01:00
To update your version of `lnd` to the latest version run the following
2017-08-03 03:52:37 +02:00
commands:
2017-01-06 01:35:09 +01:00
```
2018-04-03 11:19:07 +02:00
cd $GOPATH/src/github.com/lightningnetwork/lnd
2018-03-30 08:49:46 +02:00
git pull
make & & make install
2017-01-06 01:35:09 +01:00
```
2018-04-28 15:47:46 +02:00
On FreeBSD, use gmake instead of make.
2018-05-04 01:27:09 +02:00
Alternatively, if one doesn't wish to use `make` , then the `go` commands can be
used directly:
```
cd $GOPATH/src/github.com/lightningnetwork/lnd
git pull
dep ensure -v
2018-05-15 00:56:36 +02:00
go install -v ./...
2018-05-04 01:27:09 +02:00
```
2017-08-03 03:52:37 +02:00
**Tests**
2017-04-01 16:03:34 +02:00
2017-08-03 03:52:37 +02:00
To check that `lnd` was installed properly run the following command:
2017-01-06 01:35:09 +01:00
```
2018-03-30 08:49:46 +02:00
make check
2017-01-06 01:35:09 +01:00
```
2018-04-28 15:47:46 +02:00
On FreeBSD, use gmake instead of make.
2017-08-24 23:09:18 +02:00
### Installing btcd
2017-04-01 16:03:34 +02:00
2018-06-05 03:41:08 +02:00
To install btcd, run the following commands:
2017-08-03 03:52:37 +02:00
2018-06-05 03:41:08 +02:00
Install **btcd** :
2017-01-06 01:35:09 +01:00
```
2018-05-15 00:59:10 +02:00
make btcd
2017-01-06 01:35:09 +01:00
```
2018-06-05 03:41:08 +02:00
Alternatively, you can install [`btcd` directly from its
repo](https://github.com/btcsuite/btcd).
2017-08-03 03:52:37 +02:00
### Starting btcd
Running the following command will create `rpc.cert` and default `btcd.conf` .
```
2018-06-18 14:58:24 +02:00
btcd --testnet --rpcuser=REPLACEME --rpcpass=REPLACEME
2017-08-03 03:52:37 +02:00
```
If you want to use `lnd` on testnet, `btcd` needs to first fully sync the
testnet blockchain. Depending on your hardware, this may take up to a few
2018-06-18 15:01:25 +02:00
hours. Note that adding `--txindex` is optional, as it will take longer to sync
the node, but then `lnd` will generally operate faster as it can hit the index
directly, rather than scanning blocks or BIP 158 filters for relevant items.
2017-01-06 01:35:09 +01:00
2017-04-01 16:03:34 +02:00
(NOTE: It may take several minutes to find segwit-enabled peers.)
2017-01-06 01:35:09 +01:00
2017-08-03 03:52:37 +02:00
While `btcd` is syncing you can check on its progress using btcd's `getinfo`
2017-04-01 16:03:34 +02:00
RPC command:
2017-01-06 01:35:09 +01:00
```
2018-01-21 10:03:13 +01:00
btcctl --testnet --rpcuser=REPLACEME --rpcpass=REPLACEME getinfo
2017-04-01 16:03:34 +02:00
{
"version": 120000,
"protocolversion": 70002,
2018-05-15 00:59:10 +02:00
"blocks": 1114996,
2017-04-01 16:03:34 +02:00
"timeoffset": 0,
"connections": 7,
"proxy": "",
"difficulty": 422570.58270815,
"testnet": true,
"relayfee": 0.00001,
"errors": ""
}
2017-01-06 01:35:09 +01:00
```
2017-04-01 16:03:34 +02:00
Additionally, you can monitor btcd's logs to track its syncing progress in real
2018-05-15 00:59:10 +02:00
time.
2017-03-01 02:32:28 +01:00
2017-04-01 16:03:34 +02:00
You can test your `btcd` node's connectivity using the `getpeerinfo` command:
2017-01-06 01:35:09 +01:00
```
2018-01-21 10:03:13 +01:00
btcctl --testnet --rpcuser=REPLACEME --rpcpass=REPLACEME getpeerinfo | more
2017-01-06 01:35:09 +01:00
```
2017-08-23 06:01:20 +02:00
### lnd
2017-04-01 16:03:34 +02:00
2017-08-03 03:52:37 +02:00
#### Simnet vs. Testnet Development
2017-04-01 16:03:34 +02:00
2017-08-03 03:52:37 +02:00
If you are doing local development, such as for the tutorial, you'll want to
start both `btcd` and `lnd` in the `simnet` mode. Simnet is similar to regtest
in that you'll be able to instantly mine blocks as needed to test `lnd`
locally. In order to start either daemon in the `simnet` mode use `simnet`
2017-08-09 07:30:51 +02:00
instead of `testnet` , adding the `--bitcoin.simnet` flag instead of the
2017-05-03 05:46:29 +02:00
`--bitcoin.testnet` flag.
2017-04-01 16:03:34 +02:00
Another relevant command line flag for local testing of new `lnd` developments
is the `--debughtlc` flag. When starting `lnd` with this flag, it'll be able to
automatically settle a special type of HTLC sent to it. This means that you
won't need to manually insert invoices in order to test payment connectivity.
To send this "special" HTLC type, include the `--debugsend` command at the end
of your `sendpayment` commands.
2017-08-03 03:52:37 +02:00
2017-08-23 06:01:20 +02:00
2018-01-15 16:30:41 +01:00
There are currently two primary ways to run `lnd` : one requires a local `btcd`
instance with the RPC service exposed, and the other uses a fully integrated
2017-08-23 06:01:20 +02:00
light client powered by [neutrino ](https://github.com/lightninglabs/neutrino ).
2018-01-15 16:30:41 +01:00
#### Running lnd in Light Client Mode
2017-08-23 06:01:20 +02:00
In order to run `lnd` in its light client mode, you'll need to locate a
2018-06-05 03:41:08 +02:00
full-node which is capable of serving this new light client mode. `lnd` uses
[BIP 157 ](https://github.com/bitcoin/bips/tree/master/bip-0157 ) and [BIP
158](https://github.com/bitcoin/bips/tree/master/bip-0158) for its light client
mode. A public instance of such a node can be found at
`faucet.lightning.community` .
2017-08-23 06:01:20 +02:00
To run lnd in neutrino mode, run `lnd` with the following arguments, (swapping
2018-01-15 16:30:41 +01:00
in `--bitcoin.simnet` if needed), and also your own `btcd` node if available:
2017-08-23 06:01:20 +02:00
```
2018-01-13 06:34:46 +01:00
lnd --bitcoin.active --bitcoin.testnet --debuglevel=debug --bitcoin.node=neutrino --neutrino.connect=faucet.lightning.community
2017-08-23 06:01:20 +02:00
```
#### Running lnd using the btcd backend
2017-08-03 03:52:37 +02:00
If you are on testnet, run this command after `btcd` has finished syncing.
2017-12-03 03:59:11 +01:00
Otherwise, replace `--bitcoin.testnet` with `--bitcoin.simnet` . If you are
2017-08-09 07:30:51 +02:00
installing `lnd` in preparation for the
2017-11-28 00:16:24 +01:00
[tutorial ](http://dev.lightning.community/tutorial ), you may skip this step.
2017-01-06 01:35:09 +01:00
```
2018-01-13 06:34:46 +01:00
lnd --bitcoin.active --bitcoin.testnet --debuglevel=debug --btcd.rpcuser=kek --btcd.rpcpass=kek --externalip=X.X.X.X
```
2018-03-14 08:24:48 +01:00
#### Running lnd using the bitcoind or litecoind backend
The configuration for bitcoind and litecoind are nearly identical, the following
steps can be mirrored with loss of generality to enable a litecoind backend.
2018-03-17 00:28:01 +01:00
Setup will be described in regards to `bitcoind` , but note that `lnd` uses a
2018-03-14 08:24:48 +01:00
distinct `litecoin.node=litecoind` argument and analogous subconfigurations
2018-06-18 15:01:25 +02:00
prefixed by `litecoind` . Note that adding `--txindex` is optional, as it will
take longer to sync the node, but then `lnd` will generally operate faster as
it can hit the index directly, rather than scanning blocks or BIP 158 filters
for relevant items.
2018-03-14 08:24:48 +01:00
To configure your bitcoind backend for use with lnd, first complete and verify
the following:
2018-06-18 14:58:24 +02:00
- Since `lnd` uses
2018-03-14 08:24:48 +01:00
[ZeroMQ ](https://github.com/bitcoin/bitcoin/blob/master/doc/zmq.md ) to
interface with `bitcoind` , *your `bitcoind` installation must be compiled with
2018-05-23 02:31:05 +02:00
ZMQ*. Note that if you installed `bitcoind` from source and ZMQ was not present,
then ZMQ support will be disabled, and `lnd` will quit on a `connection refused` error.
If you installed `bitcoind` via Homebrew in the past ZMQ may not be included
([this has now been fixed](https://github.com/Homebrew/homebrew-core/pull/23088)
in the latest Homebrew recipe for bitcoin)
2018-03-14 08:24:48 +01:00
- Configure the `bitcoind` instance for ZMQ with `--zmqpubrawblock` and
2018-07-17 02:23:21 +02:00
`--zmqpubrawtx` . These options must each use their own unique address in order
to provide a reliable delivery of notifications (e.g.
`--zmqpubrawblock=tcp://127.0.0.1:28332` and
`--zmqpubrawtx=tcp://127.0.0.1:28333` ).
2018-03-14 08:24:48 +01:00
- Start `bitcoind` running against testnet, and let it complete a full sync with
the testnet chain (alternatively, use `--bitcoind.regtest` instead).
2018-01-21 10:03:13 +01:00
2018-02-03 23:57:05 +01:00
Here's a sample `bitcoin.conf` for use with lnd:
```
testnet=1
server=1
daemon=1
2018-03-17 22:37:57 +01:00
zmqpubrawblock=tcp://127.0.0.1:28332
2018-07-17 02:23:21 +02:00
zmqpubrawtx=tcp://127.0.0.1:28333
2018-02-03 23:57:05 +01:00
```
2018-07-17 02:23:21 +02:00
Once all of the above is complete, and you've confirmed `bitcoind` is fully
updated with the latest blocks on testnet, run the command below to launch `lnd`
with `bitcoind` as your backend (as with `bitcoind` , you can create an
`lnd.conf` to save these options, more info on that is described further below):
2018-01-21 10:03:13 +01:00
2018-01-13 06:34:46 +01:00
```
2018-08-10 08:50:36 +02:00
lnd --bitcoin.active --bitcoin.testnet --debuglevel=debug --bitcoin.node=bitcoind --bitcoind.rpcuser=REPLACEME --bitcoind.rpcpass=REPLACEME --bitcoind.zmqpubrawblock=tcp://127.0.0.1:28332 --bitcoind.zmqpubrawtx=tcp://127.0.0.1:28333 --externalip=X.X.X.X
2017-01-06 01:35:09 +01:00
```
2018-05-15 00:59:10 +02:00
*NOTE:*
2018-07-17 02:23:21 +02:00
- The auth parameters `rpcuser` and `rpcpass` parameters can typically be
determined by `lnd` for a `bitcoind` instance running under the same user,
including when using cookie auth. In this case, you can exclude them from the
`lnd` options entirely.
- If you DO choose to explicitly pass the auth parameters in your `lnd.conf` or
command line options for `lnd` (`bitcoind.rpcuser` and `bitcoind.rpcpass` as
shown in example command above), you must also specify the
`bitcoind.zmqpubrawblock` and `bitcoind.zmqpubrawtx` options. Otherwise, `lnd`
will attempt to get the configuration from your `bitcoin.conf` .
- You must ensure the same addresses are used for the `bitcoind.zmqpubrawblock`
and `bitcoind.zmqpubrawtx` options passed to `lnd` as for the `zmqpubrawblock`
and `zmqpubrawtx` passed in the `bitcoind` options respectively.
- When running lnd and bitcoind on the same Windows machine, ensure you use
127.0.0.1, not localhost, for all configuration options that require a TCP/IP
host address. If you use "localhost" as the host name, you may see extremely
slow inter-process-communication between lnd and the bitcoind backend. If lnd
is experiencing this issue, you'll see "Waiting for chain backend to finish
sync, start_height=XXXXXX" as the last entry in the console or log output, and
lnd will appear to hang. Normal lnd output will quickly show multiple
messages like this as lnd consumes blocks from bitcoind.
- Don't connect more than two or three instances of `lnd` to `bitcoind` . With
the default `bitcoind` settings, having more than one instance of `lnd` , or
`lnd` plus any application that consumes the RPC could cause `lnd` to miss
crucial updates from the backend.
2018-01-21 10:03:13 +01:00
2018-01-15 16:30:41 +01:00
#### Macaroons
`lnd` 's authentication system is called **macaroons** , which are decentralized
bearer credentials allowing for delegation, attenuation, and other cool
features. You can learn more about them in Alex Akselrod's [writeup on
Github](https://github.com/lightningnetwork/lnd/issues/20).
Running `lnd` for the first time will by default generate the `admin.macaroon` ,
`read_only.macaroon` , and `macaroons.db` files that are used to authenticate
2018-08-22 22:11:20 +02:00
into `lnd` . They will be stored in the network directory (default:
`lnddir/data/chain/bitcoin/mainnet` ) so that it's possible to use a distinct
password for mainnet, testnet, simnet, etc. Note that if you specified an
alternative data directory (via the `--datadir` argument), you will have to
additionally pass the updated location of the `admin.macaroon` file into `lncli`
using the `--macaroonpath` argument.
2018-01-15 16:30:41 +01:00
To disable macaroons for testing, pass the `--no-macaroons` flag into *both*
`lnd` and `lncli` .
2018-05-15 00:59:10 +02:00
#### Network Reachability
2017-08-23 06:01:20 +02:00
2017-08-03 03:52:37 +02:00
If you'd like to signal to other nodes on the network that you'll accept
incoming channels (as peers need to connect inbound to initiate a channel
funding workflow), then the `--externalip` flag should be set to your publicly
reachable IP address.
# Creating an lnd.conf (Optional)
2017-04-01 16:03:34 +02:00
Optionally, if you'd like to have a persistent configuration between `lnd`
2017-05-03 05:46:29 +02:00
launches, allowing you to simply type `lnd --bitcoin.testnet --bitcoin.active`
2018-05-15 00:59:10 +02:00
at the command line, you can create an `lnd.conf` .
2017-04-01 16:03:34 +02:00
**On MacOS, located at:**
`/Users/[username]/Library/Application Support/Lnd/lnd.conf`
**On Linux, located at:**
`~/.lnd/lnd.conf`
2018-01-13 06:34:46 +01:00
Here's a sample `lnd.conf` for `btcd` to get you started:
2017-01-06 01:35:09 +01:00
```
2017-04-01 16:03:34 +02:00
[Application Options]
debuglevel=trace
debughtlc=true
maxpendingchannels=10
2017-05-03 05:46:29 +02:00
[Bitcoin]
bitcoin.active=1
2017-01-06 01:35:09 +01:00
```
2017-05-03 05:46:29 +02:00
Notice the `[Bitcoin]` section. This section houses the parameters for the
2017-08-03 03:52:37 +02:00
Bitcoin chain. `lnd` also supports Litecoin testnet4 (but not both BTC and LTC
at the same time), so when working with Litecoin be sure to set to parameters
2018-01-13 06:34:46 +01:00
for Litecoin accordingly. For node configuration, the sections are called
2018-03-14 08:24:48 +01:00
`[Btcd]` , `[Bitcoind]` , `[Neutrino]` , `[Ltcd]` , and `[Litecoind]` depending on
which chain and node type you're using.