Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clarify setup specific instructions #6

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
10bcb4d
Setup specific instructions
rrybarczyk Jul 12, 2024
073253d
Rm ref to participant docker-not in this PR
rrybarczyk Jul 14, 2024
7c906df
Name as Setup Instruction Manual
rrybarczyk Jul 14, 2024
37d2f62
Update headings
rrybarczyk Jul 14, 2024
cd4ce83
Note Genesis can be used for blk explorer
rrybarczyk Jul 14, 2024
bd675e7
How to host the slides
rrybarczyk Jul 14, 2024
feee8b7
Rm prereqs + update overview
rrybarczyk Jul 14, 2024
7440bed
Clarity on blk explorer node use
rrybarczyk Jul 14, 2024
bfe0361
Diff mempool docker compose yml
rrybarczyk Jul 14, 2024
b24711f
Rm unused ref to cpuminer
rrybarczyk Jul 14, 2024
d1005b1
Rm repeative sw versioning
rrybarczyk Jul 14, 2024
71b4f26
marp instructions
rrybarczyk Jul 14, 2024
a7076ca
Include genesis node sh script
rrybarczyk Jul 14, 2024
4f1ecaa
Improve slides instructions
rrybarczyk Jul 14, 2024
cf83028
Restructure setup instructions + blk explorer materials
rrybarczyk Jul 14, 2024
206b7ba
Give README Header 1 name
rrybarczyk Jul 14, 2024
90a5b23
Rm marp sh, instructions in mds
rrybarczyk Jul 14, 2024
ab581d6
Uniform slides info
rrybarczyk Jul 14, 2024
e17a5e8
Uniform custom signet info
rrybarczyk Jul 14, 2024
55c805b
Uniform block explorer info
rrybarczyk Jul 14, 2024
4e744fe
Update mempool docker compose diff
rrybarczyk Jul 14, 2024
26e80ce
Materials info
rrybarczyk Jul 14, 2024
31aac93
Rename docs/setup -> docs/instructor-setup
rrybarczyk Jul 14, 2024
cad6c2c
Add nix bitcion build instructions
rrybarczyk Jul 15, 2024
5e94384
Rm dup signet gen node sh
rrybarczyk Jul 15, 2024
2aa8381
Build btc from src or nix only
rrybarczyk Jul 15, 2024
d5361d8
Clarify bitcoin paths
rrybarczyk Jul 15, 2024
d2fabe3
All instructor docs in docs dir
rrybarczyk Jul 15, 2024
877a935
Rm redundant genesis bitcoin conf
rrybarczyk Jul 15, 2024
b507be9
All setup instructions in README
rrybarczyk Jul 15, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
211 changes: 172 additions & 39 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,70 +1,198 @@
# sv2-workshop
This repository contains materials for a [StratumV2 Reference Implementation](https://github.com/stratum-mining/stratum) workshop.

# Slides
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).
* For useful materials see the [materials/](https://github.com/stratum-mining/sv2-workshop/blob/main/materials) directory.

As an alternative to `marp.sh`, you can just install `marp` on the system and do:
```
These instructions cover the setup required for the instructor running the Stratum V2 workshop.

1. Configuring and hosting the slides to be accessible by the participants.
2. Configuring a publicly accessible Genesis node for participants to sync their nodes.
3. Configuring the block explorer to display participants' mined blocks.

## Slides

### Config
The `html/index.html` is built with [`marp`](https://marp.app/) and is based on the
[`md/sv2-workshop.md`](https://github.com/stratum-mining/sv2-workshop/blob/main/md/sv2-workshop.md)
file, and is committed to this repo.
To generate the `html/index.html` file on changes to `sv2-workshop.md`, install `marp` on your
system and run:

```sh
marp md/sv2-workshop.md -o html/sv2-workshop.html --theme-set css/sv2-workshop.css
```

The slides can be served via:
Or, if using `nix`, run (assuming nix flakes are available):

```sh
nix run github:tweag/nix-marp -- md/sv2-workshop.md -o html/sv2-workshop.html --theme-set css/sv2-workshop.css
```
cd html

### Run
Serve the slides:

```sh
python3 -m http.server 8888
```

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

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

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.
> Note: This can be done on any machine, however the slides specifically point the user to the SRI
VM URL. If you choose to host the slides on another machine, remember to update the slides with the
update endpoint.

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

In order to use this script, you should first export some environment variables. For example:
```
- We want a confined hashrate environment, so `mainnet`, `testnet3`, `testnet4` and the public `signet` are ill suited.
- `regtest` is too isolated and requires manual block generation, which is not practical for a collaborative workshop setting.
- We will mine on a custom `signet` that does not require coinbase signatures.
- This way, we can deploy pools + hashers and emulate a confined hashrate environment.

Participants will connect to this Genesis node to sync their blocks.

### Genesis Node
The instructor can use the existing Genesis node hosted on the SRI VM, or spin up their own. The
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:

* Deploys a local signet.
* Mines 16 blocks as bootstrapping for the SRI pool.

Before executing the script, ensure the following environment variables are defined:

```sh
$ export BITCOIND=$HOME/bitcoin/src/bitcoind
$ export BITCOIN_CLI=$HOME/bitcoin/src/bitcoin-cli
$ export BITCOIN_UTIL=$HOME/bitcoin/src/bitcoin-util
$ export MINER=$HOME/bitcoin/contrib/signet/miner
$ export BITCOIN_DATA_DIR=$HOME/.bitcoin
```

# Blockchain Explorer
#### SRI Node
A Genesis node that is publicly accessible is needed for participants to sync their Bitcoin nodes.
This can be set up by the instructor or use the existing SRI VM node.

If using the SRI hosted Genesis node, verify it is running by remoting into the SRI VM and finding
its process:

```sh
ps -ef | grep -i bitcoind
> 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
```

If spinning up a new node, see the instructions to install `bitcoin-core` in the Block Explorer
section below.

## Block Explorer
A block explorer is needed to display participants' mined blocks on the custom `signet`. A custom
`signet` Bitcoin node, [`electrs`](https://github.com/romanz/electrs), and
[`mempool.space`](https://github.com/mempool/mempool) is used for this purpose.

> Note: The steps for deploying a local `mempool.space` have not yet been automated and will need to
be performed manually.

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

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

First, clone and start `electrs`:
#### Install
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):

```sh
git clone https://github.com/Sjors/bitcoin.git
cd bitcoin
git fetch --all
git checkout sv2-tp-0.1.3
./autogen.sh
./configure --disable-tests --disable-bench --enable-wallet --with-gui=no
make # or `make -j <num cores>`
```

Or alternatively via `nix`:
```sh
git clone https://github.com/plebhash/nix-bitcoin-core-archive
cd nix-bitcoin-core-archive/fork/sv2
nix-build # the executables are available at `result/bin`
```

#### Config
Ensure the [`bitcoin.conf`](https://github.com/stratum-mining/sv2-workshop/blob/main/materials/block-explorer-bitcoin.conf)
in the `datadir` contains:

```conf
[signet]
signetchallenge=51 # OP_TRUE
prune=0
txindex=1
server=1
connect=75.119.150.111 # Genesis Node
rpcallowip=0.0.0.0/0
rpcbind=0.0.0.0
rpcuser=mempool
rpcpassword=mempool
```

#### Run
Add the Bitcoin binaries to `$PATH`:
```sh
echo 'export PATH="$HOME/bitcoin/src:$PATH"' >> ~/.bashrc && export PATH="$HOME/bitcoin/src:$PATH"
```
$ git clone https://github.com/romanz/electrs
$ cd electrs
$ git checkout v0.10.5
$ cat << EOF > electrs.toml

Start the Bitcoin node:

```sh
bitcoind -datadir=$HOME/.bitcoin-sv2-workshop -signet -sv2
```

### `electrs`

#### Install
Clone, checkout the `v0.10.5` branch, and configure:

```sh
git clone https://github.com/romanz/electrs
cd electrs
git checkout v0.10.5
cat << EOF > electrs.toml
network="signet"
auth="mempool:mempool"
EOF
$ cargo run -- --signet-magic=54d26fbd
```

Then, clone `mempool`:
#### Run
Run the server:

```sh
cargo run -- --signet-magic=54d26fbd
```
$ git clone https://github.com/mempool/mempool
$ cd mempool
$ git checkout v2.5.0

### `mempool.space`

#### Install
Clone and checkout the `v2.5.0` branch:

```sh
git clone https://github.com/mempool/mempool
cd mempool
git checkout v2.5.0
```

We are going to use the docker deployment, so we need to adjust some configs.
```diff
#### Config
The docker deployment is used with the following adjustments to the `docker/docker-compose.yml`:

```sh
git diff docker/docker-compose.yml
diff --git a/docker/docker-compose.yml b/docker/docker-compose.yml
index 68e73a1c8..98fa6a174 100644
index 68e73a1c8..300aa3d80 100644
--- a/docker/docker-compose.yml
+++ b/docker/docker-compose.yml
@@ -14,9 +14,12 @@ services:
Expand All @@ -73,18 +201,23 @@ index 68e73a1c8..98fa6a174 100644
environment:
- MEMPOOL_BACKEND: "none"
+ MEMPOOL_BACKEND: "electrum"
+ ELECTRUM_HOST: "172.27.0.1"
+ ELECTRUM_PORT: "50002"
+ ELECTRUM_HOST: "host.docker.internal" # or the IP address of the Electrum server
+ ELECTRUM_PORT: "60601" # match this with the port on which electrs is listening
+ ELECTRUM_TLS_ENABLED: "false"
CORE_RPC_HOST: "172.27.0.1"
- CORE_RPC_HOST: "172.27.0.1"
+ CORE_RPC_HOST: "host.docker.internal"
- CORE_RPC_PORT: "8332"
+ CORE_RPC_PORT: "38332"
CORE_RPC_USERNAME: "mempool"
CORE_RPC_PASSWORD: "mempool"
DATABASE_ENABLED: "true"
```

From the `docker` directory, you can start it via:
#### Run
Start the docker container:

```sh
docker-compose up
```
$ docker-compose up
```

Navigate to the exposed `localhost` endpoint.
189 changes: 99 additions & 90 deletions html/sv2-workshop.html

Large diffs are not rendered by default.

3 changes: 0 additions & 3 deletions marp.sh

This file was deleted.

6 changes: 6 additions & 0 deletions materials/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Materials
Useful configuration files or other materials both the instructor and participants.

## Instructor
* [`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.
* [`signet-genesis-node.sh`](https://github.com/stratum-mining/sv2-workshop/blob/main/materials/signet-genesis-node.sh): Genesis node setup script.
11 changes: 11 additions & 0 deletions materials/block-explorer-bitcoin.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[signet]
signetchallenge=51 # OP_TRUE
prune=0
txindex=1
server=1
connect=75.119.150.111 # Genesis Node
rpcallowip=0.0.0.0/0
rpcbind=0.0.0.0
rpcuser=mempool
rpcpassword=mempool

15 changes: 14 additions & 1 deletion signet_genesis_node.sh → materials/signet-genesis-node.sh
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,4 +1,18 @@
#!/bin/bash
#
# Genesis Node Setup
#
# - Deploys a local signet.
# - Mines 16 blocks as bootstrapping for the SRI pool.
#
# Ensure the following environment variables are set:
#
# $BITCOIND=$HOME/bitcoin/src/bitcoind
# $BITCOIN_CLI=$HOME/bitcoin/src/bitcoin-cli
# $BITCOIN_UTIL=$HOME/bitcoin/src/bitcoin-util
# $MINER=$HOME/bitcoin/contrib/signet/miner
# $BITCOIN_DATA_DIR=$HOME/.bitcoin
#

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

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

44 changes: 28 additions & 16 deletions md/sv2-workshop.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,24 @@ git checkout workshop

## Get a release from SV2 Bitcoin Core fork

Grab a release from https://github.com/plebhash/bitcoin/releases/tag/btc-prague
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):

```sh
git clone https://github.com/Sjors/bitcoin.git
cd bitcoin
git fetch --all
git checkout sv2-tp-0.1.3
./autogen.sh
./configure --disable-tests --disable-bench --enable-wallet --with-gui=no
make # or `make -j <num cores>`
```

Or alternatively via `nix`:
```
git clone https://github.com/plebhash/nix-bitcoin-core-archive
cd nix-bitcoin-core-archive/fork/sv2
nix-build
# the executables are available at `result/bin`
```
```sh
git clone https://github.com/plebhash/nix-bitcoin-core-archive
cd nix-bitcoin-core-archive/fork/sv2
nix-build # the executables are available at `result/bin`
```

---

Expand Down Expand Up @@ -207,10 +216,15 @@ loglevel=sv2:debug

## Start `bitcoind` Template Provider

assuming `$TP` is the path to `bitcoind`:

Add the Bitcoin binaries to `$PATH`:
```sh
echo 'export PATH="$HOME/bitcoin/src:$PATH"' >> ~/.bashrc && export PATH="$HOME/bitcoin/src:$PATH"
```
$TP -datadir=$HOME/.bitcoin-sv2-workshop -signet -sv2

Start the Bitcoin node:

```sh
bitcoind -datadir=$HOME/.bitcoin-sv2-workshop -signet -sv2
```

---
Expand All @@ -232,24 +246,22 @@ Miners can jump to slide 28

## Create wallet (Pool)

assuming `$CLI` is the path to `bitcoin-cli`

```
$CLI -signet -datadir=$HOME/.bitcoin-sv2-workshop createwallet sv2-workshop
bitcoin-cli -signet -datadir=$HOME/.bitcoin-sv2-workshop createwallet sv2-workshop
```

## Generate address (Pool)

```
$CLI -signet -datadir=$HOME/.bitcoin-sv2-workshop getnewaddress sv2-workshop-address
bitcoin-cli -signet -datadir=$HOME/.bitcoin-sv2-workshop getnewaddress sv2-workshop-address
```

---

## Get pubkey (Pool)

```
$CLI -signet -datadir=$HOME/.bitcoin-sv2-workshop getaddressinfo <sv2-workshop-address>
bitcoin-cli -signet -datadir=$HOME/.bitcoin-sv2-workshop getaddressinfo <sv2-workshop-address>
```

⚠️ 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.
Expand Down Expand Up @@ -343,4 +355,4 @@ minerd -a sha256d -o stratum+tcp://localhost:34255 -q -D -P

---

# Thank you
# Thank you