About lottery mining
This is an expansion of my previous article "How to get started with Bitcoin Lottery Mining".
So if you're just interested in lottery mining on public pools, you can stop reading here and go to the previous article.
Why solo mining on a private pool?
Preferring a private pool instead of relying on public pools such as public-pool.io or ckpool.org has several advantages:
- Privacy: You don't have to share your mining power with others.
- Control: You can set your own rules and fees.
- Security: You can be sure that the pool is not cheating.
- In particular this is important for lottery mining; in public-pools some miners are just malicious machines with a fake hashrate, which can steal your lottery ticket.
- No fee: Some pool have a minimum of 5% or more fee to pay to the pool owner.
- Downtimes: public-pool is quite often down, so you can't mine for a while.
If I have convinced you on setting up your own pool, let's start!
Setting up the Pool
Requirements
In order to set your own pool, you'll need a Linux machine that can basically run 24/7.
I suggest you using a Raspberry pi model 4 or 3, because it's cheap, but at the same time we require a decent amount of RAM and CPU.
Raspberry pi 2 is probably too slow, and Raspberry pi 1 is definitely out of the question.
You also need a minimum knowledge of Linux and shell scripting.
You also need for sure these dependencies to be installed with apt:
sudo apt updatesudo apt install build-essential libtool autotools-dev automake pkg-config libssl-dev libevent-dev bsdmainutils git screen yasm libzmq3-dev
Monitoring
Since we need that our pool runs 24/7, we need a software that checks if the pool is running and restart it if it's not.
I usually opt for monit. So let's see the setup for it.
sudo apt updatesudo apt install monit# Enable monitsudo systemctl enable monitsudo systemctl start monit
Then you need to create a configuration file for monit.
First let's move to the monit configuration folder:
cd /etc/monit/conf-available
And let's write all the configuration services that we need.
nano bitcoin-pool
check process bitcoind with pidfile /var/run/bitcoind.pidstart program = "/app/bitcoin/service.sh start"stop program = "/app/bitcoin/service.sh stop"check process ckpool with pidfile /tmp/ckpool/main.pidstart program = "/app/ckpool/service.sh start"stop program = "/app/ckpool/service.sh stop"# check that network is always reachablecheck host internet with address 1.1.1.1if failed ping 3 times within 30 cycles then exec "/usr/sbin/reboot"# optional; only if you want to mine with your raspberry as wellcheck process cpuminer with pidfile /var/run/cpuminer.pidstart program = "/app/cpuminer-multi/service.sh start"stop program = "/app/cpuminer-multi/service.sh stop"
At this point we link the configuration to enabled configs and reload monit:
cd /etc/monit/conf-enabledln -s /etc/monit/conf-available/bitcoin-poolmonit reload
Setup Bitcoin-RPC
At this point we need to setup the Bitcoind service.
Indeed in order to run our pool, we need to have a full node running, but don't worry about disk space, we'll just keep the minimum amount of data, about 5000 blocks. (minimum required for ckpool should be between 500-1000).
You can get the latest version of Bitcoin Core from the official website.
Here get the link for ARM 64 Linux (64bit)
. for Raspberry pi 3/4.
mkdir -p /appwget -O /tmp/bitcoin.tar.gz https://bitcoin.org/bin/bitcoin-core-27.0/bitcoin-27.0-aarch64-linux-gnu.tar.gztar xzvf /tmp/bitcoin.tar.gzcd /app/bitcoin-27.0sudo cp bin/* /usr/local/bin# set configuration for bitcoindnano /etc/bitcoin.conf
And write this to your configuration (you can change the rpcuser and rpcpassword if you wish):
# block to keepprune=5000# data dirdatadir=/app/bitcoin/datanodebuglogfile=1server=1rpcuser=pirpcpassword=bitcoindrpcallowip=127.0.0.1rpcbind=127.0.0.1
Finally we need to setup the directory for bitcoin:
mkdir -p /app/bitcoin/datatouch /app/bitcoin/service.shchmod +x /app/bitcoin/service.shnano /app/bitcoin/service.sh
And write this to your service script:
#!/bin/shcd "$(dirname "$0")" || exit 1APP_NAME="bitcoind"PIDFILE="/var/run/$APP_NAME.pid"info() {printf '%s\n' "${BOLD}${GREY}>${NO_COLOR} $*"}error() {printf '%s\n' "${RED}x $*${NO_COLOR}" >&2}start() {screen -S "$APP_NAME" -d -m bitcoind -pid="$PIDFILE" -conf="/etc/bitcoin.conf" -zmqpubhashblock=tcp://127.0.0.1:28332return 0}stop() {info "stopping $APP_NAME"PID=$(cat $PIDFILE)if [ -z "$PID" ]; thenerror "Could not find any PID for $APP_NAME"return 1fiinfo "killing PID $PID"kill $PIDreturn 0}case "$1" in"start")start;;"stop")stop;;"restart")stopstart;;*)"unknown operation $OP"exit 1;;esac
And for bitcoind we're done. Consider that once started bitcoind it may take a very long time to sync the blockchain.
In my case it took about one week to sync the blockchain.
Setup CkPool
Now we need to setup the ckpool software.
CkPool is an opensource software that allows you to run your own mining pool.
First of all clone the git repository and build it:
git clone https://bitbucket.org/ckolivas/ckpool.git /app/ckpoolcd /app/ckpool./autogen.sh./configuremake -j 2# link binaries to PATHln -s /app/ckpool/src/ckpool /usr/local/bin/ckpoolln -s /app/ckpool/src/ckpmsg /usr/local/bin/ckpmsg
Then we need to setup the service script for ckpool:
nano service.sh
#!/bin/shcd "$(dirname "$0")" || exit 1APP_NAME="ckpool"PIDFILE="/tmp/ckpool/main.pid"info() {printf '%s\n' "${BOLD}${GREY}>${NO_COLOR} $*"}error() {printf '%s\n' "${RED}x $*${NO_COLOR}" >&2}start() {screen -S "$APP_NAME" -d -m ckpool -Breturn 0}stop() {info "stopping $APP_NAME"PID=$(cat $PIDFILE)if [ -z "$PID" ]; thenerror "Could not find any PID for $APP_NAME"return 1fiinfo "killing PID $PID"kill $PIDreturn 0}case "$1" in"start")start;;"stop")stop;;"restart")stopstart;;*)"unknown operation $OP"exit 1;;esac
And finally let's configure ckpool:
nano /app/ckpool/ckpool.conf
{"btcd": [{"url": "localhost:8332","auth": "BITCOIN_RPC_USERNAME","pass": "BITCOIN_RPC_PASSWORD","notify": true}],"btcaddress": "YOUR_BITCOIN_ADDRESS_WHERE_TO_RECEIVE_BTC","btcsig": "/Proudly mined by a Solo Miner/","blockpoll": 100,"nonce1length": 4,"nonce2length": 8,"update_interval": 30,"version_mask": "1fffe000","mindiff": 1,"startdiff": 42,"maxdiff": 0,"zmqblock": "tcp://127.0.0.1:28332","logdir": "logs"}
So just change:
BITCOIN_RPC_USERNAME
andBITCOIN_RPC_PASSWORD
with the values you set in thebitcoin.conf
file.YOUR_BITCOIN_ADDRESS_WHERE_TO_RECEIVE_BTC
with your Bitcoin address, where you want to receive the mined BTC.
Connect your Miners to the pool
And that's it! You can now connect your miners to your pool.
To do so, just set the RPC url as IP_OF_YOUR_RASPBERRY:3333
.
In case it's required just set your username as YOUR_BITCOIN_ADDRESS.HOSTNAME
, where:
YOUR_BITCOIN_ADDRESS
is your Bitcoin address.HOSTNAME
is the hostname of your miner machine.
Check if it works
At this point, if you've already run monit reload
, you should see the services running.
You can check with monit summary
and check if everything is set to OK
.
Actually you can also check the logs of the services using screen
:
screen -r bitcoind# output of the log# press CTRL+A and then D to detach from the screenscreen -r ckpool# output of the log# press CTRL+A and then D to detach from the screen
Conclusions
So that's it! You've successfully setup your own Bitcoin Solo Mining Pool.
This should be considered along with "How to get started with Bitcoin Lottery Mining", the Ultimate guide to Solo Mining On Bitcoin.
