Feat:create a new script to generate signet challenge

This commit is contained in:
Elyan 2024-02-20 01:20:07 -08:00
parent 18333d9140
commit 8fda01b586
4 changed files with 56 additions and 37 deletions

View File

@ -1,43 +1,53 @@
FROM ubuntu:20.04 # Build stage for Bitcoin Core
FROM ubuntu as builder
# Install dependencies # Install build dependencies
RUN apt-get update && apt-get install -y \ RUN apt-get update && apt-get install -y \
build-essential libtool autotools-dev automake \ build-essential libtool autotools-dev automake \
pkg-config bsdmainutils python3 libssl-dev \ pkg-config bsdmainutils python3 libssl-dev \
libevent-dev libboost-system-dev libboost-filesystem-dev \ libevent-dev libboost-system-dev libboost-filesystem-dev \
libboost-chrono-dev libboost-test-dev libboost-thread-dev \ libboost-chrono-dev libboost-test-dev libboost-thread-dev \
libdb-dev libdb++-dev python3-pip jq libdb-dev libdb++-dev python3-pip jq git
# Clone Bitcoin Core # Clone and build Bitcoin Core
RUN apt-get install -y git RUN git clone --depth 1 https://github.com/bitcoin/bitcoin.git
RUN git clone https://github.com/bitcoin/bitcoin.git
# Build Bitcoin Core # Build Bitcoin core
WORKDIR /bitcoin WORKDIR /bitcoin
RUN ./autogen.sh RUN ./autogen.sh
RUN ./configure RUN ./configure
RUN make RUN make
# Copy, Prepare Signet configuration and run signet script # Application stage
COPY generate_signet.sh . FROM ubuntu
RUN chmod +x generate_signet.sh
# Install runtime dependencies
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 generate_signet.sh /usr/local/bin
RUN chmod +x /usr/local/bin/generate_signet.sh
# Copy Bitcoin.conf file # Copy Bitcoin.conf file
COPY bitcoin.conf /root/.bitcoin/bitcoin.conf COPY bitcoin.conf /root/.bitcoin/bitcoin.conf
# Copy the generate.py script from the Bitcoin core source # Copy the logtail.sh script
COPY --from=0 /bitcoin/contrib/signet/miner.py /usr/local/bin/ COPY logtail.sh /usr/local/bin/
RUN chmod +x /usr/local/bin/miner.py RUN chmod +x usr/local/bin/logtail.sh
# Copy the .bashrc file to the container's root directory # Copy the .bashrc file to the container's root directory
COPY .bashrc /root/.bashrc COPY .bashrc /root/.bashrc
# Copy the logtail.sh script
COPY logtail.sh .
RUN chmod +x logtail.sh
# Expose necessary ports # Expose necessary ports
EXPOSE 38333 38332 EXPOSE 38333 38332
# Start Bitcoin Core # Start Bitcoin Core
CMD ["./generate_signet.sh"] CMD ["usr/local/bin/generate_signet.sh"]

View File

@ -3,8 +3,8 @@ signet=1
daemon=1 daemon=1
# Custom Signet challenge # Custom Signet challenge
# we would add our custom signet parameters here(currently generic parameters are used) # This was generated by running the signet challenge script.
signetchallenge=5121<PUBKEY>51ae signetchallenge= 512102a353dc1b52018dce23d364bb007608a2849caef3f11fe655c9c5d439656d669851ae
#rpcauth=would be provided when needed #rpcauth=would be provided when needed

28
generate_signet.sh Normal file → Executable file
View File

@ -1,18 +1,18 @@
#!/bin/sh #!/bin/sh
# Start Bitcoind in regtest mode # Start Bitcoind in Signet mode
./src/bitcoind -regtest -daemon -wallet="test" #change wallet name /usr/local/bin/bitcoind -signet -daemon -wallet="test" #change wallet name
echo "wating for regtest bitcoind to start..." echo "wating for signet bitcoind to start..."
while ! ./src/bitcoin-cli -regtest getconnectioncount 2>/dev/null 1>&2; do while ! /usr/local/bin/bitcoin-cli -signet getconnectioncount 2>/dev/null 1>&2; do
echo -n "."; echo -n ".";
sleep 1; sleep 1;
done done
echo "started" echo "started"
# Generate mew address and keys # Generate mew address and keys
ADDR=$(./src/bitcoin-cli -regtest getnewaddress '' bech32) ADDR=$(/usr/local/bin/bitcoin-cli -signet getnewaddress '' bech32)
PRIVKEY=$(./src/bitcoin-cli -regtest dumpprivkey $ADDR) PRIVKEY=$(/usr/local/bin/bitcoin-cli -signet dumpprivkey $ADDR)
PUBKEY=$(./src/bitcoin-cli -regtest getaddressinfo $ADDR | jq -r .scriptPubKey) PUBKEY=$(/usr/local/bin/bitcoin-cli -signet getaddressinfo $ADDR | jq -r .pubKey)
# Calculate script length and keys # Calculate script length and keys
LENX2=$(printf $PUBKEY | wc -c) LENX2=$(printf $PUBKEY | wc -c)
@ -28,9 +28,6 @@ PUBKEY=$PUBKEY
SCRIPT=$SCRIPT SCRIPT=$SCRIPT
EOF EOF
# Stop the regtest node
./src/bitcoin-cli -regtest stop
# Create a new directory for the custom signet # Create a new directory for the custom signet
datadir=/root/signet-custom datadir=/root/signet-custom
mkdir $datadir mkdir $datadir
@ -44,29 +41,26 @@ signetchallenge=$SCRIPT
EOF EOF
# Start bitcoind with the custom signet configuration # Start bitcoind with the custom signet configuration
./src/bitcoind -datadir=$datadir -wallet="test" /usr/local/bin/bitcoind -datadir=$datadir -signet -wallet="test"
# Wait for the custom signet to start # Wait for the custom signet to start
echo "Waiting for custom Signet bitcoind to start" echo "Waiting for custom Signet bitcoind to start"
while ! ./src/bitcoin-cli -datadir=$datadir getconnectioncount 2>/dev/null 1>&2; do while ! /usr/local/bin/bitcoin-cli -datadir=$datadir getconnectioncount 2>/dev/null 1>&2; do
echo -n "."; echo -n ".";
sleep 1; sleep 1;
done done
echo "Started" echo "Started"
# Import the private key to the custom signet node # Import the private key to the custom signet node
./src/bitcoin-cli -datadir=$datadir importprivkey "$PRIVKEY" /usr/local/bin/bitcoin-cli -datadir=$datadir importprivkey "$PRIVKEY"
# Generate a new address for mining # Generate a new address for mining
NADDR=$(./src/bitcoin-cli -datadir=$datadir getnewaddress) NADDR=$(/usr/local/bin/bitcoin-cli -datadir=$datadir getnewaddress)
# Examples from # Examples from
# https://github.com/bitcoin/bitcoin/pull/19937#issuecomment-696419619 # https://github.com/bitcoin/bitcoin/pull/19937#issuecomment-696419619
# Navigate to the src directory(this assume that Docker workdir is set to the root)
cd src/
# Define neccessary commands and paths # Define neccessary commands and paths
MINER="../contrib/signet/miner" MINER="../contrib/signet/miner"
GRIND="./bitcoin-util grind" GRIND="./bitcoin-util grind"

15
signet_challenge.sh Executable file
View File

@ -0,0 +1,15 @@
#!/bin/bash
# Create a new wallet
WALLET_NAME="custom_signet_wallet"
bitcoin-cli -signet createwallet "$WALLET_NAME"
# Generate a new address and retrieve the public key
ADDRESS=$(bitcoin-cli -signet -rpcwallet="$WALLET_NAME" getnewaddress)
PUBKEY=$(bitcoin-cli -signet -rpcwallet="$WALLET_NAME" getaddressinfo "$ADDRESS" | jq -r .pubkey)
# Construct the signetchallenge script
SIGNETCHALLENGE="5121${PUBKEY}51ae"
# Output the signetchallenge
echo "signetchallenge: $SIGNETCHALLENGE"