Skip to content

Commit cf428f5

Browse files
committed
Mine Bitcoin blocks using a dedicated wallet
1 parent c1a531f commit cf428f5

File tree

3 files changed

+59
-22
lines changed

3 files changed

+59
-22
lines changed

README.md

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ make down-prom
163163
## Containers
164164

165165
- **bitcoin**: Runs a bitcoin regtest node
166-
- **bitcoin-miner**: creates 3 bitcoin regtest wallets and mines regtest blocks at a configurable cadence
166+
- **bitcoin-miner**: creates 3 bitcoin regtest wallets and mines regtest blocks at a configurable cadence. After initial setup (~200 blocks), creates a dedicated "block-producer" wallet for ongoing Bitcoin block production to prevent conflicts with Stacks mining operations
167167
- **stacks-miner-1**: mines stacks blocks and sends events to stacks-signer-1
168168
- **stacks-miner-2**: mines stacks blocks and sends events to stacks-signer-2
169169
- **stacks-miner-3**: mines stacks blocks and sends events to stacks-signer-3
@@ -175,6 +175,16 @@ make down-prom
175175
- **stacker**: stack for `stacks-signer-1`, `stacks-signer-2` and `stacks-signer-3`
176176
- **tx-broadcaster**: submits token transfer txs to ensure stacks block production during a sortition
177177

178+
## Bitcoin Miner
179+
*Dedicated address for Bitcoin block production after initial setup (~200 blocks). This prevents conflicts with Stacks mining operations.*
180+
181+
```text
182+
‣ Private Key: 4e24c0d8c63ea819073a1f06975086c841410fbb343eb0ac4e26a64e358a5ce801
183+
‣ Public Key: 02a0ea619414702c61a854d28c6806b436c814b85245b50b494a7df680b69ae4d1
184+
‣ BTC Address: mjVRH4vD5bAy3r5Z9FEjhHfA9mLZHQMKkC
185+
‣ WIF: cQKvvYqV5TcQyw7TTn6g4pMGm8BaweJvKg8TTR8iN5RHCihREFx8
186+
```
187+
178188
## Stacks Miner Accounts
179189

180190
### Miner 1
@@ -183,7 +193,7 @@ make down-prom
183193
‣ Mnemonic: lunar amount hard result reunion aisle goat fluid sorry modify minute pretty point visa cart material left tilt travel sausage library clutch wire tuna
184194
‣ Private Key: 23ad69119000a241706486b9349556bdc6dfabdf9d9131b153a57c6b0330fb0d01
185195
‣ Public Key: 0383bca67d28fce336ea7c2fc1120ecc63fbe55e89251e20587c2eb877f971e56b
186-
‣ BTC Address: miEJtNKa3ASpA19v5ZhvbKTEieYjLpzCYT
196+
‣ BTC Address: moARgPEufCG3BXqpZLR9wLZZufzeASFjxY
187197
‣ Stacks Address: ST19XY8C456FWH704JR77ZKFTPBNVNK52Q1CK01JD
188198
‣ WIF: cNn45HMeSuFeqg3pQESEuLz9FnmiYS83s11snXqDFqX4audaJbcb
189199
‣ Miner Rewards
@@ -196,33 +206,29 @@ make down-prom
196206
### Miner 2
197207

198208
```text
199-
‣ Mnemonic: cherry lawn pull huge drift wisdom capable bulk tragic street first foam onion above come smart eyebrow about soon jungle select used front ecology
200-
‣ Private Key: 1415e80bf3fe30fe95889c676681b4f64447f8888f718381840224b14ef4b97801
201-
‣ Public Key: 03a1940aedd43c39a39c73a1686faaabc67b6bd918d9710292e6c400308df0130e
202-
‣ BTC Address: mxxRn3xP98tSJCUXxABq4dgg4SziNacF1Y
203-
‣ Stacks Address: ST2ZMPYMHV80HGY99P9B81CN8E66JHBYVXB8P5F55
204-
‣ WIF: cNFkBfqr4tz3V7pcKbBvcibKsZ6XnTmcTwyWoqGm4CStmqN1bqh8
209+
‣ Private Key: ca9401c893f2036f480205948d8f142bca1cbe970978a97439ba1ccf4dbabb2a01
210+
‣ Public Key: 037f705fffab4de974d10563828ee3bf0c3e2e4f318f9ae670b8374a7b890195a2
211+
‣ BTC Address: muKzige2rgaiSC9kxYhwHydeCtwdA49D7b
212+
‣ Stacks Address: ST2BQYDCV0CG5Q4DRZBBB3DFZW5DS6NN5HSSXH39X
213+
‣ WIF: cUNVCr3LXpQmZciFRmz7m2JVozRZuRE7dYUXzRUcfXjnYN5SgyBL
205214
‣ Miner Rewards
206215
‣ Stacks address: ST2FW15NGB4H76FMVXKHYYSM865YVS6V3SA1GNABC
207216
‣ Private Key: fe3087801196d8027008146b13e6d365920c2e4b7bc9969729ec2f0f22ef74fc01
208-
‣ Mnemonic: acoustic physical genre canal today zone confirm whale fashion payment blanket slush crumble version exercise catch candy birth meadow penalty until protect kid wage
209217
‣ WIF: cW6p6zjVTXFXKQu3JmwfvRtkM5nAqCe1nakyhbd1VrZU59FJLew1
210218
211219
```
212220

213221
### Miner 3
214222

215223
```text
216-
‣ Mnemonic: identify test gallery pave now pet just gospel erupt walnut demand oyster old trigger soup zoo sheriff oyster twenty tragic license casual twelve depth
217-
‣ Private Key: c1c3f3f7bb8cc0b64c3be0f79488a3b1e3dbca62f23a5ac84e13beba78cc961301
218-
‣ Public Key: 025511871cb065df0ac108d149b5abe2267242745fd02b1d7a5fafb8dcf3ad66ce
219-
‣ BTC Address: miBGjFEQveJSbzFwB9XJ9a4GmkY3Unmb7b
220-
‣ Stacks Address: STEJYWJ2Y7E72AF9JMRWZWNR11ADBJBHD45P7D7K
221-
‣ WIF: cU5McyYQu1VJw6tzekyAJd1Jm9NVtjkPhrcbyVm8LgGdiW1Htrf4
224+
‣ Private Key: a549000d3c6da1037c2ae8201400d1abb2cc1230f9e415f9000af94d1ffd7ee601
225+
‣ Public Key: 03180a98f60f943f1594adec7cd39d639a0cc5109a33219c268c796d55096fe66b
226+
‣ BTC Address: mzD36ZSkb2bKw9ZXC6ihuYqfXWE29SakAF
227+
‣ Stacks Address: ST36GDT9KR00X36ZR4JJC6634MPS7W0KMX38P3DT1
228+
‣ WIF: cT7zdNXZErXZxNqEPuuH8rFZU9shEhJ2Ri8YEYFiB9NiUrLgYEyC
222229
‣ Miner Rewards
223230
‣ Stacks address: ST2MES40ZEXTX9M4YXW9QSWHRVC9HYT419S198VPM
224231
‣ Private Key: ed7eb063c61b8e892987228f1fcfb74eab5009568861613dc4b074b708a7893701
225-
‣ Mnemonic: verb face bag shaft snack alcohol consider fork boat gate any energy property vessel olive system spin seek mean recipe layer catch anger bacon
226232
‣ WIF: cVYMsUwHAZCdwfXZ2rgXWrFJDfqW2TrvLBAVpWCLCteCTTbv7UXL
227233
228234

docker/bitcoin/miner.sh

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -117,13 +117,35 @@ function mining_loop(){
117117
echo
118118
local mined_block_counter
119119
local block_height
120+
local bitcoin_block_producer_wallet="${BITCOIN_BLOCK_PRODUCER_BTC_WALLET}"
121+
local bitcoin_block_producer_addr="${BITCOIN_BLOCK_PRODUCER_BTC_ADDR}"
122+
123+
# Create dedicated block producer wallet for mining after initial setup
124+
echo "Setting up dedicated block producer wallet..."
125+
echo " - wallet: ${bitcoin_block_producer_wallet}"
126+
echo " - address: ${bitcoin_block_producer_addr}"
127+
if ! get_wallet_info "${bitcoin_block_producer_wallet}"; then
128+
if ! create_wallet "${bitcoin_block_producer_wallet}"; then
129+
echo "ERROR creating block producer wallet"
130+
exit 1
131+
fi
132+
fi
133+
# Import the predefined block producer address
134+
if ! get_address_info "${bitcoin_block_producer_wallet}" "${bitcoin_block_producer_addr}"; then
135+
if ! import_address "${bitcoin_block_producer_wallet}" "${bitcoin_block_producer_addr}"; then
136+
echo "ERROR importing block producer address"
137+
exit 1
138+
fi
139+
fi
140+
echo "Block producer wallet setup complete"
141+
echo
142+
120143
mined_block_counter=0 # set the counter before the loop starts
121144
block_height=$(get_height) # get the block height
122145
while true; do
123146
echo "******************************************"
124147
local conf_counter=0
125148
local confs=""
126-
local random="" # for tracking which array element we're using
127149
local sleep_duration=${MINE_INTERVAL}
128150
# loop through addresses and see if there are any mining txs in the list
129151
for i in $(seq 0 $((NUM_MINERS - 1)));do
@@ -139,11 +161,11 @@ function mining_loop(){
139161
else
140162
echo "Detected Stacks mining mempool tx, mining btc block..."
141163
fi
142-
random=$((0 + RANDOM % NUM_MINERS )) # random int with a range based on how many miners are defined. start from 0 since we're using an array
143-
echo "Mining block to:"
144-
echo " - wallet: ${!WALLETS[$random]}"
145-
echo " - address: ${!ADDRESSES[$random]}"
146-
echo " - block hash: $(bitcoin-cli -rpcwallet="${!WALLETS[$random]}" -rpcconnect=bitcoin generatetoaddress 1 "${!ADDRESSES[$random]}" | awk -F, 'NR==2{ gsub(/[",]/,"");gsub (" ", "", $0);print $1}')"
164+
# Mine to dedicated block producer address (not used for Stacks mining)
165+
echo "Mining block to dedicated block producer:"
166+
echo " - wallet: ${bitcoin_block_producer_wallet}"
167+
echo " - address: ${bitcoin_block_producer_addr}"
168+
echo " - block hash: $(bitcoin-cli -rpcwallet="${bitcoin_block_producer_wallet}" -rpcconnect=bitcoin generatetoaddress 1 "${bitcoin_block_producer_addr}" | awk -F, 'NR==2{ gsub(/[",]/,"");gsub (" ", "", $0);print $1}')"
147169
mined_block_counter=$((mined_block_counter + 1 )) # increment the mined block counter (used when restarting from a chainstate snapshot)
148170
block_height=$((block_height + 1)) # increment the already retrieved block_height, incrementing in the loop
149171
DEFAULT_TIMEOUT=$(($(date +%s) + 30))

docker/docker-compose.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,13 @@ x-common-vars:
3838
- &STACKS_MINER_3_BTC_ADDR mzD36ZSkb2bKw9ZXC6ihuYqfXWE29SakAF
3939
- &STACKS_MINER_3_BTC_WALLET stacks-miner-3
4040
- &STACKS_MINER_3_BLOCK_PUSH_FAIL_PROBABILITY 0
41+
# bitcoin block producer vars (mines Bitcoin blocks after initial setup)
42+
# priv_key: 4e24c0d8c63ea819073a1f06975086c841410fbb343eb0ac4e26a64e358a5ce801
43+
# pub_key: 02a0ea619414702c61a854d28c6806b436c814b85245b50b494a7df680b69ae4d1
44+
# btc: mjVRH4vD5bAy3r5Z9FEjhHfA9mLZHQMKkC
45+
# wif: cQKvvYqV5TcQyw7TTn6g4pMGm8BaweJvKg8TTR8iN5RHCihREFx8
46+
- &BITCOIN_BLOCK_PRODUCER_BTC_ADDR mjVRH4vD5bAy3r5Z9FEjhHfA9mLZHQMKkC
47+
- &BITCOIN_BLOCK_PRODUCER_BTC_WALLET block-producer
4148

4249
# Container Static IP assignments
4350
# *Note*: The stacks miner ip's are used for the bootstrap config later in this file
@@ -219,6 +226,8 @@ services:
219226
STACKS_MINER_2_BTC_WALLET: *STACKS_MINER_2_BTC_WALLET
220227
STACKS_MINER_3_BTC_ADDR: *STACKS_MINER_3_BTC_ADDR
221228
STACKS_MINER_3_BTC_WALLET: *STACKS_MINER_3_BTC_WALLET
229+
BITCOIN_BLOCK_PRODUCER_BTC_ADDR: *BITCOIN_BLOCK_PRODUCER_BTC_ADDR
230+
BITCOIN_BLOCK_PRODUCER_BTC_WALLET: *BITCOIN_BLOCK_PRODUCER_BTC_WALLET
222231
MINE_INTERVAL: *MINE_INTERVAL
223232
MINE_INTERVAL_EPOCH3: *MINE_INTERVAL_EPOCH3
224233
MINE_INTERVAL_EPOCH25: *MINE_INTERVAL_EPOCH25

0 commit comments

Comments
 (0)