From 2d5f75e6a093dd5524245fc551c6c7a9e9bd3fee Mon Sep 17 00:00:00 2001 From: Elyan Date: Wed, 21 Feb 2024 10:34:40 -0800 Subject: [PATCH] reworked docker to use lncm images --- Dockerfile | 40 ++++------------ bitcoin.conf | 6 +-- docker-compose.yml | 29 ++++++++++++ generate_signet.sh | 112 +++++++-------------------------------------- 4 files changed, 56 insertions(+), 131 deletions(-) create mode 100644 docker-compose.yml diff --git a/Dockerfile b/Dockerfile index 9e2ca6b..d850bff 100644 --- a/Dockerfile +++ b/Dockerfile @@ -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"] + diff --git a/bitcoin.conf b/bitcoin.conf index 5b0f43d..2a142e3 100644 --- a/bitcoin.conf +++ b/bitcoin.conf @@ -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 diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..aed82ed --- /dev/null +++ b/docker-compose.yml @@ -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: diff --git a/generate_signet.sh b/generate_signet.sh index b995ba9..ed3fcf7 100755 --- a/generate_signet.sh +++ b/generate_signet.sh @@ -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 < $datadir/bitcoin.conf </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 \ No newline at end of file