From eef8978250b7753c441f98debb5ec54eba829a9e Mon Sep 17 00:00:00 2001 From: Thomas Shufps Date: Tue, 28 Nov 2023 14:07:57 +0100 Subject: [PATCH] Adds a full setup (bitcoin core + public-pool) (#10) * full setup bitcoin + public-pool for docker --- .dockerignore | 3 +- .gitignore | 1 + Dockerfile | 2 +- README.md | 2 +- full-setup/README.md | 66 +++++++++++++++++++++++++++ full-setup/bitcoin-mainnet.conf | 28 ++++++++++++ full-setup/bitcoin-testnet.conf | 28 ++++++++++++ full-setup/docker-compose-mainnet.yml | 42 +++++++++++++++++ full-setup/docker-compose-testnet.yml | 43 +++++++++++++++++ full-setup/docker/bitcoin/Dockerfile | 38 +++++++++++++++ full-setup/prepare.sh | 5 ++ full-setup/public-pool-mainnet.env | 34 ++++++++++++++ full-setup/public-pool-testnet.env | 34 ++++++++++++++ src/models/StratumV1Client.ts | 2 +- 14 files changed, 324 insertions(+), 4 deletions(-) create mode 100644 full-setup/README.md create mode 100644 full-setup/bitcoin-mainnet.conf create mode 100644 full-setup/bitcoin-testnet.conf create mode 100644 full-setup/docker-compose-mainnet.yml create mode 100644 full-setup/docker-compose-testnet.yml create mode 100644 full-setup/docker/bitcoin/Dockerfile create mode 100755 full-setup/prepare.sh create mode 100644 full-setup/public-pool-mainnet.env create mode 100644 full-setup/public-pool-testnet.env diff --git a/.dockerignore b/.dockerignore index 37a40c7..068f8f8 100644 --- a/.dockerignore +++ b/.dockerignore @@ -3,4 +3,5 @@ README.md LICENSE.txt Dockerfile .vscode -.gitignore \ No newline at end of file +.gitignore +full-setup/ diff --git a/.gitignore b/.gitignore index 4ac20fc..ca73bba 100644 --- a/.gitignore +++ b/.gitignore @@ -38,6 +38,7 @@ settings.json #DB **.sqlite** +./full-setup/data/* #https **.pem \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index 0989b56..894bdbd 100644 --- a/Dockerfile +++ b/Dockerfile @@ -24,6 +24,6 @@ EXPOSE 8332 WORKDIR /public-pool COPY --from=build /build . -COPY .env.example .env +#COPY .env.example .env CMD ["/usr/local/bin/node", "dist/main"] diff --git a/README.md b/README.md index 2808c89..c083953 100644 --- a/README.md +++ b/README.md @@ -86,4 +86,4 @@ The docker-compose binds to `127.0.0.1` by default. To expose the Stratum servic rpcallowip=172.16.0.0/12 ``` -to your bitcoin.conf. \ No newline at end of file +to your bitcoin.conf. diff --git a/full-setup/README.md b/full-setup/README.md new file mode 100644 index 0000000..07a48fc --- /dev/null +++ b/full-setup/README.md @@ -0,0 +1,66 @@ +# Full Setup for public pool + +This setup provides a docker-compose setup consisting of Bitcoin Core Node and Public-Pool running in Mainnet or Testnet. + +It exposes following ports: + +- `8332/18332` Bitcoin RPC on `localhost` +- `8333/18333` Bitcoin peering on `0.0.0.0` +- `3333/13333` Public-Pool Stratum port on `0.0.0.0` +- `3334/13334` Public-Pool API port on `localhost` + +The docker-compose setups for Mainnet and Testnet can be run in parallel without any problems. + +# Building Images + +The images are built with + +``` +docker compose -f docker-compose-mainnet.yml build +``` + +Instead of `-mainnet` you can use `-testnet` for Testnet + +# Preparing directories + +Before starting the setup, directories need to be created. + +``` +sudo ./prepare.sh +``` + +# Config files + +There are 4 config files for Mainnet and Testnet + +`mainnet`: +- `public-pool-mainnet.env` +- `bitcoin-mainnet.conf` + +`testnet`: +- `public-pool-testnet.env` +- `bitcoin-testnet.conf` + +**note: pruning (`prune=550`) is enabled by default in the config** +# Running the setup + +To start the setup in foreground mode: + +``` +docker compose -f docker-compose-mainnet.yml up +``` + +To run the setup in detached / background mode use `up -d`. + +In detached mode logs can be watched with: +``` +docker compose -f docker-compose-mainnet.yml logs --tail 100 -f +``` + +# Stopping the setup + +To stop the setup use: + +``` +docker compose -f docker-compose-mainnet.yml down +``` \ No newline at end of file diff --git a/full-setup/bitcoin-mainnet.conf b/full-setup/bitcoin-mainnet.conf new file mode 100644 index 0000000..716ad14 --- /dev/null +++ b/full-setup/bitcoin-mainnet.conf @@ -0,0 +1,28 @@ +# condensed bitcoin config + +# pruning setting +prune=550 + +# allow docker IPs +rpcallowip=172.16.0.0/12 +rpcallowip=127.0.0.1 + +# bind docker container to 0.0.0.0:8332 +rpcbind=0.0.0.0 +rpcport=8332 + +# rpc user and password +rpcpassword=bitcoin +rpcuser=bitcoin + +# enable server +server=1 + +[main] +[test] +rpcbind=0.0.0.0 +rpcport=18332 +# no additional testnet settings + +[signet] +[regtest] diff --git a/full-setup/bitcoin-testnet.conf b/full-setup/bitcoin-testnet.conf new file mode 100644 index 0000000..2734ed1 --- /dev/null +++ b/full-setup/bitcoin-testnet.conf @@ -0,0 +1,28 @@ +# condensed bitcoin config + +# pruning setting +prune=550 + +# allow docker IPs +rpcallowip=172.16.0.0/12 +rpcallowip=127.0.0.1 + +# bind docker container to 0.0.0.0:8332 +rpcbind=0.0.0.0 +rpcport=8332 + +# rpc user and password +rpcpassword=bitcoin +rpcuser=bitcoin + +# enable server +server=1 + +[main] +[test] +rpcbind=0.0.0.0 +rpcport=18332 +# no additional testnet settings + +[signet] +[regtest] \ No newline at end of file diff --git a/full-setup/docker-compose-mainnet.yml b/full-setup/docker-compose-mainnet.yml new file mode 100644 index 0000000..a97ed43 --- /dev/null +++ b/full-setup/docker-compose-mainnet.yml @@ -0,0 +1,42 @@ +version: '3.8' + +services: + bitcoin: + container_name: bitcoin + build: + context: ./docker/bitcoin + dockerfile: Dockerfile + restart: unless-stopped + stop_grace_period: 30s + networks: + - bitcoin + ports: + - "127.0.0.1:8332:8332/tcp" + - "0.0.0.0:8333:8333/tcp" + command: > + -printtoconsole + -datadir=/app/data + volumes: + - "./data/mainnet/bitcoin:/app/data" + - "./bitcoin-mainnet.conf:/app/data/bitcoin.conf:ro" + + public-pool: + container_name: public-pool + build: + context: .. + dockerfile: Dockerfile + restart: unless-stopped + stop_grace_period: 30s + networks: + - bitcoin + ports: + - "0.0.0.0:3333:3333/tcp" + - "127.0.0.1:3334:3334/tcp" + volumes: + - "./data/mainnet/public-pool:/public-pool/DB" + - "./public-pool-mainnet.env:/public-pool/.env:ro" + environment: + - NODE_ENV=production + +networks: + bitcoin: diff --git a/full-setup/docker-compose-testnet.yml b/full-setup/docker-compose-testnet.yml new file mode 100644 index 0000000..fc1abfe --- /dev/null +++ b/full-setup/docker-compose-testnet.yml @@ -0,0 +1,43 @@ +version: '3.8' + +services: + bitcoin-testnet: + container_name: bitcoin-testnet + build: + context: ./docker/bitcoin + dockerfile: Dockerfile + restart: unless-stopped + stop_grace_period: 30s + networks: + - bitcoin-testnet + ports: + - "127.0.0.1:18332:18332/tcp" + - "0.0.0.0:18333:18333/tcp" + command: > + -printtoconsole + -datadir=/app/data + -testnet + volumes: + - "./data/testnet/bitcoin:/app/data" + - "./bitcoin-testnet.conf:/app/data/bitcoin.conf:ro" + + public-pool-testnet: + container_name: public-pool-testnet + build: + context: .. + dockerfile: Dockerfile + restart: unless-stopped + stop_grace_period: 30s + networks: + - bitcoin-testnet + ports: + - "0.0.0.0:13333:13333/tcp" + - "127.0.0.1:13334:13334/tcp" + volumes: + - "./data/testnet/public-pool:/public-pool/DB" + - "./public-pool-testnet.env:/public-pool/.env:ro" + environment: + - NODE_ENV=production + +networks: + bitcoin-testnet: diff --git a/full-setup/docker/bitcoin/Dockerfile b/full-setup/docker/bitcoin/Dockerfile new file mode 100644 index 0000000..d7479ae --- /dev/null +++ b/full-setup/docker/bitcoin/Dockerfile @@ -0,0 +1,38 @@ +# Use an official Ubuntu as a parent image +FROM ubuntu:22.04 AS build + +ARG BITCOIN_CORE_VER=25.1 + +# Install Bitcoin Core +RUN apt-get update && \ + apt-get install -y curl wget tar + +WORKDIR /app + +# download and extract bitcoin core +RUN wget https://bitcoincore.org/bin/bitcoin-core-${BITCOIN_CORE_VER}/bitcoin-${BITCOIN_CORE_VER}-x86_64-linux-gnu.tar.gz -O - | tar xzv --strip-components=1 + +RUN pwd +RUN find -ls + +# use nonroot container +FROM gcr.io/distroless/cc-debian11:nonroot + +# Copy the app dir into distroless image +COPY --chown=1000:1000 --from=build /app /app + +# Expose port 8332/18332 for RPC and 8333/18333 for peer connections +EXPOSE 8332 8333 +EXPOSE 18332 18333 + +# Run bitcoind by default when the container starts. +ENTRYPOINT ["/app/bin/bitcoind"] + +# use user with 1000:1000 for simplicity of ownerships +# because it's the default UID:GID on debian and Ubuntu and derivatives +USER 1000:1000 + +# Additional arguments can be passed to bitcoind via CMD +# For example, to run in testnet mode, use docker run with the argument `-testnet` +CMD ["-printtoconsole", "-datadir=/app/data"] + diff --git a/full-setup/prepare.sh b/full-setup/prepare.sh new file mode 100755 index 0000000..698ec1e --- /dev/null +++ b/full-setup/prepare.sh @@ -0,0 +1,5 @@ +#!/bin/bash + +mkdir -p data/{mainnet,testnet}/bitcoin +mkdir -p data/{mainnet,testnet}/public-pool + diff --git a/full-setup/public-pool-mainnet.env b/full-setup/public-pool-mainnet.env new file mode 100644 index 0000000..3a5592c --- /dev/null +++ b/full-setup/public-pool-mainnet.env @@ -0,0 +1,34 @@ +BITCOIN_RPC_URL=http://bitcoin +BITCOIN_RPC_USER=bitcoin +BITCOIN_RPC_PASSWORD=bitcoin +BITCOIN_RPC_PORT=8332 +BITCOIN_RPC_TIMEOUT=10000 + +# Enable in bitcoin.conf with +# zmqpubrawblock=tcp://*:3000 +# BITCOIN_ZMQ_HOST="tcp://192.168.1.100:3000" + +API_PORT=3334 +STRATUM_PORT=3333 + +#optional telegram bot +#TELEGRAM_BOT_TOKEN= + +#optional discord bot +#DISCORD_BOT_CLIENTID= +#DISCORD_BOT_GUILD_ID= +#DISCORD_BOT_CHANNEL_ID= + +#optional +DEV_FEE_ADDRESS= +# mainnet | testnet +NETWORK=mainnet + +API_SECURE=false + +ENABLE_SOLO=true +ENABLE_PROXY=false + +BRAIINS_ACCESS_TOKEN= + +PROXY_PORT=3333 diff --git a/full-setup/public-pool-testnet.env b/full-setup/public-pool-testnet.env new file mode 100644 index 0000000..d548f0b --- /dev/null +++ b/full-setup/public-pool-testnet.env @@ -0,0 +1,34 @@ +BITCOIN_RPC_URL=http://bitcoin-testnet +BITCOIN_RPC_USER=bitcoin +BITCOIN_RPC_PASSWORD=bitcoin +BITCOIN_RPC_PORT=18332 +BITCOIN_RPC_TIMEOUT=10000 + +# Enable in bitcoin.conf with +# zmqpubrawblock=tcp://*:3000 +# BITCOIN_ZMQ_HOST="tcp://192.168.1.100:3000" + +API_PORT=13334 +STRATUM_PORT=13333 + +#optional telegram bot +#TELEGRAM_BOT_TOKEN= + +#optional discord bot +#DISCORD_BOT_CLIENTID= +#DISCORD_BOT_GUILD_ID= +#DISCORD_BOT_CHANNEL_ID= + +#optional +DEV_FEE_ADDRESS= +# mainnet | testnet +NETWORK=testnet + +API_SECURE=false + +ENABLE_SOLO=true +ENABLE_PROXY=false + +BRAIINS_ACCESS_TOKEN= + +PROXY_PORT=3333 diff --git a/src/models/StratumV1Client.ts b/src/models/StratumV1Client.ts index 789d90c..be643cd 100644 --- a/src/models/StratumV1Client.ts +++ b/src/models/StratumV1Client.ts @@ -622,4 +622,4 @@ export class StratumV1Client { } } -} \ No newline at end of file +}