Mining Pool

Run your own private solo mining pool with Public Pool.

Public Pool home screen

Run your own mining pool

After the Microbolt runs your own fully validated node, acts as a backend for your hardware signing device with Electrum server, can explore the blockchain on a web browser, the last important puzzle piece to improve privacy and financial sovereignty is your own mining pool. It lets you connect your own nerdminer and/or bitaxe to your Microbolt and try to “find” a block in Solo Bitcoin Mining Pool. You no longer need to leak information by querying your hashrate to a third-party Mining Pool.

Preparations

Install dependencies

  • Install Node.js using the apk package manager.

These are build dependencies (safe to remove after installation, if you want)

$SU apk add --virtual .build-deps git npm

These are runtime dependencies

$SU apk add nodejs-current

Create the public-pool user/group

$SU addgroup -S public-pool
$SU adduser \
    -S \
    -D \
    -H \
    -h /dev/null \
    -s /sbin/nologin \
    -G public-pool \
    -g public-pool \
    public-pool

Add public-pool user to the bitcoin group

$SU adduser public-pool bitcoin

Add satoshi user to the public-pool group

$SU adduser satoshi public-pool && exec su -l satoshi

Reverse proxy

In the Security section, we set up a reverse proxy. Now we can add the Public Pool configuration.

  • Enable the reverse proxy to route external encrypted HTTPS traffic internally to the Public Pool
$SU $EDITOR /etc/caddy/sites/public-pool.caddy
/etc/caddy/sites/public-pool.caddy
:4040 {
    import tls
    root /var/www/public-pool-ui
 
    handle /api/* {
        reverse_proxy 127.0.0.1:23334
    }
 
    handle {
        try_files {path} {path}/ =404
        file_server
    }
}
  • Reload Caddy
$SU rc-service caddy restart

Firewall

  • Configure the firewall to allow incoming HTTPS requests
$SU $EDITOR /etc/awall/optional/pool-ui.json
/etc/awall/optional/pool-ui.json
{
  "description": "Allow Public Pool UI SSL",
 
  "filter": [
    {
      "in": "internet",
      "out": "_fw",
      "service": { "proto": "tcp", "port": 4040 },
      "action": "accept",
      "conn-limit": { "count": 10, "interval": 60 }
    }
  ]
}
$SU $EDITOR /etc/awall/optional/pool-stratum.json
/etc/awall/optional/pool-stratum.json
{
  "description": "Allow Public Pool Stratum",
 
  "filter": [
    {
      "in": "internet",
      "out": "_fw",
      "service": { "proto": "tcp", "port": 23333 },
      "action": "accept",
      "conn-limit": { "count": 10, "interval": 60 }
    }
  ]
}
  • Enable it
$SU awall enable pool-ui pool-stratum
$SU awall activate

Installation

Public Pool provides a lightweight and easy to use web interface to accomplish just that, a solo mining pool.

Backend

We get the latest commit of the Public Pool server source code and install it.

  • Download the source code for the latest Public Pool server commit. You can check the release page to see if a newer release is available. Other releases might not have been properly tested with the rest of the Microbolt configuration, though.
cd /tmp
git clone https://github.com/benjamin-wilson/public-pool.git && cd public-pool
git checkout 8ce057b3b51c33bf915f57f3a30822b449613276
  • Install all dependencies using the Node Package Manager (NPM).
npm ci

Installation can take some time. There might be a lot of confusing output, but if you see something similar to the following, the installation was successful:

⚠️

At 2024-09-01 there is at least 23 vulnerabilities not addressable without breaking changes

npm audit fix
output
23 vulnerabilities (2 low, 14 moderate, 6 high, 1 critical)

To address issues that do not require attention, run:
  npm audit fix

To address all issues possible (including breaking changes), run:
  npm audit fix --force

Some issues need review, and may require choosing
a different dependency.

Run `npm audit` for details.
  • Make it a global permanent installation
npm run build
mkdir ./dist/bin
printf "%s\n" \
    "#!/bin/sh" \
    "node \$@ /var/lib/public-pool/main" \
    > ./dist/bin/cli.sh
chmod +x ./dist/bin/cli.sh
$SU install -D -m 0660 -o public-pool -g public-pool ./.env.example /etc/public-pool/public-pool.env
$SU mv -f /tmp/public-pool/dist /var/lib/public-pool
$SU cp -R node_modules /var/lib/public-pool
$SU ln -s /var/lib/public-pool /usr/lib/node_modules/public-pool
$SU ln -s ../lib/node_modules/public-pool/bin/cli.sh /usr/bin/public-pool

Frontend

We get the latest commit of the Public Pool source code and install it.

  • Download the source code for the latest Public Pool commit. You can check the release page to see if a newer release is available. Other releases might not have been properly tested with the rest of the Microbolt configuration, though.
cd /tmp
git clone https://github.com/benjamin-wilson/public-pool-ui.git && cd public-pool-ui
git checkout 80081e337d3af829b0edf3990ad97ea430bd73d4
  • Install all dependencies using the Node Package Manager (NPM).
npm ci
⚠️

At 2024-09-01 there is at least 3 moderate vulnerabilities not addressable without breaking changes

npm audit fix

Installation can take some time. There might be a lot of confusing output, but if you see something similar to the following, the installation was successful:

output
3 moderate severity vulnerabilities

To address issues that do not require attention, run:
  npm audit fix

To address all issues, run:
  npm audit fix --force

Run `npm audit` for details.
  • Make it a global permanent installation
printf "%s\n" \
    "let path = window.location.origin + window.location.pathname;" \
    "path = path.endsWith('/') ? path.slice(0, -1) : path;" \
    "let stratumUrl = path.replace(/(^\\w+:|^)\\/\\//, '').replace(/:\\d+/, '');" \
    "" \
    "export const environment = {" \
    "    production: true," \
    "    API_URL: path," \
    "    STRATUM_URL: stratumUrl + ':23333'" \
    "};" \
    > ./src/environments/environment.prod.ts
npm run build
$SU mv -f ./dist/public-pool-ui /var/www/

Cleanup

cd
rm -rf /tmp/public-pool*
$SU apk del .build-deps

Configuration

  • Activate any setting by removing the # at the beginning of the line.
$SU $EDITOR /etc/public-pool/public-pool.env
/etc/public-pool/public-pool.env
[...]
BITCOIN_RPC_URL=http://127.0.0.1
[...]
BITCOIN_RPC_COOKIEFILE="/var/lib/bitcoind/.cookie"
[...]
BITCOIN_ZMQ_HOST="tcp://127.0.0.1:28332"
[...]
API_PORT=23334
STRATUM_PORT=23333
[...]
POOL_IDENTIFIER="microbolt"
[...]
Remote access UI over Tor
  • Add the following three lines in the “location-hidden services” section in the torrc file.
$SU $EDITOR /etc/tor/torrc
/etc/tor/torrc
# Hidden Service Public Pool
HiddenServiceDir /var/lib/tor/public-pool/
HiddenServiceVersion 3
HiddenServicePoWDefensesEnabled 1
HiddenServicePort 443 127.0.0.1:4040
  • Reload Tor configuration and get your connection address.
$SU rc-service tor reload
$SU cat /var/lib/tor/public-pool/hostname
output
abcdefg..............xyz.onion
  • You should now be able to connect to your Public Pool remotely via Tor using your hostname

Autostart on boot

Now we’ll make sure our mining pool starts as a service on the computer so that it’s always running.

  • Create the Public Pool init.d unit and copy/paste the following configuration. Save and exit.
$SU $EDITOR /etc/init.d/public-pool
/etc/init.d/public-pool
#!/sbin/openrc-run
 
: ${PUBLICPOOL_ENVFILE:=/etc/public-pool/public-pool.env}
: ${PUBLICPOOL_WEBUI:=/var/www/public-pool-ui}
: ${PUBLICPOOL_DATADIR:=/var/lib/public-pool}
: ${PUBLICPOOL_LOGDIR:=/var/log/public-pool}
: ${PUBLICPOOL_USER:=public-pool}
: ${PUBLICPOOL_GROUP:=public-pool}
: ${PUBLICPOOL_BIN:=/usr/bin/public-pool}
: ${PUBLICPOOL_OPTS=${PUBLICPOOL_OPTS}}
: ${PUBLICPOOL_SIGTERM_TIMEOUT:=600}
 
PUBLICPOOL_PIDDIR="/run/public-pool"
 
directory="${PUBLICPOOL_DATADIR}"
required_files="${PUBLICPOOL_ENVFILE}"
pidfile="${PUBLICPOOL_PIDDIR}/${SVCNAME}.pid"
 
name="Public Pool"
description="Fully Open Source Solo Bitcoin Mining Pool"
 
command="${PUBLICPOOL_BIN}"
command_args="--env-file=${PUBLICPOOL_ENVFILE}
              ${PUBLICPOOL_OPTS}"
command_user="${PUBLICPOOL_USER}:${PUBLICPOOL_GROUP}"
command_background="true"
 
start_stop_daemon_args="--stdout ${PUBLICPOOL_LOGDIR}/debug.log
                        --stderr ${PUBLICPOOL_LOGDIR}/debug.log"
 
depend() {
    need bitcoind
}
 
start_pre() {
    checkpath --file      --mode 0660 --owner "${command_user}" "${PUBLICPOOL_ENVFILE}"
    checkpath --directory --mode 0750 --owner "${command_user}" "${PUBLICPOOL_DATADIR}"
    checkpath --directory --mode 0755 --owner "${command_user}" "${PUBLICPOOL_LOGDIR}"
    checkpath --directory --mode 0755 --owner "${command_user}" "${PUBLICPOOL_PIDDIR}"
    checkpath --directory --mode 0755 --owner "${command_user}" "${PUBLICPOOL_WEBUI}"
    checkconfig
}
 
checkconfig() {
    if ! grep -qs '^BITCOIN_RPC_COOKIEFILE=' "${PUBLICPOOL_ENVFILE}"
    then
        eerror ""
        eerror "ERROR: You must set a BITCOIN_RPC_COOKIEFILE path"
        eerror "to run Public pool."
        eerror "The setting must appear in ${PUBLICPOOL_ENVFILE}"
        eerror ""
        return 1
    fi
}
 
stop() {
    ebegin "Stopping ${SVCNAME}"
    pkill -TERM -P "$(cat ${pidfile})"
    start-stop-daemon \
        --stop \
        --pidfile="${pidfile}" \
        --retry="${PUBLICPOOL_SIGTERM_TIMEOUT}" \
        --exec="${PUBLICPOOL_BIN}"
    eend $?
}
  • Enable execution permission
$SU chmod +x /etc/init.d/public-pool

Enable logrotate

  • Enter the complete next configuration. Save and exit
$SU $EDITOR /etc/logrotate.d/public-pool
/etc/logrotate.d/public-pool
/var/log/public-pool/*.log {
    weekly
    missingok
    rotate 104
    compress
    delaycompress
    notifempty
    create 0640 public-pool public-pool
    sharedscripts
    postrotate
        kill -HUP `cat /run/public-pool/public-pool.pid`
    endscript
}
  • Test
$SU logrotate /etc/logrotate.d/public-pool --debug

Enable and start Public Pool

$SU rc-update add public-pool
$SU rc-service public-pool start
🎉

Congratulations! You now have Public Pool up and running

  • Check the log to see Public Pool output. Exit with Ctrl-C
tail -f /var/log/public-pool/debug.log

For the future: Public Pool update

⚠️

There is no existing version in the public-pool yet, so please update it when enough time has passed or follow the project to see if there is anything interesting

Follow again Mining Pool page replacing the environment variable VERSION=x.xx value for the latest if it has not been already changed in this guide.

  • Update the Public Pool configuration if necessary (see release notes)
$SU $EDITOR /etc/public-pool/.env
  • Restart the service to apply the changes
$SU rc-service public-pool restart