forked from nbd-wtf/bitcoin_signet
-
Notifications
You must be signed in to change notification settings - Fork 23
Expand file tree
/
Copy pathmine.sh
More file actions
executable file
·45 lines (38 loc) · 1.67 KB
/
mine.sh
File metadata and controls
executable file
·45 lines (38 loc) · 1.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#!/bin/bash
set -Eeuo pipefail
# Define mining constants
CLI="bitcoin-cli -datadir=${BITCOIN_DIR} -rpcwallet=custom_signet"
GRIND="bitcoin-util grind"
NBITS=${NBITS:-"1e0377ae"} #minimum difficulty in signet
# UTXO consolidation interval
CONSOLIDATE_INTERVAL=${CONSOLIDATE_INTERVAL:-10}
echo "Waiting until Chain tip age is < $CHAIN_TIP_AGE seconds before mining start..."
wait_chain_sync.sh $CHAIN_TIP_AGE
while true; do
if [[ -f "${BITCOIN_DIR}/MINE_ADDRESS.txt" ]]; then
ADDR=$(cat ~/.bitcoin/MINE_ADDRESS.txt)
else
ADDR=${MINETO:-$(bitcoin-cli -rpcwallet=custom_signet getnewaddress)}
fi
if [[ -f "${BITCOIN_DIR}/BLOCKPRODUCTIONDELAY.txt" ]]; then
BLOCKPRODUCTIONDELAY_OVERRIDE=$(cat ~/.bitcoin/BLOCKPRODUCTIONDELAY.txt)
echo "Delay OVERRIDE before next block" $BLOCKPRODUCTIONDELAY_OVERRIDE "seconds."
sleep $BLOCKPRODUCTIONDELAY_OVERRIDE
else
BLOCKPRODUCTIONDELAY=${BLOCKPRODUCTIONDELAY:="0"}
if [[ BLOCKPRODUCTIONDELAY -gt 0 ]]; then
echo "Delay before next block" $BLOCKPRODUCTIONDELAY "seconds."
sleep $BLOCKPRODUCTIONDELAY
fi
fi
#echo "Mine To:" $ADDR --addr=$ADDR
miner --debug --cli="$CLI" generate --grind-cmd="$GRIND" --addr=$ADDR --nbits=$NBITS --set-block-time=$(date +%s) || true
# Purge Cloudflare cache for tip height
purge-tip.sh 2>/dev/null &
# Check block count and consolidate UTXOs every N blocks
BLOCK_COUNT=$($CLI getblockcount)
if [ $((BLOCK_COUNT % CONSOLIDATE_INTERVAL)) -eq 0 ]; then
echo "Consolidating UTXOs at block $BLOCK_COUNT..."
consolidate_utxos.sh || echo "Warning: UTXO consolidation failed"
fi
done