This will be a high level explanation of how my node works, it's not an exhaustive tutorial...
So here goes...
I built this over a year ago (when p2pool.info died) in a bit if a rush, and there are certainly things I would change today to make it more efficient....
It runs an an AWS LAMP server, and pulls data from both bitcoind and p2pool. Everything is gathered and stored locally on the server, there are no external API's.
The first thing you will need to do (in addition to the existing p2pool setup) is add
txindex=1
to your bitcoin.conf, restart it, and force a re-scan. This will force a lengthy re-index, and makes the data of all transactions available from the bitcoin API. (note: if you do this on an operating node be prepared for some extended downtime during the re-index).
Next I set up the DB (MySQL), again it was quick and dirty, and this DB is specifically focused on p2pool:
-- Host: localhost:3306
-- Generation Time: Jun 06, 2015 at 11:56 AM
-- Server version: 5.5.36
-- PHP Version: 5.4.28
SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
SET time_zone = "+00:00";
--
-- Database: `p2pool`
--
-- --------------------------------------------------------
--
-- Table structure for table `block_payout`
--
CREATE TABLE IF NOT EXISTS `block_payout` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`block_id` int(11) NOT NULL,
`address` varchar(34) NOT NULL,
`ammount` decimal(10,8) NOT NULL,
PRIMARY KEY (`id`),
KEY `address` (`address`),
KEY `block_id` (`block_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=587605 ;
-- --------------------------------------------------------
--
-- Table structure for table `found_blocks`
--
CREATE TABLE IF NOT EXISTS `found_blocks` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`share` varchar(15) NOT NULL,
`time` datetime NOT NULL,
`hash` varchar(64) NOT NULL,
`height` int(8) DEFAULT NULL,
`orphan` tinyint(1) NOT NULL DEFAULT '0',
`luck` decimal(8,2) DEFAULT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `height` (`height`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=2555 ;
-- --------------------------------------------------------
--
-- Table structure for table `found_shares`
--
CREATE TABLE IF NOT EXISTS `found_shares` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`address` varchar(34) NOT NULL,
`share` varchar(15) NOT NULL,
`time` datetime NOT NULL,
`doa` tinyint(1) NOT NULL DEFAULT '0',
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=17889 ;
-- --------------------------------------------------------
--
-- Table structure for table `pool_stats`
--
CREATE TABLE IF NOT EXISTS `pool_stats` (
`id` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
`global_rate` varchar(72) NOT NULL,
`global_nonstale_rate` varchar(20) NOT NULL,
`diff` varchar(20) NOT NULL,
`miners` int(7) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
So some quick explanation of the DB structure:
3 things not to overlook: charset = UTF8, SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO", and SET time_zone = "+00:00".
The first 2 are self explanatory, the timezone must be set to UTC as that is what bitcoin uses globally in the block chain, was going to add a way for miners to set their local timezone in the views, but never got around to it.
Table
block_payout contains the payout data by public address for every block P2Pool has found, it facilitates displaying total as well as per block payouts for miners (
example). Originally I wrote a script to go over all the historical blocks and let it run, now it pulls them as we find blocks.
Table
found_blocks has every block P2Pool has found, the p2pool share that found it, whether it was orphaned, and its luck. Again, added historical ones from a few sources provided by someone probably 100 pages back in this thread, new ones are added as they are found.
Table
found_shares is specific to my node (I hated loosing all the shares on a re-start), so if you have ever found a share mining on my node, it's in there (
example on miner shares tab).
Table
pool_stats stores the bitcoin difficulty from bitcoind and pool hashrate from p2pool every minute, this is how luck is calculated - and why I could not calculate luck for historical blocks when I built it (no one had historical pool hashrate data).
The rest of the back end is basically 2 cron files, 1 that polls p2pool's log file and another that polls bitcoind. Both run once a minute, pull new data, check for orphans, calculate luck for new blocks, and store it in the DB.
The cron also renames the p2pool log file and saves it as a date stamped archive every 10MB, this greatly reduces memory usage when reading the log into memory.
Originally was adding blocks by searching the log for "GOT BLOCK", however this missed any stale shares that happened to find a block (and there are quite a few), so now I monitor a p2pool miner payout address for generation transactions as well (look out for donations!).
The front end is an ugly (code wise) mashup of p2pool's JS front ends and PHP running on the server. I used Bootstrap, a lot of cut and paste hacking, and some PHP to query the DB, calculate everything for the view, and display it.
In a nut shell, that's it.
All of this was done pretty openly in this thread with a lot of help from the community, a lot of the code logic is buried in this thread if you want to take a look at it.
If you give it a try and have any specific questions I'd be happy to try and help out.