Skip to content

feat: add zmq support #3

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 10 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
PRIVKEY=cUdVo9US5MwknUaHjSUu64iJD2DNtPv11Z8chgZHtLfydyaJqUsS
MINERENABLED=1
SIGNETCHALLENGE=51210232cc77c0e1ac931c691d2bd5e413523e9a284e96b7056cc202f119634465e9c551ae
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.env
19 changes: 13 additions & 6 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
FROM debian:buster-slim as builder

ARG BITCOIN_VERSION=${BITCOIN_VERSION:-27.0}
ARG BITCOIN_VERSION=${BITCOIN_VERSION:-d8434da3c14e}

ARG TARGETPLATFORM

Expand All @@ -14,7 +14,7 @@ WORKDIR /tmp
linux/arm64) \
echo "arm64" && export TRIPLET="aarch64-linux-gnu";; \
esac && \
BITCOIN_URL="https://bitcoincore.org/bin/bitcoin-core-${BITCOIN_VERSION}/bitcoin-${BITCOIN_VERSION}-${TRIPLET}.tar.gz" && \
BITCOIN_URL="https://github.com/benthecarman/bitcoin/releases/download/custom-signet-blocktime/bitcoin-${BITCOIN_VERSION}-${TRIPLET}.tar.gz" && \
BITCOIN_FILE="bitcoin-${BITCOIN_VERSION}-${TRIPLET}.tar.gz" && \
wget -qO "${BITCOIN_FILE}" "${BITCOIN_URL}" && \
mkdir -p bin && \
Expand All @@ -41,15 +41,22 @@ ENV TORCONTROL=${TORCONTROL:-""}
ENV I2PSAM=${I2PSAM:-""}

ENV UACOMMENT=${UACOMMENT:-"CustomSignet"}
ENV ZMQPUBRAWBLOCK=${ZMQPUBRAWBLOCK:-"tcp://0.0.0.0:28332"}
ENV ZMQPUBRAWTX=${ZMQPUBRAWTX:-"tcp://0.0.0.0:28333"}
ENV ZMQPUBHASHBLOCK=${ZMQPUBHASHBLOCK:-"tcp://0.0.0.0:28334"}
ENV ZMQPUBHASHBLOCK=${ZMQPUBHASHBLOCK:-"tcp://0.0.0.0:28332"}
ENV ZMQPUBHASHTX=${ZMQPUBRAWTX:-"tcp://0.0.0.0:28333"}
ENV ZMQPUBRAWBLOCK=${ZMQPUBRAWBLOCK:-"tcp://0.0.0.0:28334"}
ENV ZMQPUBRAWTX=${ZMQPUBRAWTX:-"tcp://0.0.0.0:28335"}
ENV ZMQPUBSEQUENCE=${ZMQPUBSEQUENCE:-"tcp://0.0.0.0:28336"}

ENV RPCTHREADS=${RPCTHREADS:-"16"}
ENV RPCSERVERTIMEOUT=${RPCSERVERTIMEOUT:-"600"}
ENV RPCWORKQUEUE=${RPCWORKQUEUE:-"50"}


ENV RPCBIND=${RPCBIND:-"0.0.0.0:38332"}
ENV RPCALLOWIP=${RPCALLOWIP:-"0.0.0.0/0"}
ENV WHITELIST=${WHITELIST:-"0.0.0.0/0"}
ENV ADDNODE=${ADDNODE:-""}
ENV BLOCKPRODUCTIONDELAY=${BLOCKPRODUCTIONDELAY:-""}
ENV BLOCKPRODUCTIONDELAY=${BLOCKPRODUCTIONDELAY:-"30"}
ENV MINERENABLED=${MINERENABLED:-"1"}
ENV MINETO=${MINETO:-""}
ENV EXTERNAL_IP=${EXTERNAL_IP:-""}
Expand Down
26 changes: 26 additions & 0 deletions docker-compose-28.1.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
services:
bitcoind-miner:
build:
context: .
dockerfile: official.Dockerfile
args:
TARGETPLATFORM: linux/arm64
container_name: bitcoin-miner-28.1
env_file:
.env
environment:
BLOCKPRODUCTIONDELAY: 600
RPCUSER: user
RPCPASSWORD: password
PRIVKEY: $PRIVKEY
SIGNETCHALLENGE: $SIGNETCHALLENGE
MINERENABLED: $MINERENABLED
OFFICIAL_MINING: true

ports:
- "28332:28332"
- "28333:28333"
- "28334:28334"
- "38332:38332"
- "38333:38333"
- "38334:38334"
42 changes: 42 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
services:
bitcoind-miner:
container_name: bitcoin-miner
# image: alpen_signet:1.0
build:
context: .
dockerfile: Dockerfile
env_file:
.env
environment:
BLOCKPRODUCTIONDELAY: 10
RPCUSER: user
RPCPASSWORD: password
PRIVKEY: $PRIVKEY
SIGNETCHALLENGE: $SIGNETCHALLENGE
MINERENABLED: $MINERENABLED
ports:
- "28332:28332"
- "28333:28333"
- "28334:28334"
- "38332:38332"
- "38333:38333"
- "38334:38334"

bitcoind-fullnode:
container_name: bitcoin-fullnode
# image: alpen_signet:1.0
build:
context: .
dockerfile: Dockerfile

environment:
BLOCKPRODUCTIONDELAY: 10
RPCPASSWORD: password
SIGNETCHALLENGE: 512102a772f06f3860f4c1b803734db603f1c0cd86601a27670aadf5ff364a1d34f92551ae
MINERENABLED: 0
ADDNODE: bitcoin-miner:38333

ports:
- "38335:38332"
- "38336:38333"
- "38337:38334"
2 changes: 1 addition & 1 deletion docker-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ else
fi

$@ &
echo "Infinate loop"
echo "Infinite loop"
while true
do
tail -f /dev/null & wait ${!}
Expand Down
18 changes: 17 additions & 1 deletion gen-bitcoind-conf.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,35 @@ if [[ "$EXTERNAL_IP" != "" ]]; then
done
fi

echo "rpcthreads=$RPCTHREADS
rpcservertimeout=$RPCSERVERTIMEOUT
rpcworkqueue=$RPCWORKQUEUE"

echo "[signet]
rest=1
daemon=1
listen=1
server=1
acceptnonstdtxn=1
v2transport=1
discover=1
signetblocktime=$BLOCKPRODUCTIONDELAY
signetchallenge=$SIGNETCHALLENGE

zmqpubhashblock=$ZMQPUBHASHBLOCK
zmqpubrawblock=$ZMQPUBRAWBLOCK
zmqpubrawtx=$ZMQPUBRAWTX
zmqpubhashtx=$ZMQPUBHASHTX
zmqpubhashblock=$ZMQPUBHASHBLOCK
zmqpubsequence=$ZMQPUBSEQUENCE

rpcbind=$RPCBIND
rpcallowip=$RPCALLOWIP
whitelist=$WHITELIST
fallbackfee=0.0002"
fallbackfee=0.0002
minrelaytxfee=0.0
blockmintxfee=0.0
dustRelayFee=0.0"

if [[ "$ADDNODE" != "" ]]; then
echo $ADDNODE | tr ',' '\n' | while read node; do
Expand Down
2 changes: 1 addition & 1 deletion gen-signet-keys.sh
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ if [[ "$MINERENABLED" == "1" && ("$SIGNETCHALLENGE" == "" || "$PRIVKEY" == "") ]
rpcpassword=bitcoin
" >$DATADIR/bitcoin.conf
#start daemon
$BITCOIND -wallet="temp"
$BITCOIND -wallet="temp" -deprecatedrpc=create_bdb
#wait a bit for startup
sleep 5s
#create wallet
Expand Down
24 changes: 22 additions & 2 deletions mine.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,28 @@
#!/bin/bash
NBITS=${NBITS:-"1e0377ae"} #minimum difficulty in signet
if [[ -f "${BITCOIN_DIR}/MINE_ADDRESS.txt" ]]; then
ADDR=$(cat ~/.bitcoin/MINE_ADDRESS.txt)
else
ADDR=${MINETO:-$(bitcoin-cli -rpcwallet=custom_signet getnewaddress)}
fi
echo "Mineto: $MINETO"
echo "Initial mining address: $ADDR"

# Initial mining of 101 blocks if blocks count is less than 101
BLOCKS_COUNT=$(bitcoin-cli -rpcwallet=custom_signet getblockcount)
if [[ $BLOCKS_COUNT -lt 101 ]]; then
echo "Mining initial blocks until 101"
while [[ $BLOCKS_COUNT -lt 101 ]]; do
echo "Mining initial block $BLOCKS_COUNT"
miner --cli="bitcoin-cli" generate --grind-cmd="bitcoin-util grind" --address=$ADDR --nbits=$NBITS --set-block-time=$(date +%s)
BLOCKS_COUNT=$(bitcoin-cli -rpcwallet=custom_signet getblockcount)
done
else
echo "Starting bitcoind mining from block $BLOCKS_COUNT"
fi


while true; do
ADDR=${MINETO:-$(bitcoin-cli getnewaddress)}
if [[ -f "${BITCOIN_DIR}/BLOCKPRODUCTIONDELAY.txt" ]]; then
BLOCKPRODUCTIONDELAY_OVERRIDE=$(cat ~/.bitcoin/BLOCKPRODUCTIONDELAY.txt)
echo "Delay OVERRIDE before next block" $BLOCKPRODUCTIONDELAY_OVERRIDE "seconds."
Expand All @@ -16,4 +36,4 @@ while true; do
fi
echo "Mine To:" $ADDR
miner --cli="bitcoin-cli" generate --grind-cmd="bitcoin-util grind" --address=$ADDR --nbits=$NBITS --set-block-time=$(date +%s)
done
done
87 changes: 87 additions & 0 deletions official.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
FROM debian:bookworm-slim as builder

ARG BITCOIN_VERSION=${BITCOIN_VERSION:-28.1}

ARG TARGETPLATFORM

RUN apt-get update && \
apt-get install -qq --no-install-recommends ca-certificates dirmngr gosu wget libc6 procps python3
WORKDIR /tmp
# install bitcoin binaries
RUN case $TARGETPLATFORM in \
linux/amd64) \
echo "amd64" && export TRIPLET="x86_64-linux-gnu";; \
linux/arm64) \
echo "arm64" && export TRIPLET="aarch64-linux-gnu";; \
esac && \
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}" && \
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" "bitcoin-${BITCOIN_VERSION}/bin/bitcoin-util"

# Download zipped sourced code for the tag and extract miner.py

# FROM debian:buster-slim as custom-signet-bitcoin
FROM debian:bookworm-slim as custom-signet-bitcoin


LABEL org.opencontainers.image.authors="Alpenlabs"
LABEL org.opencontainers.image.licenses=MIT
LABEL org.opencontainers.image.source="https://github.com/alpenlabs/bitcoin_signet"

ENV BITCOIN_DIR /root/.bitcoin


ENV RPCUSER=${RPCUSER:-"bitcoin"}
ENV RPCPASSWORD=${RPCPASSWORD:-"bitcoin"}
ENV COOKIEFILE=${COOKIEFILE:-"false"}
ENV ONIONPROXY=${ONIONPROXY:-""}
ENV TORPASSWORD=${TORPASSWORD:-""}
ENV TORCONTROL=${TORCONTROL:-""}
ENV I2PSAM=${I2PSAM:-""}

ENV UACOMMENT=${UACOMMENT:-"CustomSignet"}

ENV ZMQPUBHASHBLOCK=${ZMQPUBHASHBLOCK:-"tcp://0.0.0.0:28332"}
ENV ZMQPUBHASHTX=${ZMQPUBRAWTX:-"tcp://0.0.0.0:28333"}
ENV ZMQPUBRAWBLOCK=${ZMQPUBRAWBLOCK:-"tcp://0.0.0.0:28334"}
ENV ZMQPUBRAWTX=${ZMQPUBRAWTX:-"tcp://0.0.0.0:28335"}
ENV ZMQPUBSEQUENCE=${ZMQPUBSEQUENCE:-"tcp://0.0.0.0:28336"}

ENV RPCTHREADS=${RPCTHREADS:-"16"}
ENV RPCSERVERTIMEOUT=${RPCSERVERTIMEOUT:-"600"}
ENV RPCWORKQUEUE=${RPCWORKQUEUE:-"50"}


ENV RPCBIND=${RPCBIND:-"0.0.0.0:38332"}
ENV RPCALLOWIP=${RPCALLOWIP:-"0.0.0.0/0"}
ENV WHITELIST=${WHITELIST:-"0.0.0.0/0"}
ENV ADDNODE=${ADDNODE:-""}
ENV BLOCKPRODUCTIONDELAY=${BLOCKPRODUCTIONDELAY:-"30"}
ENV MINERENABLED=${MINERENABLED:-"1"}
ENV MINETO=${MINETO:-""}
ENV EXTERNAL_IP=${EXTERNAL_IP:-""}

# Variable used to generate wallets used by bridge operators
# TODO: update this logic to match Testnet I requirement
ENV NUM_WALLETS=${NUM_WALLETS:-0}
VOLUME $BITCOIN_DIR
EXPOSE 28332 28333 28334 38332 38333 38334
RUN apt-get update && \
apt-get install -qq --no-install-recommends procps python3 python3-pip jq && \
apt-get clean
COPY --from=builder "/tmp/bin" /usr/local/bin
COPY *.sh /usr/local/bin/

# TODO: figure out these imports for the miner script
COPY miner_imports /usr/local/bin
# FIXME: the miner script should be used from the tar file of the downloaded source code
COPY miner /usr/local/bin/miner
COPY rpcauth.py /usr/local/bin/rpcauth.py
# RUN pip3 install setuptools
RUN pip3 install --break-system-packages setuptools

ENTRYPOINT ["/usr/local/bin/docker-entrypoint.sh"]

CMD ["run.sh"]
2 changes: 1 addition & 1 deletion run.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/bash

# run bitcoind
bitcoind --daemonwait
bitcoind --daemonwait -deprecatedrpc=create_bdb
sleep 5
echo "get magic"
magic=$(cat /root/.bitcoin/signet/debug.log | grep -m1 magic)
Expand Down
2 changes: 1 addition & 1 deletion setup-signet.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
PRIVKEY=${PRIVKEY:-$(cat ~/.bitcoin/PRIVKEY.txt)}
DATADIR=${DATADIR:-~/.bitcoin/}
bitcoind -datadir=$DATADIR --daemonwait -persistmempool
bitcoind -datadir=$DATADIR --daemonwait -persistmempool -deprecatedrpc=create_bdb
bitcoin-cli -datadir=$DATADIR -named createwallet wallet_name="custom_signet" load_on_startup=true descriptors=false

#only used in case of mining node
Expand Down