Skip to content

Commit

Permalink
Add elementsd container, improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
MrHash committed Jul 3, 2019
1 parent 0c8f720 commit b5caf82
Show file tree
Hide file tree
Showing 13 changed files with 533 additions and 21 deletions.
8 changes: 8 additions & 0 deletions .env
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,13 @@ LNDBOB_PORT=19745
LNDBOB_REST_PORT=8090
LNDBOB_RPC_PORT=10019

ELEMENTS_HOST=elementsd
ELEMENTS_PORT=18887
ELEMENTS_RPC_USER=elements
ELEMENTS_RPC_PASSWORD=elements
ELEMENTS_RPC_PORT=18886
ELEMENTS_ZMQ_TX_PORT=28886
ELEMENTS_ZMQ_BLOCK_PORT=28887

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

## 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.
- Changed Ubuntu base containers to specific date version tag.
- Minor configuration tweaks.
- Add MPL2.0 license.

## 2019-07-02
- Initial release.
373 changes: 373 additions & 0 deletions LICENSE

Large diffs are not rendered by default.

34 changes: 24 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,24 +1,29 @@
# Docker setup for Bitcoind & LND in regtest mode

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

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

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

### Notes
- `docker` and `docker-compose` installation required (https://docs.docker.com/install/)
- `bitcoind 0.18.0` is built from an Ubuntu repository and should not be used in production.
- `lnd 0.7.0` containers will sync to chain after first Bitcoin regtest blocks are generated (see below).
- Ports and other deamon configuration can be changed in the `.env` and `docker-compose.yml` files.
### Notes & prerequisites
- `docker` and `docker-compose` installation is required (https://docs.docker.com/install/).
- `jq` tool is used in examples for parsing json responses.
- `bitcoind 0.17.1` is built from an Ubuntu repository and should not be used in production.
- `lnd 0.7.0-beta` containers will sync to chain after first Bitcoin regtest blocks are generated.
- Ports and other daemon configuration can be changed in the `.env` and `docker-compose.yml` files.
- See the [changelog](CHANGELOG.md) when upgrading.

## How to run
It may take several minutes if containers need to be built. From your terminal in this folder:
It may take up to 30 minutes to launch the stack if container images are not already compiled, since they are built from source. From your terminal in this folder:

```
$ docker-compose up -d bitcoind
$ bin/b-cli generate 101
$ docker-compose up -d lndalice lndbob
# elements can be started optionally
$ docker-compose up -d elementsd
$ bin/e-cli generate 1
```

Check containers are up and running with:
Expand All @@ -43,10 +48,16 @@ $ bin/ln-alice listchannels
$ bin/ln-bob listchannels
```

Elements sidechain is available and can be pegged in from dev bitcoin chain using the provided convenience script.
```
$ bin/e-pegin
$ bin/e-cli getwalletinfo
```

REST/RPC queries can be executed directly from the host to the daemons as follows:
```
#bitcoind
$ curl --data-binary '{"jsonrpc":"1.0","id":"curltext","method":"getblockchaininfo","params":[]}' -H 'content-type:text/plain;' http://bitcoin:bitcoin@127.0.0.1:18889/
$ curl --data-binary '{"jsonrpc":"1.0","id":"curltext","method":"getwalletinfo","params":[]}' -H 'content-type:text/plain;' http://bitcoin:bitcoin@127.0.0.1:18889/
#lnd
$ ALICE_MACAROON_HEADER="Grpc-Metadata-macaroon: `docker-compose exec -T lndalice cat /shared/admin.macaroon | xxd -ps -u -c 1000`"
Expand All @@ -55,11 +66,14 @@ $ BOB_MACAROON_HEADER="Grpc-Metadata-macaroon: `docker-compose exec -T lndbob ca
$ echo "$(docker-compose exec -T lndbob cat /shared/tls.cert)" > ./bob-tls.cert
$ curl -XGET --cacert ./alice-tls.cert --header "$ALICE_MACAROON_HEADER" https://127.0.0.1:8080/v1/balance/channels
$ curl -XGET --cacert ./bob-tls.cert --header "$BOB_MACAROON_HEADER" https://127.0.0.1:8090/v1/balance/channels
#elementsd
$ curl --data-binary '{"jsonrpc":"1.0","id":"curltext","method":"getwalletinfo","params":[]}' -H 'content-type:text/plain;' http://elements:elements@127.0.0.1:18886/
```

View daemon logs as follows:
```
$ docker-compose logs -f bitcoind lndalice lndbob
$ docker-compose logs -f
```

When you are done you can destroy all running containers and volumes with:
Expand Down
2 changes: 1 addition & 1 deletion bin/b-cli
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

source .env

docker-compose exec bitcoind bitcoin-cli \
docker-compose exec -T bitcoind bitcoin-cli \
-datadir=/bitcoin \
-rpcuser=$BITCOIN_RPC_USER \
-rpcpassword=$BITCOIN_RPC_PASSWORD \
Expand Down
10 changes: 10 additions & 0 deletions bin/e-cli
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/usr/bin/env bash

source .env

docker-compose exec -T elementsd elements-cli \
-datadir=/elements \
-rpcuser=$ELEMENTS_RPC_USER \
-rpcpassword=$ELEMENTS_RPC_PASSWORD \
-rpcport=$ELEMENTS_RPC_PORT \
"$@"
12 changes: 12 additions & 0 deletions bin/e-pegin
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/usr/bin/env bash

bin/e-cli generate 1
ADDRS=$(bin/e-cli getpeginaddress)
MAINCHAIN=$(echo $ADDRS | jq '.mainchain_address' | tr -d '"')
SIDECHAIN=$(echo $ADDRS | jq '.claim_script' | tr -d '"')
TXID=$(bin/b-cli sendtoaddress $MAINCHAIN 1)
bin/b-cli generate 101
PROOF=$(bin/b-cli gettxoutproof '''["'''$TXID'''"]''')
RAW=$(bin/b-cli getrawtransaction $TXID)
bin/e-cli claimpegin $RAW $PROOF
bin/e-cli generate 1
2 changes: 1 addition & 1 deletion bin/ln-alice
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

source .env

docker-compose exec lndalice lncli \
docker-compose exec -T lndalice lncli \
--macaroonpath /shared/admin.macaroon \
--tlscertpath /shared/tls.cert \
--rpcserver 127.0.0.1:$LNDALICE_RPC_PORT \
Expand Down
2 changes: 1 addition & 1 deletion bin/ln-bob
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

source .env

docker-compose exec lndbob lncli \
docker-compose exec -T lndbob lncli \
--macaroonpath /shared/admin.macaroon \
--tlscertpath /shared/tls.cert \
--rpcserver 127.0.0.1:$LNDBOB_RPC_PORT \
Expand Down
25 changes: 22 additions & 3 deletions bitcoind/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,10 +1,29 @@
FROM ubuntu:18.04
FROM ubuntu:bionic-20190612 as builder

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

RUN add-apt-repository -y ppa:bitcoin/bitcoin \
&& add-apt-repository -y universe && apt-get update

RUN apt-get install -y bitcoind
RUN apt-get install -y --fix-missing build-essential libtool \
autotools-dev autoconf pkg-config libssl-dev \
libboost-all-dev libprotobuf-dev protobuf-compiler \
libqrencode-dev autoconf openssl libssl-dev libevent-dev \
libminiupnpc-dev libzmq5-dev libdb4.8-dev libdb4.8++-dev \
git jq

ADD ./bitcoin.conf /bitcoin/bitcoin.conf
WORKDIR /build

RUN git clone -n https://github.com/bitcoin/bitcoin . \
&& git checkout ef70f9b52b851c7997a9f1a0834714e3eebc1fd8 \
&& ./autogen.sh \
&& ./configure --without-gui --disable-tests \
&& make && make install


FROM ubuntu:bionic-20190612

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

ADD ./bitcoin.conf /bitcoin/bitcoin.conf
44 changes: 39 additions & 5 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,22 @@ volumes:
lndalice_shared:
lndbob_data:
lndbob_shared:
elements_data:

services:
bitcoind:
container_name: ${COMPOSE_PROJECT_NAME}_bitcoind
image: bitcoind:latest
image: bitcoind:0.17.1
build: ./bitcoind
command: [
"bitcoind",
"-datadir=/bitcoin",
"-port=${BITCOIN_PORT}",
"-upnp=0",
"-dnsseed=0",
"-txindex=1",
"-listen=0",
"-server=1",
"-onlynet=ipv4",
"-regtest=1",
"-deprecatedrpc=generate",
"-regtest.rpcport=${BITCOIN_RPC_PORT}",
"-regtest.port=${BITCOIN_PORT}",
"-rpcport=${BITCOIN_RPC_PORT}",
Expand Down Expand Up @@ -112,4 +110,40 @@ services:
- "127.0.0.1:${LNDBOB_REST_PORT}:${LNDBOB_REST_PORT}"
volumes:
- lndbob_data:/lnd
- lndbob_shared:/shared
- lndbob_shared:/shared

elementsd:
container_name: ${COMPOSE_PROJECT_NAME}_elementsd
image: elementsd:0.17.0
build: ./elementsd
command: [
"elementsd",
"-datadir=/elements",
"-port=${ELEMENTS_PORT}",
"-upnp=0",
"-server=1",
"-txindex=1",
"-rpcport=${ELEMENTS_RPC_PORT}",
"-rpcuser=${ELEMENTS_RPC_USER}",
"-rpcpassword=${ELEMENTS_RPC_PASSWORD}",
"-rpcallowip=0.0.0.0/0",
"-rpcbind=127.0.0.1",
"-rpcbind=elementsd",
"-zmqpubrawtx=tcp://0.0.0.0:${ELEMENTS_ZMQ_TX_PORT}",
"-zmqpubhashblock=tcp://0.0.0.0:${ELEMENTS_ZMQ_BLOCK_PORT}",
"-mainchainrpchost=${BITCOIN_HOST}",
"-mainchainrpcport=${BITCOIN_RPC_PORT}",
"-mainchainrpcuser=${BITCOIN_RPC_USER}",
"-mainchainrpcpassword=${BITCOIN_RPC_PASSWORD}",
"-onlynet=ipv4",
"-chain=liquidregtest",
"-validatepegin=1",
"-initialfreecoins=0"
]
depends_on:
- bitcoind
ports:
- "${ELEMENTS_PORT}:${ELEMENTS_PORT}"
- "127.0.0.1:${ELEMENTS_RPC_PORT}:${ELEMENTS_RPC_PORT}"
volumes:
- elements_data:/elements
29 changes: 29 additions & 0 deletions elementsd/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
FROM ubuntu:bionic-20190612 as builder

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

RUN add-apt-repository -y ppa:bitcoin/bitcoin \
&& add-apt-repository -y universe && apt-get update

RUN apt-get install -y --fix-missing build-essential libtool \
autotools-dev autoconf pkg-config libssl-dev \
libboost-all-dev libprotobuf-dev protobuf-compiler \
libqrencode-dev autoconf openssl libssl-dev libevent-dev \
libminiupnpc-dev libzmq5-dev libdb4.8-dev libdb4.8++-dev \
git jq

WORKDIR /build

RUN git clone -n https://github.com/ElementsProject/elements.git . \
&& git checkout 551483eae50ff2ee48ed17d6b22bb1a26284b635 \
&& ./autogen.sh \
&& ./configure --without-gui --disable-tests \
&& make && make install


FROM ubuntu:bionic-20190612

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

ADD ./elements.conf /elements/elements.conf
2 changes: 2 additions & 0 deletions elementsd/elements.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
daemon=0
printtoconsole=1

0 comments on commit b5caf82

Please sign in to comment.