Set up your own private stratum pool


#1

Important: this will work with only zcash 1.0.3
So, you will have to use https://github.com/zcash/zcash/tree/v1.0.3 when downloading zcash


I thought I'd share with you all what I have learned in building a privet (or if you want public) zec pool. I pursued this in hope that maybe if can build my own farm, I will have it work on my own private pool, instead of using a public pool.

The core of the pool (and 90% of what I will write) is from eXtremal-ik7 work Zcash Pool Frontend, but I had a lot of help from the zog team (mainly @voxelot) who helped me to get it to work (and I'm waiting for my first block to show my appreciation :slight_smile: )

I used ubuntu 16.04 server edition to set it up, and it has 4GB ram right now, and that's it.

If you think this was useful for you, you can always send a few :wink: to my ZEC addr: t1eYeHJKV6Ku9VzadpS8p1LDBeYXqQtRjvw :))))

So, here it goes:

  • install ubuntu server and get it updated:

sudo apt-get update && sudo apt-get upgrade && sudo apt-get dist-upgrade

  • install a few dependencies (mainly Zcash's) **update thanks to @dukemc

sudo apt-get install cmake libssl-dev libsodium-dev libpcre3-dev libleveldb-dev libboost-all-dev libgmp-dev libprotobuf-dev protobuf-compiler libjansson-dev screen build-essential pkg-config libc6-dev m4 g++-multilib autoconf libtool ncurses-dev unzip git python zlib1g-dev wget bsdmainutils automake

  • create a dir for your installation, and lets assume you are in your home folder named , so you should be now in /home/user, and you will create ZEC as your installation folder

mkdir ZEC
cd ZEC

now start with eXtremal-ik7 guide

git clone https://github.com/zcash/zcash
git clone https://github.com/config4star/config4cpp
git clone https://github.com/google/flatbuffers
git clone https://github.com/eXtremal-ik7/libp2p -b version/0.3
git clone https://github.com/eXtremal-ik7/poolcore
git clone https://github.com/eXtremal-ik7/pool_frontend_zcash
git clone https://github.com/eXtremal-ik7/poolrestapi
git clone https://github.com/eXtremal-ik7/ngxrest
git clone https://github.com/eXtremal-ik7/pooljs
wget https://nginx.org/download/nginx-1.11.5.tar.gz
tar -xzf nginx-1.11.5.tar.gz

  • although it doesn't say so in the steps, but it seems that you need to compile zcash first before going forward, so you that :

  • create zcash.conf file (put your rpcuser name instead of "user") ... thanks @voidwalkerz9

mkdir -p ~/.zcash
echo "addnode=mainnet.z.cash" >~/.zcash/zcash.conf
echo "rpcuser=user" >>~/.zcash/zcash.conf
echo "rpcpassword=head -c 32 /dev/urandom | base64" >>~/.zcash/zcash.conf

  • then build zcash in order to get v 1.0.3 i believe the way is to check out v 1.0.3

cd zcash
git checkout v1.0.3
./zcutil/fetch-params.sh
./zcutil/build.sh -j$(nproc)

  • now move back and start configuring the rest of the parts (make sure you replace with your user's home dir name):

cd ..
cd config4cpp
make -j4
cd ..

cd flatbuffers
mkdir build
cd build
cmake ..
make -j4
sudo make install
cd ../..

cd libp2p
mkdir x86_64-Linux
cd x86_64-Linux
cmake ../src
make -j4
cd ../..

cd poolcore
mkdir x86_64-Linux
cd x86_64-Linux
cmake ../src -DROOT_SOURCE_DIR=/home/user/ZEC -DZCASH_ENABLED=1
make -j4
cd ../..

cd pool_frontend_zcash
mkdir x86_64-Linux
cd x86_64-Linux
cmake ../src -DROOT_SOURCE_DIR=/home/user/ZEC
make -j4
cd ../..

cd poolrestapi
mkdir x86_64-Linux
cd x86_64-Linux
cmake ../src -DROOT_SOURCE_DIR=/home/user/ZEC
make -j4
cd ../..

  • now you are back at /home/user, lets create the nginx folder and compile it

mkdir nginx
cd ZEC/nginx-1.11.5
./configure --prefix=/home/user/nginx --add-module=/home/user/ZEC/ngxrest
make -j4
make install
cd ..

  • if you want to add SSL certificate (thanks to @GreaterNinja) instead of the above ./configure line

./configure --prefix=/home/user/nginx --add-module=/home/user/ZEC/ngxrest --with-http_ssl_module --with-http_v2_module

  • next you need to patch zcash and recompile it

cd zcash
patch -p0 < /home/user/ZEC/pool_frontend_zcash/pool.diff

  • next you need to edit the Makefile in both zcash root folder & in zcash/src folder (i use nano to edit it)
  • open each file and search (in nano its ctrl+w) for

LIBZCASH_LIBS =

  • and replace it (or append to the end of the line) and save it (ctrl-x then y)

LIBZCASH_LIBS = -lsnark -lgmp -lgmpxx -lboost_system-mt -lcrypto -lsodium -fopenmp -L/home/user/ZEC/poolcore/x86_64-Linux/zcash -lpoolrpczcash -L/home/user/ZEC/libp2p/x86_64-Linux/p2p -lp2p -L/home/user/ZEC/libp2p/x86_64-Linux/asyncio -lasyncio-0.3 -lrt

  • then build zcash again

make -j4

  • now comes the tricky parts :slight_smile:
  • you need to move some files into the right locations and to make things easy I put mine in the ./zcash folder
  • so move into that folder and create the following:

cd /home/user/.zcash
nano poolrestapi.cfg

  • add the following:

poolrestapi {
listenAddress = "cxxrestapi://127.0.0.1:19999";
coins = ["zec"];
}

zec {
frontends = ["p2p://127.0.0.1:13301"];
poolAppName = "pool_frontend_zcash";
}

  • next file

nano zcash.cfg

  • add the following: (add your own created z & t addr) i added 2 different t-addr for poolFeeAddr & pool_taddr

pool_frontend_zcash {
isMaster = "true";
poolFee = "1";
poolFeeAddr = "t1Lbnzr5Jtykyjvm8JRDAnUTxxxxxxxxxxxx";
walletAddrs = ["p2p://127.0.0.1:12201"];
localAddress = "p2p://127.0.0.1:13301";
walletAppName = "pool_rpc";
poolAppName = "pool_frontend_zcash";
requiredConfirmations = "10";
defaultMinimalPayout = "0.01";
dbPath = "/home/user/pool.zcash";
keepRoundTime = "3";
keepStatsTime = "2";
confirmationsCheckInterval = "7";
payoutInterval = "30";
balanceCheckInterval = "3";
statisticCheckInterval = "1";

zmqclientHost = "192.168.1.120";
zmqclientListenPort = "6668";
zmqclientWorkPort = "60200";

pool_zaddr = "zcG47QGy8g2md2uUg6dtQBKgT75hz4bJ1974rmdxxxxxxxxxxxxxxxxxxxxx";
pool_taddr = "t1UrNsXAQjrDKpwovMs5xxxxxxxxxxxx";
}

  • also change the zmqclientHost to your local

  • next file is the nginx config file so move to the nginx folder:

cd /home/user/nginx/conf
nano nginx.conf

  • if the file exists, back it up and create a new one:

mv nginx.conf nginx.conf.back
nano nginx.conf

  • add the following

worker_processes 4;

events {
worker_connections 10240;
multi_accept on;
}

http {
include mime.types;
default_type application/octet-stream;

sendfile        on;
tcp_nopush      on;
tcp_nodelay     on;

keepalive_timeout  65;

upstream api_backend {
    server     127.0.0.1:19999;
    keepalive  32;
}

server {
    listen       *:80 reuseport;
    server_name  pool;

    location / {
        root   html;
        index  index.html index.htm;
        expires 5s;
    }

    location /api {
        cxxrest_pass api_backend;
    }

    location ~* ^.+\.(jpg|jpeg|gif|png|ico)$ {
      expires 3d; # 3 days
    }
}

}

  • now copy the actual frontend to its location in nginx

cd /home/user/ZEC/pooljs/coins-for-all/webapp
cp -r /home/user/ZEC/pooljs/coins-for-all/webapp/* /home/user/nginx/html

  • edit the coins.json file

cd
nano /home/user/nginx/html/static/f/coins.json

  • make it the following:

[
{
"title": "Z-Cash",
"code": "ZEC",
"desc": "Z-Cash Private Mining",
"icon_url": "static/i/zcash.png",
"block_url": "https://explorer.zcha.in/blocks/:hash",
"transaction_url": "https://explorer.zcha.in/transactions/:txid",
"power": {
"type": "SOLS",
"name": "sols/s",
"rate": "sols rate"
}
}
]

  • rename or copy a few files to match the "ZEC" changes

mv /home/user/nginx/html/static/s/templates/zcash-description.html /home/user/nginx/html/static/s/templates/zec-description.html
mv /home/user/nginx/html/static/s/templates/zcash-mining.html /home/user/nginx/html/static/s/templates/zec-mining.html
mv /home/user/nginx/html/static/s/templates/zcash-servers.html /home/user/nginx/html/static/s/templates/zec-servers.html

  • time to build the frontend

cd ZEC/pool_frontend_zcash
cd x86_64-Linux
make clean
cmake ../src -DROOT_SOURCE_DIR=/home/user/ZEC
make -j4
cd ../..

  • and all you have to do is run it :smiley:

  • first run, you have to get zcash to sync all blocks, so do that (thanks @dukemc :slight_smile: ) :

/usr/bin/screen -dmS "zecnode" ./ZEC/zcash/src/zcashd

  • once updated and all synced ... stop zcashd and re-run everything

screen -r zecnode
ctrl+c

  • i made a script to run all parts:

cd
nano zec.pool.sh

  • add the following:(there was an error here because of the editor uses '#' as char for bold ... sorry )

#!/bin/bash

echo "starting up ZEC Pool"

echo "Starting ZEC node"
/usr/bin/screen -dmS "zecnode" ./ZEC/zcash/src/zcashd -p2pport=12201

echo "Starting Frontend"
/usr/bin/screen -dmS "zecpool" ./ZEC/pool_frontend_zcash/x86_64-Linux/pool_frontend_zcash ~/.zcash/zcash.cfg

echo "Starting Rest API"
/usr/bin/screen -dmS "zecapi" ./ZEC/poolrestapi/x86_64-Linux/poolrestapi ~/.zcash/poolrestapi.cfg

echo "Starting Nginx"
sudo nginx/sbin/nginx

and voila ... you should have a running zec stratum pool !!!

so if you find this all insightful and helpful, you can always show that to:

eXtremal: by mining on his pool i was trying to locate his zec addr !! or btc for that matter

@voxelot: also by mining his pool or his newly luck / solo pool
or directly to him t1PGgRgVQ14utsD7mp2dzGdykTDFUCKzPQ5 :slight_smile:
also they released a fork of eXtremal's ZogPool Source

or :slight_smile:

myself: t1eYeHJKV6Ku9VzadpS8p1LDBeYXqQtRjvw

in all cases, if i get anything off this guide, i will make sure to pass third & third to them :)))


How do I start my own mining pool? Is it worth? What it takes?
Anyone tried eXtremal-ik7 pool frontend?
Starting new pool? Anyone?
Miner- Optiminer/Zcash GPU miner v1.7!
Trouble Building Poolcore for ZCash Pool
#2

@ megacrypto
thanks for info.
when it works i will send you my first zec :slight_smile:


#3

to build zcash you should install

sudo apt-get install \
build-essential pkg-config libc6-dev m4 g++-multilib \
autoconf libtool ncurses-dev unzip git python \
zlib1g-dev wget bsdmainutils automake

or your tutorial fails on the zcash compile.


#4

Also everyone can keep an eye on our forked eXtremal repo. There are some new things in there that are not in eXtremals base yet.

After the holidays I will clean the code up and add some more new features / complete some things that eXtremal left open like var diff and some stats reporting. Then submit PRs to eXtremal base if he feels the updates are worth adding.

Let me know if anyone has any questions getting set up.


#5

updated the guide and added them ... thank you :slight_smile:


#6

@megacrypto

I have tried out your Tutorial your bash skript looks fine but on my installation the nginx webserver was not started before so your last command should be sudo nginx/sbin/nginx without -s and reload cause thats the command when the nginx server is started already.

Second thing i think is to write down that the blocks from zcash should be synced first before starting anything else :slight_smile:


#7

Error on compile poolcore
cmake ../src -DROOT_SOURCE_DIR=/home/user/ZEC -DZCASH_ENABLED=1 - Ok, then "make" and:
[ 27%] Building CXX object poolcore/CMakeFiles/poolcore.dir/api.cpp.o
In file included from /opt/poolcore/src/include/poolcore/accounting.h:6:0,
from /opt/poolcore/src/include/poolcore/backend.h:4,
from /opt/poolcore/src/poolcore/api.cpp:4:
/opt/poolcore/src/include/poolcore/kvdb.h:4:24: fatal error: leveldb/db.h: No such file or directory
#include "leveldb/db.h"
^
compilation terminated.
make[2]: *** [poolcore/CMakeFiles/poolcore.dir/api.cpp.o] Error 1
make[1]: *** [poolcore/CMakeFiles/poolcore.dir/all] Error 2
make: *** [all] Error 2


#8

@dukemc updated :))))


#9

is your source dir also /home/USER/zec or something else? like home/XXX/zec ?


#10

you shouldn't use /home/ user /ZEC ... change it to your actual path ... usually its your login name


#11

Yes, add user "user"! And compile from it
-DROOT_SOURCE_DIR=/home/user/ZEC -DZCASH_ENABLED=1
I need zcashd source in folder?
Update: all sources in /opt - folder

if cmake ../src -DROOT_SOURCE_DIR=/opt/ZEC -DZCASH_ENABLED=1 - same error
CentOS 7

Yes! yum install leveldb-devel
I`m dumbass

And next...
pool_frontend_zcash
make
Building CXX object CMakeFiles/pool_frontend_zcash.dir/main.cpp.o
In file included from /opt/ZEC/pool_frontend_zcash/src/main.cpp:1:0:
/opt/ZEC/pool_frontend_zcash/src/zcashpool.h:83:3: error: ‘set’ in namespace ‘std’ does not name a type
std::set uniqueShares;
^
/opt/ZEC/pool_frontend_zcash/src/main.cpp: In function ‘void* timerProc(void*)’:
/opt/ZEC/pool_frontend_zcash/src/main.cpp:332:14: error: ‘struct poolContext’ has no member named ‘uniqueShares’
ctx->uniqueShares.clear();
^
/opt/ZEC/pool_frontend_zcash/src/main.cpp: In function ‘void signalHandler(p2pPeer*, void*, size_t, void*)’:
/opt/ZEC/pool_frontend_zcash/src/main.cpp:454:16: error: ‘struct poolContext’ has no member named ‘uniqueShares’
context->uniqueShares.clear();
^
make[2]: *** [CMakeFiles/pool_frontend_zcash.dir/main.cpp.o] Error 1
make[1]: *** [CMakeFiles/pool_frontend_zcash.dir/all] Error 2


#12

I'm a bit confused... you created a user named "user"?

if so, why didn't you just use your default login user?

also, what OS are you using? is it ubuntu?


#13

after i do all steps how i start the pool?


#14

you have first to run zcash and wait until it's synced

and then (for simplicty) exit it and run the bash script


#15

Hi!
Thanks a lot for your guide.

I did all good (I guess!!) but I am still getting the

nginx: [error] ngx_http_cxxrest_pass_handler: got destination: api_backend

when I start nginx at the end...
What I am missing?

Also I get an error message on Zcash Wallet:
Violación de segmento (`core' generado)

When I start the pool frontend.
And at pool frontend I get
getCurrentBlock call failed
I mean.. when I start poolfrontend, I get this CurrentBlock call fail and zcash wallet closes.

May be becouse wallet still not up to date?
How can I know?

And why I getting that error en nginx?

Thanks again for your help!


#16

Ok,
I see wallet error and frontend errors are gone, it must be becouse wallet was not sync.
Now it all good but webpage.

I can mine on local pointing at miner ip adress and all working good:
clients: 1, workers: 1, cpus: 0, gpus: 0, asics: 0, other: 0, latency: 0, power: 25600
* new block signal: 17259, diff=116116531.15134, approximate shares per block: 14514621
clients: 1, workers: 1, cpus: 0, gpus: 0, asics: 0, other: 0, latency: 0, power: 42666

So the only think is not working is nginx and api for web stats...
Any Ideas?
nginx: [error] ngx_http_cxxrest_pass_handler: got destination: api_backend
I did checked and redo all nginx and api steps and it seems all good :confused:

Thanks!


#17

i keep also getting the nginx api error .... in all honesty i dont know how to get rid of it ... but it doesn't seem to be affecting anything in the workings of the pool ... i know zog were using the same code and it worked fine with them and found blocks and payments also went ok.

and for the getCurrentBlock call failed ... this will keep popping until you find a block

this is my pool if you want to check it out: my pool and see if its like what you are getting (btw ... i've been running it for a week now and still waiting for a block :smile: )


#18

Mmm...
then I must have something wrong, becouse my webpage is not working.
I mean, nginx is working fine, I can see the website, but cant see any workers stats.
Its just a static frontend.
I must see myself mining.. and my worker stats when I put my adress on worker name field.

In coinsforall.io I can see pool stats:

Clients:
31
Workers:
50
Latency:
176 ms
Power:
1831.639 sols/s
GPUs:
71
Difficulty:
?

So that means it must be working..
Can you see stats on your website?

Ty!


#19

i put up a link to my pool, and yes i can see the stats.

did you run this? the restapi ?


#20

Yes I did.

you can see my web up here:

http://theminingpool.mine.nu

I'll check that part again ^^