Skip to content

Commit

Permalink
Add a c-lightning node
Browse files Browse the repository at this point in the history
  • Loading branch information
MrHash committed Jul 4, 2019
1 parent 5a03619 commit 360c740
Show file tree
Hide file tree
Showing 9 changed files with 93 additions and 5 deletions.
3 changes: 3 additions & 0 deletions .env
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,8 @@ ELEMENTS_RPC_PORT=18886
ELEMENTS_ZMQ_TX_PORT=28886
ELEMENTS_ZMQ_BLOCK_PORT=28887

LIGHTNINGDCAROL_HOST=lightningdcarol
LIGHTNINGDCAROL_PORT=19755

COMPOSE_FILE=docker-compose.yml
COMPOSE_PROJECT_NAME=bitcoindevstack
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## 2019-07-04
- `bitcoind` Dockerfile updated to allowing sharing of `bitcoin-cli` for `lightningd`.
- Added a `lightningd` node setup and tooling.

## 2019-07-03
- Replaced `bitcoind` Dockerfile with fully compiled version of 0.17.1 to match latest `elementsd` version.
- Added `elementsd` container configuration and tooling, compiled from source.
Expand Down
22 changes: 18 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

### ONLY FOR DEVELOPMENT and TESTING. These tools may not be suitable for production deployments.

This `docker-compose` template launches `bitcoind`, two `lnd` containers named `lndalice` and `lndbob`, and optionally an `elementsd` side chain (aka Liquid).
This `docker-compose` template launches `bitcoind`, two `lnd` containers named `lndalice` and `lndbob`, and optionally an `elementsd` side chain (aka Liquid), and `lightningd` as `lightningdcarol`.

It is configured to run in **regtest** mode but can be modified to suit your needs.

Expand All @@ -21,9 +21,13 @@ It may take up to 30 minutes to launch the stack if container images are not alr
$ docker-compose up -d bitcoind
$ bin/b-cli generate 101
$ docker-compose up -d lndalice lndbob
# elements can be started optionally
# elements/liquid can be started optionally
$ docker-compose up -d elementsd
$ bin/e-cli generate 1
# lightningd can also be started
$ docker-compose up -d lightningdcarol
```

Check containers are up and running with:
Expand All @@ -34,12 +38,13 @@ $ docker-compose ps
Use the provided cli tools to execute commands in the containers:
```
$ bin/b-cli getwalletinfo
$ bin/e-cli getwalletinfo
$ bin/ln-alice getinfo
$ bin/ln-bob getinfo
$ bin/e-cli getwalletinfo
$ bin/ld-carol getinfo
```

A convenience script is provided to create a channel with some funding between the two `lnd` containers.
A convenience script is provided to create a channel from `bob` to `alice` with some funding between the two `lnd` containers.
```
$ bin/ln-connect
# once channels are opened a payment can be simulated
Expand All @@ -49,6 +54,15 @@ $ bin/ln-alice listchannels
$ bin/ln-bob listchannels
```

Another convenience script will connect `bob` to `carol` on the `lightningd` implementation of LN.
```
$ bin/ld-connect
# once channels are opened a payment can be simulated (note amount in *mSats*)
$ TEST_INVOICE=$(bin/ld-carol invoice 10000000 "test" "" | jq '.bolt11' | tr -d '"')
$ bin/ln-bob payinvoice $TEST_INVOICE
$ bin/ld-carol listfunds
```

Elements sidechain is available and can be pegged in from dev bitcoin chain using the provided convenience script.
```
$ bin/e-pegin 1.337
Expand Down
7 changes: 7 additions & 0 deletions bin/ld-carol
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/usr/bin/env bash

source .env

docker-compose exec -T lightningdcarol lightning-cli \
--lightning-dir=/lightningd \
"$@"
10 changes: 10 additions & 0 deletions bin/ld-connect
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/usr/bin/env bash

source .env

bin/b-cli sendtoaddress $(bin/ln-bob newaddress np2wkh | jq '.address' | tr -d '"') 1
bin/b-cli generate 1
LIGHTNINGDCAROL_NODEID=$(bin/ld-carol getinfo | jq '.id' | tr -d '"')
bin/ln-bob connect $LIGHTNINGDCAROL_NODEID@$LIGHTNINGDCAROL_HOST:$LIGHTNINGDCAROL_PORT
bin/ln-bob openchannel --node_key $LIGHTNINGDCAROL_NODEID --local_amt=10000000 --push_amt=5000000 --private
bin/b-cli generate 5
1 change: 1 addition & 0 deletions bitcoind/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,6 @@ FROM ubuntu:bionic-20190612

COPY --from=builder /usr/lib /usr/lib
COPY --from=builder /usr/local/bin /usr/local/bin
COPY --from=builder /usr/local/bin/bitcoin-cli /shared/

ADD ./bitcoin.conf /bitcoin/bitcoin.conf
27 changes: 26 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@ version: "2.4"

volumes:
bitcoin_data:
bitcoin_shared:
lndalice_data:
lndalice_shared:
lndbob_data:
lndbob_shared:
elements_data:
lightningdcarol_data:

services:
bitcoind:
Expand Down Expand Up @@ -39,6 +41,7 @@ services:
- "127.0.0.1:${BITCOIN_RPC_PORT}:${BITCOIN_RPC_PORT}"
volumes:
- bitcoin_data:/bitcoin
- bitcoin_shared:/shared

lndalice:
container_name: ${COMPOSE_PROJECT_NAME}_lndalice
Expand Down Expand Up @@ -146,4 +149,26 @@ services:
- "${ELEMENTS_PORT}:${ELEMENTS_PORT}"
- "127.0.0.1:${ELEMENTS_RPC_PORT}:${ELEMENTS_RPC_PORT}"
volumes:
- elements_data:/elements
- elements_data:/elements

lightningdcarol:
container_name: ${COMPOSE_PROJECT_NAME}_lightningdcarol
image: lightningd:0.7.1
build: ./lightningd
command: [
"lightningd",
"--lightning-dir=/lightningd",
"--network=regtest",
"--addr=0.0.0.0:${LIGHTNINGDCAROL_PORT}",
"--bitcoin-cli=/bitcoin/bitcoin-cli",
"--bitcoin-datadir=/bitcoin",
"--bitcoin-rpcconnect=${BITCOIN_HOST}",
"--bitcoin-rpcport=${BITCOIN_RPC_PORT}",
"--bitcoin-rpcuser=${BITCOIN_RPC_USER}",
"--bitcoin-rpcpassword=${BITCOIN_RPC_PASSWORD}"
]
depends_on:
- elementsd
volumes:
- lightningdcarol_data:/lightningd
- bitcoin_shared:/bitcoin
23 changes: 23 additions & 0 deletions lightningd/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
FROM ubuntu:bionic-20190612 as builder

RUN apt-get -qq update && apt-get install -y software-properties-common

RUN apt-get install -y --fix-missing \
autoconf automake build-essential git libtool libgmp-dev \
libsqlite3-dev python python3 net-tools zlib1g-dev libsodium-dev \
libboost-all-dev libevent-dev

WORKDIR /build

RUN git clone -n https://github.com/ElementsProject/lightning.git . \
&& git checkout 43d5492619b00e42bd34492f8b9a837b6a03df65 \
&& ./configure \
&& make && make install

FROM ubuntu:bionic-20190612

COPY --from=builder /usr/lib /usr/lib
COPY --from=builder /usr/local/libexec /usr/local/libexec
COPY --from=builder /usr/local/bin /usr/local/bin

ADD ./lightning.conf /lightningd/lightning.conf
1 change: 1 addition & 0 deletions lightningd/lightning.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
daemon=0

0 comments on commit 360c740

Please sign in to comment.