Skip to content

Commit 2cf82ee

Browse files
Merge pull request #32 from BowTiedRadone/feat/dedicated-bitcoin-mining
Mine Bitcoin blocks using a dedicated wallet
2 parents c1a531f + 543a682 commit 2cf82ee

File tree

4 files changed

+88
-48
lines changed

4 files changed

+88
-48
lines changed

README.md

Lines changed: 30 additions & 21 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,17 +175,28 @@ 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+
‣ Mnemonic: foot script pledge suit bread thing stage long auction craft label injury helmet drum ice govern glass tag lamp shield bike raccoon cloud hat
183+
‣ Private Key: 372aace2f66b6af7b195cffd5168133917fa87504acc422db4e8c273ce10d56f01
184+
‣ Public Key: 03d9ea1e7b47857ffc7611adc93eb2819d5996d3f63bcfd01508b51a4861671db1
185+
‣ BTC Address: mqiURdmHMv61yJYjxKyMUjk7dfQRV9ffFF
186+
‣ WIF: cPRwPMm4JdEmJpCzFiwGP5ntdKj3pYN6ZWLQNRMAuH3HHei4Ph9N
187+
```
188+
178189
## Stacks Miner Accounts
179190

180191
### Miner 1
181192

182193
```text
183-
‣ 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
184-
‣ Private Key: 23ad69119000a241706486b9349556bdc6dfabdf9d9131b153a57c6b0330fb0d01
185-
‣ Public Key: 0383bca67d28fce336ea7c2fc1120ecc63fbe55e89251e20587c2eb877f971e56b
186-
‣ BTC Address: miEJtNKa3ASpA19v5ZhvbKTEieYjLpzCYT
187-
‣ Stacks Address: ST19XY8C456FWH704JR77ZKFTPBNVNK52Q1CK01JD
188-
‣ WIF: cNn45HMeSuFeqg3pQESEuLz9FnmiYS83s11snXqDFqX4audaJbcb
194+
‣ Mnemonic: dream toast small waste nature name common infant forget win box mountain climb genuine pole vote usage move frown onion raise lend cluster domain
195+
‣ Private Key: e63a284b28a3144036dc7f789c4eaa0edd637a94f8be9124f12157f2f740186301
196+
‣ Public Key: 02377723916737a6436171dd7bb6e1b01d30958d29c1818f169c53448b45610bb1
197+
‣ BTC Address: ms7WBhM8uXkvfxEQvVVTpr4AuL3KpnqPsv
198+
‣ Stacks Address: ST1ZK49D6T6XDDMDVR7V3T5SYF0ET9N7DMCJV9ZKV
199+
‣ WIF: cVJEUhWLAVG9vx7RcnF6djdnXqkTG4qkPvjbgpbQBePF8FQyUpHb
189200
‣ Miner Rewards
190201
‣ Stacks address: ST1XVSVQN0KP5SDYFNT8E5TXWVW0XZVQEDBMCJ3XM
191202
‣ Private Key: a6143d20cd73d0dce2179e2af7771372a95b9d6795924492bd4d15d17709531e01
@@ -196,33 +207,31 @@ make down-prom
196207
### Miner 2
197208

198209
```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
210+
‣ Mnemonic: olive you plate doctor robot venture sniff aisle coffee roast resist leader language exist wreck alcohol feature best series social click company entire peanut
211+
‣ Private Key: 9803278e4c1db9e6d26c902549f52b3fe3c88fe9a5293c774721a9bc5bc9dfb301
212+
‣ Public Key: 0371b15f50be3a3498a2c26ce4d616c506ed0d8e6ce050c4ac7b0ffa40ca081829
213+
‣ BTC Address: msgxV5Z9poN2SKent3RhURjiEqJy7WUCnD
214+
‣ Stacks Address: ST22RBMZ4CMXYAVBED3KTMZEWRMA0ST6XSGBSX10H
215+
‣ WIF: cSgCBxt7hidTVjsCLm8wGBxKWa4JDjYPmHUsX41xbMc5cdkBMUvY
205216
‣ Miner Rewards
206217
‣ Stacks address: ST2FW15NGB4H76FMVXKHYYSM865YVS6V3SA1GNABC
207218
‣ 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
209219
‣ WIF: cW6p6zjVTXFXKQu3JmwfvRtkM5nAqCe1nakyhbd1VrZU59FJLew1
210220
211221
```
212222

213223
### Miner 3
214224

215225
```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
226+
‣ Mnemonic: rude fabric harsh mechanic until cricket field flag draw enough bitter flower people opera tackle horse unusual mass property height olympic artist demise major
227+
‣ Private Key: 19ff71655f1f5992f865fac2c840587ed328da32042a1c20e8b8be199a0b7b4101
228+
‣ Public Key: 03d13351e8f7b356b32289812479f7376dcd620cd76acad02352e41fe4edce500a
229+
‣ BTC Address: mgKsVRnASphbAiSp81Ct9sJ4bgNkhtayij
230+
‣ Stacks Address: ST4DZ2J4VWYBEQC0319V7CN8JDYE2WMESPSWMGDE
231+
‣ WIF: cNTEkvsFoTZnd3eJMH477uELJnktYZeCDWwy5PHgWYg6XvxHKNo5
222232
‣ Miner Rewards
223233
‣ Stacks address: ST2MES40ZEXTX9M4YXW9QSWHRVC9HYT419S198VPM
224234
‣ 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
226235
‣ WIF: cVYMsUwHAZCdwfXZ2rgXWrFJDfqW2TrvLBAVpWCLCteCTTbv7UXL
227236
228237

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/chainstate.tar.zstd

-804 KB
Binary file not shown.

docker/docker-compose.yml

Lines changed: 30 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -9,35 +9,42 @@ x-common-vars:
99
- &STACKS_LOG_JSON ${STACKS_LOG_JSON:-0}
1010
- &STACKS_LOG_FORMAT_TIME ${STACKS_LOG_FORMAT_TIME:-%Y-%m-%d %H:%M:%S}
1111
# stacks miner-1 vars
12-
# priv_key: 23ad69119000a241706486b9349556bdc6dfabdf9d9131b153a57c6b0330fb0d01
13-
# pub_key: 0383bca67d28fce336ea7c2fc1120ecc63fbe55e89251e20587c2eb877f971e56b
14-
# stx: ST19XY8C456FWH704JR77ZKFTPBNVNK52Q1CK01JD
15-
# btc: moARgPEufCG3BXqpZLR9wLZZufzeASFjxY
16-
# wif: cNn45HMeSuFeqg3pQESEuLz9FnmiYS83s11snXqDFqX4audaJbcb
17-
- &STACKS_MINER_1_PRIVATE_KEY 23ad69119000a241706486b9349556bdc6dfabdf9d9131b153a57c6b0330fb0d01
18-
- &STACKS_MINER_1_BTC_ADDR moARgPEufCG3BXqpZLR9wLZZufzeASFjxY
12+
# priv_key: e63a284b28a3144036dc7f789c4eaa0edd637a94f8be9124f12157f2f740186301
13+
# pub_key: 02377723916737a6436171dd7bb6e1b01d30958d29c1818f169c53448b45610bb1
14+
# stx: ST1ZK49D6T6XDDMDVR7V3T5SYF0ET9N7DMCJV9ZKV
15+
# btc: ms7WBhM8uXkvfxEQvVVTpr4AuL3KpnqPsv
16+
# wif: cVJEUhWLAVG9vx7RcnF6djdnXqkTG4qkPvjbgpbQBePF8FQyUpHb
17+
- &STACKS_MINER_1_PRIVATE_KEY e63a284b28a3144036dc7f789c4eaa0edd637a94f8be9124f12157f2f740186301
18+
- &STACKS_MINER_1_BTC_ADDR ms7WBhM8uXkvfxEQvVVTpr4AuL3KpnqPsv
1919
- &STACKS_MINER_1_BTC_WALLET stacks-miner-1
2020
- &STACKS_MINER_1_BLOCK_PUSH_FAIL_PROBABILITY 0
2121
# stacks miner-2 vars
22-
# priv_key: ca9401c893f2036f480205948d8f142bca1cbe970978a97439ba1ccf4dbabb2a01
23-
# pub_key: 037f705fffab4de974d10563828ee3bf0c3e2e4f318f9ae670b8374a7b890195a2
24-
# stx: ST2BQYDCV0CG5Q4DRZBBB3DFZW5DS6NN5HSSXH39X
25-
# btc: muKzige2rgaiSC9kxYhwHydeCtwdA49D7b
26-
# wif: cUNVCr3LXpQmZciFRmz7m2JVozRZuRE7dYUXzRUcfXjnYN5SgyBL
27-
- &STACKS_MINER_2_PRIVATE_KEY ca9401c893f2036f480205948d8f142bca1cbe970978a97439ba1ccf4dbabb2a01
28-
- &STACKS_MINER_2_BTC_ADDR muKzige2rgaiSC9kxYhwHydeCtwdA49D7b
22+
# priv_key: 9803278e4c1db9e6d26c902549f52b3fe3c88fe9a5293c774721a9bc5bc9dfb301
23+
# pub_key: 0371b15f50be3a3498a2c26ce4d616c506ed0d8e6ce050c4ac7b0ffa40ca081829
24+
# stx: ST22RBMZ4CMXYAVBED3KTMZEWRMA0ST6XSGBSX10H
25+
# btc: msgxV5Z9poN2SKent3RhURjiEqJy7WUCnD
26+
# wif: cSgCBxt7hidTVjsCLm8wGBxKWa4JDjYPmHUsX41xbMc5cdkBMUvY
27+
- &STACKS_MINER_2_PRIVATE_KEY 9803278e4c1db9e6d26c902549f52b3fe3c88fe9a5293c774721a9bc5bc9dfb301
28+
- &STACKS_MINER_2_BTC_ADDR msgxV5Z9poN2SKent3RhURjiEqJy7WUCnD
2929
- &STACKS_MINER_2_BTC_WALLET stacks-miner-2
3030
- &STACKS_MINER_2_BLOCK_PUSH_FAIL_PROBABILITY 0
3131
# stacks miner-3 vars
32-
# priv_key: a549000d3c6da1037c2ae8201400d1abb2cc1230f9e415f9000af94d1ffd7ee601
33-
# pub_key: 03180a98f60f943f1594adec7cd39d639a0cc5109a33219c268c796d55096fe66b
34-
# stx: ST36GDT9KR00X36ZR4JJC6634MPS7W0KMX38P3DT1
35-
# btc: mzD36ZSkb2bKw9ZXC6ihuYqfXWE29SakAF
36-
# wif: cT7zdNXZErXZxNqEPuuH8rFZU9shEhJ2Ri8YEYFiB9NiUrLgYEyC
37-
- &STACKS_MINER_3_PRIVATE_KEY a549000d3c6da1037c2ae8201400d1abb2cc1230f9e415f9000af94d1ffd7ee601
38-
- &STACKS_MINER_3_BTC_ADDR mzD36ZSkb2bKw9ZXC6ihuYqfXWE29SakAF
32+
# priv_key: 19ff71655f1f5992f865fac2c840587ed328da32042a1c20e8b8be199a0b7b4101
33+
# pub_key: 03d13351e8f7b356b32289812479f7376dcd620cd76acad02352e41fe4edce500a
34+
# stx: ST4DZ2J4VWYBEQC0319V7CN8JDYE2WMESPSWMGDE
35+
# btc: mgKsVRnASphbAiSp81Ct9sJ4bgNkhtayij
36+
# wif: cNTEkvsFoTZnd3eJMH477uELJnktYZeCDWwy5PHgWYg6XvxHKNo5
37+
- &STACKS_MINER_3_PRIVATE_KEY 19ff71655f1f5992f865fac2c840587ed328da32042a1c20e8b8be199a0b7b4101
38+
- &STACKS_MINER_3_BTC_ADDR mgKsVRnASphbAiSp81Ct9sJ4bgNkhtayij
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: 372aace2f66b6af7b195cffd5168133917fa87504acc422db4e8c273ce10d56f01
43+
# pub_key: 03d9ea1e7b47857ffc7611adc93eb2819d5996d3f63bcfd01508b51a4861671db1
44+
# btc: mqiURdmHMv61yJYjxKyMUjk7dfQRV9ffFF
45+
# wif: cPRwPMm4JdEmJpCzFiwGP5ntdKj3pYN6ZWLQNRMAuH3HHei4Ph9N
46+
- &BITCOIN_BLOCK_PRODUCER_BTC_ADDR mqiURdmHMv61yJYjxKyMUjk7dfQRV9ffFF
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)