From 678baf3938a541be0a5511c805202a2846c2a831 Mon Sep 17 00:00:00 2001 From: Purushotam Date: Tue, 17 Sep 2024 17:50:58 +0545 Subject: [PATCH 1/8] Signet network with 10 seconds block time - Used legacy wallet as descriptor wallets failed signing PSBT. - Created and example docker compose - Used -deprecatedrpc=create_bdb for wallet and signet client --- .env.example | 2 ++ .gitignore | 1 + Dockerfile | 8 ++++---- docker-compose.yml | 36 ++++++++++++++++++++++++++++++++++++ gen-signet-keys.sh | 2 +- setup-signet.sh | 4 ++-- 6 files changed, 46 insertions(+), 7 deletions(-) create mode 100644 .env.example create mode 100644 .gitignore create mode 100644 docker-compose.yml diff --git a/.env.example b/.env.example new file mode 100644 index 0000000..12b974a --- /dev/null +++ b/.env.example @@ -0,0 +1,2 @@ +PRIVKEY=cUdVo9US5MwknUaHjSUu64iJD2DNtPv11Z8chgZHtLfydyaJqUsS +MINERENABLED=1 \ No newline at end of file diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..2eea525 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.env \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index 2aedee5..06e9bd6 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,6 +1,6 @@ FROM debian:buster-slim as builder -ARG BITCOIN_VERSION=${BITCOIN_VERSION:-27.0} +ARG BITCOIN_VERSION=${BITCOIN_VERSION:-c23afab47fbe} ARG TARGETPLATFORM @@ -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/mutinynet-cat-lnhance/bitcoin-${BITCOIN_VERSION}-${TRIPLET}.tar.gz" && \ BITCOIN_FILE="bitcoin-${BITCOIN_VERSION}-${TRIPLET}.tar.gz" && \ wget -qO "${BITCOIN_FILE}" "${BITCOIN_URL}" && \ mkdir -p bin && \ @@ -49,7 +49,7 @@ 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:-"10"} ENV MINERENABLED=${MINERENABLED:-"1"} ENV MINETO=${MINETO:-""} ENV EXTERNAL_IP=${EXTERNAL_IP:-""} @@ -69,4 +69,4 @@ RUN pip3 install setuptools ENTRYPOINT ["/usr/local/bin/entrypoint.sh"] -CMD ["run.sh"] +CMD ["run.sh"] \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..dd19b01 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,36 @@ +services: + bitcoind-miner: + container_name: bitcoin-miner + image: alpen_signet:1.0 + env_file: + .env + environment: + BLOCKPRODUCTIONDELAY: 10 + RPCUSER: user + RPCPASSWORD: password + PRIVKEY: $PRIVKEY + SIGNETCHALLENGE: 512102a772f06f3860f4c1b803734db603f1c0cd86601a27670aadf5ff364a1d34f92551ae + 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 + + environment: + BLOCKPRODUCTIONDELAY: 10 + RPCPASSWORD: password + SIGNETCHALLENGE: 512102a772f06f3860f4c1b803734db603f1c0cd86601a27670aadf5ff364a1d34f92551ae + MINERENABLED: 0 + ADDNODE: bitcoin-miner:38333 + + ports: + - "38335:38332" + - "38336:38333" + - "38337:38334" \ No newline at end of file diff --git a/gen-signet-keys.sh b/gen-signet-keys.sh index aaafd06..9e5444d 100755 --- a/gen-signet-keys.sh +++ b/gen-signet-keys.sh @@ -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 diff --git a/setup-signet.sh b/setup-signet.sh index 5299320..aed5e6e 100755 --- a/setup-signet.sh +++ b/setup-signet.sh @@ -1,7 +1,7 @@ PRIVKEY=${PRIVKEY:-$(cat ~/.bitcoin/PRIVKEY.txt)} DATADIR=${DATADIR:-~/.bitcoin/} -bitcoind -datadir=$DATADIR --daemonwait -persistmempool -bitcoin-cli -datadir=$DATADIR -named createwallet wallet_name="custom_signet" load_on_startup=true descriptors=false +bitcoind -datadir=$DATADIR --daemonwait -persistmempool -deprecatedrpc=create_bdb +bitcoin-cli -datadir=$DATADIR -named createwallet wallet_name="alpen_wallet" load_on_startup=true descriptors=false #only used in case of mining node if [[ "$MINERENABLED" == "1" ]]; then From a6082434f0a162e68a7c72f6b4334d3bc28ded6f Mon Sep 17 00:00:00 2001 From: Purushotam Date: Tue, 17 Sep 2024 17:55:19 +0545 Subject: [PATCH 2/8] signagte challenge updated corresponding to unexposed private key --- .env.example | 3 ++- docker-compose.yml | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/.env.example b/.env.example index 12b974a..d37378b 100644 --- a/.env.example +++ b/.env.example @@ -1,2 +1,3 @@ PRIVKEY=cUdVo9US5MwknUaHjSUu64iJD2DNtPv11Z8chgZHtLfydyaJqUsS -MINERENABLED=1 \ No newline at end of file +MINERENABLED=1 +SIGNETCHALLENGE=51210232cc77c0e1ac931c691d2bd5e413523e9a284e96b7056cc202f119634465e9c551ae \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index dd19b01..a79a379 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -9,7 +9,7 @@ services: RPCUSER: user RPCPASSWORD: password PRIVKEY: $PRIVKEY - SIGNETCHALLENGE: 512102a772f06f3860f4c1b803734db603f1c0cd86601a27670aadf5ff364a1d34f92551ae + SIGNETCHALLENGE: $SIGNETCHALLENGE MINERENABLED: $MINERENABLED ports: - "28332:28332" From 50e70bac35ed95ceda5a1ecfb87115fa3b3e93d9 Mon Sep 17 00:00:00 2001 From: Sapin Bajracharya Date: Fri, 25 Oct 2024 14:01:27 +0545 Subject: [PATCH 3/8] custom signet blocktime --- Dockerfile | 6 +++--- gen-bitcoind-conf.sh | 6 +++++- mine.sh | 8 ++++++-- run.sh | 2 +- setup-signet.sh | 2 +- 5 files changed, 16 insertions(+), 8 deletions(-) diff --git a/Dockerfile b/Dockerfile index 06e9bd6..c29bc31 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,6 +1,6 @@ FROM debian:buster-slim as builder -ARG BITCOIN_VERSION=${BITCOIN_VERSION:-c23afab47fbe} +ARG BITCOIN_VERSION=${BITCOIN_VERSION:-d8434da3c14e} ARG TARGETPLATFORM @@ -14,7 +14,7 @@ WORKDIR /tmp linux/arm64) \ echo "arm64" && export TRIPLET="aarch64-linux-gnu";; \ esac && \ - BITCOIN_URL="https://github.com/benthecarman/bitcoin/releases/download/mutinynet-cat-lnhance/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 && \ @@ -49,7 +49,7 @@ 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:-"10"} +ENV BLOCKPRODUCTIONDELAY=${BLOCKPRODUCTIONDELAY:-"30"} ENV MINERENABLED=${MINERENABLED:-"1"} ENV MINETO=${MINETO:-""} ENV EXTERNAL_IP=${EXTERNAL_IP:-""} diff --git a/gen-bitcoind-conf.sh b/gen-bitcoind-conf.sh index 9432b50..f9d9ea6 100755 --- a/gen-bitcoind-conf.sh +++ b/gen-bitcoind-conf.sh @@ -27,10 +27,14 @@ if [[ "$EXTERNAL_IP" != "" ]]; then fi echo "[signet] +rest=1 daemon=1 listen=1 server=1 +acceptnonstdtxn=1 +v2transport=1 discover=1 +signetblocktime=$BLOCKPRODUCTIONDELAY signetchallenge=$SIGNETCHALLENGE zmqpubrawblock=$ZMQPUBRAWBLOCK zmqpubrawtx=$ZMQPUBRAWTX @@ -60,4 +64,4 @@ fi if [[ "$TORCONTROL" != "" ]]; then echo "torcontrol=$TORCONTROL" -fi +fi \ No newline at end of file diff --git a/mine.sh b/mine.sh index 8a975a2..1d4ee3a 100755 --- a/mine.sh +++ b/mine.sh @@ -2,7 +2,11 @@ NBITS=${NBITS:-"1e0377ae"} #minimum difficulty in signet while true; do - ADDR=${MINETO:-$(bitcoin-cli getnewaddress)} + if [[ -f "${BITCOIN_DIR}/MINE_ADDRESS.txt" ]]; then + ADDR=$(cat ~/.bitcoin/MINE_ADDRESS.txt) + else + ADDR=${MINETO:-$(bitcoin-cli getnewaddress)} + fi if [[ -f "${BITCOIN_DIR}/BLOCKPRODUCTIONDELAY.txt" ]]; then BLOCKPRODUCTIONDELAY_OVERRIDE=$(cat ~/.bitcoin/BLOCKPRODUCTIONDELAY.txt) echo "Delay OVERRIDE before next block" $BLOCKPRODUCTIONDELAY_OVERRIDE "seconds." @@ -16,4 +20,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 \ No newline at end of file diff --git a/run.sh b/run.sh index 44cf5c0..7b0d2ef 100755 --- a/run.sh +++ b/run.sh @@ -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) diff --git a/setup-signet.sh b/setup-signet.sh index aed5e6e..bb4a64b 100755 --- a/setup-signet.sh +++ b/setup-signet.sh @@ -1,7 +1,7 @@ PRIVKEY=${PRIVKEY:-$(cat ~/.bitcoin/PRIVKEY.txt)} DATADIR=${DATADIR:-~/.bitcoin/} bitcoind -datadir=$DATADIR --daemonwait -persistmempool -deprecatedrpc=create_bdb -bitcoin-cli -datadir=$DATADIR -named createwallet wallet_name="alpen_wallet" load_on_startup=true descriptors=false +bitcoin-cli -datadir=$DATADIR -named createwallet wallet_name="custom_signet" load_on_startup=true descriptors=false #only used in case of mining node if [[ "$MINERENABLED" == "1" ]]; then From c8d8cdbefc85bc89defee9d9a2e7e93414540ea4 Mon Sep 17 00:00:00 2001 From: Purushotam Date: Thu, 7 Nov 2024 21:25:19 +0545 Subject: [PATCH 4/8] rpc parameters added in config --- Dockerfile | 5 +++++ gen-bitcoind-conf.sh | 4 ++++ 2 files changed, 9 insertions(+) diff --git a/Dockerfile b/Dockerfile index c29bc31..b0969aa 100644 --- a/Dockerfile +++ b/Dockerfile @@ -45,6 +45,11 @@ 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 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"} diff --git a/gen-bitcoind-conf.sh b/gen-bitcoind-conf.sh index f9d9ea6..f2dfab9 100755 --- a/gen-bitcoind-conf.sh +++ b/gen-bitcoind-conf.sh @@ -26,6 +26,10 @@ if [[ "$EXTERNAL_IP" != "" ]]; then done fi +echo "rpcthreads=$RPCTHREADS +rpcservertimeout=$RPCSERVERTIMEOUT +rpcworkqueue=$RPCWORKQUEUE" + echo "[signet] rest=1 daemon=1 From d8a5e2fe352ae1e1780572978d960b34cc80e06e Mon Sep 17 00:00:00 2001 From: Purushotam Date: Fri, 7 Mar 2025 14:05:35 +0545 Subject: [PATCH 5/8] build context added in build context --- docker-compose.yml | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index a79a379..1fbad7a 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,7 +1,10 @@ services: bitcoind-miner: container_name: bitcoin-miner - image: alpen_signet:1.0 + # image: alpen_signet:1.0 + build: + context: . + dockerfile: Dockerfile env_file: .env environment: @@ -21,7 +24,10 @@ services: bitcoind-fullnode: container_name: bitcoin-fullnode - image: alpen_signet:1.0 + # image: alpen_signet:1.0 + build: + context: . + dockerfile: Dockerfile environment: BLOCKPRODUCTIONDELAY: 10 From 1dcdbb5fb9f3e6207f262d414f803b87d2fd2e26 Mon Sep 17 00:00:00 2001 From: Purushotam Date: Mon, 18 Nov 2024 11:47:15 +0545 Subject: [PATCH 6/8] Multi wallet create and load including custom_signet - Any arbritrary number of wallets can be created to receive miner reward - Preexisting custom_signet is still rewarded - A new script "setup-mineto-address.sh" is added which got major logic for this update --- Dockerfile | 3 ++ docker-compose.yml | 17 +++---- install.sh | 3 +- mine.sh | 12 ++--- setup-mineto-address.sh | 102 ++++++++++++++++++++++++++++++++++++++++ 5 files changed, 122 insertions(+), 15 deletions(-) create mode 100755 setup-mineto-address.sh diff --git a/Dockerfile b/Dockerfile index b0969aa..b0f8cb6 100644 --- a/Dockerfile +++ b/Dockerfile @@ -59,6 +59,8 @@ ENV MINERENABLED=${MINERENABLED:-"1"} ENV MINETO=${MINETO:-""} ENV EXTERNAL_IP=${EXTERNAL_IP:-""} +# Variable used to generate wallets used by bridge operators +ENV NUM_WALLETS=${NUM_WALLETS:-5} VOLUME $BITCOIN_DIR EXPOSE 28332 28333 28334 38332 38333 38334 RUN apt-get update && \ @@ -66,6 +68,7 @@ RUN apt-get update && \ apt-get clean COPY --from=builder "/tmp/bin" /usr/local/bin COPY docker-entrypoint.sh /usr/local/bin/entrypoint.sh +COPY setup-mineto-address.sh /usr/local/bin/setup-mineto-address.sh COPY miner_imports /usr/local/bin COPY miner /usr/local/bin/miner COPY *.sh /usr/local/bin/ diff --git a/docker-compose.yml b/docker-compose.yml index 1fbad7a..5cde46c 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,10 +1,11 @@ services: bitcoind-miner: - container_name: bitcoin-miner - # image: alpen_signet:1.0 - build: + build: context: . - dockerfile: Dockerfile + dockerfile: Dockerfile + + container_name: bitcoin-miner + image: public.ecr.aws/s6b4k6i9/strata/signet:mw0.0.2 env_file: .env environment: @@ -23,11 +24,11 @@ services: - "38334:38334" bitcoind-fullnode: - container_name: bitcoin-fullnode - # image: alpen_signet:1.0 - build: + build: context: . - dockerfile: Dockerfile + dockerfile: Dockerfile + container_name: bitcoin-fullnode + image: public.ecr.aws/s6b4k6i9/strata/signet:mw0.0.2 environment: BLOCKPRODUCTIONDELAY: 10 diff --git a/install.sh b/install.sh index f423e43..b3a5342 100755 --- a/install.sh +++ b/install.sh @@ -4,7 +4,8 @@ echo "Generate bitcoind configuration" gen-bitcoind-conf.sh >~/.bitcoin/bitcoin.conf echo "Setup Signet" setup-signet.sh - +echo "Setup Mineto address(es)" +setup-mineto-address.sh if [[ "$MINE_GENESIS" == "1" ]]; then echo "Mine Genesis Block" mine-genesis.sh diff --git a/mine.sh b/mine.sh index 1d4ee3a..8f71342 100755 --- a/mine.sh +++ b/mine.sh @@ -1,12 +1,11 @@ #!/bin/bash +source setup-mineto-address.sh + NBITS=${NBITS:-"1e0377ae"} #minimum difficulty in signet while true; do - if [[ -f "${BITCOIN_DIR}/MINE_ADDRESS.txt" ]]; then - ADDR=$(cat ~/.bitcoin/MINE_ADDRESS.txt) - else - ADDR=${MINETO:-$(bitcoin-cli getnewaddress)} - fi + # Get address to receive miner reward. + ADDR=$(get_next_address) if [[ -f "${BITCOIN_DIR}/BLOCKPRODUCTIONDELAY.txt" ]]; then BLOCKPRODUCTIONDELAY_OVERRIDE=$(cat ~/.bitcoin/BLOCKPRODUCTIONDELAY.txt) echo "Delay OVERRIDE before next block" $BLOCKPRODUCTIONDELAY_OVERRIDE "seconds." @@ -19,5 +18,6 @@ while true; do fi fi echo "Mine To:" $ADDR - miner --cli="bitcoin-cli" generate --grind-cmd="bitcoin-util grind" --address=$ADDR --nbits=$NBITS --set-block-time=$(date +%s) + # We must specify rpcwallet when multiple wallets are loaded + miner --cli="bitcoin-cli -rpcwallet=custom_signet" generate --grind-cmd="bitcoin-util grind" --address=$ADDR --nbits=$NBITS --set-block-time=$(date +%s) done \ No newline at end of file diff --git a/setup-mineto-address.sh b/setup-mineto-address.sh new file mode 100755 index 0000000..2452713 --- /dev/null +++ b/setup-mineto-address.sh @@ -0,0 +1,102 @@ +#!/bin/bash +# This script creates n different wallets and addresses to receive miner reward. +# For generated n wallets, each will receive rewards in the order they are +# specified in a `ADDRESS.txt` file. +# Index of reward receiving wallet for current round will be maintained in a `MINETO_IDX` +# text file. + + +DATADIR=${DATADIR:-~/.bitcoin} +# Number of wallets to create (you can change this) +NUM_WALLETS=${NUM_WALLETS:-5} + +# CSV file to store wallet names and addresses +OUTPUT_FILE="$DATADIR/wallets.csv" +INDEX_FILE="$DATADIR/MINETO_IDX" + +# Check if a wallet already exists +wallet_exists() { + local wallet_name=$1 + if bitcoin-cli -datadir="$DATADIR" listwalletdir | grep -q "\"$wallet_name\""; then + return 0 # Wallet exists + else + return 1 # Wallet does not exist + fi +} + +if [ ! -f "$OUTPUT_FILE" ]; then + + # Generate an address for custom_signet wallet which is used by sequencer + # to add btc txs. + ADDRESS=$(bitcoin-cli -datadir="$DATADIR" -rpcwallet="custom_signet" getnewaddress) + + # Add the custom_signet as our first address + # This is needed for backward compatibility + echo "custom_signet,$ADDRESS" > "$OUTPUT_FILE" + + # Create wallets, generate addresses, and store in CSV + for ((i=1; i<=NUM_WALLETS; i++)); do + WALLET_NAME="wallet_$i" + if wallet_exists "$WALLET_NAME"; then + echo "Wallet $WALLET_NAME already exists. Skipping..." + else + bitcoin-cli -datadir="$DATADIR" -named createwallet wallet_name="$WALLET_NAME" load_on_startup=true descriptors=false + fi + # Generate new address since we do not already have the wallets.csv + ADDRESS=$(bitcoin-cli -datadir="$DATADIR" -rpcwallet="$WALLET_NAME" getnewaddress) + + echo "$WALLET_NAME,$ADDRESS" >> "$OUTPUT_FILE" + echo "Created wallet: $WALLET_NAME with address: $ADDRESS" + done + + echo "All wallets created and addresses saved in $OUTPUT_FILE." +else + echo "wallet list already exists" +fi + + + +# Function to load addresses from the CSV file into an array +load_addresses() { + addresses=() + while IFS=',' read -r wallet address; do + # Skip the header line + if [[ "$wallet" != "wallet_name" ]]; then + addresses+=("$address") + fi + done < "$OUTPUT_FILE" +} + + +# Initialize first address as the Mineto address +# Function to get the next address to receive mining rewards + +get_next_address() { + load_addresses + + # Check if the addresses array is empty + if [ ${#addresses[@]} -eq 0 ]; then + echo "Error: No addresses found in $OUTPUT_FILE" + exit 1 + fi + + # Read the current index from the file, or initialize to 0 if not found + if [ -f "$INDEX_FILE" ]; then + current_index=$(cat "$INDEX_FILE") + else + current_index=0 + fi + + # Get the address at the current index + next_address=${addresses[$current_index]} + + # Increment the index, wrapping around if necessary + new_index=$(( (current_index + 1) % ${#addresses[@]} )) + + # Save the updated index back to the file + echo "$new_index" > "$INDEX_FILE" + + # Return the next address + echo "$next_address" +} +# echo "Next Address" $(get_next_address) \ No newline at end of file From f4b39aa16683795954e659edb38238f72268cb40 Mon Sep 17 00:00:00 2001 From: Purushotam Date: Sun, 9 Mar 2025 15:47:27 +0545 Subject: [PATCH 7/8] premining of blocks if block-height<100 --- mine.sh | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/mine.sh b/mine.sh index 8f71342..6b97a95 100755 --- a/mine.sh +++ b/mine.sh @@ -2,6 +2,20 @@ source setup-mineto-address.sh NBITS=${NBITS:-"1e0377ae"} #minimum difficulty in signet +ADDR=$(get_next_address) # It will get the first address from the wallet ie. cusomt_signet + +# Initial mining of 100 blocks if blocks count is less than 100 +BLOCKS_COUNT=$(bitcoin-cli -rpcwallet=custom_signet getblockcount) +if [[ $BLOCKS_COUNT -lt 100 ]]; then + echo "Mining initial 100 blocks" + for ((i = BLOCKS_COUNT; i <= 100; i++)); do + echo "Minining initial block $i" + miner --cli="bitcoin-cli -rpcwallet=custom_signet" generate --grind-cmd="bitcoin-util grind" --address=$ADDR --nbits=$NBITS --set-block-time=$(date +%s) + done +else + echo "Starting bitcoind mining from block $BLOCKS_COUNT" +fi + while true; do # Get address to receive miner reward. From 08b3b1f146e258d0237ea11d57897a3d32089f23 Mon Sep 17 00:00:00 2001 From: Purushotam Date: Sun, 9 Mar 2025 16:02:45 +0545 Subject: [PATCH 8/8] fix: deterministically get first address with a index --- mine.sh | 4 +++- setup-mineto-address.sh | 8 +++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/mine.sh b/mine.sh index 6b97a95..233e12e 100755 --- a/mine.sh +++ b/mine.sh @@ -2,7 +2,9 @@ source setup-mineto-address.sh NBITS=${NBITS:-"1e0377ae"} #minimum difficulty in signet -ADDR=$(get_next_address) # It will get the first address from the wallet ie. cusomt_signet +ADDR=$(get_first_address) # It will get the first address from the wallet ie. custom_signet + +echo "Starting mining with address $ADDR" # Initial mining of 100 blocks if blocks count is less than 100 BLOCKS_COUNT=$(bitcoin-cli -rpcwallet=custom_signet getblockcount) diff --git a/setup-mineto-address.sh b/setup-mineto-address.sh index 2452713..ee2cb79 100755 --- a/setup-mineto-address.sh +++ b/setup-mineto-address.sh @@ -99,4 +99,10 @@ get_next_address() { # Return the next address echo "$next_address" } -# echo "Next Address" $(get_next_address) \ No newline at end of file +# echo "Next Address" $(get_next_address) + +# get first address +get_first_address() { + load_addresses + echo ${addresses[0]} +} \ No newline at end of file