Skip to content

Commit

Permalink
fix: limit the UTXOs of the miners to avoid bug
Browse files Browse the repository at this point in the history
  • Loading branch information
obycode committed Sep 23, 2024
1 parent d40cfb4 commit 19656d5
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,16 @@ services:
bitcoin-cli -rpcconnect=bitcoind importaddress $${BTC_ADDR} "" false
bitcoin-cli -rpcconnect=bitcoind generatetoaddress $${INIT_BLOCKS} $${BTC_ADDR}
DEFAULT_TIMEOUT=$$(($$(date +%s) + 30))
RANDOM_ADDR=$$(bitcoin-cli -rpcconnect=bitcoind getnewaddress)
while true; do
UTXO_COUNT=$$(bitcoin-cli -rpcconnect=bitcoind listunspent 0 9999999 '[ "'"$${BTC_ADDR}"'" ]' | jq '. | length')
echo "UTXO_COUNT: $${UTXO_COUNT}"
if [ "$${UTXO_COUNT}" -gt 100 ]; then
MINING_ADDR="$${RANDOM_ADDR}"
else
MINING_ADDR="$${BTC_ADDR}"
fi
echo "Mining to $${MINING_ADDR}"
TX=$$(bitcoin-cli -rpcconnect=bitcoind listtransactions '*' 1 0 true)
CONFS=$$(echo "$${TX}" | jq '.[].confirmations')
if [ "$${CONFS}" = "0" ] || [ $$(date +%s) -gt $$DEFAULT_TIMEOUT ]; then
Expand All @@ -92,7 +101,7 @@ services:
else
echo "Detected Stacks mining mempool tx, mining btc block..."
fi
bitcoin-cli -rpcconnect=bitcoind generatetoaddress 1 "$${BTC_ADDR}"
bitcoin-cli -rpcconnect=bitcoind generatetoaddress 1 "$${MINING_ADDR}"
DEFAULT_TIMEOUT=$$(($$(date +%s) + 30))
else
echo "No Stacks mining tx detected"
Expand Down

0 comments on commit 19656d5

Please sign in to comment.