reworked docker to use lncm images

This commit is contained in:
Elyan 2024-02-21 10:34:40 -08:00
parent c20a8643b3
commit 2d5f75e6a0
4 changed files with 56 additions and 131 deletions

View File

@ -1,24 +1,4 @@
# Build stage for Bitcoin Core
FROM ubuntu as builder
# Install build dependencies
RUN apt-get update && apt-get install -y \
build-essential libtool autotools-dev automake \
pkg-config bsdmainutils python3 libssl-dev \
libevent-dev libboost-system-dev libboost-filesystem-dev \
libboost-chrono-dev libboost-test-dev libboost-thread-dev \
libdb-dev libdb++-dev python3-pip jq git
# Clone and build Bitcoin Core
RUN git clone https://github.com/bitcoin/bitcoin.git
# Build Bitcoin core
WORKDIR /bitcoin
RUN ./autogen.sh
RUN ./configure
RUN make
# Application stage
# Use a base image with the necessary runtime dependencies
FROM ubuntu
# Install runtime dependencies
@ -26,13 +6,7 @@ RUN apt-get update && apt-get install -y \
python3 libssl-dev libevent-dev libboost-system-dev libboost-filesystem-dev \
libboost-chrono-dev libboost-test-dev libboost-thread-dev libdb-dev libdb++-dev python3-pip jq
# Copy Binaries and scripts from the builder stage
COPY --from=builder /bitcoin/src/bitcoind /usr/local/bin/
COPY --from=builder /bitcoin/src/bitcoin-cli /usr/local/bin/
COPY --from=builder /bitcoin/contrib/signet/miner /usr/local/bin/
RUN chmod +x /usr/local/bin/miner
# Copy and prepare sript for signet configurations
# Copy and prepare script for signet configurations
COPY generate_signet.sh /usr/local/bin
RUN chmod +x /usr/local/bin/generate_signet.sh
@ -41,13 +15,15 @@ COPY bitcoin.conf /root/.bitcoin/bitcoin.conf
# Copy the logtail.sh script
COPY logtail.sh /usr/local/bin/
RUN chmod +x usr/local/bin/logtail.sh
RUN chmod +x /usr/local/bin/logtail.sh
# Copy the .bashrc file to the container's root directory
COPY .bashrc /root/.bashrc
# Expose necessary ports
EXPOSE 38333 38332
# Expose necessary ports (update these if needed)
EXPOSE 18443
# EXPOSE 38333
# Start Bitcoin Core
CMD ["usr/local/bin/generate_signet.sh"]
CMD ["/usr/local/bin/generate_signet.sh"]

View File

@ -4,7 +4,7 @@ daemon=1
# Custom Signet challenge
# This is generated by running the signet challenge script.
signetchallenge=512102a353dc1b52018dce23d364bb007608a2849caef3f11fe655c9c5d439656d669851ae
#signetchallenge=512102a353dc1b52018dce23d364bb007608a2849caef3f11fe655c9c5d439656d669851ae
#rpcauth=would be provided when needed
@ -17,13 +17,13 @@ maxtxfee=1.0
mintxfee=0.00000001
minrelaytxfee=0.00000001
rpcbind=0.0.0.0:38332
rpcbind=0.0.0.0:18443
rpcallowip=0.0.0.0/0
whitelist=0.0.0.0/0
# Basic Network
listen=1
bind=127.0.0.1
bind=0.0.0.0
# ZeroMQ notification settings
zmqpubrawblock=tcp://0.0.0.0:28332

29
docker-compose.yml Normal file
View File

@ -0,0 +1,29 @@
version: '3'
services:
bitcoind:
image: lncm/bitcoind:v26.0
container_name: easepay-bitcoind
command: -conf=/bitcoin/.bitcoin/bitcoin.conf
volumes:
- ./bitcoin.conf:/bitcoin/.bitcoin/bitcoin.conf
- bitcoind-data:/bitcoin/.bitcoin
ports:
- "18443:18443" # RPC port
- "48333:38333" # P2P port for Signet
restart: unless-stopped
fulcrum:
image: cculianu/fulcrum:latest # Replace with the desired Fulcrum version
container_name: easepay-fulcrum
volumes:
- fulcrum-data:/data
ports:
- "50002:50002" # Electrum server port
restart: unless-stopped
depends_on:
- bitcoind
volumes:
bitcoind-data:
fulcrum-data:

View File

@ -1,105 +1,25 @@
#!/bin/sh
# Start Bitcoind in Signet mode
/usr/local/bin/bitcoind -signet -daemon
echo "wating for signet bitcoind to start..."
while ! /usr/local/bin/bitcoin-cli -signet getconnectioncount 2>/dev/null 1>&2; do
echo -n ".";
sleep 1;
done
echo "started"
# Define container name = should match name in docker-compose
BICOIND_CONTAINER_NAME="easepay-bitcoind"
# check if custom_signet_wallet exist, create it if not
if ! /usr/local/bin/bitcoin-cli -signet listwallets | grep -q "custom_signet_wallet"; then
echo "Creating wallet: custom_signet_wallet"
/usr/local/bin/bitcoin-cli -signet createwallet "custom_signet_wallet"
else
echo "Wallet custom_signet-wallet already exists"
fi
# Start Bitcoind in Regtest mode
docker exec -it $BITCOIND_CONTAINER_NAME bitcoind -regtest -daemon
# Generate mew address and keys
ADDR=$(/usr/local/bin/bitcoin-cli -signet -rpcwallet="custom_signet_wallet" getnewaddress '' bech32)
if [ -z "$ADDR" ]; then
echo "Failed to get new address"
fi
# Wait for Bitcoind to start running
sleep 5
PRIVKEY=$(/usr/local/bin/bitcoin-cli -signet -rpcwallet="custom_signet_wallet" dumpprivkey $ADDR)
PUBKEY=$(/usr/local/bin/bitcoin-cli -signet -rpcwallet="custom_signet_wallet" getaddressinfo $ADDR | jq -r .pubkey)
# Generate a new address and get the private key and public key
ADDR=$(docker exec $BITCOIND_CONTAINER bitcoin-cli -regtest getnewaddress)
PRIVKEY=$(docker exec $BITCOIND_CONTAINER bitcoin-cli -regtest dumpprivkey $ADDR)
PUBKEY=$(docker exec $BITCOIND_CONTAINER bitcoin-cli -regtest getaddressinfo $ADDR | jq -r '.pubkey')
# Calculate script length and keys
LENX2=$(printf $PUBKEY | wc -c)
LEN=$((LENX2/2))
LENHEX=$(printf '%x\n' $LEN)
SCRIPT="51${LENHEX}${PUBKEY}51ae"
# Echo the generated values
echo "Address: $ADDR"
echo "Private Key: $PRIVKEY"
echo "Public Key: $PUBKEY"
# Output the generated values
cat <<EOF
ADDR=$ADDR
PRIVKEY=$PRIVKEY
PUBKEY=$PUBKEY
SCRIPT=$SCRIPT
EOF
# Create a new directory for the custom signet
datadir=/root/signet-custom
mkdir $datadir
# Write the custom signet configuration
cat > $datadir/bitcoin.conf <<EOF
signet=1
[signet]
daemon=1
signetchallenge=$SCRIPT
EOF
# Start bitcoind with the custom signet configuration
/usr/local/bin/bitcoind -datadir=$datadir -signet -wallet="test"
# Wait for the custom signet to start
echo "Waiting for custom Signet bitcoind to start"
while ! /usr/local/bin/bitcoin-cli -datadir=$datadir getconnectioncount 2>/dev/null 1>&2; do
echo -n ".";
sleep 1;
done
echo "Started"
# Import the private key to the custom signet node
/usr/local/bin/bitcoin-cli -datadir=$datadir importprivkey "$PRIVKEY"
# Generate a new address for mining
NADDR=$(/usr/local/bin/bitcoin-cli -datadir=$datadir getnewaddress)
# Examples from
# https://github.com/bitcoin/bitcoin/pull/19937#issuecomment-696419619
# Optionally, stop the regtest node
# docker exec $BITCOIND_CONTAINER bitcoin-cli -regtest stop
# Define neccessary commands and paths
MINER="../contrib/signet/miner"
GRIND="./bitcoin-util grind"
CLI="./bitcoin-cli -datadir=$datadir"
# Calibrate to find a suitable nbits value (Note: it is possible to adjust this as you see fit)
NBITS=$($MINER calibrate --grind-cmd="$GRIND" --seconds=160)
# Generate an address for receiving mining rewards
ADDR=$($CLI -signet getnewaddress)
# Advanced Block Generation Process
# Generate and create a block template. This generates a PSBT, processes it, and submits the block to the Signet network
$CLI -signet getblocktemplate '{"rules": ["signet","segwit"]}' \
| $MINER --cli="$CLI" genpsbt --address="$ADDR" \
| $CLI -signet -stdin walletprocesspsbt \
| jq -r .psbt \
| $MINER --cli="$CLI" solvepsbt --grind-cmd="$GRIND" \
| $CLI -signet -stdin submitblock
# Optional for continues mining
# $MINER --cli="$CLI" generate --grind-cmd="$GRIND" --address="$ADDR" --nbits=$NBITS --ongoing
# Stop the custom Signet node
./bitcoin-cli -datadir=$datadir stop
# -wallet="custom_signet_wallet" #Wallet name must match the name we have in signet_challenge script