Mining Pool
Run your own private solo mining pool with Public Pool (opens in a new tab).
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 (opens in a new tab) and/or bitaxe (opens in a new tab) 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 make dependencies (safe to remove after installation, if you want)
$SU apk add 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
Firewall & reverse proxy
In the Security section, we set up NGINX as a reverse proxy. Now we can add the Public Pool configuration.
- Enable NGINX reverse proxy to route external encrypted HTTPS traffic internally to the Public Pool
$SU $EDITOR /etc/nginx/sites-available/public-pool-reverse-proxy.conf
server {
listen 4040 ssl;
root /var/www/public-pool-ui;
index index.html;
location / {
try_files $uri $uri/ =404;
}
location ~* ^/api/ {
proxy_pass http://127.0.0.1:23334;
}
}
$SU ln \
-s \
../sites-available/public-pool-reverse-proxy.conf \
/etc/nginx/sites-enabled/public-pool-reverse-proxy.conf
- Test and reload NGINX configuration
$SU nginx -t
$SU rc-service nginx restart
- Configure the firewall to allow incoming HTTPS requests
$SU ufw allow 4040/tcp comment 'allow Public Pool UI SSL from anywhere'
$SU ufw allow 23333/tcp comment 'allow Public Pool Stratum from anywhere'
Modify node flags
printf "%s\n" \
"export npm_config_cache=\"./npm-cache\"" \
"export npm_config_devdir=\"./.gyp\"" \
| $SU tee -a /etc/profile.d/node.sh
. /etc/profile.d/node.sh
Installation
Public Pool (opens in a new tab) provides a lightweight and easy to use web interface to accomplish just that, a solo mining pool.
Download server source code
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 (opens in a new tab) 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
Configure and install
- Install all dependencies using the Node Package Manager (NPM).
npm install
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:
At 2024-03-18
there is at least 8 moderate vulnerabilities not addressable
without breaking changes
npm audit fix --force
8 moderate severity vulnerabilities
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.
- Make it a global permanent installation
mkdir ./bin
printf "%s\n" \
"#!/bin/sh" \
"./node_modules/.bin/nest start --config ./nest-cli.json" \
> ./bin/cli.sh
chmod +x ./bin/cli.sh
$SU install -D -m 0660 -o public-pool -g public-pool ./.env.example /etc/public-pool/.env
$SU mv -f /tmp/public-pool /var/lib/
$SU ln -s /etc/public-pool/.env /var/lib/public-pool/.env
$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
Download UI source code
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 (opens in a new tab) 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
Configure, patch and install
- Install all dependencies using the Node Package Manager (NPM).
npm install
npm audit fix
At 2024-03-06
there is at least 8 vulnerabilities (5 moderate, 2 high, 1
critical) not addressable without breaking changes
npm audit fix --force
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:
npm WARN deprecated uuid@2.0.3: Please upgrade to version 7 or higher. Older versions may use Math.random() in certain circumstances, which is known to be problematic. See https://v8.dev/blog/math-random for details.
added 1040 packages, and audited 1041 packages in 10s
144 packages are looking for funding
run `npm fund` for details
8 vulnerabilities (5 moderate, 2 high, 1 critical)
To address all issues, run:
npm audit fix
Run `npm audit` for details.
- Make it a global permanent installation
printf "%s\n" \
"export const environment = {" \
" production: true," \
" API_URL: 'https://nakamoto01.local:4040'," \
" STRATUM_URL: 'nakamoto01.local:23333'" \
"};" \
> ./src/environments/environment.prod.ts
npm run build
$SU mv -f ./dist/public-pool-ui /var/www/
Configuration
- Activate any setting by removing the
#
at the beginning of the line.
$EDITOR /etc/public-pool/.env
[...]
BITCOIN_RPC_URL=http://127.0.0.1
[...]
BITCOIN_RPC_USER=microbolt
BITCOIN_RPC_PASSWORD="[ B ] Bitcoin RPC password"
BITCOIN_RPC_PORT=8332
[...]
BITCOIN_ZMQ_HOST="tcp://127.0.0.1:28332"
[...]
API_PORT=23334
STRATUM_PORT=23333
[...]
NETWORK=mainnet
[...]
ENABLE_SOLO=true
ENABLE_PROXY=false
[...]
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
# Hidden Service Public Pool
HiddenServiceDir /var/lib/tor/public-pool/
HiddenServiceVersion 3
HiddenServicePoWDefensesEnabled 1
HiddenServicePort 80 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
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
#!/sbin/openrc-run
: ${PUBLICPOOL_CONFIGFILE:=/etc/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_CONFIGFILE}"
pidfile="${PUBLICPOOL_PIDDIR}/${SVCNAME}.pid"
name="Public Pool"
description="Fully Open Source Solo Bitcoin Mining Pool"
command="${PUBLICPOOL_BIN}"
command_args="${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_CONFIGFILE}"
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
}
start_post() {
checkpath --file --owner "${command_user}" "${pidfile}"
chown -R "${command_user}" "${PUBLICPOOL_WEBUI}"
}
checkconfig() {
if ! grep -qs '^BITCOIN_RPC_USER=' "${PUBLICPOOL_CONFIGFILE}" &&
! grep -qs '^BITCOIN_RPC_PASSWORD=' "${PUBLICPOOL_CONFIGFILE}"
then
eerror ""
eerror "ERROR: You must set a BITCOIN_RPC_USER and"
eerror "BITCOIN_RPC_PASSWORD path to run Public pool."
eerror "The setting must appear in ${PUBLICPOOL_CONFIGFILE}"
eerror ""
return 1
fi
}
stop() {
ebegin "Stopping ${SVCNAME}"
pkill -TERM -P "$(pgrep -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
/var/log/public-pool/*.log {
weekly
missingok
rotate 104
compress
delaycompress
notifempty
create 0640 public-pool public-pool
sharedscripts
postrotate
killall -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
- You can now access your own Public Pool from within your local network by browsing to https://nakamoto01:4040 (opens in a new tab), https://nakamoto01.local:4040 (opens in a new tab) (or your equivalent IP address).
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 (opens in a new tab))
$SU $EDITOR /etc/public-pool/.env
- Restart the service to apply the changes
$SU rc-service public-pool restart