How to install PHP-Pool

in gridcoin •  6 years ago  (edited)

Here is insructions to install grcpool clone from github: https://github.com/gridcoin-community/PHP-Pool

Pre-requirements

You need:

  • Apache2
  • MySQL
  • php 7
  • phpmyadmin
  • Composer
  • Gridcoin research
  • domain. For this sample it will be 'testphppool.arikado.ru'
  • Enough amount GRC for solo mining
  • certbot for obtaining HTTPS certificate

Getting started

Install apache2, mysql, php. Setup instructions can be easily found in internet.

You shoud have GUI and CLI for next steps.

BOINC

Install BOINC:

sudo apt-get install boinc-manager

Register on some BOINC whitelisted projects with single mail and single username. Let username be testphppool and mail [email protected]. It is not necessary to register on every project, only those you want for your pool. Join Gridcoin team for each account. Start contributing to all projects. Wait until all CPIDs are match for all projects.

BOINC crypt_prog

Install software for compilation, download BOINC sources and compile:

sudo apt-get install make g++ m4 pkg-config dh-autoreconf libssl-dev
git clone https://github.com/BOINC/boinc
cd boinc
./_autosetup
./configure --disable-manager --disable-server --disable-client
make
cd tools
make -f makefile_sign_executable

Then generate keys:

./crypt_prog -genkey 1024 private_keyfile public_keyfile

Save public_keyfile somewhere. It will used later.

Then sign URL for each project:

./crypt_prog -sign_string "URL" private_keyfile

For projects URL see 'projects' command in Gridcoin Research below. Save result somewhere for each URL. It will be used later.

Gridcoin Research

Install the gridcoin research client:

sudo apt-get install gridcoinresearchd gridcoinresearch-qt

Check where gridcoinresearchd located, thet path will be used later

which gridcoinresearchd

Start gridcoin research wallet, wait until it syncs. Fill with coins, send beacon:

gridcoinresearchd advertisebeacon

Check that your wallet is staking.

In settings set Gridcoin Research autostart during system start up.

Then execute

gridcoinresearchd projects

That information will be required later.

Also you need add group access permissions to your gridcoinresearch.conf

chmod 660 ~/.GridcoinResearch/gridcoinresearch.conf
sudo usermod -G www-data `whoami`

Restart apache2 to apply group change

service apache2 restart

Phpmyadmin

I recommend to install phpmyadmin, because PHP-Pool has no web interface for administration:

sudo apt-get install phpmyadmin

After install move phpmyadmin from default folder to another:

nano /etc/apache2/conf-enabled/phpmyadmin.conf

Change string

Alias /phpmyadmin /usr/share/phpmyadmin

To something else:

Alias /dsnjkdvpefme /usr/share/phpmyadmin

Then restart apache

sudo service apache2 reload

Then go to your site/dsnjkdvpefme folder and log in to phpmyadmin with your root login and password. Go to "User accounts" tab, click "Add user accoount" with name testphppool, random password, and check "Create database with same name and grant all privileges.". Record password somewhere, then click Go.

Then go to your new database ("testphppool" on the right), click "SQL" on the top.

Get tables creation query from the https://github.com/gridcoin-community/PHP-Pool/blob/master/schema_2018.05.23.sql

Then replace string 217 from

CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `view_all_orphans`  AS  select `grcpool`.`member_host_credit`.`id` AS `id`,`grcpool`.`member_host_credit`.`hostDbid` AS `hostDbid`,`grcpool`.`member_host_credit`.`hostCpid` AS `hostCpid`,`grcpool`.`member_host_credit`.`totalCredit` AS `totalCredit`,`grcpool`.`member_host_credit`.`avgCredit` AS `avgCredit`,`grcpool`.`member_host_credit`.`accountId` AS `accountId`,`grcpool`.`member_host_credit`.`lastSeen` AS `lastSeen`,`grcpool`.`member_host_credit`.`mag` AS `mag`,`grcpool`.`member_host_credit`.`magTotalCredit` AS `magTotalCredit`,`grcpool`.`member_host_credit`.`owed` AS `owed`,`grcpool`.`member_host_credit`.`owedCalc` AS `owedCalc`,`grcpool`.`member_host_credit`.`memberIdPayout` AS `memberIdPayout`,`grcpool`.`member_host_credit`.`memberIdCredit` AS `memberIdCredit` from `grcpool`.`member_host_credit` where ((not((`grcpool`.`member_host_credit`.`hostDbid`,`grcpool`.`member_host_credit`.`accountId`) in (select `grcpool`.`member_host_project`.`hostDbid`,`grcpool`.`member_host_project`.`accountId` from `grcpool`.`member_host_project`))) and (`grcpool`.`member_host_credit`.`owed` > 0)) order by `grcpool`.`member_host_credit`.`owed` desc ;

to

CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `view_all_orphans`  AS  select `member_host_credit`.`id` AS `id`,`member_host_credit`.`hostDbid` AS `hostDbid`,`member_host_credit`.`hostCpid` AS `hostCpid`,`member_host_credit`.`totalCredit` AS `totalCredit`,`member_host_credit`.`avgCredit` AS `avgCredit`,`member_host_credit`.`accountId` AS `accountId`,`member_host_credit`.`lastSeen` AS `lastSeen`,`member_host_credit`.`mag` AS `mag`,`member_host_credit`.`magTotalCredit` AS `magTotalCredit`,`member_host_credit`.`owed` AS `owed`,`member_host_credit`.`owedCalc` AS `owedCalc`,`member_host_credit`.`memberIdPayout` AS `memberIdPayout`,`member_host_credit`.`memberIdCredit` AS `memberIdCredit` from `member_host_credit` where ((not((`member_host_credit`.`hostDbid`,`member_host_credit`.`accountId`) in (select `member_host_project`.`hostDbid`,`member_host_project`.`accountId` from `member_host_project`))) and (`member_host_credit`.`owed` > 0)) order by `member_host_credit`.`owed` desc ;

Then click Go.

Then execute another query (insert your CPID, seed, and hot wallet address):

INSERT INTO `settings` (`theName`,`theValue`) VALUES ('TOTAL_PAID_OUT', '0'),
('CPID', 'Your BOINC CPID'),
('MIN_OWE_AMOUNT', '1'),
('PAYOUT_FEE', '0.005'),
('MIN_ORPHAN_PAYOUT_ZERO_MAG', '1'),
('MIN_ORPHAN_PAYOUT_WITH_MAG', '5'),
('SEED', 'you should se this to how much GRC you start with staking'),
('GRC_CLIENT_ONLINE', '1'),
('GRC_CLIENT_MESSAGE', 'empty string'),
('MIN_STAKE_BALANCE', '5'),
('HOT_WALLET_ADDRESS', 'your pool wallet'),
('POOL_WHITELIST_COUNT', '20);

Then your should fill data for each project to tables boinc_account, boinc_account_key, boinc_account_url:
To boinc_account:

  • id - unique serial number for this project
  • name - project name for pool stats page (users see that name)
  • auto - 1
  • urlId - unique serial number for this project (same as id)
  • whiteList - 1
  • rac - 0
  • baseUrl - project URL
  • teamId - gridcoin team id, you can find this in URL when viewing Gridcoin team (like teamid=2069 for NumberFields)
  • attachable - 1
  • message - blank
  • grcname - lowercase project name from 'gridcoinresearchd projects' command
  • lastSeen - blank
  • secure - 1 if project uses https
  • minRac - 0
  • android - 1 if project has workunits for android, 0 otherwise
  • raspberryPi - 1 if project has workunits for raspberry pi, 0 otherwise
  • linux - 1 if project has workunits for linux, 0 otherwise
  • windows - 1 if project has workunits for windows, 0 otherwisev (suggestion: 1 for all project)
  • virtualBox - 1 if project uses VirtualBox, 0 otherwise
  • intel - 1 if project has workunits for intel GPU, 0 otherwise
  • amd - 1 if project has workunits for AMD/ATI, 0 otherwise
  • nvidia - 1 if project has workunits for Nvidia GPU, 0 otherwise
  • mac - 1 if project has workunits for Mac OS, 0 otherwise

To boinc_account_key

  • id - unique serial number for this project (same as id from boinc_account table)
  • accountId - unique serial number for this project (same as id from boinc_account table)
  • strong - account key from BOINC project. You can see it in your BOINC account
  • weak - weak account key from BOINC project. You can see it in your BOINC account
  • attachable - 1

To boinc_account_url

  • id - unique serial number for this project (same as id from boinc_account table)
  • accountId - unique serial number for this project (same as id from boinc_account table)
  • url - project URL
  • signature - use BOINC crypt_prog for generate signature for URL

I will add only one project - Number Fields.

Google recaptcha

Go to https://www.google.com/recaptcha/admin
Enter name, your domain name, accept agreement, click 'register'. Write key and private key somewhere.

Email service

Register on the https://www.smtp2go.com/pricing/
Write CNAME and TXT records for your domain.

Add API key in https://app.smtp2go.com/settings/apikeys/
Write your login, password, server, API key and port somewhere.

Pool software

Download pool software to your folder. For sample it will be '/var/www/testphppool'

cd /var/www/testphppool
git clone https://github.com/gridcoin-community/PHP-Pool.git
cd PHP-Pool/composer
composer install
cd ..
chown -R www-data *

Then fix gridcoin commands in classes/core/GridcoinDaemon.php

nano classes/core/GridcoinDaemon.php

Remove 'list ' from strings 78, 80, remove 'execute ' from line 102

Change line 104 from

$data = $data[1];

to

//$data = $data[1];

Then edit PHP-Pool configuration files:

nano sample.props.json

Set databaseUser, databasePassword, emailServer, emailPort, emailSslPort, emailUsername, emailPassword, googleCaptchaPublic, googleCaptchaPrivate.
Set cacheDir to /tmp
Set path to your gridcoinresearchd path (see 'which gridcoinresearchd' command)
Set datadir to '/home/[USERNAME]/.GridcoinResearch' where [USERNAME] is your username.
Leave testnet false.
Set also attributes emailKey and emailRest near other email attributes (see email section above):

"emailKey" : "api-xxxxxxxxxxxxxxxxxxxxxxxxxxx",
"emailRest" : "https://api.smtp2go.com/v3/",

Create XML logs directory:

mkdir /var/log/testphppoologs
chown www-data /var/log/testphppoologs

Then edit second settings file:

nano classes/core/Constants.php

Set these constants

const DATABASE_NAME = 'testphppool';
const DATABASE_SERVER = '127.0.0.1';
const BOINC_XML_LOG_DIR = '/var/log/testphppoologs';
const BOINC_POOL_NAME = 'testphppool';
const POOL_DOMAIN = 'testphppool.arikado.ru';
const ADMIN_EMAIL_ADDRESS = '[email protected]';
const PROPERTY_FILE = '/var/www/testphppool/PHP-Pool/sample.props.json';
const SESSION_COOKIE_DOMAIN = '.testphppool.arikado.ru';
const PAYOUT_LOCK_FILE = '/var/www/testphppool/PHP-Pool/tasks/payout.lock';

And URL_SIGNING_KEY to your public_keyfile content (see BOINC crypt_prog section)

Add cron jobs

Add cron jobs to /etc/crontab

# 15 minutes
*/15 * * * * www-data php /var/www/testphppool/PHP-Pool/tasks/_15minute/getSuperblockAge.php

# Hourly
5 * * * * www-data php /var/www/testphppool/PHP-Pool/tasks/_hourly/01_sessionCleanup.php
15 * * * * www-data php /var/www/testphppool/PHP-Pool/tasks/_hourly/02_updateOwed.php
25 * * * * www-data php /var/www/testphppool/PHP-Pool/tasks/_hourly/03_getProjectCredit.php

# Daily
35 1 * * * www-data php /var/www/testphppool/PHP-Pool/tasks/_daily/01_doPayout.php
35 2 * * * www-data php /var/www/testphppool/PHP-Pool/tasks/_daily/02_getPoolStats.php

# Weekly
40 2 * * 7 www-data php /var/www/testphppool/PHP-Pool/tasks/_weekly/doPayoutOrphans.php

Wait 5 hours and check that projects are whitelisted and available for attach.

Apache site config

Make apache2 site config file

sudo nano /etc/apache2/sites-available/testphppool.conf

With content

<VirtualHost *:80>
    ServerName testphppool.arikado.ru
    ServerAlias testphppool.arikado.ru
    DocumentRoot /var/www/testphppool/PHP-Pool/public
    Alias /assets /var/www/testphppool/PHP-Pool/assets
    ErrorLog "/var/log/apache2/testphppool.error.log"
    CustomLog "/var/log/apache2/testphppool.log" common
    RewriteEngine off
    <Location />
        RewriteEngine On
        RewriteCond %{REQUEST_FILENAME} -s [OR]
        RewriteCond %{REQUEST_FILENAME} -l [OR]
        RewriteCond %{REQUEST_FILENAME} -d
        RewriteRule ^.*$ - [NC,L]
        RewriteRule ^.*$ /index.php [NC,L]
 </Location>
</VirtualHost>

Then enable site and reload apache

sudo a2ensite testphppool
service apache2 reload

Then install certificate using certbot:

sudo certbot --apache

You should set redirect to HTTPS, because otherwise you can not log in.

Check user interface

Do not use testphppool.arikado.ru as pool, it just a sample
https://testphppool.arikado.ru/
Register, check email validation (see in spam folder too, because I used fake 'from' address), set GRC address, attach pool to your BOINC. Then try to reach payout. If payout works too, then all correct - congratulations!

Do not use testphppool.arikado.ru as pool, it just a sample

Note

In gridcoin research v3.7.15.0 something wrong with "gettransaction" for superblocks, thus pool cannot receive whitelisted projects list using superblock info. You can fix this manually in classes/core/GridcoinDaemon.php, replace:

        public function getWhitelistedProjects($block = '') {
                if ($block == '') {
                        $data = $this->getSuperBlockAge();
                        $block = $data['block'];
                }
                if ($block == '') return;
                $blockHash = $this->getBlockHash($block);
                if ($blockHash == '') return;
                $blockData = $this->getBlock($blockHash);
                if ($blockData['IsSuperBlock'] == '') return;
                $txHash = $blockData['tx'][0];
                $txJson = $this->executeDaemon('gettransaction '.$txHash);
                $txJson = $this->utf8ize($txJson);
                $tx = json_decode($txJson,true);
                $hashBoinc = $tx['hashboinc'];
                $thisMatchArray = null;
                preg_match_all("/<(?'Key'[a-zA-Z].*?)>(?'Value'.*?)<\/.*?>/m", $hashBoinc, $thisMatch);
                for($c=0;$c < count($thisMatch['Key']);$c++) {
                        if($thisMatch['Key'][$c] == "|") {
                                $thisMatchArray[$thisMatch['Key'][$c]][] = addslashes($thisMatch['Value'][$c]);
                        } else {
                                $thisMatchArray[$thisMatch['Key'][$c]] = addslashes($thisMatch['Value'][$c]);
                        }
                }
                preg_match_all("/(?'Project'.*?),(?'TotalRAC'.*?);/m", $thisMatchArray['AVERAGES'], $thisMatchProjects);
                $projects = $thisMatchProjects['Project'];
                array_pop($projects);
                return $projects;
                

        }

to

        public function getWhitelistedProjects($block = '') {
                $txJson = $this->executeDaemon('projects');
                $projectsInfo = json_decode($txJson,true);
                for($c=0;$c < count($projectsInfo);$c++) {
                        $projects[]=$projectsInfo[$c]['Project'];
                }
                return $projects;
        }

I think it should work without that update in next release.

Thanks for @bgb for tips.


Gridcoin is an open source cryptocurrency (Ticker: GRC) which securely rewards volunteer computing performed upon the BOINC platform in a decentralized manner on top of proof of stake.

BOINC (Berkeley Open Infrastructure for Network Computing) is a distributed Internet platform launched beginning of 2002 and rewards participants with credits for performed work. BOINC is an application available for multiple Operating Systems and utilises the unused CPU and GPU cycles on computers to perform scientific work.

Authors get paid when people like you upvote their post.
If you enjoyed what you read here, create your account today and start earning FREE STEEM!
Sort Order:  

Thank you for writing this guide! This will help to get some more pools out there.

Awesome. About damn time someone did a " how-to" finish the grcpool install so others whom are not programmers do not have to dig threw the code to figure out " ok whats the other 10% " I am sorry but it will not let me upvote. I am anti pool , yes I know you run a pool but if there was a payout for releasing one to the public it should have been full.. You are un-related to grcpool and run your own .ru pool and should not have had to do this for BGB but I thank you. I might stop crunching and just run a pool F it. Thank you for your time , i see you translating things too and helping and I do not know if you have been told directly , but your services and help is greatly appreciated.

It doesn't matter how slowly you go as long as you do not stop.