Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Sjors/sv2-workshop

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 

Repository files navigation

Stratum v2 workshop

Create a directory for this workshop where you'll put Bitcoin Core, SRI and configuration files.

E.g. mkdir sv2-workshop

Bitcoin Core

Download Bitcoin Core v30 or later:

No need to replace your existing node, just extract it into the workshop directory.

Sanity check:

./bitcoin-30.0/bin/bitcoin --version

Before you run the node, create a bitcoin.conf and put it in the workshop dir:

chain=signet

[signet]
# OP_PUSHDATA1 32 sha256(sjors)
signetchallenge=4c200a7dd26236968bacb6401df5fff23e5863ad6c4949c44ac5e943f23311638994

# Allow connection from sv2-tp (Template Provider)
ipcbind=unix
# Initial peer
connect=91.98.71.169
# Fee estimation doesn't work due to empty blocks
fallbackfee=0.0001

Start the node:

./bitcoin-30.0/bin/bitcoin -m node -datadir=$PWD

You should see at least 100 blocks scroll by in the log.

Open a new terminal tab to connect to your node via RPC:

./bitcoin-30.0/bin/bitcoin rpc -datadir=$PWD getblockchaininfo

Depending on Wi-Fi restrictions, you may be able to connect to your neighbors:

./bitcoin-30.0/bin/bitcoin rpc -datadir=$PWD addnode 192.168.x.x onetry
./bitcoin-30.0/bin/bitcoin rpc -datadir=$PWD getpeerinfo

Otherwise, any block you mine will reach your neighbors via the cloud peer.

Finally, let's create a wallet and generate an address to receive our plentiful coinbase bounty!

./bitcoin-30.0/bin/bitcoin rpc -datadir=$PWD createwallet Miner
./bitcoin-30.0/bin/bitcoin rpc -datadir=$PWD getnewaddress Pool bech32m

Add wallet=Miner to your bitcoin.conf so it's automatically loaded in the future.

Stratum v2 Template Provider (sv2-tp)

Download sv2-tp or build it from source:

Open a new terminal tab and sanity check it:

./sv2-tp-1.0.3/bin/sv2-tp --version

Create an sv2-tp.conf and put it in the workshop dir:

chain=signet

[signet]
debug=sv2
loglevel=sv2:trace
# Create a new template every N seconds
sv2interval=10
# But only if fees rise by at least 1 sat
sv2feedelta=1

Start the Template Provider:

./sv2-tp-1.0.3/bin/sv2-tp -datadir=$PWD

You should see the following log entry:

[sv2:info] Template Provider listening on 127.0.0.1:38336

Stratum Reference Implementation (SRI)

In a new terminal tab, clone the repo:

git clone https://github.com/stratum-mining/sv2-apps.git

Be Your Own Pool

First copy the example config file:

cp sv2-apps/pool-apps/pool/config-examples/pool-config-local-tp-example.toml pool.toml

Edit the config file:

  • under coinbase_reward_script change the address to the one you generated above
  • pool_signature: pick a cool name
  • tp_address: change the port to 38336

Now let's start your pool:

cd sv2-apps/pool-apps/pool
cargo run -- -c ~/sv2-workshop/pool.toml

The first time, it has to download a bunch of crates.

It should then connect to your template provider. You should see NewTemplate and SetNewPrevHash in both the pool and template provider logs.

CPU mining

SRI comes with a Stratum v2 native CPU miner. It's not very efficient, but it should find a block within a few seconds on most laptops.

In yet another new tab:

cd sv2-apps/miner-apps/mining-device
cargo run --release -- --address-pool 127.0.0.1:34254

It won't output any logs, but in the pool tab you'll see 💰 Block Found!!! 💰.

For each block, you'll see a SubmitSolution entry in the Template Provider logs.

On the node side, you'll see UpdateTip, which could be your block or it could be another block. But you'll also see [Miner] AddToWallet with your new wealth!

BitAxe mining

If you brought a BitAxe, you can mine much faster than with a CPU. But it doesn't speak Stratum v2, so you'll first need to run a translator. Your laptop firewall and Wi-Fi network restrictions may also get in the way, but let's try...

SRI Translator

Time for another terminal tab.

First you'll need another config file:

cp sv2-apps/miner-apps/translator/config-examples/tproxy-config-local-pool-example.toml translator.toml

Adjust min_individual_miner_hashrate for the BitAxe hash rate; it doesn't have to be accurate, though. E.g., make it 1 TH/s: 1_000_000_000_000.0

cd sv2-apps/miner-apps/translator
cargo run -- -c ~/sv2-workshop/translator.toml

You should see Translator Proxy: listening on 0.0.0.0:34255

Connect the BitAxe

Find your local IP address, e.g., ifconfig | grep 192

Log in to your BitAxe and change the pool address to 192.168.x.x:34255.

If it works, the translator and pool logs will go berserk. Once you find a few blocks, please turn it off again so we don't raise the difficulty.

If it doesn't work, check the logs. Restart the device and refresh your browser tab to see logs from the beginning.

Note: if you're on public Wi-Fi, anyone can edit your BitAxe settings and steal your precious Sjorsnet coins. When you get back home, recheck the settings!

Join another pool

Try to connect to your neighbor's pool and mine on it. Note that you may get rugged, since Stratum v2 does not specify how pools should distribute their coins. Maybe if you ask nicely, they'll use the send RPC to send your rewards (after coinbase maturity).

Mine your own templates

Without any transactions on the network, this is kind of pointless.

But the approach is:

  • the pool runs a Job Declarator Server (pool-apps/jd-server, needs RPC access to your node)
  • the miner runs a Job Declarator Client (miner-apps/jd-client)

Note that, although you get to decide which transactions go into the block, you still don't get to control who gets the coinbase reward. That goes to the pool, which then needs to distribute it.

About

Stratum v2 workshop

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published