diff --git a/GNUmakefile b/GNUmakefile new file mode 100644 index 0000000..cd671dd --- /dev/null +++ b/GNUmakefile @@ -0,0 +1,91 @@ +SHELL := /bin/bash + +PWD ?= pwd_unknown + +THIS_FILE := $(lastword $(MAKEFILE_LIST)) +export THIS_FILE +TIME := $(shell date +%s) +export TIME + +ifeq ($(docker),) +DOCKER := $(shell which docker) +else +DOCKER := $(docker) +endif +export DOCKER + +ifeq ($(compose),) +DOCKER_COMPOSE := $(shell which docker-compose) +else +DOCKER_COMPOSE := $(compose) +endif +export DOCKER_COMPOSE + + + +PYTHON := $(shell which python) +export PYTHON +PYTHON2 := $(shell which python2) +export PYTHON2 +PYTHON3 := $(shell which python3) +export PYTHON3 + +PIP := $(shell which pip) +export PIP +PIP2 := $(shell which pip2) +export PIP2 +PIP3 := $(shell which pip3) +export PIP3 + +python_version_full := $(wordlist 2,4,$(subst ., ,$(shell python3 --version 2>&1))) +python_version_major := $(word 1,${python_version_full}) +python_version_minor := $(word 2,${python_version_full}) +python_version_patch := $(word 3,${python_version_full}) + +my_cmd.python.3 := $(PYTHON3) some_script.py3 +my_cmd := ${my_cmd.python.${python_version_major}} + +PYTHON_VERSION := ${python_version_major}.${python_version_minor}.${python_version_patch} +PYTHON_VERSION_MAJOR := ${python_version_major} +PYTHON_VERSION_MINOR := ${python_version_minor} + +export python_version_major +export python_version_minor +export python_version_patch +export PYTHON_VERSION + +# PROJECT_NAME defaults to name of the current directory. +ifeq ($(project),) +PROJECT_NAME := $(notdir $(PWD)) +else +PROJECT_NAME := $(project) +endif +export PROJECT_NAME + + + + +.PHONY: venv +venv: + test -d .venv || $(PYTHON3) -m virtualenv .venv + ( \ + source .venv/bin/activate; pip install -r requirements.txt; \ + ); + @echo "To activate (venv)" + @echo "try:" + @echo ". .venv/bin/activate" + @echo "or:" + @echo "make test-venv" +##: test-venv source .venv/bin/activate; pip install -r requirements.txt; +test-venv: + # insert test commands here + test -d .venv || $(PYTHON3) -m virtualenv .venv + ( \ + source .venv/bin/activate; pip install -r requirements.txt; \ + ); +####################### +.PHONY: prune-network +prune-network: + $(DOCKER_COMPOSE) -p $(PROJECT_NAME) down + docker network rm $(PROJECT_NAME)_default 2>/dev/null || echo "retry..." +####################### \ No newline at end of file diff --git a/bitcoin-signet/Dockerfile b/bitcoin-signet/Dockerfile index 7c4cd96..7b1640d 100644 --- a/bitcoin-signet/Dockerfile +++ b/bitcoin-signet/Dockerfile @@ -3,7 +3,6 @@ FROM debian:buster-slim as builder ARG BITCOIN_VERSION=23.0 ARG TRIPLET=${TRIPLET} - #RUN apt-add-repository ppa:bitcoin/bitcoin && apt-get update && apt-get install bitcoin #RUN /lib64/ld-linux-x86-64.so.2 /bin/chmod +x /bin/chmod @@ -15,7 +14,9 @@ WORKDIR /tmp # install bitcoin binaries RUN BITCOIN_URL="https://bitcoincore.org/bin/bitcoin-core-${BITCOIN_VERSION}/bitcoin-${BITCOIN_VERSION}-${TRIPLET}.tar.gz" && \ BITCOIN_FILE="bitcoin-${BITCOIN_VERSION}-${TRIPLET}.tar.gz" && \ - wget -qO "${BITCOIN_FILE}" "${BITCOIN_URL}" && \ + BITCOIN_SHA_URL="https://bitcoincore.org/bin/bitcoin-core-${BITCOIN_VERSION}/SHA256SUMS" && \ + wget -qO "${BITCOIN_FILE}" "${BITCOIN_URL}" && wget -qO SHA256SUMS.asc "${BITCOIN_SHA_URL}" && \ + grep "${BITCOIN_FILE}" SHA256SUMS.asc | sha256sum -c - && \ mkdir -p bin && \ tar -xzvf "${BITCOIN_FILE}" -C /tmp/bin --strip-components=2 "bitcoin-${BITCOIN_VERSION}/bin/bitcoin-cli" "bitcoin-${BITCOIN_VERSION}/bin/bitcoind" "bitcoin-${BITCOIN_VERSION}/bin/bitcoin-wallet" diff --git a/bitcoin-signet/bitcoin.conf b/bitcoin-signet/bitcoin.conf index a6e4d54..5b737d5 100644 --- a/bitcoin-signet/bitcoin.conf +++ b/bitcoin-signet/bitcoin.conf @@ -12,4 +12,4 @@ zmqpubrawblock=tcp://0.0.0.0:28332 zmqpubrawtx=tcp://0.0.0.0:28333 zmqpubhashblock=tcp://0.0.0.0:28334 signetchallenge=512102ee856c56a5aaadd1656f849bafa4c9dacc86a2878fe546c6189185f842ae2c1851ae -addnode=104.131.10.218:38333 +addnode=104.131.10.218:38333 diff --git a/bitcoin-signet/docker-entrypoint.sh b/bitcoin-signet/docker-entrypoint.sh deleted file mode 100755 index 9d1b5f4..0000000 --- a/bitcoin-signet/docker-entrypoint.sh +++ /dev/null @@ -1,13 +0,0 @@ -#!/bin/bash -set -eo pipefail - -mkdir -p "${BITCOIN_DIR}" - -if [[ ! -f "${BITCOIN_DIR}/bitcoin.conf" ]]; then - echo "bitcoin.conf file not found in volume, copying to ${BITCOIN_DIR}/bitcoin.conf" - cp /usr/local/etc/bitcoin.conf "${BITCOIN_DIR}/bitcoin.conf" -else - echo "bitcoin.conf file exists, skipping." -fi - -exec "$@" diff --git a/docker-compose.yaml.template b/docker-compose.yaml.template index 1a93a5b..553d958 100644 --- a/docker-compose.yaml.template +++ b/docker-compose.yaml.template @@ -3,7 +3,7 @@ networks: {} services: bitcoind: build: - context: ./bitcoin-signet + context: ../bitcoin-signet dockerfile: Dockerfile args: - TRIPLET=${TRIPLET} @@ -25,10 +25,7 @@ services: source: ${oc.env:PWD}/volumes/bitcoin_datadir_${bitcoind_i} target: /root/.bitcoin/ lnd: - build: - context: ./lnd-signet - dockerfile: Dockerfile - image: playground-cluster-lnd + image: ghcr.io/plebnet-playground/playground-lnd:latest links: - bitcoind-${bitcoind_i} - tor-${tor_i} @@ -60,10 +57,7 @@ services: target: /root/.lnd/ tor: restart: unless-stopped - build: - context: ./tor - dockerfile: Dockerfile - image: playground-cluster-tor + image: ghcr.io/plebnet-playground/playground-tor:latest container_name: playground-tor-${tor_i} environment: TRIPLET: '${TRIPLET}' diff --git a/lnd-signet/docker-entrypoint.sh b/lnd-signet/docker-entrypoint.sh index cfcd4b7..4b4e17d 100755 --- a/lnd-signet/docker-entrypoint.sh +++ b/lnd-signet/docker-entrypoint.sh @@ -74,4 +74,4 @@ if [[ "$@" = "lnd" ]]; then exec lnd "--tor.targetipaddress=${localhostip}" else exec "$@" -fi \ No newline at end of file +fi diff --git a/lnd-signet/docker-initwalletcreate.sh b/lnd-signet/docker-initwalletcreate.sh deleted file mode 100755 index f5b495a..0000000 --- a/lnd-signet/docker-initwalletcreate.sh +++ /dev/null @@ -1,59 +0,0 @@ - -echo "[lnd_unlock] Waiting 2 seconds for lnd..." -sleep 2 - -LND_DIR=/root/.lnd - -echo "waiting for wallet create phase" -while - if grep -q 'lncli create' $LND_DIR/logs/bitcoin/signet/lnd.log; - then - echo "ready to create...." - #Need to run the python gRPC HERE - break; - else - sleep 2; - echo "waiting to create." - fi -do true; done - -#once we get here we will want to change lnd.conf with wallet-unlock-file stuff - -curl -X GET --cacert $LND_DIR/tls.cert https://localhost:8080/v1/genseed | jq .cipher_seed_mnemonic | tr -d '\n'| tr -d ' ' > $LND_DIR/seeds.txt - # { - # "cipher_seed_mnemonic": , - # "enciphered_seed": , - # } - # cat seeds.txt | jq .cipher_seed_mnemonic | tr -d '\n' -#password is 12345678 -postdata='{"wallet_password":"MTIzNDU2Nzg=","cipher_seed_mnemonic":' -postdata+=$(cat $LND_DIR/seeds.txt) -postdata+='}' - -curl -X POST --cacert $LND_DIR/tls.cert -s https://localhost:8080/v1/initwallet -d $postdata - -echo "12345678" > /root/.lnd/unlock.password -echo "wallet-unlock-password-file=/root/.lnd/unlock.password" >> /root/.lnd/lnd.conf - - -# ensure that lnd is up and running before proceeding -while - CA_CERT="/root/.lnd/tls.cert" - LND_WALLET_DIR="/root/.lnd/data/chain/bitcoin/signet/" - MACAROON_HEADER="Grpc-Metadata-macaroon: $(xxd -p -c 1000 /root/.lnd/data/chain/bitcoin/signet/admin.macaroon | tr '[:lower:]' '[:upper:]')" - echo $MACAROON_HEADER - STATUS_CODE=$(curl -s --cacert "$CA_CERT" -H "$MACAROON_HEADER" -o /dev/null -w "%{http_code}" https://localhost:8080/v1/getinfo) - # if lnd is running it'll either return 200 if unlocked (noseedbackup=1) or 404 if it needs initialization/unlock - if [ "$STATUS_CODE" == "200" ] || [ "$STATUS_CODE" == "404" ] ; then - PUBKEY=$(curl -X GET --cacert "$CA_CERT" -s --header "$MACAROON_HEADER" https://localhost:8080/v1/getinfo | jq .identity_pubkey | tr -d '"') - echo "Public Key: ${PUBKEY}" - echo "alias=${n}-${PUBKEY:0:16}" >> /root/.lnd/lnd.conf - break - else - echo "[lnd_unlock] LND still didn't start, got $STATUS_CODE status code back... waiting another 2 seconds..." - sleep 2 - fi -do true; done - -echo "Restarting to grab new alias." -reboot diff --git a/make-bitcoin-config.sh b/make-bitcoin-config.sh deleted file mode 100755 index e5d9472..0000000 --- a/make-bitcoin-config.sh +++ /dev/null @@ -1,24 +0,0 @@ -declare LND_LISTEN=playground-lnd:9735 -declare LND_RPCLISTEN=playground-lnd:10009 -declare LND_RESTLISTEN=playground-lnd:8080 -declare zmqpubrawblock=tcp://playground-bitcoind:28332 -declare zmqpubrawtx=tcp://playground-bitcoind:28333 -declare torsocks=playground-tor:9050 -declare torcontrol=playground-tor:9051 -echo " -signet=1 -rpcauth=bitcoin:c8c8b9740a470454255b7a38d4f38a52\$e8530d1c739a3bb0ec6e9513290def11651afbfd2b979f38c16ec2cf76cf348a -txindex=1 -server=1 -dnsseed=0 -[signet] -rpcbind=0.0.0.0:38332 -rpcallowip=0.0.0.0/0 -whitelist=0.0.0.0/0 -zmqpubrawblock=tcp://0.0.0.0:28332 -zmqpubrawtx=tcp://0.0.0.0:28333 -zmqpubhashblock=tcp://0.0.0.0:28334 -signetchallenge=512102ee856c56a5aaadd1656f849bafa4c9dacc86a2878fe546c6189185f842ae2c1851ae -addnode=104.131.10.218:38333 - -" \ No newline at end of file diff --git a/make-lnd-config.sh b/make-lnd-config.sh deleted file mode 100755 index 7b764e3..0000000 --- a/make-lnd-config.sh +++ /dev/null @@ -1,43 +0,0 @@ -declare LND_LISTEN=playground-lnd:9735 -declare LND_RPCLISTEN=playground-lnd:10009 -declare LND_RESTLISTEN=playground-lnd:8080 -declare zmqpubrawblock=tcp://playground-bitcoind:28332 -declare zmqpubrawtx=tcp://playground-bitcoind:28333 -declare torsocks=playground-tor:9050 -declare torcontrol=playground-tor:9051 -echo " -[Application Options] -listen=${LND_LISTEN} -rpclisten=${LND_RPCLISTEN} -rpclisten=127.0.0.1:10009 -restlisten=${LND_RESTLISTEN} -restlisten=127.0.0.1:8080 -minchansize=100000 -ignore-historical-gossip-filters=true -accept-keysend=true -accept-amp=true -allow-circular-route=true -numgraphsyncpeers=3 -[Bitcoin] -bitcoin.active=true -bitcoin.mainnet=false -bitcoin.signet=true -bitcoin.signetseednode=104.131.10.218 -bitcoin.node=bitcoind -bitcoin.dnsseed=0 -[Bitcoind] -bitcoind.dir=/var/lib/bitcoind/ -bitcoind.rpchost=playground-bitcoind -bitcoind.rpcuser=bitcoin -bitcoind.rpcpass=bitcoin -bitcoind.zmqpubrawblock=${zmqpubrawblock} -bitcoind.zmqpubrawtx=${zmqpubrawtx} -[tor] -tor.active=true -tor.socks=${torsocks} -tor.control=${torcontrol} -tor.password=hello -tor.v3=true -[protocol] -protocol.wumbo-channels=true -" \ No newline at end of file diff --git a/plebnet_generate.py b/plebnet_generate.py index 9100161..26e2356 100644 --- a/plebnet_generate.py +++ b/plebnet_generate.py @@ -69,8 +69,8 @@ def get_service_values(i, node_counts, **kwargs): service_values, conf.services[service]) # remove build for additional nodes - if i > 0: - conf.services[service_name].pop('build') + # if i > 0: + # conf.services[service_name].pop('build') conf.services.pop(service) try: OmegaConf.resolve(conf) diff --git a/tor/docker-entrypoint.sh b/tor/docker-entrypoint.sh deleted file mode 100755 index 38d6472..0000000 --- a/tor/docker-entrypoint.sh +++ /dev/null @@ -1,22 +0,0 @@ -#!/bin/sh - -mkdir -p "$(dirname $TOR_CONFIG)" - -mkdir -p "$TOR_DATA" -chown -R tor "$TOR_DATA" -chmod 700 "$TOR_DATA" - -mkdir -p "/var/lib/tor/hidden_services" -chown -R tor /var/lib/tor/hidden_services -chmod 700 /var/lib/tor/hidden_services - -if [[ ! -f $TOR_CONFIG ]]; then - echo "$TOR_CONFIG file not found in volume." - cp /torrc $TOR_CONFIG -else - echo "$TOR_CONFIG file exists, skipping." -fi - -chown -R tor "$(dirname $TOR_CONFIG)" - -exec gosu tor "$@" \ No newline at end of file diff --git a/tor/torrc b/tor/torrc deleted file mode 100644 index 9a91551..0000000 --- a/tor/torrc +++ /dev/null @@ -1,5 +0,0 @@ -ControlPort 0.0.0.0:9051 -SOCKSPort 0.0.0.0:9050 -HashedControlPassword 16:A170E9325684E5366021C2AA404D4CA5AAE0D6FFE947E60B939083EF61 -CookieAuthentication 1 -CookieAuthFileGroupReadable 1 \ No newline at end of file diff --git a/up-generic.sh b/up-generic.sh index b8fd092..ce7a70b 100755 --- a/up-generic.sh +++ b/up-generic.sh @@ -1,32 +1,33 @@ #This is for internal testing only +if [ -z "$1" ]; then + $1=5 +fi : ${TRIPLET:=x86_64-linux-gnu} -: ${bitcoind=1} -: ${lnd=1} -: ${tor=1} +: ${bitcoind=$1} +: ${lnd=$1} +: ${tor=$1} python plebnet_generate.py TRIPLET=$TRIPLET bitcoind=$bitcoind lnd=$lnd tor=$tor #Remove -docker-compose down -sudo rm -rf volumes - +docker-compose down #Create Datafile +mkdir -p volumes -mkdir volumes for (( i=0; i<=$bitcoind-1; i++ )) do - mkdir volumes/bitcoin_datadir_$i + mkdir -p volumes/bitcoin_datadir_$i done for (( i=0; i<=$lnd-1; i++ )) do - mkdir volumes/lnd_datadir_$i + mkdir -p volumes/lnd_datadir_$i done for (( i=0; i<=$tor-1; i++ )) do - mkdir volumes/tor_datadir_$i - mkdir volumes/tor_servicesdir_$i - mkdir volumes/tor_torrcdir_$i + mkdir -p volumes/tor_datadir_$i + mkdir -p volumes/tor_servicesdir_$i + mkdir -p volumes/tor_torrcdir_$i done docker-compose build --build-arg TRIPLET=$TRIPLET diff --git a/up-x64.sh b/up-x64.sh index 0bc9c47..f342d7a 100755 --- a/up-x64.sh +++ b/up-x64.sh @@ -1,37 +1,66 @@ if [[ $# -ne 1 ]]; -then +then echo "up-x64.sh (# of instances)" exit fi +while ! docker system info > /dev/null 2>&1; do + echo "Waiting for docker to start..." + if [[ "$(uname -s)" == "Linux" ]]; then + systemctl restart docker.service + fi + if [[ "$(uname -s)" == "Darwin" ]]; then + open --background -a /./Applications/Docker.app/Contents/MacOS/Docker + fi + + sleep 1; + +done + #This is for internal testing only declare TRIPLET=x86_64-linux-gnu declare torcount=$(expr $1 / 8 + 1) python plebnet_generate.py TRIPLET=x86_64-linux-gnu bitcoind=$1 lnd=$1 tor=$torcount #Remove -docker-compose down -sudo rm -rf volumes - +docker compose down || docker-compose down +sudo -s chown -R $(id -u) * +sudo -s rm -rf volumes + #Create Datafile +sudo -s mkdir volumes -mkdir volumes +sudo -s chown -R $(id -u) * declare n=$1 for (( i=0; i<=n-1; i++ )) do - mkdir volumes/lnd_datadir_$i - mkdir volumes/bitcoin_datadir_$i - + echo $i + mkdir -p volumes/lnd_datadir_$i + mkdir -p volumes/bitcoin_datadir_$i + # mkdir volumes/tor_torrcdir_1 done -for (( i=0; i<=torcount-1; i++ )) -do - mkdir volumes/tor_datadir_$i - mkdir volumes/tor_servicesdir_$i - mkdir volumes/tor_torrcdir_$i +for (( i=0; i<=torcount; i++ )) +do + echo $i + mkdir -p volumes/tor_datadir_$i + mkdir -p volumes/tor_servicesdir_$i + mkdir -p volumes/tor_torrcdir_$i +done + +while ! docker system info > /dev/null 2>&1; do + echo "Waiting for docker to start..." + if [[ "$(uname -s)" == "Linux" ]]; then + systemctl restart docker.service + fi + if [[ "$(uname -s)" == "Darwin" ]]; then + open --background -a /./Applications/Docker.app/Contents/MacOS/Docker + fi + + sleep 1; + done -docker-compose build --build-arg TRIPLET=$TRIPLET -docker-compose up -d +docker compose build --parallel --build-arg TRIPLET=$TRIPLET || docker-compose build --parallel --build-arg TRIPLET=$TRIPLET +docker compose up --remove-orphans -d || docker-compose up --remove-orphans -d -