Skip to content

Commit 6312062

Browse files
authoredJul 15, 2024
Merge pull request #6 from rrybarczyk/2024.07-improve-setup-instructions
Clarify setup specific instructions
2 parents 778c61a + b507be9 commit 6312062

7 files changed

+330
-149
lines changed
 

‎README.md

+172-39
Original file line numberDiff line numberDiff line change
@@ -1,70 +1,198 @@
1+
# sv2-workshop
12
This repository contains materials for a [StratumV2 Reference Implementation](https://github.com/stratum-mining/stratum) workshop.
23

3-
# Slides
4-
Slides leverage [`marp`](https://marp.app/). They are compiled from `md` to `html` via `marp.sh` (which assumes nix flakes are available on your system).
4+
* For useful materials see the [materials/](https://github.com/stratum-mining/sv2-workshop/blob/main/materials) directory.
55

6-
As an alternative to `marp.sh`, you can just install `marp` on the system and do:
7-
```
6+
These instructions cover the setup required for the instructor running the Stratum V2 workshop.
7+
8+
1. Configuring and hosting the slides to be accessible by the participants.
9+
2. Configuring a publicly accessible Genesis node for participants to sync their nodes.
10+
3. Configuring the block explorer to display participants' mined blocks.
11+
12+
## Slides
13+
14+
### Config
15+
The `html/index.html` is built with [`marp`](https://marp.app/) and is based on the
16+
[`md/sv2-workshop.md`](https://github.com/stratum-mining/sv2-workshop/blob/main/md/sv2-workshop.md)
17+
file, and is committed to this repo.
18+
To generate the `html/index.html` file on changes to `sv2-workshop.md`, install `marp` on your
19+
system and run:
20+
21+
```sh
822
marp md/sv2-workshop.md -o html/sv2-workshop.html --theme-set css/sv2-workshop.css
923
```
1024

11-
The slides can be served via:
25+
Or, if using `nix`, run (assuming nix flakes are available):
26+
27+
```sh
28+
nix run github:tweag/nix-marp -- md/sv2-workshop.md -o html/sv2-workshop.html --theme-set css/sv2-workshop.css
1229
```
13-
cd html
30+
31+
### Run
32+
Serve the slides:
33+
34+
```sh
1435
python3 -m http.server 8888
1536
```
1637

17-
# Custom Signet
18-
Which network should we do our workshop?
38+
To make the slides accessible on the SRI VM for participants to view on their machines:
1939

20-
- `testnet3`? Well, [Lopp broke it](https://blog.lopp.net/griefing-bitcoin-testnet/).
21-
- `signet`? Well, we need the audience to be able to mine blocks.
22-
- `testnet4`? Well, we want a controlled hashrate environment.
40+
1. Remote into the SRI VM.
41+
2. Create a new `tmux` session.
42+
3. `cd ~/sv2-workshop`.
43+
4. Make sure the correct `workshop` branch (or branch of your choosing) is checked out.
44+
5. Run the HTTP server.
2345

24-
Therefore, this workshop is based on a custom signet that does not require coinbase signatures. This way, the audience can deploy pools + hashers and emulate a confined hashrate environment.
46+
> Note: This can be done on any machine, however the slides specifically point the user to the SRI
47+
VM URL. If you choose to host the slides on another machine, remember to update the slides with the
48+
update endpoint.
2549

26-
The `signet_genesis_node.sh` is responsible for:
27-
- Deploy a local signet.
28-
- Mine 16 blocks as bootstrapping for the SRI pool.
50+
## Custom Signet
51+
This workshop uses a custom `signet` for the following reasons:
2952

30-
In order to use this script, you should first export some environment variables. For example:
31-
```
53+
- We want a confined hashrate environment, so `mainnet`, `testnet3`, `testnet4` and the public `signet` are ill suited.
54+
- `regtest` is too isolated and requires manual block generation, which is not practical for a collaborative workshop setting.
55+
- We will mine on a custom `signet` that does not require coinbase signatures.
56+
- This way, we can deploy pools + hashers and emulate a confined hashrate environment.
57+
58+
Participants will connect to this Genesis node to sync their blocks.
59+
60+
### Genesis Node
61+
The instructor can use the existing Genesis node hosted on the SRI VM, or spin up their own. The
62+
Genesis node should be configured via the [materials/signet-genesis-node.sh](https://github.com/stratum-mining/sv2-workshop/blob/main/materials/signet-genesis-node.sh) script which:
63+
64+
* Deploys a local signet.
65+
* Mines 16 blocks as bootstrapping for the SRI pool.
66+
67+
Before executing the script, ensure the following environment variables are defined:
68+
69+
```sh
3270
$ export BITCOIND=$HOME/bitcoin/src/bitcoind
3371
$ export BITCOIN_CLI=$HOME/bitcoin/src/bitcoin-cli
3472
$ export BITCOIN_UTIL=$HOME/bitcoin/src/bitcoin-util
3573
$ export MINER=$HOME/bitcoin/contrib/signet/miner
3674
$ export BITCOIN_DATA_DIR=$HOME/.bitcoin
3775
```
3876

39-
# Blockchain Explorer
77+
#### SRI Node
78+
A Genesis node that is publicly accessible is needed for participants to sync their Bitcoin nodes.
79+
This can be set up by the instructor or use the existing SRI VM node.
80+
81+
If using the SRI hosted Genesis node, verify it is running by remoting into the SRI VM and finding
82+
its process:
83+
84+
```sh
85+
ps -ef | grep -i bitcoind
86+
> sri 3935787 1 0 Jun29 ? 01:19:13 /home/sri/btc_prague_workshop/bitcoin/src/bitcoind -signet -datadir=/home/sri/btc_prague_workshop/bitcoin_data_dir/ -fallbackfee=0.01 -daemon -sv2 -sv2port=38442
87+
```
88+
89+
If spinning up a new node, see the instructions to install `bitcoin-core` in the Block Explorer
90+
section below.
91+
92+
## Block Explorer
93+
A block explorer is needed to display participants' mined blocks on the custom `signet`. A custom
94+
`signet` Bitcoin node, [`electrs`](https://github.com/romanz/electrs), and
95+
[`mempool.space`](https://github.com/mempool/mempool) is used for this purpose.
96+
97+
> Note: The steps for deploying a local `mempool.space` have not yet been automated and will need to
98+
be performed manually.
4099

41-
In order to allow the audience to explore the blockchain, it's also recommended to provide a blockchain explorer.
100+
> Note: The Genesis node can also be used for this purpose. A second Bitcoin node for the block
101+
explorer only is needed if the instructor is running the block explorer on another machine (like
102+
their local machine).
42103

43-
The steps for deploying a local `mempool.space` have not yet been automated, so they need to be performed manually.
104+
### Custom Signet `bitcoin-core`
44105

45-
First, clone and start `electrs`:
106+
#### Install
107+
Install the required `bitcoin-core` fork by building from
108+
[Sjors's `sv2-tp-0.1.3` tag](https://github.com/Sjors/bitcoin/tree/sv2-tp-0.1.3):
109+
110+
```sh
111+
git clone https://github.com/Sjors/bitcoin.git
112+
cd bitcoin
113+
git fetch --all
114+
git checkout sv2-tp-0.1.3
115+
./autogen.sh
116+
./configure --disable-tests --disable-bench --enable-wallet --with-gui=no
117+
make # or `make -j <num cores>`
118+
```
119+
120+
Or alternatively via `nix`:
121+
```sh
122+
git clone https://github.com/plebhash/nix-bitcoin-core-archive
123+
cd nix-bitcoin-core-archive/fork/sv2
124+
nix-build # the executables are available at `result/bin`
125+
```
126+
127+
#### Config
128+
Ensure the [`bitcoin.conf`](https://github.com/stratum-mining/sv2-workshop/blob/main/materials/block-explorer-bitcoin.conf)
129+
in the `datadir` contains:
130+
131+
```conf
132+
[signet]
133+
signetchallenge=51 # OP_TRUE
134+
prune=0
135+
txindex=1
136+
server=1
137+
connect=75.119.150.111 # Genesis Node
138+
rpcallowip=0.0.0.0/0
139+
rpcbind=0.0.0.0
140+
rpcuser=mempool
141+
rpcpassword=mempool
142+
```
143+
144+
#### Run
145+
Add the Bitcoin binaries to `$PATH`:
146+
```sh
147+
echo 'export PATH="$HOME/bitcoin/src:$PATH"' >> ~/.bashrc && export PATH="$HOME/bitcoin/src:$PATH"
46148
```
47-
$ git clone https://github.com/romanz/electrs
48-
$ cd electrs
49-
$ git checkout v0.10.5
50-
$ cat << EOF > electrs.toml
149+
150+
Start the Bitcoin node:
151+
152+
```sh
153+
bitcoind -datadir=$HOME/.bitcoin-sv2-workshop -signet -sv2
154+
```
155+
156+
### `electrs`
157+
158+
#### Install
159+
Clone, checkout the `v0.10.5` branch, and configure:
160+
161+
```sh
162+
git clone https://github.com/romanz/electrs
163+
cd electrs
164+
git checkout v0.10.5
165+
cat << EOF > electrs.toml
51166
network="signet"
52167
auth="mempool:mempool"
53168
EOF
54-
$ cargo run -- --signet-magic=54d26fbd
55169
```
56170

57-
Then, clone `mempool`:
171+
#### Run
172+
Run the server:
173+
174+
```sh
175+
cargo run -- --signet-magic=54d26fbd
58176
```
59-
$ git clone https://github.com/mempool/mempool
60-
$ cd mempool
61-
$ git checkout v2.5.0
177+
178+
### `mempool.space`
179+
180+
#### Install
181+
Clone and checkout the `v2.5.0` branch:
182+
183+
```sh
184+
git clone https://github.com/mempool/mempool
185+
cd mempool
186+
git checkout v2.5.0
62187
```
63188

64-
We are going to use the docker deployment, so we need to adjust some configs.
65-
```diff
189+
#### Config
190+
The docker deployment is used with the following adjustments to the `docker/docker-compose.yml`:
191+
192+
```sh
193+
git diff docker/docker-compose.yml
66194
diff --git a/docker/docker-compose.yml b/docker/docker-compose.yml
67-
index 68e73a1c8..98fa6a174 100644
195+
index 68e73a1c8..300aa3d80 100644
68196
--- a/docker/docker-compose.yml
69197
+++ b/docker/docker-compose.yml
70198
@@ -14,9 +14,12 @@ services:
@@ -73,18 +201,23 @@ index 68e73a1c8..98fa6a174 100644
73201
environment:
74202
- MEMPOOL_BACKEND: "none"
75203
+ MEMPOOL_BACKEND: "electrum"
76-
+ ELECTRUM_HOST: "172.27.0.1"
77-
+ ELECTRUM_PORT: "50002"
204+
+ ELECTRUM_HOST: "host.docker.internal" # or the IP address of the Electrum server
205+
+ ELECTRUM_PORT: "60601" # match this with the port on which electrs is listening
78206
+ ELECTRUM_TLS_ENABLED: "false"
79-
CORE_RPC_HOST: "172.27.0.1"
207+
- CORE_RPC_HOST: "172.27.0.1"
208+
+ CORE_RPC_HOST: "host.docker.internal"
80209
- CORE_RPC_PORT: "8332"
81210
+ CORE_RPC_PORT: "38332"
82211
CORE_RPC_USERNAME: "mempool"
83212
CORE_RPC_PASSWORD: "mempool"
84213
DATABASE_ENABLED: "true"
85214
```
86215

87-
From the `docker` directory, you can start it via:
216+
#### Run
217+
Start the docker container:
218+
219+
```sh
220+
docker-compose up
88221
```
89-
$ docker-compose up
90-
```
222+
223+
Navigate to the exposed `localhost` endpoint.

‎html/sv2-workshop.html

+99-90
Large diffs are not rendered by default.

‎marp.sh

-3
This file was deleted.

‎materials/README.md

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Materials
2+
Useful configuration files or other materials both the instructor and participants.
3+
4+
## Instructor
5+
* [`block-explorer-bitcoin.conf`](https://github.com/stratum-mining/sv2-workshop/blob/main/materials/block-explorer-bitcoin.conf): `bitcoin.conf` for the node use with the block explorer.
6+
* [`signet-genesis-node.sh`](https://github.com/stratum-mining/sv2-workshop/blob/main/materials/signet-genesis-node.sh): Genesis node setup script.

‎materials/block-explorer-bitcoin.conf

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
[signet]
2+
signetchallenge=51 # OP_TRUE
3+
prune=0
4+
txindex=1
5+
server=1
6+
connect=75.119.150.111 # Genesis Node
7+
rpcallowip=0.0.0.0/0
8+
rpcbind=0.0.0.0
9+
rpcuser=mempool
10+
rpcpassword=mempool
11+

‎signet_genesis_node.sh ‎materials/signet-genesis-node.sh

+14-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,18 @@
11
#!/bin/bash
2+
#
3+
# Genesis Node Setup
4+
#
5+
# - Deploys a local signet.
6+
# - Mines 16 blocks as bootstrapping for the SRI pool.
7+
#
8+
# Ensure the following environment variables are set:
9+
#
10+
# $BITCOIND=$HOME/bitcoin/src/bitcoind
11+
# $BITCOIN_CLI=$HOME/bitcoin/src/bitcoin-cli
12+
# $BITCOIN_UTIL=$HOME/bitcoin/src/bitcoin-util
13+
# $MINER=$HOME/bitcoin/contrib/signet/miner
14+
# $BITCOIN_DATA_DIR=$HOME/.bitcoin
15+
#
216

317
# Check if the environment variables are set
418
if [ -z "$BITCOIND" ] || [ -z "$BITCOIN_CLI" ] || [ -z "$BITCOIN_UTIL" ] || [ -z "$BITCOIN_DATA_DIR" ] || [ -z "$MINER" ]; then
@@ -52,4 +66,3 @@ done
5266

5367
echo "script finalized... running getblockchaininfo as the last step"
5468
$BITCOIN_CLI -signet -datadir=$BITCOIN_DATA_DIR getblockchaininfo
55-

‎md/sv2-workshop.md

+28-16
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,24 @@ git checkout workshop
3535

3636
## Get a release from SV2 Bitcoin Core fork
3737

38-
Grab a release from https://github.com/plebhash/bitcoin/releases/tag/btc-prague
38+
Install the required `bitcoin-core` fork by building from [Sjors's `sv2-tp-0.1.3` tag](https://github.com/Sjors/bitcoin/tree/sv2-tp-0.1.3):
39+
40+
```sh
41+
git clone https://github.com/Sjors/bitcoin.git
42+
cd bitcoin
43+
git fetch --all
44+
git checkout sv2-tp-0.1.3
45+
./autogen.sh
46+
./configure --disable-tests --disable-bench --enable-wallet --with-gui=no
47+
make # or `make -j <num cores>`
48+
```
3949

4050
Or alternatively via `nix`:
41-
```
42-
git clone https://github.com/plebhash/nix-bitcoin-core-archive
43-
cd nix-bitcoin-core-archive/fork/sv2
44-
nix-build
45-
# the executables are available at `result/bin`
46-
```
51+
```sh
52+
git clone https://github.com/plebhash/nix-bitcoin-core-archive
53+
cd nix-bitcoin-core-archive/fork/sv2
54+
nix-build # the executables are available at `result/bin`
55+
```
4756

4857
---
4958

@@ -207,10 +216,15 @@ loglevel=sv2:debug
207216

208217
## Start `bitcoind` Template Provider
209218

210-
assuming `$TP` is the path to `bitcoind`:
211-
219+
Add the Bitcoin binaries to `$PATH`:
220+
```sh
221+
echo 'export PATH="$HOME/bitcoin/src:$PATH"' >> ~/.bashrc && export PATH="$HOME/bitcoin/src:$PATH"
212222
```
213-
$TP -datadir=$HOME/.bitcoin-sv2-workshop -signet -sv2
223+
224+
Start the Bitcoin node:
225+
226+
```sh
227+
bitcoind -datadir=$HOME/.bitcoin-sv2-workshop -signet -sv2
214228
```
215229

216230
---
@@ -232,24 +246,22 @@ Miners can jump to slide 28
232246

233247
## Create wallet (Pool)
234248

235-
assuming `$CLI` is the path to `bitcoin-cli`
236-
237249
```
238-
$CLI -signet -datadir=$HOME/.bitcoin-sv2-workshop createwallet sv2-workshop
250+
bitcoin-cli -signet -datadir=$HOME/.bitcoin-sv2-workshop createwallet sv2-workshop
239251
```
240252

241253
## Generate address (Pool)
242254

243255
```
244-
$CLI -signet -datadir=$HOME/.bitcoin-sv2-workshop getnewaddress sv2-workshop-address
256+
bitcoin-cli -signet -datadir=$HOME/.bitcoin-sv2-workshop getnewaddress sv2-workshop-address
245257
```
246258

247259
---
248260

249261
## Get pubkey (Pool)
250262

251263
```
252-
$CLI -signet -datadir=$HOME/.bitcoin-sv2-workshop getaddressinfo <sv2-workshop-address>
264+
bitcoin-cli -signet -datadir=$HOME/.bitcoin-sv2-workshop getaddressinfo <sv2-workshop-address>
253265
```
254266

255267
⚠️ Take note of the `pubkey` value so you can use it on the next step, and also to check your mining rewards on mempool later.
@@ -343,4 +355,4 @@ minerd -a sha256d -o stratum+tcp://localhost:34255 -q -D -P
343355

344356
---
345357

346-
# Thank you
358+
# Thank you

0 commit comments

Comments
 (0)
Please sign in to comment.