2017-01-12 01:12:32 +01:00
This document is written for people who are eager to do something with
2017-01-13 02:11:46 +01:00
the Lightning Network Daemon (`lnd`). This folder uses `docker-compose` to
package `lnd` and `btcd` together to make deploying the two daemons as easy as
typing a few commands. All configuration between `lnd` and `btcd` are handled
automatically by their `docker-compose` config file.
2017-01-18 00:32:12 +01:00
### Prerequisites
2018-08-28 04:30:59 +02:00
Name | Version
--------|---------
docker-compose | 1.9.0
docker | 1.13.0
2017-01-18 00:32:12 +01:00
### Table of content
* [Create lightning network cluster ](#create-lightning-network-cluster )
* [Connect to faucet lightning node ](#connect-to-faucet-lightning-node )
2024-01-08 05:06:31 +01:00
* [Building standalone docker images ](#building-standalone-docker-images )
* [Using bitcoind version ](#using-bitcoind-version )
* [Start Bitcoin Node with bitcoind using Docker Compose ](#start-bitcoin-node-with-bitcoind-using-docker-compose )
* [Generating RPCAUTH ](#generating-rpcauth )
* [Mining in regtest using bitcoin-cli ](#mining-in-regtest-using-bitcoin-cli )
2017-01-18 00:32:12 +01:00
* [Questions ](#questions )
### Create lightning network cluster
This section describes a workflow on `simnet` , a development/test network
2017-01-13 02:11:46 +01:00
that's similar to Bitcoin Core's `regtest` mode. In `simnet` mode blocks can be
2017-03-01 02:33:59 +01:00
generated at will, as the difficulty is very low. This makes it an ideal
2017-01-13 02:11:46 +01:00
environment for testing as one doesn't need to wait tens of minutes for blocks
to arrive in order to test channel related functionality. Additionally, it's
possible to spin up an arbitrary number of `lnd` instances within containers to
create a mini development cluster. All state is saved between instances using a
2020-03-26 10:09:09 +01:00
shared volume.
2017-01-13 02:11:46 +01:00
Current workflow is big because we recreate the whole network by ourselves,
next versions will use the started `btcd` bitcoin node in `testnet` and
`faucet` wallet from which you will get the bitcoins.
2017-12-23 21:25:41 +01:00
In the workflow below, we describe the steps required to recreate the following
2017-01-13 02:11:46 +01:00
topology, and send a payment from `Alice` to `Bob` .
2021-01-17 14:59:23 +01:00
```text
2017-01-12 01:12:32 +01:00
+ ----- + + --- +
| Alice | < --- channel --- > | Bob | < --- Bob and Alice are the lightning network daemons which
2017-12-23 21:25:41 +01:00
+ ----- + + --- + create channels and interact with each other using the
2017-01-12 01:12:32 +01:00
| | Bitcoin network as source of truth.
| |
+ - - - - - + - - - - - - +
|
2017-01-18 00:32:12 +01:00
+ --------------- +
2017-12-23 21:25:41 +01:00
| Bitcoin network | < --- In the current scenario for simplicity we create only one
+ --------------- + "btcd" node which represents the Bitcoin network, in a
2017-01-12 01:12:32 +01:00
real situation Alice and Bob will likely be
connected to different Bitcoin nodes.
```
2017-03-28 01:20:31 +02:00
**General workflow is the following:**
2017-01-13 02:11:46 +01:00
* Create a `btcd` node running on a private `simnet` .
2017-03-21 14:17:24 +01:00
* Create `Alice` , one of the `lnd` nodes in our simulation network.
* Create `Bob` , the other `lnd` node in our simulation network.
* Mine some blocks to send `Alice` some bitcoins.
2017-01-13 02:11:46 +01:00
* Open channel between `Alice` and `Bob` .
* Send payment from `Alice` to `Bob` .
2017-03-28 01:20:31 +02:00
* Close the channel between `Alice` and `Bob` .
* Check that on-chain `Bob` balance was changed.
2017-01-13 02:11:46 +01:00
Start `btcd` , and then create an address for `Alice` that we'll directly mine
bitcoin into.
2021-01-17 14:59:23 +01:00
```shell
2017-01-18 00:32:12 +01:00
# Init bitcoin network env variable:
2022-10-28 18:06:35 +02:00
$ export NETWORK="simnet"
2017-01-18 00:32:12 +01:00
2019-01-23 14:34:09 +01:00
# Create persistent volumes for alice and bob.
2022-10-28 18:06:35 +02:00
$ docker volume create simnet_lnd_alice
$ docker volume create simnet_lnd_bob
2019-01-23 14:34:09 +01:00
2017-01-13 02:11:46 +01:00
# Run the "Alice" container and log into it:
2022-10-28 18:06:35 +02:00
$ docker-compose run -d --name alice --volume simnet_lnd_alice:/root/.lnd lnd
$ docker exec -i -t alice bash
2017-01-12 01:12:32 +01:00
2017-01-18 00:32:12 +01:00
# Generate a new backward compatible nested p2sh address for Alice:
2022-10-28 18:06:35 +02:00
alice $ lncli --network=simnet newaddress np2wkh
2017-01-12 01:12:32 +01:00
2017-01-13 02:11:46 +01:00
# Recreate "btcd" node and set Alice's address as mining address:
2024-02-07 12:51:04 +01:00
$ export MINING_ADDRESS=< alice_address >
$ docker-compose up -d btcd
2017-01-12 01:12:32 +01:00
2017-12-23 21:25:41 +01:00
# Generate 400 blocks (we need at least "100 >=" blocks because of coinbase
2017-01-18 00:32:12 +01:00
# block maturity and "300 ~=" in order to activate segwit):
2022-10-28 18:06:35 +02:00
$ docker exec -it btcd /start-btcctl.sh generate 400
2017-01-12 01:12:32 +01:00
# Check that segwit is active:
2022-10-28 18:06:35 +02:00
$ docker exec -it btcd /start-btcctl.sh getblockchaininfo | grep -A 1 segwit
2017-01-12 01:12:32 +01:00
```
2017-03-28 01:20:31 +02:00
Check `Alice` balance:
2021-01-17 14:59:23 +01:00
```shell
2022-10-28 18:06:35 +02:00
alice $ lncli --network=simnet walletbalance
2017-01-12 01:12:32 +01:00
```
Connect `Bob` node to `Alice` node.
2017-03-28 01:20:31 +02:00
2021-01-17 14:59:23 +01:00
```shell
2017-01-12 01:12:32 +01:00
# Run "Bob" node and log into it:
2022-10-28 18:06:35 +02:00
$ docker-compose run -d --name bob --volume simnet_lnd_bob:/root/.lnd lnd
$ docker exec -i -t bob bash
2017-01-12 01:12:32 +01:00
2017-01-13 02:11:46 +01:00
# Get the identity pubkey of "Bob" node:
2022-10-28 18:06:35 +02:00
bob $ lncli --network=simnet getinfo
2017-01-13 02:11:46 +01:00
{
2017-03-21 14:17:24 +01:00
----->"identity_pubkey": "0343bc80b914aebf8e50eb0b8e445fc79b9e6e8e5e018fa8c5f85c7d429c117b38",
"alias": "",
"num_pending_channels": 0,
"num_active_channels": 0,
2018-08-28 18:25:55 +02:00
"num_inactive_channels": 0,
2017-03-21 14:17:24 +01:00
"num_peers": 0,
"block_height": 1215,
"block_hash": "7d0bc86ea4151ed3b5be908ea883d2ac3073263537bcf8ca2dca4bec22e79d50",
"synced_to_chain": true,
"testnet": false
2017-05-03 05:49:40 +02:00
"chains": [
"bitcoin"
]
2017-01-13 02:11:46 +01:00
}
2017-01-12 01:12:32 +01:00
# Get the IP address of "Bob" node:
2022-10-28 18:06:35 +02:00
$ docker inspect bob | grep IPAddress
2017-01-12 01:12:32 +01:00
# Connect "Alice" to the "Bob" node:
2022-10-28 18:06:35 +02:00
alice $ lncli --network=simnet connect < bob_pubkey > @< bob_host >
2017-01-12 01:12:32 +01:00
# Check list of peers on "Alice" side:
2022-10-28 18:06:35 +02:00
alice $ lncli --network=simnet listpeers
2017-01-13 02:11:46 +01:00
{
2017-03-21 14:17:24 +01:00
"peers": [
{
"pub_key": "0343bc80b914aebf8e50eb0b8e445fc79b9e6e8e5e018fa8c5f85c7d429c117b38",
2017-08-22 09:40:51 +02:00
"address": "172.19.0.4:9735",
2017-03-21 14:17:24 +01:00
"bytes_sent": "357",
"bytes_recv": "357",
"sat_sent": "0",
"sat_recv": "0",
"inbound": true,
"ping_time": "0"
}
]
2017-01-13 02:11:46 +01:00
}
2017-01-12 01:12:32 +01:00
# Check list of peers on "Bob" side:
2022-10-28 18:06:35 +02:00
bob $ lncli --network=simnet listpeers
2017-01-13 02:11:46 +01:00
{
2017-03-21 14:17:24 +01:00
"peers": [
{
"pub_key": "03d0cd35b761f789983f3cfe82c68170cd1c3266b39220c24f7dd72ef4be0883eb",
"address": "172.19.0.3:51932",
"bytes_sent": "357",
"bytes_recv": "357",
"sat_sent": "0",
"sat_recv": "0",
"inbound": false,
"ping_time": "0"
}
]
2017-01-13 02:11:46 +01:00
}
2017-01-12 01:12:32 +01:00
```
2017-01-13 02:11:46 +01:00
Create the `Alice<->Bob` channel.
2021-01-17 14:59:23 +01:00
```shell
2017-01-12 01:12:32 +01:00
# Open the channel with "Bob":
2022-10-28 18:06:35 +02:00
alice $ lncli --network=simnet openchannel --node_key=< bob_identity_pubkey > --local_amt=1000000
2017-01-12 01:12:32 +01:00
2017-12-23 21:25:41 +01:00
# Include funding transaction in block thereby opening the channel:
2022-10-28 18:06:35 +02:00
$ docker exec -it btcd /start-btcctl.sh generate 3
2017-01-12 01:12:32 +01:00
2017-12-23 21:25:41 +01:00
# Check that channel with "Bob" was opened:
2022-10-28 18:06:35 +02:00
alice $ lncli --network=simnet listchannels
2017-01-13 02:11:46 +01:00
{
2017-03-21 14:17:24 +01:00
"channels": [
{
"active": true,
"remote_pubkey": "0343bc80b914aebf8e50eb0b8e445fc79b9e6e8e5e018fa8c5f85c7d429c117b38",
"channel_point": "3511ae8a52c97d957eaf65f828504e68d0991f0276adff94c6ba91c7f6cd4275:0",
"chan_id": "1337006139441152",
"capacity": "1005000",
"local_balance": "1000000",
"remote_balance": "0",
2017-12-23 21:25:41 +01:00
"commit_fee": "8688",
"commit_weight": "600",
"fee_per_kw": "12000",
2017-03-21 14:17:24 +01:00
"unsettled_balance": "0",
"total_satoshis_sent": "0",
"total_satoshis_received": "0",
2017-12-23 21:25:41 +01:00
"num_updates": "0",
"pending_htlcs": [
],
"csv_delay": 4
2017-03-21 14:17:24 +01:00
}
]
2017-01-13 02:11:46 +01:00
}
2017-01-12 01:12:32 +01:00
```
2017-12-23 21:25:41 +01:00
Send the payment from `Alice` to `Bob` .
2021-01-17 14:59:23 +01:00
```shell
2017-01-12 01:12:32 +01:00
# Add invoice on "Bob" side:
2022-10-28 18:06:35 +02:00
bob $ lncli --network=simnet addinvoice --amt=10000
2017-01-13 02:11:46 +01:00
{
"r_hash": "< your_random_rhash_here > ",
"pay_req": "< encoded_invoice > ",
}
2017-01-12 01:12:32 +01:00
# Send payment from "Alice" to "Bob":
2022-10-28 18:06:35 +02:00
alice $ lncli --network=simnet sendpayment --pay_req=< encoded_invoice >
2017-01-12 01:12:32 +01:00
2017-07-04 22:25:24 +02:00
# Check "Alice"'s channel balance
2022-10-28 18:06:35 +02:00
alice $ lncli --network=simnet channelbalance
2017-01-12 01:12:32 +01:00
2017-07-04 22:25:24 +02:00
# Check "Bob"'s channel balance
2022-10-28 18:06:35 +02:00
bob $ lncli --network=simnet channelbalance
2017-01-12 01:12:32 +01:00
```
2017-03-01 02:33:59 +01:00
Now we have open channel in which we sent only one payment, let's imagine
2017-12-23 21:25:41 +01:00
that we sent lots of them and we'd now like to close the channel. Let's do
2017-01-13 02:11:46 +01:00
it!
2021-01-17 14:59:23 +01:00
```shell
2017-12-23 21:25:41 +01:00
# List the "Alice" channel and retrieve "channel_point" which represents
2017-01-12 01:12:32 +01:00
# the opened channel:
2022-10-28 18:06:35 +02:00
alice $ lncli --network=simnet listchannels
2017-01-13 02:11:46 +01:00
{
2017-03-21 14:17:24 +01:00
"channels": [
{
"active": true,
"remote_pubkey": "0343bc80b914aebf8e50eb0b8e445fc79b9e6e8e5e018fa8c5f85c7d429c117b38",
---->"channel_point": "3511ae8a52c97d957eaf65f828504e68d0991f0276adff94c6ba91c7f6cd4275:0",
"chan_id": "1337006139441152",
"capacity": "1005000",
"local_balance": "990000",
"remote_balance": "10000",
2017-12-23 21:25:41 +01:00
"commit_fee": "8688",
"commit_weight": "724",
"fee_per_kw": "12000",
2017-03-21 14:17:24 +01:00
"unsettled_balance": "0",
"total_satoshis_sent": "10000",
"total_satoshis_received": "0",
2017-12-23 21:25:41 +01:00
"num_updates": "2",
"pending_htlcs": [
],
"csv_delay": 4
2017-03-21 14:17:24 +01:00
}
]
2017-01-13 02:11:46 +01:00
}
2017-12-23 21:25:41 +01:00
# Channel point consists of two numbers separated by a colon. The first one
2017-01-18 00:32:12 +01:00
# is "funding_txid" and the second one is "output_index":
2022-10-28 18:06:35 +02:00
alice $ lncli --network=simnet closechannel --funding_txid=< funding_txid > --output_index=< output_index >
2017-01-12 01:12:32 +01:00
2017-12-23 21:25:41 +01:00
# Include close transaction in a block thereby closing the channel:
2022-10-28 18:06:35 +02:00
$ docker exec -it btcd /start-btcctl.sh generate 3
2017-01-12 01:12:32 +01:00
2017-01-13 02:11:46 +01:00
# Check "Alice" on-chain balance was credited by her settled amount in the channel:
2022-10-28 18:06:35 +02:00
alice $ lncli --network=simnet walletbalance
2017-01-12 01:12:32 +01:00
2017-01-13 02:11:46 +01:00
# Check "Bob" on-chain balance was credited with the funds he received in the
# channel:
2022-10-28 18:06:35 +02:00
bob $ lncli --network=simnet walletbalance
2017-03-21 14:17:24 +01:00
{
2017-12-23 21:25:41 +01:00
"total_balance": "10000",
"confirmed_balance": "10000",
2017-11-26 14:33:32 +01:00
"unconfirmed_balance": "0"
2017-03-21 14:17:24 +01:00
}
2017-01-12 01:12:32 +01:00
```
2017-01-18 00:32:12 +01:00
### Connect to faucet lightning node
In order to be more confident with `lnd` commands I suggest you to try
2017-03-01 02:33:59 +01:00
to create a mini lightning network cluster ([Create lightning network cluster](#create-lightning-network-cluster)).
2017-01-18 00:32:12 +01:00
2017-04-04 14:28:05 +02:00
In this section we will try to connect our node to the faucet/hub node
2017-12-23 21:25:41 +01:00
which we will create a channel with and send some amount of
2017-01-18 00:32:12 +01:00
bitcoins. The schema will be following:
2021-01-17 14:59:23 +01:00
```text
2017-01-18 00:32:12 +01:00
+ ----- + + ------ + (1) + --- +
| Alice | < --- channel --- > | Faucet | < --- channel --- > | Bob |
+ ----- + + ------ + + --- +
| | |
| | | < --- ( 2 )
+ - - - - - - - - - - - - - + - - - - - - - - - - - - - +
|
+ --------------- +
| Bitcoin network | < --- ( 3 )
+ --------------- +
2018-02-07 04:11:11 +01:00
(1) You may connect an additional node "Bob" and make the multihop
2017-01-18 00:32:12 +01:00
payment Alice->Faucet->Bob
(2) "Faucet", "Alice" and "Bob" are the lightning network daemons which
2017-12-23 21:25:41 +01:00
create channels to interact with each other using the Bitcoin network
2017-01-18 00:32:12 +01:00
as source of truth.
(3) In current scenario "Alice" and "Faucet" lightning network nodes
2017-12-23 21:25:41 +01:00
connect to different Bitcoin nodes. If you decide to connect "Bob"
to "Faucet" then the already created "btcd" node would be sufficient.
2017-01-18 00:32:12 +01:00
```
2017-11-28 00:18:30 +01:00
First of all you need to run `btcd` node in `testnet` and wait for it to be
2017-08-04 01:33:54 +02:00
synced with test network (`May the Force and Patience be with you`).
2021-01-17 14:59:23 +01:00
```shell
2017-01-18 00:32:12 +01:00
# Init bitcoin network env variable:
2022-10-28 18:06:35 +02:00
$ NETWORK="testnet" docker-compose up
2017-01-18 00:32:12 +01:00
```
After `btcd` synced, connect `Alice` to the `Faucet` node.
2017-12-23 21:25:41 +01:00
The `Faucet` node address can be found at the [Faucet Lightning Community webpage ](https://faucet.lightning.community ).
2021-01-17 14:59:23 +01:00
```shell
2017-01-18 00:32:12 +01:00
# Run "Alice" container and log into it:
2022-10-28 18:06:35 +02:00
$ docker-compose run -d --name alice lnd_btc; docker exec -i -t "alice" bash
2017-01-18 00:32:12 +01:00
# Connect "Alice" to the "Faucet" node:
2022-10-28 18:06:35 +02:00
alice $ lncli --network=testnet connect < faucet_identity_address > @< faucet_host >
2017-01-18 00:32:12 +01:00
```
2017-12-23 21:25:41 +01:00
After a connection is achieved, the `Faucet` node should create the channel
2017-01-18 00:32:12 +01:00
and send some amount of bitcoins to `Alice` .
**What you may do next?:**
- Send some amount to `Faucet` node back.
- Connect `Bob` node to the `Faucet` and make multihop payment (`Alice->Faucet->Bob`)
- Close channel with `Faucet` and check the onchain balance.
2017-01-12 01:12:32 +01:00
2019-02-06 22:47:06 +01:00
### Building standalone docker images
Instructions on how to build standalone docker images (for development or
production), outside of `docker-compose` , see the
[docker docs ](../docs/DOCKER.md ).
2024-01-08 05:06:31 +01:00
### Using bitcoind version
If you are using the bitcoind version of the compose file i.e `docker-compose-bitcoind.yml` , follow these additional instructions:
#### Start Bitcoin Node with bitcoind using Docker Compose
To launch the Bitcoin node using bitcoind in the regtest network using Docker Compose, use the following command:
```shell
$ NETWORK="regtest" docker-compose -f docker-compose-bitcoind.yml up
```
#### Generating RPCAUTH
In bitcoind, the usage of `rpcuser` and `rpcpassword` for server-side authentication has been deprecated. To address this, we now use `rpcauth` instead. You can generate the necessary rpcauth credentials using the [rpcauth.py script ](https://github.com/bitcoin/bitcoin/blob/master/share/rpcauth/rpcauth.py ) from the Bitcoin Core repository.
Note: When using any RPC client, such as `lnd` or `bitcoin-cli` , It is crucial to either provide a clear text password with username or employ cookie authentication.
#### Mining in regtest using bitcoin-cli
1. Log into the `lnd` container:
```shell
$ docker exec -it lnd bash
```
2. Generate a new backward compatible nested p2sh address:
```shell
lnd$ lncli --network=regtest newaddress np2wkh
```
3. Log into the `bitcoind` container:
```shell
$ docker exec -it bitcoind bash
```
4. Generate 101 blocks:
```shell
# Note: We need at least "100 >=" blocks because of coinbase block maturity.
bitcoind$ bitcoin-cli -chain=regtest -rpcuser=devuser -rpcpassword=devpass generatetoaddress 101 2N1NQzFjCy1NnpAH3cT4h4GoByrAAkiH7zu
```
5. Check your lnd wallet balance in regtest network:
```shell
lnd$ lncli --network=regtest walletbalance
```
Note: The address `2N1NQzFjCy1NnpAH3cT4h4GoByrAAkiH7zu` is just a random example. Feel free to use an address generated from your `lnd` wallet to send coins to yourself.
2017-01-12 01:12:32 +01:00
### Questions
2021-07-22 03:32:42 +02:00
[![Irc ](https://img.shields.io/badge/chat-on%20libera-brightgreen.svg )](https://web.libera.chat/#lnd)
2017-01-18 00:32:12 +01:00
2024-01-08 05:06:31 +01:00
* How to see `alice` | `bob` | `btcd` | `lnd` | `bitcoind` logs?
2021-01-17 14:59:23 +01:00
```shell
2024-01-08 05:06:31 +01:00
$ docker-compose logs < alice | bob | btcd | lnd | bitcoind >
2017-03-01 02:33:59 +01:00
```