Skip to content

Commit f2b9f08

Browse files
committed
init commit of 24.0.1 custom signet image
1 parent 533595d commit f2b9f08

37 files changed

+9789
-2
lines changed

Dockerfile

+65
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
FROM debian:buster-slim as builder
2+
3+
ARG BITCOIN_VERSION=${BITCOIN_VERSION:-24.0.1}
4+
ARG TRIPLET=${TRIPLET:-"x86_64-linux-gnu"}
5+
6+
RUN apt-get update && \
7+
apt-get install -qq --no-install-recommends ca-certificates dirmngr gosu wget libc6 procps python3
8+
WORKDIR /tmp
9+
10+
# install bitcoin binaries
11+
RUN BITCOIN_URL="https://bitcoincore.org/bin/bitcoin-core-${BITCOIN_VERSION}/bitcoin-${BITCOIN_VERSION}-${TRIPLET}.tar.gz" && \
12+
BITCOIN_FILE="bitcoin-${BITCOIN_VERSION}-${TRIPLET}.tar.gz" && \
13+
wget -qO "${BITCOIN_FILE}" "${BITCOIN_URL}" && \
14+
mkdir -p bin && \
15+
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"
16+
FROM debian:buster-slim as custom-signet-bitcoin
17+
18+
LABEL org.opencontainers.image.authors="NBD"
19+
LABEL org.opencontainers.image.licenses=MIT
20+
LABEL org.opencontainers.image.source="https://github.com/nbd-wtf/bitcoin_signet"
21+
22+
ENV BITCOIN_DIR /root/.bitcoin
23+
24+
ENV NBITS=${NBITS}
25+
ENV SIGNETCHALLENGE=${SIGNETCHALLENGE}
26+
ENV PRIVKEY=${PRIVKEY}
27+
28+
ENV RPCUSER=${RPCUSER:-"bitcoin"}
29+
ENV RPCPASSWORD=${RPCPASSWORD:-"bitcoin"}
30+
ENV COOKIEFILE=${COOKIEFILE:-"false"}
31+
ENV ONIONPROXY=${ONIONPROXY:-""}
32+
ENV TORPASSWORD=${TORPASSWORD:-""}
33+
ENV TORCONTROL=${TORCONTROL:-""}
34+
ENV I2PSAM=${I2PSAM:-""}
35+
36+
ENV UACOMMENT=${UACOMMENT:-"CustomSignet"}
37+
ENV ZMQPUBRAWBLOCK=${ZMQPUBRAWBLOCK:-"tcp://0.0.0.0:28332"}
38+
ENV ZMQPUBRAWTX=${ZMQPUBRAWTX:-"tcp://0.0.0.0:28333"}
39+
ENV ZMQPUBHASHBLOCK=${ZMQPUBHASHBLOCK:-"tcp://0.0.0.0:28334"}
40+
41+
ENV RPCBIND=${RPCBIND:-"0.0.0.0:38332"}
42+
ENV RPCALLOWIP=${RPCALLOWIP:-"0.0.0.0/0"}
43+
ENV WHITELIST=${WHITELIST:-"0.0.0.0/0"}
44+
ENV ADDNODE=${ADDNODE:-""}
45+
ENV BLOCKPRODUCTIONDELAY=${BLOCKPRODUCTIONDELAY:-""}
46+
ENV MINERENABLED=${MINERENABLED:-"1"}
47+
ENV MINETO=${MINETO:-""}
48+
ENV EXTERNAL_IP=${EXTERNAL_IP:-""}
49+
50+
VOLUME $BITCOIN_DIR
51+
EXPOSE 28332 28333 28334 38332 38333 38334
52+
RUN apt-get update && \
53+
apt-get install -qq --no-install-recommends procps python3 python3-pip jq && \
54+
apt-get clean
55+
COPY --from=builder "/tmp/bin" /usr/local/bin
56+
COPY docker-entrypoint.sh /usr/local/bin/entrypoint.sh
57+
COPY miner_imports /usr/local/bin
58+
COPY miner /usr/local/bin/miner
59+
COPY *.sh /usr/local/bin/
60+
COPY rpcauth.py /usr/local/bin/rpcauth.py
61+
RUN pip3 install setuptools
62+
63+
ENTRYPOINT ["/usr/local/bin/entrypoint.sh"]
64+
65+
CMD ["run.sh"]

README.md

+33-2
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,33 @@
1-
# bitcoin_signet
2-
Generic Signet Dockerfiles
1+
# Bitcoin Signet Docker Image
2+
## ENV Variables
3+
4+
* `BLOCKPRODUCTIONDELAY` - default sleep period between mining blocks (**mining mode only**)
5+
* if ~/.bitcoin/BLOCKPRODUCTIONDELAY.txt is present will use this value, allowing the delay to be dynamically changed.
6+
* `MINERENABLED` - flag for enabling mining chain
7+
* `NBITS` - sets min difficulty in mining (**mining mode only**)
8+
* `PRIVKEY` - private key of signet signer (**mining mode only**)
9+
* if `MINERENABLED=1` and not provided will generate this
10+
* `MINETO` - mine to a static address, if not provided will make new address for each block (**mining mode only**)
11+
* `SIGNETCHALLENGE` - sets the valid block producer for this signet
12+
* if `MINERENABLED=1` and not provided will generate this, if provded PRIVKEY also must be populated
13+
* Requied for client-mode
14+
*
15+
* `RPCUSER` - bitcoind RPC User
16+
* `RPCPASSWORD` - bitcoind RPC password
17+
*
18+
* `ONIONPROXY` - tor SOCK5 endpoint
19+
* `TORPASSWORD` - tor control port password
20+
* `TORCONTROL` - tor control port endpoint
21+
* `I2PSAM` - I2P control endpoint
22+
* `UACOMMENT` - UA Comment which would show on bitcoin-cli -netinfo printout
23+
*
24+
* `ZMQPUBRAWBLOCK` - bitcoind setting
25+
* `ZMQPUBRAWTX` - bitcoind setting
26+
* `ZMQPUBHASHBLOCK` - bitcoind setting
27+
*
28+
* `RPCBIND` - bitcoind setting
29+
* `RPCALLOWIP` - bitcoind setting
30+
* `WHITELIST` - bitcoind setting
31+
* `ADDNODE` - add seeding node location, comma-separate for multiple nodes (needed for client-mode)
32+
* `EXTERNAL_IP` - add public IP/onion endpoint information, comma-seperated for multiple IPs.
33+

docker-entrypoint.sh

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#!/bin/bash
2+
set -eo pipefail
3+
4+
shutdown_gracefully(){
5+
6+
echo "Container is shutting down, lets make sure bitcoind flushes the db."
7+
bitcoin-cli stop
8+
sleep 5
9+
}
10+
trap shutdown_gracefully SIGTERM SIGHUP SIGQUIT SIGINT
11+
12+
mkdir -p "${BITCOIN_DIR}"
13+
# check if this is first run if so run init if config
14+
if [[ ! -f "${BITCOIN_DIR}/install_done" ]]; then
15+
echo "install_done file not found, running install.sh."
16+
install.sh #this is config based on args passed into mining node or peer.
17+
else
18+
echo "install_done file exists, skipping setup process."
19+
echo "rewrite bitcoin.conf"
20+
gen-bitcoind-conf.sh >~/.bitcoin/bitcoin.conf
21+
fi
22+
23+
$@ &
24+
echo "Infinate loop"
25+
while true
26+
do
27+
tail -f /dev/null & wait ${!}
28+
done

gen-bitcoind-conf.sh

+63
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
SIGNETCHALLENGE=${SIGNETCHALLENGE:-$(cat ~/.bitcoin/SIGNETCHALLENGE.txt)}
2+
3+
RPCAUTH=$(/usr/local/bin/rpcauth.py $RPCUSER $RPCPASSWORD | tr -d '\n')
4+
echo "signet=1"
5+
6+
if [[ "$COOKIEFILE" == "true" ]]; then
7+
echo "rpccookiefile=/root/.bitcoin/.cookie
8+
rpcauth=$RPCAUTH"
9+
else
10+
echo "rpcauth=$RPCAUTH
11+
rpcuser=$RPCUSER
12+
rpcpassword=$RPCPASSWORD"
13+
fi
14+
15+
echo "txindex=1
16+
blockfilterindex=1
17+
peerblockfilters=1
18+
coinstatsindex=1
19+
dnsseed=0
20+
persistmempool=1
21+
uacomment=$UACOMMENT"
22+
23+
if [[ "$EXTERNAL_IP" != "" ]]; then
24+
echo $EXTERNAL_IP | tr ',' '\n' | while read ip; do
25+
echo "externalip=$ip"
26+
done
27+
fi
28+
29+
echo "[signet]
30+
daemon=1
31+
listen=1
32+
server=1
33+
discover=1
34+
signetchallenge=$SIGNETCHALLENGE
35+
zmqpubrawblock=$ZMQPUBRAWBLOCK
36+
zmqpubrawtx=$ZMQPUBRAWTX
37+
zmqpubhashblock=$ZMQPUBHASHBLOCK
38+
rpcbind=$RPCBIND
39+
rpcallowip=$RPCALLOWIP
40+
whitelist=$WHITELIST
41+
fallbackfee=0.0002"
42+
43+
if [[ "$ADDNODE" != "" ]]; then
44+
echo $ADDNODE | tr ',' '\n' | while read node; do
45+
echo "addnode=$node"
46+
done
47+
fi
48+
49+
50+
if [[ "$I2PSAM" != "" ]]; then
51+
echo "i2psam=$I2PSAM"
52+
fi
53+
if [[ "$ONIONPROXY" != "" ]]; then
54+
echo "onion=$ONIONPROXY" # unless have static IP won't resolve the control port as domain
55+
fi
56+
57+
if [[ "$TORPASSWORD" != "" ]]; then
58+
echo "torpassword=$TORPASSWORD"
59+
fi
60+
61+
if [[ "$TORCONTROL" != "" ]]; then
62+
echo "torcontrol=$TORCONTROL"
63+
fi

gen-signet-keys.sh

+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
DATADIR=${DATADIR:-"regtest-temp"}
2+
BITCOINCLI=${BITCOINCLI:-"bitcoin-cli -regtest -datadir=$DATADIR "}
3+
BITCOIND=${BITCOIND:-"bitcoind -datadir=$DATADIR -regtest -daemon "}
4+
5+
write_files() {
6+
# echo "ADDR=" $ADDR
7+
echo "PRIVKEY=" $PRIVKEY
8+
# echo "PUBKEY=" $PUBKEY
9+
echo "SIGNETCHALLENGE=" $SIGNETCHALLENGE
10+
# echo $ADDR > ~/.bitcoin/ADDR.txt
11+
echo $PRIVKEY >~/.bitcoin/PRIVKEY.txt
12+
# echo $PUBKEY > ~/.bitcoin/PUBKEY.txt
13+
echo $SIGNETCHALLENGE >~/.bitcoin/SIGNETCHALLENGE.txt
14+
}
15+
16+
if [[ "$MINERENABLED" == "1" && ("$SIGNETCHALLENGE" == "" || "$PRIVKEY" == "") ]]; then
17+
echo "Generating new signetchallange and privkey."
18+
#clean if exists
19+
rm -rf $DATADIR
20+
#make it fresh
21+
mkdir $DATADIR
22+
#kill any daemon running stuff
23+
pkill bitcoind
24+
#minimal config file (hardcode bitcoin:bitcoin for rpc)
25+
echo "
26+
regtest=1
27+
server=1
28+
rpcauth=bitcoin:c8c8b9740a470454255b7a38d4f38a52\$e8530d1c739a3bb0ec6e9513290def11651afbfd2b979f38c16ec2cf76cf348a
29+
rpcuser=bitcoin
30+
rpcpassword=bitcoin
31+
" >$DATADIR/bitcoin.conf
32+
#start daemon
33+
$BITCOIND -wallet="temp"
34+
#wait a bit for startup
35+
sleep 5s
36+
#create wallet
37+
$BITCOINCLI createwallet "temp"
38+
#export future signet seeding key data
39+
ADDR=$($BITCOINCLI getnewaddress)
40+
PRIVKEY=$($BITCOINCLI dumpprivkey $ADDR)
41+
PUBKEY=$($BITCOINCLI getaddressinfo $ADDR | jq .pubkey | tr -d '""')
42+
#don't need regtest anymore
43+
$BITCOINCLI stop
44+
SIGNETCHALLENGE=$(echo '5121'$PUBKEY'51ae')
45+
46+
#cleanup
47+
rm -rf $DATADIR
48+
else
49+
echo "Imported signetchallange and privkey being used."
50+
fi
51+
52+
write_files

install.sh

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
echo "Generate or import keyset"
2+
gen-signet-keys.sh
3+
echo "Generate bitcoind configuration"
4+
gen-bitcoind-conf.sh >~/.bitcoin/bitcoin.conf
5+
echo "Setup Signet"
6+
setup-signet.sh
7+
8+
if [[ "$MINE_GENESIS" == "1" ]]; then
9+
echo "Mine Genesis Block"
10+
mine-genesis.sh
11+
fi
12+
13+
touch ~/.bitcoin/install_done

mine-genesis.sh

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/bin/bash
2+
ADDR=${ADDR:-$(bitcoin-cli getnewaddress)}
3+
NBITS=${NBITS:-"1e0377ae"} #minimum difficulty in signet
4+
miner --cli="bitcoin-cli" generate --address=$ADDR --grind-cmd="bitcoin-util grind" --nbits=$NBITS --set-block-time=$(date +%s)
5+
6+

mine.sh

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#!/bin/bash
2+
NBITS=${NBITS:-"1e0377ae"} #minimum difficulty in signet
3+
4+
while true; do
5+
ADDR=${MINETO:-$(bitcoin-cli getnewaddress)}
6+
if [[ -f "${BITCOIN_DIR}/BLOCKPRODUCTIONDELAY.txt" ]]; then
7+
BLOCKPRODUCTIONDELAY_OVERRIDE=$(cat ~/.bitcoin/BLOCKPRODUCTIONDELAY.txt)
8+
echo "Delay OVERRIDE before next block" $BLOCKPRODUCTIONDELAY_OVERRIDE "seconds."
9+
sleep $BLOCKPRODUCTIONDELAY_OVERRIDE
10+
else
11+
BLOCKPRODUCTIONDELAY=${BLOCKPRODUCTIONDELAY:="0"}
12+
if [[ BLOCKPRODUCTIONDELAY -gt 0 ]]; then
13+
echo "Delay before next block" $BLOCKPRODUCTIONDELAY "seconds."
14+
sleep $BLOCKPRODUCTIONDELAY
15+
fi
16+
fi
17+
echo "Mine To:" $ADDR
18+
miner --cli="bitcoin-cli" generate --grind-cmd="bitcoin-util grind" --address=$ADDR --nbits=$NBITS --set-block-time=$(date +%s)
19+
done

0 commit comments

Comments
 (0)