From 7378e593bdf0d85fe5f92778fd69ba6ac38337ae Mon Sep 17 00:00:00 2001 From: obigal Date: Tue, 2 Jul 2013 14:43:11 -0400 Subject: [PATCH 01/60] Update share.class.php --- public/include/classes/share.class.php | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/public/include/classes/share.class.php b/public/include/classes/share.class.php index 9fe1ff16..b4b4bab4 100644 --- a/public/include/classes/share.class.php +++ b/public/include/classes/share.class.php @@ -11,7 +11,7 @@ class Share { private $oUpstream; private $iLastUpstreamId; // This defines each share - public $rem_host, $username, $our_result, $upstream_result, $reason, $solution, $time; + public $rem_host, $username, $our_result, $upstream_result, $reason, $solution, $time, $difficulty; public function __construct($debug, $mysqli, $user, $block, $config) { $this->debug = $debug; @@ -70,7 +70,7 @@ class Share { **/ public function getRoundShares($previous_upstream=0, $current_upstream) { $stmt = $this->mysqli->prepare("SELECT - count(id) as total + SUM(difficulty) as total FROM $this->table WHERE our_result = 'Y' AND id > ? AND id <= ? @@ -98,8 +98,8 @@ class Share { a.id, SUBSTRING_INDEX( s.username , '.', 1 ) as username, a.no_fees AS no_fees, - IFNULL(SUM(IF(our_result='Y', 1, 0)), 0) AS valid, - IFNULL(SUM(IF(our_result='N', 1, 0)), 0) AS invalid + IFNULL(SUM(IF(our_result='Y', difficulty, 0)), 0) AS valid, + IFNULL(SUM(IF(our_result='N', difficulty, 0)), 0) AS invalid FROM $this->table AS s LEFT JOIN " . $this->user->getTableName() . " AS a ON a.username = SUBSTRING_INDEX( s.username , '.', 1 ) @@ -188,7 +188,7 @@ class Share { **/ public function moveArchive($current_upstream, $block_id, $previous_upstream=0) { $archive_stmt = $this->mysqli->prepare(" - INSERT INTO $this->tableArchive (share_id, username, our_result, upstream_result, block_id, time) + INSERT INTO $this->tableArchive (share_id, username, our_result, upstream_result, block_id, time, difficulty) SELECT id, username, our_result, upstream_result, ?, time FROM $this->table WHERE id > ? AND id <= ?"); @@ -277,6 +277,7 @@ class Share { SUBSTRING_INDEX( `username` , '.', 1 ) AS account, id FROM $this->table WHERE upstream_result = 'Y' + AND UNIX_TIMESTAMP(time) BETWEEN (?) AND (? + 120) AND id > ? AND UNIX_TIMESTAMP(time) >= ? AND UNIX_TIMESTAMP(time) <= ( ? + 60 ) From a42adb11b2df7ad0f025d9894ec457e9cf44d1bb Mon Sep 17 00:00:00 2001 From: obigal Date: Tue, 2 Jul 2013 14:47:43 -0400 Subject: [PATCH 02/60] Update statistics.class.php --- public/include/classes/statistics.class.php | 56 ++++++++++----------- 1 file changed, 28 insertions(+), 28 deletions(-) diff --git a/public/include/classes/statistics.class.php b/public/include/classes/statistics.class.php index 1452db89..aeb59ddb 100644 --- a/public/include/classes/statistics.class.php +++ b/public/include/classes/statistics.class.php @@ -105,13 +105,9 @@ class Statistics { SELECT ( ( - SELECT IFNULL(ROUND(COUNT(id) * POW(2, " . $this->config['difficulty'] . ")/600/1000), 0) AS hashrate - FROM " . $this->share->getTableName() . " - WHERE time > DATE_SUB(now(), INTERVAL 10 MINUTE) + SELECT ROUND(SUM(difficulty) * 65536/600/1000) AS hashrate FROM " . $this->share->getTableName() . " WHERE time > DATE_SUB(now(), INTERVAL 10 MINUTE) ) + ( - SELECT IFNULL(ROUND(COUNT(id) * POW(2, " . $this->config['difficulty'] . ")/600/1000), 0) AS hashrate - FROM " . $this->share->getArchiveTableName() . " - WHERE time > DATE_SUB(now(), INTERVAL 10 MINUTE) + SELECT ROUND(SUM(difficulty) * 65536/600/1000) AS hashrate FROM " . $this->share->getArchiveTableName() . " WHERE time > DATE_SUB(now(), INTERVAL 10 MINUTE) ) ) AS hashrate FROM DUAL"); @@ -130,9 +126,12 @@ class Statistics { $this->debug->append("STA " . __METHOD__, 4); if ($data = $this->memcache->get(__FUNCTION__)) return $data; $stmt = $this->mysqli->prepare(" - SELECT ROUND(COUNT(id) / 600, 2) AS sharerate - FROM " . $this->share->getTableName() . " - WHERE time > DATE_SUB(now(), INTERVAL 10 MINUTE)"); + SELECT ROUND(SUM(sharerate) / 600, 2) AS sharerate FROM + ( + SELECT SUM(difficulty) AS sharerate FROM " . $this->share->getTableName() . " WHERE time > DATE_SUB(now(), INTERVAL 10 MINUTE) + UNION ALL + SELECT SUM(difficulty) AS sharerate FROM " . $this->share->getArchiveTableName() . " WHERE time > DATE_SUB(now(), INTERVAL 10 MINUTE) + ) AS sum"); if ($this->checkStmt($stmt) && $stmt->execute() && $result = $stmt->get_result() ) return $this->memcache->setCache(__FUNCTION__, $result->fetch_object()->sharerate); // Catchall $this->debug->append("Failed to fetch share rate: " . $this->mysqli->error); @@ -149,8 +148,8 @@ class Statistics { if ($this->getGetCache() && $data = $this->memcache->get(__FUNCTION__)) return $data; $stmt = $this->mysqli->prepare(" SELECT - IFNULL(SUM(IF(our_result='Y', 1, 0)), 0) AS valid, - IFNULL(SUM(IF(our_result='N', 1, 0)), 0) AS invalid + SUM(IF(our_result='Y', difficulty, 0)) AS valid, + SUM(IF(our_result='N', difficulty, 0)) AS invalid FROM " . $this->share->getTableName() . " WHERE UNIX_TIMESTAMP(time) >IFNULL((SELECT MAX(time) FROM " . $this->block->getTableName() . "),0)"); if ( $this->checkStmt($stmt) && $stmt->execute() && $result = $stmt->get_result() ) @@ -171,8 +170,8 @@ class Statistics { if ($this->getGetCache() && $data = $this->memcache->get(__FUNCTION__)) return $data; $stmt = $this->mysqli->prepare(" SELECT - IFNULL(SUM(IF(our_result='Y', 1, 0)), 0) AS valid, - IFNULL(SUM(IF(our_result='N', 1, 0)), 0) AS invalid, + SUM(IF(our_result='Y', difficulty, 0)) AS valid, + SUM(IF(our_result='N', difficulty, 0)) AS invalid, u.id AS id, u.username AS username FROM " . $this->share->getTableName() . " AS s, @@ -197,8 +196,8 @@ class Statistics { if ($this->getGetCache() && $data = $this->memcache->get(__FUNCTION__ . $account_id)) return $data; $stmt = $this->mysqli->prepare(" SELECT - IFNULL(SUM(IF(our_result='Y', 1, 0)), 0) AS valid, - IFNULL(SUM(IF(our_result='N', 1, 0)), 0) AS invalid + SUM(IF(our_result='Y', difficulty, 0)) AS valid, + SUM(IF(our_result='N', difficulty, 0)) AS invalid FROM " . $this->share->getTableName() . " AS s, " . $this->user->getTableName() . " AS u WHERE @@ -228,7 +227,7 @@ class Statistics { a.username AS username, a.donate_percent AS donate_percent, a.email AS email, - COUNT(s.id) AS shares + SUM(s.difficulty) AS shares FROM " . $this->user->getTableName() . " AS a LEFT JOIN " . $this->share->getTableName() . " AS s ON a.username = SUBSTRING_INDEX( s.username, '.', 1 ) @@ -252,14 +251,14 @@ class Statistics { $stmt = $this->mysqli->prepare(" SELECT ( - SELECT IFNULL(ROUND(COUNT(s.id) * POW(2, " . $this->config['difficulty'] . ") / 600 / 1000), 0) AS hashrate + SELECT ROUND(SUM(s.difficulty) * 65536/600/1000) AS hashrate FROM " . $this->share->getTableName() . " AS s, " . $this->user->getTableName() . " AS u WHERE u.username = SUBSTRING_INDEX( s.username, '.', 1 ) AND s.time > DATE_SUB(now(), INTERVAL 10 MINUTE) AND u.id = ? ) + ( - SELECT IFNULL(ROUND(COUNT(s.id) * POW(2, " . $this->config['difficulty'] . ") / 600 / 1000), 0) AS hashrate + SELECT ROUND(SUM(s.difficulty) * 65536/600/1000) AS hashrate FROM " . $this->share->getArchiveTableName() . " AS s, " . $this->user->getTableName() . " AS u WHERE u.username = SUBSTRING_INDEX( s.username, '.', 1 ) @@ -283,7 +282,7 @@ class Statistics { $this->debug->append("STA " . __METHOD__, 4); if ($data = $this->memcache->get(__FUNCTION__ . $account_id)) return $data; $stmt = $this->mysqli->prepare(" - SELECT COUNT(s.id)/600 AS sharerate + SELECT SUM(s.difficulty)/600 AS sharerate FROM " . $this->share->getTableName() . " AS s, " . $this->user->getTableName() . " AS u WHERE u.username = SUBSTRING_INDEX( s.username, '.', 1 ) @@ -305,7 +304,7 @@ class Statistics { $this->debug->append("STA " . __METHOD__, 4); if ($data = $this->memcache->get(__FUNCTION__ . $worker_id)) return $data; $stmt = $this->mysqli->prepare(" - SELECT IFNULL(ROUND(COUNT(s.id) * POW(2,21)/600/1000), 0) AS hashrate + SELECT ROUND(SUM(s.difficulty) * 65536/600/1000) AS hashrate FROM " . $this->share->getTableName() . " AS s, " . $this->user->getTableName() . " AS u WHERE u.username = SUBSTRING_INDEX( s.username, '.', 1 ) @@ -333,7 +332,7 @@ class Statistics { SELECT a.donate_percent AS donate_percent, a.is_anonymous AS is_anonymous, - COUNT(s.id) AS shares, + SUM(difficulty) AS shares, SUBSTRING_INDEX( s.username, '.', 1 ) AS account FROM " . $this->share->getTableName() . " AS s LEFT JOIN " . $this->user->getTableName() . " AS a @@ -354,12 +353,13 @@ class Statistics { a.donate_percent AS donate_percent, a.is_anonymous AS is_anonymous, IFNULL(ROUND(COUNT(t1.id) * POW(2," . $this->config['difficulty'] . ")/600/1000, 2), 0) AS hashrate, + ROUND(SUM(t1.difficulty) * 65536/600/1000) AS hashrate, SUBSTRING_INDEX( t1.username, '.', 1 ) AS account FROM ( - SELECT id, username FROM " . $this->share->getTableName() . " WHERE time > DATE_SUB(now(), INTERVAL 10 MINUTE) AND our_result = 'Y' + SELECT id, username, difficulty FROM " . $this->share->getTableName() . " WHERE time > DATE_SUB(now(), INTERVAL 10 MINUTE) AND our_result = 'Y' UNION - SELECT id, username FROM " . $this->share->getArchiveTableName() ." WHERE time > DATE_SUB(now(), INTERVAL 10 MINUTE) AND our_result = 'Y' + SELECT id, username, difficulty FROM " . $this->share->getArchiveTableName() ." WHERE time > DATE_SUB(now(), INTERVAL 10 MINUTE) AND our_result = 'Y' ) AS t1 LEFT JOIN " . $this->user->getTableName() . " AS a ON SUBSTRING_INDEX( t1.username, '.', 1 ) = a.username @@ -367,7 +367,7 @@ class Statistics { ORDER BY hashrate DESC LIMIT ?"); if ($this->checkStmt($stmt) && $stmt->bind_param("i", $limit) && $stmt->execute() && $result = $stmt->get_result()) return $this->memcache->setCache(__FUNCTION__ . $type . $limit, $result->fetch_all(MYSQLI_ASSOC)); - $this->debug->append("Fetching shares failed: "); + $this->debug->append("Fetching shares failed: " . $this->mysqli->error); return false; break; } @@ -383,9 +383,9 @@ class Statistics { if ($data = $this->memcache->get(__FUNCTION__ . $account_id)) return $data; $stmt = $this->mysqli->prepare(" SELECT - ROUND(COUNT(s.id) * POW(2, " . $this->config['difficulty'] . ") / 3600 / 1000) AS hashrate, + ROUND(SUM(s.difficulty) * 65536/3600/1000) AS hashrate, HOUR(s.time) AS hour - FROM " . $this->share->getTableName() . " AS s, accounts AS a + FROM " . $this->share->getArchiveTableName() . " AS s, accounts AS a WHERE time < NOW() - INTERVAL 1 HOUR AND time > NOW() - INTERVAL 25 HOUR AND a.username = SUBSTRING_INDEX( s.username, '.', 1 ) @@ -423,9 +423,9 @@ class Statistics { if ($this->getGetCache() && $data = $this->memcache->get(__FUNCTION__)) return $data; $stmt = $this->mysqli->prepare(" SELECT - IFNULL(ROUND(COUNT(s.id) * POW(2, " . $this->config['difficulty'] . ") / 3600 / 1000), 0) AS hashrate, + ROUND(SUM(s.difficulty) * 65536/3600/1000) AS hashrate, HOUR(s.time) AS hour - FROM " . $this->share->getTableName() . " AS s + FROM " . $this->share->getArchiveTableName() . " AS s WHERE time < NOW() - INTERVAL 1 HOUR AND time > NOW() - INTERVAL 25 HOUR GROUP BY HOUR(time) From a45bc6dbefceebf617276edfcffeb3aac2a404a4 Mon Sep 17 00:00:00 2001 From: obigal Date: Tue, 2 Jul 2013 14:49:29 -0400 Subject: [PATCH 03/60] Update worker.class.php --- public/include/classes/worker.class.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/public/include/classes/worker.class.php b/public/include/classes/worker.class.php index 7643a6d1..26093c33 100644 --- a/public/include/classes/worker.class.php +++ b/public/include/classes/worker.class.php @@ -96,7 +96,7 @@ class Worker { $stmt = $this->mysqli->prepare(" SELECT id, username, password, monitor, ( SELECT SIGN(COUNT(id)) FROM " . $this->share->getTableName() . " WHERE username = $this->table.username AND time > DATE_SUB(now(), INTERVAL 10 MINUTE)) AS active, - ( SELECT ROUND(COUNT(id) * POW(2, " . $this->config['difficulty'] . ")/600/1000) FROM " . $this->share->getTableName() . " WHERE username = $this->table.username AND time > DATE_SUB(now(), INTERVAL 10 MINUTE)) AS hashrate + ( SELECT ROUND(SUM(difficulty) * 65536/600/1000) FROM " . $this->share->getTableName() . " WHERE username = $this->table.username AND time > DATE_SUB(now(), INTERVAL 10 MINUTE)) AS hashrate FROM $this->table WHERE id = ? "); @@ -117,7 +117,7 @@ class Worker { $stmt = $this->mysqli->prepare(" SELECT id, username, password, monitor, ( SELECT SIGN(COUNT(id)) FROM " . $this->share->getTableName() . " WHERE our_result = 'Y' AND username = $this->table.username AND time > DATE_SUB(now(), INTERVAL 10 MINUTE)) AS active, - ( SELECT ROUND(COUNT(id) * POW(2, " . $this->config['difficulty'] . ")/600/1000) FROM " . $this->share->getTableName() . " WHERE our_result = 'Y' AND username = $this->table.username AND time > DATE_SUB(now(), INTERVAL 10 MINUTE)) AS hashrate + ( SELECT ROUND(SUM(difficulty) * 65536/600/1000) FROM " . $this->share->getTableName() . " WHERE our_result = 'Y' AND username = $this->table.username AND time > DATE_SUB(now(), INTERVAL 10 MINUTE)) AS hashrate FROM $this->table WHERE account_id = ?"); if ($this->checkStmt($stmt) && $stmt->bind_param('i', $account_id) && $stmt->execute() && $result = $stmt->get_result()) From 5aae168d19894ca8bb3541a129466508daa2fe6d Mon Sep 17 00:00:00 2001 From: obigal Date: Tue, 2 Jul 2013 14:58:44 -0400 Subject: [PATCH 04/60] Update mmcfe_ng_structure.sql --- sql/000_base_structure.sql | 3 +++ 1 file changed, 3 insertions(+) diff --git a/sql/000_base_structure.sql b/sql/000_base_structure.sql index 6f475060..fc31343d 100644 --- a/sql/000_base_structure.sql +++ b/sql/000_base_structure.sql @@ -81,6 +81,7 @@ CREATE TABLE IF NOT EXISTS `pool_worker` ( `username` char(50) DEFAULT NULL, `password` char(255) DEFAULT NULL, `monitor` tinyint(1) NOT NULL DEFAULT '0', + `difficulty` int(11) NOT NULL DEFAULT '0', PRIMARY KEY (`id`), UNIQUE KEY `username` (`username`), KEY `account_id` (`account_id`) @@ -102,6 +103,7 @@ CREATE TABLE IF NOT EXISTS `shares` ( `reason` varchar(50) DEFAULT NULL, `solution` varchar(257) NOT NULL, `time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, + `difficulty` int(11) NOT NULL DEFAULT '0', PRIMARY KEY (`id`), KEY `time` (`time`), KEY `upstream_result` (`upstream_result`), @@ -117,6 +119,7 @@ CREATE TABLE IF NOT EXISTS `shares_archive` ( `upstream_result` enum('Y','N') DEFAULT NULL, `block_id` int(10) unsigned NOT NULL, `time` datetime NOT NULL, + `difficulty` int(11) NOT NULL DEFAULT '0', PRIMARY KEY (`id`), UNIQUE KEY `share_id` (`share_id`), KEY `time` (`time`) From eb17508862289acdc5dc9355c4e599db5ffb85c6 Mon Sep 17 00:00:00 2001 From: obigal Date: Wed, 3 Jul 2013 08:33:56 -0400 Subject: [PATCH 05/60] Update mmcfe_ng_structure.sql --- sql/000_base_structure.sql | 1 + 1 file changed, 1 insertion(+) diff --git a/sql/000_base_structure.sql b/sql/000_base_structure.sql index fc31343d..81aa8f81 100644 --- a/sql/000_base_structure.sql +++ b/sql/000_base_structure.sql @@ -81,6 +81,7 @@ CREATE TABLE IF NOT EXISTS `pool_worker` ( `username` char(50) DEFAULT NULL, `password` char(255) DEFAULT NULL, `monitor` tinyint(1) NOT NULL DEFAULT '0', + `hashrate` int(11) DEFAULT NULL, `difficulty` int(11) NOT NULL DEFAULT '0', PRIMARY KEY (`id`), UNIQUE KEY `username` (`username`), From fd427f77de6fecda8503ec4129d920bc3bcdb951 Mon Sep 17 00:00:00 2001 From: obigal Date: Wed, 3 Jul 2013 08:37:14 -0400 Subject: [PATCH 06/60] Update share.class.php --- public/include/classes/share.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/public/include/classes/share.class.php b/public/include/classes/share.class.php index b4b4bab4..d648694f 100644 --- a/public/include/classes/share.class.php +++ b/public/include/classes/share.class.php @@ -277,7 +277,7 @@ class Share { SUBSTRING_INDEX( `username` , '.', 1 ) AS account, id FROM $this->table WHERE upstream_result = 'Y' - AND UNIX_TIMESTAMP(time) BETWEEN (?) AND (? + 120) + AND UNIX_TIMESTAMP(time) BETWEEN (?) AND (? + 20) AND id > ? AND UNIX_TIMESTAMP(time) >= ? AND UNIX_TIMESTAMP(time) <= ( ? + 60 ) From 2b1c6282382c3c77dcf809bd9e674ecb9d6016ab Mon Sep 17 00:00:00 2001 From: obigal Date: Wed, 3 Jul 2013 08:42:21 -0400 Subject: [PATCH 07/60] Update authenticated.tpl --- public/templates/mmcFE/statistics/pool/authenticated.tpl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/public/templates/mmcFE/statistics/pool/authenticated.tpl b/public/templates/mmcFE/statistics/pool/authenticated.tpl index 394e762b..e9f8e95b 100644 --- a/public/templates/mmcFE/statistics/pool/authenticated.tpl +++ b/public/templates/mmcFE/statistics/pool/authenticated.tpl @@ -48,7 +48,7 @@ Est. Shares this Round - {(pow(2, 32 - $GLOBAL.config.targetdiff) * $DIFFICULTY)|number_format:"0"} (done: {(100 / (pow(2, 32 - $GLOBAL.config.targetdiff) * $DIFFICULTY) * $GLOBAL.roundshares.valid)|number_format:"2"} %) + {(65536 * $DIFFICULTY)|number_format:"0"} (done: {(100 / (pow(2, 32 - $GLOBAL.config.targetdiff) * $DIFFICULTY) * $GLOBAL.roundshares.valid)|number_format:"2"} %) Time Since Last Block From 2d2f4808884ccf08e5a0285937a9ca27988879b8 Mon Sep 17 00:00:00 2001 From: obigal Date: Wed, 3 Jul 2013 08:59:22 -0400 Subject: [PATCH 08/60] Update default.tpl --- public/templates/mmcFE/statistics/blocks/default.tpl | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/public/templates/mmcFE/statistics/blocks/default.tpl b/public/templates/mmcFE/statistics/blocks/default.tpl index 2871cd01..c491a8dd 100644 --- a/public/templates/mmcFE/statistics/blocks/default.tpl +++ b/public/templates/mmcFE/statistics/blocks/default.tpl @@ -12,7 +12,7 @@ Expected {section block $BLOCKSFOUND step=-1} - {round(pow(2,32 - $GLOBAL.config.targetdiff) * $BLOCKSFOUND[block].difficulty)} + {round(65536 * $BLOCKSFOUND[block].difficulty)} {/section} @@ -62,8 +62,8 @@ target and network difficulty and assuming a zero variance scenario. {$BLOCKSFOUND[block].difficulty|number_format:"2"} {$BLOCKSFOUND[block].amount|number_format:"2"} - {math assign="estshares" equation="(pow(2,32 - targetdiff) * blockdiff)" targetdiff=$GLOBAL.config.targetdiff blockdiff=$BLOCKSFOUND[block].difficulty} - {$estshares|number_format} + {math assign="estshares" equation="(65536 * blockdiff)" targetdiff=$GLOBAL.config.targetdiff blockdiff=$BLOCKSFOUND[block].difficulty} + {$estshares} {$BLOCKSFOUND[block].shares|number_format} From 31e10bfa2ffda5230b0218e42fcac57b6ec34c80 Mon Sep 17 00:00:00 2001 From: obigal Date: Wed, 3 Jul 2013 09:09:47 -0400 Subject: [PATCH 09/60] Update smarty_globals.inc.php --- public/include/smarty_globals.inc.php | 1 + 1 file changed, 1 insertion(+) diff --git a/public/include/smarty_globals.inc.php b/public/include/smarty_globals.inc.php index 64dcf2dc..a9660b78 100644 --- a/public/include/smarty_globals.inc.php +++ b/public/include/smarty_globals.inc.php @@ -38,6 +38,7 @@ $aGlobal = array( 'hashrate' => $iCurrentPoolHashrate, 'nethashrate' => $dNetworkHashrate, 'sharerate' => $iCurrentPoolShareRate, + 'ppsvalue' => number_format(round(1/(65536 * $dDifficulty) * $config['reward']), 12), 'workers' => $iCurrentActiveWorkers, 'roundshares' => $aRoundShares, 'fees' => $config['fees'], From 128050f508d8c56af63e0cfc888ec04a854036b3 Mon Sep 17 00:00:00 2001 From: obigal Date: Wed, 3 Jul 2013 09:10:48 -0400 Subject: [PATCH 10/60] Update pps_payout.php --- cronjobs/pps_payout.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/cronjobs/pps_payout.php b/cronjobs/pps_payout.php index fc66ecff..bf42be64 100755 --- a/cronjobs/pps_payout.php +++ b/cronjobs/pps_payout.php @@ -43,6 +43,8 @@ if ( $bitcoin->can_connect() === true ){ } // Value per share calculation +// We need to use this instead when running VARDIFF +// $pps_value = number_format(round(1/(65536 * $dDifficulty) * $config['reward']), 12) ,12); if ($config['reward_type'] != 'block') { $pps_value = number_format(round($config['reward'] / (pow(2,32) * $dDifficulty) * pow(2, $config['difficulty']), 12) ,12); } else { From b2a898e292461e113b0015d4bbf9dc927d3948f4 Mon Sep 17 00:00:00 2001 From: obigal Date: Wed, 3 Jul 2013 09:42:23 -0400 Subject: [PATCH 11/60] Update share.class.php --- public/include/classes/share.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/public/include/classes/share.class.php b/public/include/classes/share.class.php index d648694f..a2ee1c1c 100644 --- a/public/include/classes/share.class.php +++ b/public/include/classes/share.class.php @@ -277,7 +277,7 @@ class Share { SUBSTRING_INDEX( `username` , '.', 1 ) AS account, id FROM $this->table WHERE upstream_result = 'Y' - AND UNIX_TIMESTAMP(time) BETWEEN (?) AND (? + 20) + AND UNIX_TIMESTAMP(time) >= ? AND id > ? AND UNIX_TIMESTAMP(time) >= ? AND UNIX_TIMESTAMP(time) <= ( ? + 60 ) From 657839014a880c092cb3f511127b992ed77cc47e Mon Sep 17 00:00:00 2001 From: obigal Date: Fri, 5 Jul 2013 05:24:04 -0400 Subject: [PATCH 12/60] Update for pushpool compatibility --- public/include/classes/share.class.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/public/include/classes/share.class.php b/public/include/classes/share.class.php index a2ee1c1c..ade40cfe 100644 --- a/public/include/classes/share.class.php +++ b/public/include/classes/share.class.php @@ -70,7 +70,7 @@ class Share { **/ public function getRoundShares($previous_upstream=0, $current_upstream) { $stmt = $this->mysqli->prepare("SELECT - SUM(difficulty) as total + SUM(IF(difficulty=0, pow(2, (" . $this->config['difficulty'] . " - 16)) - 1, difficulty)) as total FROM $this->table WHERE our_result = 'Y' AND id > ? AND id <= ? @@ -98,8 +98,8 @@ class Share { a.id, SUBSTRING_INDEX( s.username , '.', 1 ) as username, a.no_fees AS no_fees, - IFNULL(SUM(IF(our_result='Y', difficulty, 0)), 0) AS valid, - IFNULL(SUM(IF(our_result='N', difficulty, 0)), 0) AS invalid + IFNULL(SUM(IF(our_result='Y', IF(difficulty=0, pow(2, (" . $this->config['difficulty'] . " - 16)) - 1, difficulty), 0)), 0) AS valid, + IFNULL(SUM(IF(our_result='N', IF(difficulty=0, pow(2, (" . $this->config['difficulty'] . " - 16)) - 1, difficulty), 0)), 0) AS invalid FROM $this->table AS s LEFT JOIN " . $this->user->getTableName() . " AS a ON a.username = SUBSTRING_INDEX( s.username , '.', 1 ) From 41183b2e65dbeed7dbcf9380e61de5195c0bb661 Mon Sep 17 00:00:00 2001 From: obigal Date: Fri, 5 Jul 2013 05:51:02 -0400 Subject: [PATCH 13/60] Update for pushpool compatibility --- public/include/classes/statistics.class.php | 36 ++++++++++----------- 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/public/include/classes/statistics.class.php b/public/include/classes/statistics.class.php index aeb59ddb..f56c6ab5 100644 --- a/public/include/classes/statistics.class.php +++ b/public/include/classes/statistics.class.php @@ -105,9 +105,9 @@ class Statistics { SELECT ( ( - SELECT ROUND(SUM(difficulty) * 65536/600/1000) AS hashrate FROM " . $this->share->getTableName() . " WHERE time > DATE_SUB(now(), INTERVAL 10 MINUTE) + SELECT ROUND(SUM(IF(difficulty=0, pow(2, (" . $this->config['difficulty'] . " - 16)) - 1, difficulty)) * 65536/600/1000) AS hashrate FROM " . $this->share->getTableName() . " WHERE time > DATE_SUB(now(), INTERVAL 10 MINUTE) ) + ( - SELECT ROUND(SUM(difficulty) * 65536/600/1000) AS hashrate FROM " . $this->share->getArchiveTableName() . " WHERE time > DATE_SUB(now(), INTERVAL 10 MINUTE) + SELECT ROUND(SUM(IF(difficulty=0, pow(2, (" . $this->config['difficulty'] . " - 16)) - 1, difficulty)) * 65536/600/1000) AS hashrate FROM " . $this->share->getArchiveTableName() . " WHERE time > DATE_SUB(now(), INTERVAL 10 MINUTE) ) ) AS hashrate FROM DUAL"); @@ -128,9 +128,9 @@ class Statistics { $stmt = $this->mysqli->prepare(" SELECT ROUND(SUM(sharerate) / 600, 2) AS sharerate FROM ( - SELECT SUM(difficulty) AS sharerate FROM " . $this->share->getTableName() . " WHERE time > DATE_SUB(now(), INTERVAL 10 MINUTE) + SELECT SUM(IF(difficulty=0, pow(2, (" . $this->config['difficulty'] . " - 16)) - 1, difficulty)) AS sharerate FROM " . $this->share->getTableName() . " WHERE time > DATE_SUB(now(), INTERVAL 10 MINUTE) UNION ALL - SELECT SUM(difficulty) AS sharerate FROM " . $this->share->getArchiveTableName() . " WHERE time > DATE_SUB(now(), INTERVAL 10 MINUTE) + SELECT SUM(IF(difficulty=0, pow(2, (" . $this->config['difficulty'] . " - 16)) - 1, difficulty)) AS sharerate FROM " . $this->share->getArchiveTableName() . " WHERE time > DATE_SUB(now(), INTERVAL 10 MINUTE) ) AS sum"); if ($this->checkStmt($stmt) && $stmt->execute() && $result = $stmt->get_result() ) return $this->memcache->setCache(__FUNCTION__, $result->fetch_object()->sharerate); // Catchall @@ -148,8 +148,8 @@ class Statistics { if ($this->getGetCache() && $data = $this->memcache->get(__FUNCTION__)) return $data; $stmt = $this->mysqli->prepare(" SELECT - SUM(IF(our_result='Y', difficulty, 0)) AS valid, - SUM(IF(our_result='N', difficulty, 0)) AS invalid + IFNULL(SUM(IF(our_result='Y', IF(difficulty=0, pow(2, (" . $this->config['difficulty'] . " - 16)) - 1, 0)), 0) AS valid, + IFNULL(SUM(IF(our_result='N', IF(difficulty=0, pow(2, (" . $this->config['difficulty'] . " - 16)) - 1, 0)), 0) AS invalid, FROM " . $this->share->getTableName() . " WHERE UNIX_TIMESTAMP(time) >IFNULL((SELECT MAX(time) FROM " . $this->block->getTableName() . "),0)"); if ( $this->checkStmt($stmt) && $stmt->execute() && $result = $stmt->get_result() ) @@ -170,8 +170,8 @@ class Statistics { if ($this->getGetCache() && $data = $this->memcache->get(__FUNCTION__)) return $data; $stmt = $this->mysqli->prepare(" SELECT - SUM(IF(our_result='Y', difficulty, 0)) AS valid, - SUM(IF(our_result='N', difficulty, 0)) AS invalid, + IFNULL(SUM(IF(our_result='Y', IF(difficulty=0, pow(2, (" . $this->config['difficulty'] . " - 16)) - 1, 0)), 0) AS valid, + IFNULL(SUM(IF(our_result='N', IF(difficulty=0, pow(2, (" . $this->config['difficulty'] . " - 16)) - 1, 0)), 0) AS invalid, u.id AS id, u.username AS username FROM " . $this->share->getTableName() . " AS s, @@ -196,8 +196,8 @@ class Statistics { if ($this->getGetCache() && $data = $this->memcache->get(__FUNCTION__ . $account_id)) return $data; $stmt = $this->mysqli->prepare(" SELECT - SUM(IF(our_result='Y', difficulty, 0)) AS valid, - SUM(IF(our_result='N', difficulty, 0)) AS invalid + IFNULL(SUM(IF(our_result='Y', IF(difficulty=0, pow(2, (" . $this->config['difficulty'] . " - 16)) - 1, 0)), 0) AS valid, + IFNULL(SUM(IF(our_result='N', IF(difficulty=0, pow(2, (" . $this->config['difficulty'] . " - 16)) - 1, 0)), 0) AS invalid FROM " . $this->share->getTableName() . " AS s, " . $this->user->getTableName() . " AS u WHERE @@ -251,14 +251,14 @@ class Statistics { $stmt = $this->mysqli->prepare(" SELECT ( - SELECT ROUND(SUM(s.difficulty) * 65536/600/1000) AS hashrate + SELECT ROUND(SUM(IF(s.difficulty=0, pow(2, (" . $this->config['difficulty'] . " - 16)) - 1, s.difficulty)) * 65536/600/1000) AS hashrate FROM " . $this->share->getTableName() . " AS s, " . $this->user->getTableName() . " AS u WHERE u.username = SUBSTRING_INDEX( s.username, '.', 1 ) AND s.time > DATE_SUB(now(), INTERVAL 10 MINUTE) AND u.id = ? ) + ( - SELECT ROUND(SUM(s.difficulty) * 65536/600/1000) AS hashrate + SELECT ROUND(SUM(IF(s.difficulty=0, pow(2, (" . $this->config['difficulty'] . " - 16)) - 1, s.difficulty)) * 65536/600/1000) AS hashrate FROM " . $this->share->getArchiveTableName() . " AS s, " . $this->user->getTableName() . " AS u WHERE u.username = SUBSTRING_INDEX( s.username, '.', 1 ) @@ -282,7 +282,7 @@ class Statistics { $this->debug->append("STA " . __METHOD__, 4); if ($data = $this->memcache->get(__FUNCTION__ . $account_id)) return $data; $stmt = $this->mysqli->prepare(" - SELECT SUM(s.difficulty)/600 AS sharerate + SELECT SUM(IF(s.difficulty=0, pow(2, (" . $this->config['difficulty'] . " - 16)) - 1, s.difficulty))/600 AS sharerate FROM " . $this->share->getTableName() . " AS s, " . $this->user->getTableName() . " AS u WHERE u.username = SUBSTRING_INDEX( s.username, '.', 1 ) @@ -304,7 +304,7 @@ class Statistics { $this->debug->append("STA " . __METHOD__, 4); if ($data = $this->memcache->get(__FUNCTION__ . $worker_id)) return $data; $stmt = $this->mysqli->prepare(" - SELECT ROUND(SUM(s.difficulty) * 65536/600/1000) AS hashrate + SELECT ROUND(SUM(IF(s.difficulty=0, pow(2, (" . $this->config['difficulty'] . " - 16)) - 1, s.difficulty)) * 65536/600/1000) AS hashrate FROM " . $this->share->getTableName() . " AS s, " . $this->user->getTableName() . " AS u WHERE u.username = SUBSTRING_INDEX( s.username, '.', 1 ) @@ -332,7 +332,7 @@ class Statistics { SELECT a.donate_percent AS donate_percent, a.is_anonymous AS is_anonymous, - SUM(difficulty) AS shares, + SUM(IF(difficulty=0, pow(2, (" . $this->config['difficulty'] . " - 16)) - 1, difficulty)) AS shares, SUBSTRING_INDEX( s.username, '.', 1 ) AS account FROM " . $this->share->getTableName() . " AS s LEFT JOIN " . $this->user->getTableName() . " AS a @@ -353,7 +353,7 @@ class Statistics { a.donate_percent AS donate_percent, a.is_anonymous AS is_anonymous, IFNULL(ROUND(COUNT(t1.id) * POW(2," . $this->config['difficulty'] . ")/600/1000, 2), 0) AS hashrate, - ROUND(SUM(t1.difficulty) * 65536/600/1000) AS hashrate, + ROUND(SUM(IF(t1.difficulty=0, pow(2, (" . $this->config['difficulty'] . " - 16)) - 1, t1.difficulty)) * 65536/600/1000) AS hashrate, SUBSTRING_INDEX( t1.username, '.', 1 ) AS account FROM ( @@ -383,7 +383,7 @@ class Statistics { if ($data = $this->memcache->get(__FUNCTION__ . $account_id)) return $data; $stmt = $this->mysqli->prepare(" SELECT - ROUND(SUM(s.difficulty) * 65536/3600/1000) AS hashrate, + ROUND(SUM(IF(s.difficulty=0, pow(2, (" . $this->config['difficulty'] . " - 16)) - 1, s.difficulty)) * 65536/3600/1000) AS hashrate, HOUR(s.time) AS hour FROM " . $this->share->getArchiveTableName() . " AS s, accounts AS a WHERE time < NOW() - INTERVAL 1 HOUR @@ -423,7 +423,7 @@ class Statistics { if ($this->getGetCache() && $data = $this->memcache->get(__FUNCTION__)) return $data; $stmt = $this->mysqli->prepare(" SELECT - ROUND(SUM(s.difficulty) * 65536/3600/1000) AS hashrate, + ROUND(SUM(IF(s.difficulty=0, pow(2, (" . $this->config['difficulty'] . " - 16)) - 1, s.difficulty)) * 65536/3600/1000) AS hashrate, HOUR(s.time) AS hour FROM " . $this->share->getArchiveTableName() . " AS s WHERE time < NOW() - INTERVAL 1 HOUR From d89c1f43c86a46ab556bfe5cd0e209de38bb8134 Mon Sep 17 00:00:00 2001 From: obigal Date: Fri, 5 Jul 2013 06:03:41 -0400 Subject: [PATCH 14/60] Update for pushpool compatibility --- public/include/classes/worker.class.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/public/include/classes/worker.class.php b/public/include/classes/worker.class.php index 26093c33..a107213b 100644 --- a/public/include/classes/worker.class.php +++ b/public/include/classes/worker.class.php @@ -96,7 +96,7 @@ class Worker { $stmt = $this->mysqli->prepare(" SELECT id, username, password, monitor, ( SELECT SIGN(COUNT(id)) FROM " . $this->share->getTableName() . " WHERE username = $this->table.username AND time > DATE_SUB(now(), INTERVAL 10 MINUTE)) AS active, - ( SELECT ROUND(SUM(difficulty) * 65536/600/1000) FROM " . $this->share->getTableName() . " WHERE username = $this->table.username AND time > DATE_SUB(now(), INTERVAL 10 MINUTE)) AS hashrate + ( SELECT ROUND(SUM(IF(difficulty=0, pow(2, (" . $this->config['difficulty'] . " - 16)) - 1, difficulty)) * 65536/600/1000) FROM " . $this->share->getTableName() . " WHERE username = $this->table.username AND time > DATE_SUB(now(), INTERVAL 10 MINUTE)) AS hashrate FROM $this->table WHERE id = ? "); @@ -117,7 +117,7 @@ class Worker { $stmt = $this->mysqli->prepare(" SELECT id, username, password, monitor, ( SELECT SIGN(COUNT(id)) FROM " . $this->share->getTableName() . " WHERE our_result = 'Y' AND username = $this->table.username AND time > DATE_SUB(now(), INTERVAL 10 MINUTE)) AS active, - ( SELECT ROUND(SUM(difficulty) * 65536/600/1000) FROM " . $this->share->getTableName() . " WHERE our_result = 'Y' AND username = $this->table.username AND time > DATE_SUB(now(), INTERVAL 10 MINUTE)) AS hashrate + ( SELECT ROUND(SUM(IF(difficulty=0, pow(2, (" . $this->config['difficulty'] . " - 16)) - 1, difficulty)) * 65536/600/1000) FROM " . $this->share->getTableName() . " WHERE our_result = 'Y' AND username = $this->table.username AND time > DATE_SUB(now(), INTERVAL 10 MINUTE)) AS hashrate FROM $this->table WHERE account_id = ?"); if ($this->checkStmt($stmt) && $stmt->bind_param('i', $account_id) && $stmt->execute() && $result = $stmt->get_result()) From 174bfdc0cf4ec06da43a9427e35f2640f001e03d Mon Sep 17 00:00:00 2001 From: obigal Date: Fri, 5 Jul 2013 11:57:16 -0400 Subject: [PATCH 15/60] Update pps_payout.php --- cronjobs/pps_payout.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cronjobs/pps_payout.php b/cronjobs/pps_payout.php index bf42be64..2d85867f 100755 --- a/cronjobs/pps_payout.php +++ b/cronjobs/pps_payout.php @@ -44,7 +44,7 @@ if ( $bitcoin->can_connect() === true ){ // Value per share calculation // We need to use this instead when running VARDIFF -// $pps_value = number_format(round(1/(65536 * $dDifficulty) * $config['reward']), 12) ,12); +// $pps_value = number_format(round((1/(65536 * $dDifficulty) * $config['reward']), 12) ,12); if ($config['reward_type'] != 'block') { $pps_value = number_format(round($config['reward'] / (pow(2,32) * $dDifficulty) * pow(2, $config['difficulty']), 12) ,12); } else { From f7a95d9f26ae333a8a63b2352ef01f68970d3f90 Mon Sep 17 00:00:00 2001 From: obigal Date: Fri, 5 Jul 2013 11:58:11 -0400 Subject: [PATCH 16/60] Update smarty_globals.inc.php --- public/include/smarty_globals.inc.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/public/include/smarty_globals.inc.php b/public/include/smarty_globals.inc.php index a9660b78..6275c5ae 100644 --- a/public/include/smarty_globals.inc.php +++ b/public/include/smarty_globals.inc.php @@ -38,7 +38,7 @@ $aGlobal = array( 'hashrate' => $iCurrentPoolHashrate, 'nethashrate' => $dNetworkHashrate, 'sharerate' => $iCurrentPoolShareRate, - 'ppsvalue' => number_format(round(1/(65536 * $dDifficulty) * $config['reward']), 12), + 'ppsvalue' => number_format(round((1/(65536 * $dDifficulty) * $config['reward']), 12) ,12), 'workers' => $iCurrentActiveWorkers, 'roundshares' => $aRoundShares, 'fees' => $config['fees'], From 5607103d81eab4d45ad26d1b5e9b1a62104df1a0 Mon Sep 17 00:00:00 2001 From: obigal Date: Fri, 5 Jul 2013 14:00:36 -0400 Subject: [PATCH 17/60] Update share.class.php --- public/include/classes/share.class.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/public/include/classes/share.class.php b/public/include/classes/share.class.php index ade40cfe..6d17a4c1 100644 --- a/public/include/classes/share.class.php +++ b/public/include/classes/share.class.php @@ -13,12 +13,19 @@ class Share { // This defines each share public $rem_host, $username, $our_result, $upstream_result, $reason, $solution, $time, $difficulty; +<<<<<<< HEAD public function __construct($debug, $mysqli, $user, $block, $config) { $this->debug = $debug; $this->mysqli = $mysqli; $this->user = $user; $this->config = $config; $this->block = $block; +======= + public function __construct($debug, $mysqli, $config, $salt) { + $this->debug = $debug; + $this->mysqli = $mysqli; + $this->config = $config; +>>>>>>> Update share.class.php $this->debug->append("Instantiated Share class", 2); } From b6f3fd5972ee329cce1a2ec736efe8f6377d6b9f Mon Sep 17 00:00:00 2001 From: obigal Date: Fri, 5 Jul 2013 14:03:19 -0400 Subject: [PATCH 18/60] Update statistics.class.php --- public/include/classes/statistics.class.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/public/include/classes/statistics.class.php b/public/include/classes/statistics.class.php index f56c6ab5..f799ea0a 100644 --- a/public/include/classes/statistics.class.php +++ b/public/include/classes/statistics.class.php @@ -148,8 +148,8 @@ class Statistics { if ($this->getGetCache() && $data = $this->memcache->get(__FUNCTION__)) return $data; $stmt = $this->mysqli->prepare(" SELECT - IFNULL(SUM(IF(our_result='Y', IF(difficulty=0, pow(2, (" . $this->config['difficulty'] . " - 16)) - 1, 0)), 0) AS valid, - IFNULL(SUM(IF(our_result='N', IF(difficulty=0, pow(2, (" . $this->config['difficulty'] . " - 16)) - 1, 0)), 0) AS invalid, + IFNULL(SUM(IF(our_result='Y', IF(difficulty=0, pow(2, (" . $this->config['difficulty'] . " - 16)) - 1, difficulty), 0)), 0) AS valid, + IFNULL(SUM(IF(our_result='N', IF(difficulty=0, pow(2, (" . $this->config['difficulty'] . " - 16)) - 1, difficulty), 0)), 0) AS invalid FROM " . $this->share->getTableName() . " WHERE UNIX_TIMESTAMP(time) >IFNULL((SELECT MAX(time) FROM " . $this->block->getTableName() . "),0)"); if ( $this->checkStmt($stmt) && $stmt->execute() && $result = $stmt->get_result() ) @@ -170,8 +170,8 @@ class Statistics { if ($this->getGetCache() && $data = $this->memcache->get(__FUNCTION__)) return $data; $stmt = $this->mysqli->prepare(" SELECT - IFNULL(SUM(IF(our_result='Y', IF(difficulty=0, pow(2, (" . $this->config['difficulty'] . " - 16)) - 1, 0)), 0) AS valid, - IFNULL(SUM(IF(our_result='N', IF(difficulty=0, pow(2, (" . $this->config['difficulty'] . " - 16)) - 1, 0)), 0) AS invalid, + IFNULL(SUM(IF(our_result='Y', IF(difficulty=0, pow(2, (" . $this->config['difficulty'] . " - 16)) - 1, difficulty), 0)), 0) AS valid, + IFNULL(SUM(IF(our_result='N', IF(difficulty=0, pow(2, (" . $this->config['difficulty'] . " - 16)) - 1, difficulty), 0)), 0) AS invalid, u.id AS id, u.username AS username FROM " . $this->share->getTableName() . " AS s, @@ -196,8 +196,8 @@ class Statistics { if ($this->getGetCache() && $data = $this->memcache->get(__FUNCTION__ . $account_id)) return $data; $stmt = $this->mysqli->prepare(" SELECT - IFNULL(SUM(IF(our_result='Y', IF(difficulty=0, pow(2, (" . $this->config['difficulty'] . " - 16)) - 1, 0)), 0) AS valid, - IFNULL(SUM(IF(our_result='N', IF(difficulty=0, pow(2, (" . $this->config['difficulty'] . " - 16)) - 1, 0)), 0) AS invalid + IFNULL(SUM(IF(our_result='Y', IF(difficulty=0, pow(2, (" . $this->config['difficulty'] . " - 16)) - 1, difficulty), 0)), 0) AS valid, + IFNULL(SUM(IF(our_result='N', IF(difficulty=0, pow(2, (" . $this->config['difficulty'] . " - 16)) - 1, difficulty), 0)), 0) AS invalid FROM " . $this->share->getTableName() . " AS s, " . $this->user->getTableName() . " AS u WHERE From 4472250d36b56f1cd09c22949398168c761a2ff6 Mon Sep 17 00:00:00 2001 From: obigal Date: Sat, 6 Jul 2013 09:23:15 -0400 Subject: [PATCH 19/60] Update mmcfe_ng_structure.sql --- sql/000_base_structure.sql | 1 - 1 file changed, 1 deletion(-) diff --git a/sql/000_base_structure.sql b/sql/000_base_structure.sql index 81aa8f81..fc31343d 100644 --- a/sql/000_base_structure.sql +++ b/sql/000_base_structure.sql @@ -81,7 +81,6 @@ CREATE TABLE IF NOT EXISTS `pool_worker` ( `username` char(50) DEFAULT NULL, `password` char(255) DEFAULT NULL, `monitor` tinyint(1) NOT NULL DEFAULT '0', - `hashrate` int(11) DEFAULT NULL, `difficulty` int(11) NOT NULL DEFAULT '0', PRIMARY KEY (`id`), UNIQUE KEY `username` (`username`), From c3a63d58ce502d8dad1d537fada66b7d707b8ed2 Mon Sep 17 00:00:00 2001 From: obigal Date: Sat, 6 Jul 2013 13:38:34 -0400 Subject: [PATCH 20/60] Updates --- public/include/classes/share.class.php | 10 +------ public/include/classes/statistics.class.php | 29 ++++++++++--------- public/include/smarty_globals.inc.php | 2 +- .../mmcFE/statistics/pool/authenticated.tpl | 2 +- 4 files changed, 19 insertions(+), 24 deletions(-) diff --git a/public/include/classes/share.class.php b/public/include/classes/share.class.php index 6d17a4c1..7abcf56a 100644 --- a/public/include/classes/share.class.php +++ b/public/include/classes/share.class.php @@ -13,19 +13,12 @@ class Share { // This defines each share public $rem_host, $username, $our_result, $upstream_result, $reason, $solution, $time, $difficulty; -<<<<<<< HEAD public function __construct($debug, $mysqli, $user, $block, $config) { $this->debug = $debug; $this->mysqli = $mysqli; $this->user = $user; $this->config = $config; $this->block = $block; -======= - public function __construct($debug, $mysqli, $config, $salt) { - $this->debug = $debug; - $this->mysqli = $mysqli; - $this->config = $config; ->>>>>>> Update share.class.php $this->debug->append("Instantiated Share class", 2); } @@ -77,7 +70,7 @@ class Share { **/ public function getRoundShares($previous_upstream=0, $current_upstream) { $stmt = $this->mysqli->prepare("SELECT - SUM(IF(difficulty=0, pow(2, (" . $this->config['difficulty'] . " - 16)) - 1, difficulty)) as total + IFNULL(SUM(IF(difficulty=0, pow(2, (" . $this->config['difficulty'] . " - 16)) - 1, difficulty)), 0) as total FROM $this->table WHERE our_result = 'Y' AND id > ? AND id <= ? @@ -284,7 +277,6 @@ class Share { SUBSTRING_INDEX( `username` , '.', 1 ) AS account, id FROM $this->table WHERE upstream_result = 'Y' - AND UNIX_TIMESTAMP(time) >= ? AND id > ? AND UNIX_TIMESTAMP(time) >= ? AND UNIX_TIMESTAMP(time) <= ( ? + 60 ) diff --git a/public/include/classes/statistics.class.php b/public/include/classes/statistics.class.php index f799ea0a..200bded5 100644 --- a/public/include/classes/statistics.class.php +++ b/public/include/classes/statistics.class.php @@ -105,9 +105,13 @@ class Statistics { SELECT ( ( - SELECT ROUND(SUM(IF(difficulty=0, pow(2, (" . $this->config['difficulty'] . " - 16)) - 1, difficulty)) * 65536/600/1000) AS hashrate FROM " . $this->share->getTableName() . " WHERE time > DATE_SUB(now(), INTERVAL 10 MINUTE) + SELECT IFNULL(ROUND(SUM(IF(difficulty=0, pow(2, (" . $this->config['difficulty'] . " - 16)) - 1, difficulty)) * 65536/600/1000), 0) AS hashrate + FROM " . $this->share->getTableName() . " + WHERE time > DATE_SUB(now(), INTERVAL 10 MINUTE) ) + ( - SELECT ROUND(SUM(IF(difficulty=0, pow(2, (" . $this->config['difficulty'] . " - 16)) - 1, difficulty)) * 65536/600/1000) AS hashrate FROM " . $this->share->getArchiveTableName() . " WHERE time > DATE_SUB(now(), INTERVAL 10 MINUTE) + SELECT IFNULL(ROUND(SUM(IF(difficulty=0, pow(2, (" . $this->config['difficulty'] . " - 16)) - 1, difficulty)) * 65536/600/1000), 0) AS hashrate + FROM " . $this->share->getArchiveTableName() . " + WHERE time > DATE_SUB(now(), INTERVAL 10 MINUTE) ) ) AS hashrate FROM DUAL"); @@ -128,9 +132,9 @@ class Statistics { $stmt = $this->mysqli->prepare(" SELECT ROUND(SUM(sharerate) / 600, 2) AS sharerate FROM ( - SELECT SUM(IF(difficulty=0, pow(2, (" . $this->config['difficulty'] . " - 16)) - 1, difficulty)) AS sharerate FROM " . $this->share->getTableName() . " WHERE time > DATE_SUB(now(), INTERVAL 10 MINUTE) + SELECT IFNULL(SUM(IF(difficulty=0, pow(2, (" . $this->config['difficulty'] . " - 16)) - 1, difficulty)), 0) AS sharerate FROM " . $this->share->getTableName() . " WHERE time > DATE_SUB(now(), INTERVAL 10 MINUTE) UNION ALL - SELECT SUM(IF(difficulty=0, pow(2, (" . $this->config['difficulty'] . " - 16)) - 1, difficulty)) AS sharerate FROM " . $this->share->getArchiveTableName() . " WHERE time > DATE_SUB(now(), INTERVAL 10 MINUTE) + SELECT IFNULL(SUM(IF(difficulty=0, pow(2, (" . $this->config['difficulty'] . " - 16)) - 1, difficulty)), 0) AS sharerate FROM " . $this->share->getArchiveTableName() . " WHERE time > DATE_SUB(now(), INTERVAL 10 MINUTE) ) AS sum"); if ($this->checkStmt($stmt) && $stmt->execute() && $result = $stmt->get_result() ) return $this->memcache->setCache(__FUNCTION__, $result->fetch_object()->sharerate); // Catchall @@ -170,8 +174,8 @@ class Statistics { if ($this->getGetCache() && $data = $this->memcache->get(__FUNCTION__)) return $data; $stmt = $this->mysqli->prepare(" SELECT - IFNULL(SUM(IF(our_result='Y', IF(difficulty=0, pow(2, (" . $this->config['difficulty'] . " - 16)) - 1, difficulty), 0)), 0) AS valid, - IFNULL(SUM(IF(our_result='N', IF(difficulty=0, pow(2, (" . $this->config['difficulty'] . " - 16)) - 1, difficulty), 0)), 0) AS invalid, + IFNULL(SUM(IF(our_result='Y', IF(s.difficulty=0, pow(2, (" . $this->config['difficulty'] . " - 16)) - 1, s.difficulty), 0)), 0) AS valid, + IFNULL(SUM(IF(our_result='N', IF(s.difficulty=0, pow(2, (" . $this->config['difficulty'] . " - 16)) - 1, s.difficulty), 0)), 0) AS invalid, u.id AS id, u.username AS username FROM " . $this->share->getTableName() . " AS s, @@ -196,8 +200,8 @@ class Statistics { if ($this->getGetCache() && $data = $this->memcache->get(__FUNCTION__ . $account_id)) return $data; $stmt = $this->mysqli->prepare(" SELECT - IFNULL(SUM(IF(our_result='Y', IF(difficulty=0, pow(2, (" . $this->config['difficulty'] . " - 16)) - 1, difficulty), 0)), 0) AS valid, - IFNULL(SUM(IF(our_result='N', IF(difficulty=0, pow(2, (" . $this->config['difficulty'] . " - 16)) - 1, difficulty), 0)), 0) AS invalid + IFNULL(SUM(IF(our_result='Y', IF(s.difficulty=0, pow(2, (" . $this->config['difficulty'] . " - 16)) - 1, s.difficulty), 0)), 0) AS valid, + IFNULL(SUM(IF(our_result='N', IF(s.difficulty=0, pow(2, (" . $this->config['difficulty'] . " - 16)) - 1, s.difficulty), 0)), 0) AS invalid FROM " . $this->share->getTableName() . " AS s, " . $this->user->getTableName() . " AS u WHERE @@ -282,7 +286,7 @@ class Statistics { $this->debug->append("STA " . __METHOD__, 4); if ($data = $this->memcache->get(__FUNCTION__ . $account_id)) return $data; $stmt = $this->mysqli->prepare(" - SELECT SUM(IF(s.difficulty=0, pow(2, (" . $this->config['difficulty'] . " - 16)) - 1, s.difficulty))/600 AS sharerate + SELECT IFNULL(SUM(IF(s.difficulty=0, pow(2, (" . $this->config['difficulty'] . " - 16)) - 1, s.difficulty)), 0)/600 AS sharerate FROM " . $this->share->getTableName() . " AS s, " . $this->user->getTableName() . " AS u WHERE u.username = SUBSTRING_INDEX( s.username, '.', 1 ) @@ -304,7 +308,7 @@ class Statistics { $this->debug->append("STA " . __METHOD__, 4); if ($data = $this->memcache->get(__FUNCTION__ . $worker_id)) return $data; $stmt = $this->mysqli->prepare(" - SELECT ROUND(SUM(IF(s.difficulty=0, pow(2, (" . $this->config['difficulty'] . " - 16)) - 1, s.difficulty)) * 65536/600/1000) AS hashrate + SELECT IFNULL(ROUND(SUM(IF(s.difficulty=0, pow(2, (" . $this->config['difficulty'] . " - 16)) - 1, s.difficulty)) * 65536/600/1000), 0) AS hashrate FROM " . $this->share->getTableName() . " AS s, " . $this->user->getTableName() . " AS u WHERE u.username = SUBSTRING_INDEX( s.username, '.', 1 ) @@ -332,7 +336,7 @@ class Statistics { SELECT a.donate_percent AS donate_percent, a.is_anonymous AS is_anonymous, - SUM(IF(difficulty=0, pow(2, (" . $this->config['difficulty'] . " - 16)) - 1, difficulty)) AS shares, + IFNULL(SUM(IF(difficulty=0, pow(2, (" . $this->config['difficulty'] . " - 16)) - 1, difficulty)), 0) AS shares, SUBSTRING_INDEX( s.username, '.', 1 ) AS account FROM " . $this->share->getTableName() . " AS s LEFT JOIN " . $this->user->getTableName() . " AS a @@ -352,8 +356,7 @@ class Statistics { SELECT a.donate_percent AS donate_percent, a.is_anonymous AS is_anonymous, - IFNULL(ROUND(COUNT(t1.id) * POW(2," . $this->config['difficulty'] . ")/600/1000, 2), 0) AS hashrate, - ROUND(SUM(IF(t1.difficulty=0, pow(2, (" . $this->config['difficulty'] . " - 16)) - 1, t1.difficulty)) * 65536/600/1000) AS hashrate, + IFNULL(ROUND(SUM(IF(t1.difficulty=0, pow(2, (" . $this->config['difficulty'] . " - 16)) - 1, t1.difficulty)) * 65536/600/1000), 0) AS hashrate, SUBSTRING_INDEX( t1.username, '.', 1 ) AS account FROM ( diff --git a/public/include/smarty_globals.inc.php b/public/include/smarty_globals.inc.php index 6275c5ae..b3c5d3ee 100644 --- a/public/include/smarty_globals.inc.php +++ b/public/include/smarty_globals.inc.php @@ -21,7 +21,7 @@ if (@$_SESSION['AUTHENTICATED']) { } } // Always fetch this since we need for ministats header -$bitcoin->can_connect() === true ? $dNetworkHashrate = $bitcoin->query('getnetworkhashps') : $dNetworkHashrate = 0; +//$bitcoin->can_connect() === true ? $dNetworkHashrate = $bitcoin->query('getnetworkhashps') : $dNetworkHashrate = 0; // Fetch some data if (!$iCurrentActiveWorkers = $worker->getCountAllActiveWorkers()) $iCurrentActiveWorkers = 0; diff --git a/public/templates/mmcFE/statistics/pool/authenticated.tpl b/public/templates/mmcFE/statistics/pool/authenticated.tpl index e9f8e95b..83ee505c 100644 --- a/public/templates/mmcFE/statistics/pool/authenticated.tpl +++ b/public/templates/mmcFE/statistics/pool/authenticated.tpl @@ -48,7 +48,7 @@ Est. Shares this Round - {(65536 * $DIFFICULTY)|number_format:"0"} (done: {(100 / (pow(2, 32 - $GLOBAL.config.targetdiff) * $DIFFICULTY) * $GLOBAL.roundshares.valid)|number_format:"2"} %) + {(65536 * $DIFFICULTY)|number_format:"0"} (done: {(100 / (65536 * $DIFFICULTY) * $GLOBAL.roundshares.valid)|number_format:"2"} %) Time Since Last Block From 1fd896dc441b2dccbe02ff169be637d51025d3e6 Mon Sep 17 00:00:00 2001 From: Sebastian Grewe Date: Fri, 2 Aug 2013 17:45:34 +0200 Subject: [PATCH 21/60] Adding SQL file for quick update to VARDIFF This branch now includes all recent changes from `next`! It might have broken some things so @obigal needs to test it again, but at least we can now continue on this with all recent additions added to this branch. Addresses #145 --- sql/issue_145_shares.sql | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 sql/issue_145_shares.sql diff --git a/sql/issue_145_shares.sql b/sql/issue_145_shares.sql new file mode 100644 index 00000000..c8367230 --- /dev/null +++ b/sql/issue_145_shares.sql @@ -0,0 +1,2 @@ +ALTER TABLE `shares` ADD `difficulty` FLOAT NOT NULL AFTER `solution` ; +ALTER TABLE `pool_worker` ADD `difficulty` FLOAT NOT NULL AFTER `password` ; From ef234fe80bf4c91702dfcd46edd6da2472313f85 Mon Sep 17 00:00:00 2001 From: obigal Date: Sun, 4 Aug 2013 01:10:00 -0400 Subject: [PATCH 22/60] Vardiff/pushpool and pps payout support --- cronjobs/pps_payout.php | 46 +++++++++++++++- public/include/classes/block.class.php | 12 ++++ public/include/classes/share.class.php | 12 ++-- public/include/classes/statistics.class.php | 55 +++++++++---------- public/include/classes/worker.class.php | 4 +- public/include/config/global.inc.dist.php | 21 +++++++ public/include/smarty_globals.inc.php | 19 ++++--- .../mmcFE/statistics/blocks/default.tpl | 4 +- .../mobile/statistics/blocks/default.tpl | 4 +- .../mobile/statistics/pool/authenticated.tpl | 2 +- sql/000_base_structure.sql | 6 +- 11 files changed, 130 insertions(+), 55 deletions(-) diff --git a/cronjobs/pps_payout.php b/cronjobs/pps_payout.php index 2d85867f..5585292c 100755 --- a/cronjobs/pps_payout.php +++ b/cronjobs/pps_payout.php @@ -45,16 +45,56 @@ if ( $bitcoin->can_connect() === true ){ // Value per share calculation // We need to use this instead when running VARDIFF // $pps_value = number_format(round((1/(65536 * $dDifficulty) * $config['reward']), 12) ,12); +// pps base payout target, default 16 = difficulty 1 shares for vardiff +// (1/(65536 * difficulty) * reward) = (reward / (pow(2,32) * difficulty) * pow(2, 16)) + +// We support some dynamic reward targets but fall back to our fixed value +// Re-calculate after each run due to re-targets in this loop +if ($config['pps']['reward']['type'] == 'blockavg' && $block->getBlockCount() > 0) { + $pps_reward = round($block->getAvgBlockReward($config['pps']['blockavg']['blockcount'])); + $log->logInfo("PPS reward using block average, amount: " . $pps_reward . "\tdifficulty: " . $dDifficulty); +} else { + if ($config['pps']['reward']['type'] == 'block') { + if ($aLastBlock = $block->getLast()) { + $pps_reward = $aLastBlock['amount']; + $log->logInfo("PPS reward using last block, amount: " . $pps_reward . "\tdifficulty: " . $dDifficulty); + } else { + $pps_reward = $config['pps']['reward']['default']; + $log->logInfo("PPS reward using default, amount: " . $pps_reward . "\tdifficulty: " . $dDifficulty); + } + } else { + $pps_reward = $config['pps']['reward']['default']; + $log->logInfo("PPS reward fixed default, amount: " . $pps_reward . "\tdifficulty: " . $dDifficulty); + } +} + +$pps_value = number_format(round($pps_reward / (pow(2,32) * $dDifficulty) * pow(2, $config['pps_target']), 12) ,12); +//$pps_value = number_format(round((1/(65536 * $dDifficulty) * $pps_reward), 12) ,12); + +/** if ($config['reward_type'] != 'block') { - $pps_value = number_format(round($config['reward'] / (pow(2,32) * $dDifficulty) * pow(2, $config['difficulty']), 12) ,12); + $pps_value = number_format(round($config['reward'] / (pow(2,32) * $dDifficulty) * pow(2, $config['pps_target']), 12) ,12); } else { // Try to find the last block value and use that for future payouts, revert to fixed reward if none found if ($aLastBlock = $block->getLast()) { - $pps_value = number_format(round($aLastBlock['amount'] / (pow(2,32) * $dDifficulty) * pow(2, $config['difficulty']), 12) ,12); + $pps_value = number_format(round($aLastBlock['amount'] / (pow(2,32) * $dDifficulty) * pow(2, $config['pps_target']), 12) ,12); } else { - $pps_value = number_format(round($config['reward'] / (pow(2,32) * $dDifficulty) * pow(2, $config['difficulty']), 12) ,12); + $pps_value = number_format(round($config['reward'] / (pow(2,32) * $dDifficulty) * pow(2, $config['pps_target']), 12) ,12); } } +**/ +/** +if ($config['reward_type'] != 'block') { + $pps_value = number_format(round((1/(65536 * $dDifficulty) * $config['reward']), 12) ,12); +} else { + // Try to find the last block value and use that for future payouts, revert to fixed reward if none found + if ($aLastBlock = $block->getLast()) { + $pps_value = number_format(round((1/(65536 * $dDifficulty) * $aLastBlock['amount']), 12) ,12); + } else { + $pps_value = number_format(round((1/(65536 * $dDifficulty) * $config['reward']), 12) ,12); + } +} +**/ // Find our last share accounted and last inserted share for PPS calculations $iPreviousShareId = $setting->getValue('pps_last_share_id'); diff --git a/public/include/classes/block.class.php b/public/include/classes/block.class.php index 8ce985d1..03f8bd13 100644 --- a/public/include/classes/block.class.php +++ b/public/include/classes/block.class.php @@ -115,6 +115,18 @@ class Block { return false; } + /** + * Fetch our average rewards for the past N blocks + * @param limit int Maximum blocks to check + * @return data float Float value of average shares + **/ + public function getAvgBlockReward($limit=1) { + $stmt = $this->mysqli->prepare("SELECT AVG(x.amount) AS average FROM (SELECT amount FROM $this->table ORDER BY height DESC LIMIT ?) AS x"); + if ($this->checkStmt($stmt) && $stmt->bind_param('i', $limit) && $stmt->execute() && $result = $stmt->get_result()) + return (float)$result->fetch_object()->average; + return false; + } + /** * Fetch all unconfirmed blocks from table * @param confirmations int Required confirmations to consider block confirmed diff --git a/public/include/classes/share.class.php b/public/include/classes/share.class.php index 7abcf56a..e47b65d6 100644 --- a/public/include/classes/share.class.php +++ b/public/include/classes/share.class.php @@ -70,7 +70,7 @@ class Share { **/ public function getRoundShares($previous_upstream=0, $current_upstream) { $stmt = $this->mysqli->prepare("SELECT - IFNULL(SUM(IF(difficulty=0, pow(2, (" . $this->config['difficulty'] . " - 16)) - 1, difficulty)), 0) as total + IFNULL(ROUND(SUM(IF(difficulty=0, pow(2, (" . $this->config['difficulty'] . " - 16)), difficulty)), 8), 0) as total FROM $this->table WHERE our_result = 'Y' AND id > ? AND id <= ? @@ -98,8 +98,8 @@ class Share { a.id, SUBSTRING_INDEX( s.username , '.', 1 ) as username, a.no_fees AS no_fees, - IFNULL(SUM(IF(our_result='Y', IF(difficulty=0, pow(2, (" . $this->config['difficulty'] . " - 16)) - 1, difficulty), 0)), 0) AS valid, - IFNULL(SUM(IF(our_result='N', IF(difficulty=0, pow(2, (" . $this->config['difficulty'] . " - 16)) - 1, difficulty), 0)), 0) AS invalid + IFNULL(ROUND(SUM(IF(our_result='Y', IF(s.difficulty=0, pow(2, (" . $this->config['difficulty'] . " - 16)), s.difficulty), 0)), 8), 0) AS valid, + IFNULL(ROUND(SUM(IF(our_result='N', IF(s.difficulty=0, pow(2, (" . $this->config['difficulty'] . " - 16)), s.difficulty), 0)), 8), 0) AS invalid FROM $this->table AS s LEFT JOIN " . $this->user->getTableName() . " AS a ON a.username = SUBSTRING_INDEX( s.username , '.', 1 ) @@ -137,8 +137,8 @@ class Share { a.id, SUBSTRING_INDEX( s.username , '.', 1 ) as account, a.no_fees AS no_fees, - IFNULL(SUM(IF(our_result='Y', 1, 0)), 0) AS valid, - IFNULL(SUM(IF(our_result='N', 1, 0)), 0) AS invalid + IFNULL(ROUND(SUM(IF(our_result='Y', IF(s.difficulty=0, pow(2, (" . $this->config['difficulty'] . " - 16)), s.difficulty), 0)), 8), 0) AS valid, + IFNULL(ROUND(SUM(IF(our_result='N', IF(s.difficulty=0, pow(2, (" . $this->config['difficulty'] . " - 16)), s.difficulty), 0)), 8), 0) AS invalid FROM $this->tableArchive AS s LEFT JOIN " . $this->user->getTableName() . " AS a ON a.username = SUBSTRING_INDEX( s.username , '.', 1 ) @@ -189,7 +189,7 @@ class Share { public function moveArchive($current_upstream, $block_id, $previous_upstream=0) { $archive_stmt = $this->mysqli->prepare(" INSERT INTO $this->tableArchive (share_id, username, our_result, upstream_result, block_id, time, difficulty) - SELECT id, username, our_result, upstream_result, ?, time + SELECT id, username, our_result, upstream_result, ?, time, IF(difficulty=0, pow(2, (" . $this->config['difficulty'] . " - 16)), difficulty) AS difficulty FROM $this->table WHERE id > ? AND id <= ?"); if ($this->checkStmt($archive_stmt) && $archive_stmt->bind_param('iii', $block_id, $previous_upstream, $current_upstream) && $archive_stmt->execute()) { diff --git a/public/include/classes/statistics.class.php b/public/include/classes/statistics.class.php index 200bded5..e3e2f793 100644 --- a/public/include/classes/statistics.class.php +++ b/public/include/classes/statistics.class.php @@ -105,11 +105,11 @@ class Statistics { SELECT ( ( - SELECT IFNULL(ROUND(SUM(IF(difficulty=0, pow(2, (" . $this->config['difficulty'] . " - 16)) - 1, difficulty)) * 65536/600/1000), 0) AS hashrate + SELECT IFNULL(ROUND(SUM(IF(difficulty=0, pow(2, (" . $this->config['difficulty'] . " - 16)), difficulty)) * 65536/600/1000), 0) AS hashrate FROM " . $this->share->getTableName() . " WHERE time > DATE_SUB(now(), INTERVAL 10 MINUTE) ) + ( - SELECT IFNULL(ROUND(SUM(IF(difficulty=0, pow(2, (" . $this->config['difficulty'] . " - 16)) - 1, difficulty)) * 65536/600/1000), 0) AS hashrate + SELECT IFNULL(ROUND(SUM(IF(difficulty=0, pow(2, (" . $this->config['difficulty'] . " - 16)), difficulty)) * 65536/600/1000), 0) AS hashrate FROM " . $this->share->getArchiveTableName() . " WHERE time > DATE_SUB(now(), INTERVAL 10 MINUTE) ) @@ -130,12 +130,9 @@ class Statistics { $this->debug->append("STA " . __METHOD__, 4); if ($data = $this->memcache->get(__FUNCTION__)) return $data; $stmt = $this->mysqli->prepare(" - SELECT ROUND(SUM(sharerate) / 600, 2) AS sharerate FROM - ( - SELECT IFNULL(SUM(IF(difficulty=0, pow(2, (" . $this->config['difficulty'] . " - 16)) - 1, difficulty)), 0) AS sharerate FROM " . $this->share->getTableName() . " WHERE time > DATE_SUB(now(), INTERVAL 10 MINUTE) - UNION ALL - SELECT IFNULL(SUM(IF(difficulty=0, pow(2, (" . $this->config['difficulty'] . " - 16)) - 1, difficulty)), 0) AS sharerate FROM " . $this->share->getArchiveTableName() . " WHERE time > DATE_SUB(now(), INTERVAL 10 MINUTE) - ) AS sum"); + SELECT ROUND(SUM(IF(difficulty=0, pow(2, (" . $this->config['difficulty'] . " - 16)), difficulty)) / 600, 2) AS sharerate + FROM " . $this->share->getTableName() . " + WHERE time > DATE_SUB(now(), INTERVAL 10 MINUTE)"); if ($this->checkStmt($stmt) && $stmt->execute() && $result = $stmt->get_result() ) return $this->memcache->setCache(__FUNCTION__, $result->fetch_object()->sharerate); // Catchall $this->debug->append("Failed to fetch share rate: " . $this->mysqli->error); @@ -152,8 +149,8 @@ class Statistics { if ($this->getGetCache() && $data = $this->memcache->get(__FUNCTION__)) return $data; $stmt = $this->mysqli->prepare(" SELECT - IFNULL(SUM(IF(our_result='Y', IF(difficulty=0, pow(2, (" . $this->config['difficulty'] . " - 16)) - 1, difficulty), 0)), 0) AS valid, - IFNULL(SUM(IF(our_result='N', IF(difficulty=0, pow(2, (" . $this->config['difficulty'] . " - 16)) - 1, difficulty), 0)), 0) AS invalid + IFNULL(SUM(IF(our_result='Y', IF(difficulty=0, pow(2, (" . $this->config['difficulty'] . " - 16)), difficulty), 0)), 0) AS valid, + IFNULL(SUM(IF(our_result='N', IF(difficulty=0, pow(2, (" . $this->config['difficulty'] . " - 16)), difficulty), 0)), 0) AS invalid FROM " . $this->share->getTableName() . " WHERE UNIX_TIMESTAMP(time) >IFNULL((SELECT MAX(time) FROM " . $this->block->getTableName() . "),0)"); if ( $this->checkStmt($stmt) && $stmt->execute() && $result = $stmt->get_result() ) @@ -174,8 +171,8 @@ class Statistics { if ($this->getGetCache() && $data = $this->memcache->get(__FUNCTION__)) return $data; $stmt = $this->mysqli->prepare(" SELECT - IFNULL(SUM(IF(our_result='Y', IF(s.difficulty=0, pow(2, (" . $this->config['difficulty'] . " - 16)) - 1, s.difficulty), 0)), 0) AS valid, - IFNULL(SUM(IF(our_result='N', IF(s.difficulty=0, pow(2, (" . $this->config['difficulty'] . " - 16)) - 1, s.difficulty), 0)), 0) AS invalid, + IFNULL(SUM(IF(our_result='Y', IF(s.difficulty=0, pow(2, (" . $this->config['difficulty'] . " - 16)), s.difficulty), 0)), 0) AS valid, + IFNULL(SUM(IF(our_result='N', IF(s.difficulty=0, pow(2, (" . $this->config['difficulty'] . " - 16)), s.difficulty), 0)), 0) AS invalid, u.id AS id, u.username AS username FROM " . $this->share->getTableName() . " AS s, @@ -200,8 +197,8 @@ class Statistics { if ($this->getGetCache() && $data = $this->memcache->get(__FUNCTION__ . $account_id)) return $data; $stmt = $this->mysqli->prepare(" SELECT - IFNULL(SUM(IF(our_result='Y', IF(s.difficulty=0, pow(2, (" . $this->config['difficulty'] . " - 16)) - 1, s.difficulty), 0)), 0) AS valid, - IFNULL(SUM(IF(our_result='N', IF(s.difficulty=0, pow(2, (" . $this->config['difficulty'] . " - 16)) - 1, s.difficulty), 0)), 0) AS invalid + IFNULL(SUM(IF(our_result='Y', IF(s.difficulty=0, pow(2, (" . $this->config['difficulty'] . " - 16)), s.difficulty), 0)), 0) AS valid, + IFNULL(SUM(IF(our_result='N', IF(s.difficulty=0, pow(2, (" . $this->config['difficulty'] . " - 16)), s.difficulty), 0)), 0) AS invalid FROM " . $this->share->getTableName() . " AS s, " . $this->user->getTableName() . " AS u WHERE @@ -231,7 +228,7 @@ class Statistics { a.username AS username, a.donate_percent AS donate_percent, a.email AS email, - SUM(s.difficulty) AS shares + IFNULL(SUM(IF(s.difficulty=0, pow(2, (" . $this->config['difficulty'] . " - 16)), s.difficulty)), 0) AS shares FROM " . $this->user->getTableName() . " AS a LEFT JOIN " . $this->share->getTableName() . " AS s ON a.username = SUBSTRING_INDEX( s.username, '.', 1 ) @@ -255,14 +252,14 @@ class Statistics { $stmt = $this->mysqli->prepare(" SELECT ( - SELECT ROUND(SUM(IF(s.difficulty=0, pow(2, (" . $this->config['difficulty'] . " - 16)) - 1, s.difficulty)) * 65536/600/1000) AS hashrate + SELECT IFNULL(ROUND(SUM(IF(difficulty=0, pow(2, (" . $this->config['difficulty'] . " - 16)), difficulty)) * 65536/600/1000), 0) AS hashrate FROM " . $this->share->getTableName() . " AS s, " . $this->user->getTableName() . " AS u WHERE u.username = SUBSTRING_INDEX( s.username, '.', 1 ) AND s.time > DATE_SUB(now(), INTERVAL 10 MINUTE) AND u.id = ? ) + ( - SELECT ROUND(SUM(IF(s.difficulty=0, pow(2, (" . $this->config['difficulty'] . " - 16)) - 1, s.difficulty)) * 65536/600/1000) AS hashrate + SELECT IFNULL(ROUND(SUM(IF(difficulty=0, pow(2, (" . $this->config['difficulty'] . " - 16)), difficulty)) * 65536/600/1000), 0) AS hashrate FROM " . $this->share->getArchiveTableName() . " AS s, " . $this->user->getTableName() . " AS u WHERE u.username = SUBSTRING_INDEX( s.username, '.', 1 ) @@ -286,7 +283,7 @@ class Statistics { $this->debug->append("STA " . __METHOD__, 4); if ($data = $this->memcache->get(__FUNCTION__ . $account_id)) return $data; $stmt = $this->mysqli->prepare(" - SELECT IFNULL(SUM(IF(s.difficulty=0, pow(2, (" . $this->config['difficulty'] . " - 16)) - 1, s.difficulty)), 0)/600 AS sharerate + SELECT IFNULL(SUM(IF(difficulty=0, pow(2, (" . $this->config['difficulty'] . " - 16)), difficulty)), 0)/600 AS sharerate FROM " . $this->share->getTableName() . " AS s, " . $this->user->getTableName() . " AS u WHERE u.username = SUBSTRING_INDEX( s.username, '.', 1 ) @@ -308,7 +305,7 @@ class Statistics { $this->debug->append("STA " . __METHOD__, 4); if ($data = $this->memcache->get(__FUNCTION__ . $worker_id)) return $data; $stmt = $this->mysqli->prepare(" - SELECT IFNULL(ROUND(SUM(IF(s.difficulty=0, pow(2, (" . $this->config['difficulty'] . " - 16)) - 1, s.difficulty)) * 65536/600/1000), 0) AS hashrate + SELECT IFNULL(ROUND(SUM(IF(difficulty=0, pow(2, (" . $this->config['difficulty'] . " - 16)), difficulty)) * 65536/600/1000), 0) AS hashrate FROM " . $this->share->getTableName() . " AS s, " . $this->user->getTableName() . " AS u WHERE u.username = SUBSTRING_INDEX( s.username, '.', 1 ) @@ -336,7 +333,7 @@ class Statistics { SELECT a.donate_percent AS donate_percent, a.is_anonymous AS is_anonymous, - IFNULL(SUM(IF(difficulty=0, pow(2, (" . $this->config['difficulty'] . " - 16)) - 1, difficulty)), 0) AS shares, + IFNULL(SUM(IF(s.difficulty=0, pow(2, (" . $this->config['difficulty'] . " - 16)), s.difficulty)), 0) AS shares, SUBSTRING_INDEX( s.username, '.', 1 ) AS account FROM " . $this->share->getTableName() . " AS s LEFT JOIN " . $this->user->getTableName() . " AS a @@ -353,16 +350,16 @@ class Statistics { case 'hashes': $stmt = $this->mysqli->prepare(" - SELECT + SELECT a.donate_percent AS donate_percent, a.is_anonymous AS is_anonymous, - IFNULL(ROUND(SUM(IF(t1.difficulty=0, pow(2, (" . $this->config['difficulty'] . " - 16)) - 1, t1.difficulty)) * 65536/600/1000), 0) AS hashrate, + IFNULL(ROUND(SUM(t1.difficulty) * 65536/600/1000, 2), 0) AS hashrate, SUBSTRING_INDEX( t1.username, '.', 1 ) AS account FROM ( - SELECT id, username, difficulty FROM " . $this->share->getTableName() . " WHERE time > DATE_SUB(now(), INTERVAL 10 MINUTE) AND our_result = 'Y' - UNION - SELECT id, username, difficulty FROM " . $this->share->getArchiveTableName() ." WHERE time > DATE_SUB(now(), INTERVAL 10 MINUTE) AND our_result = 'Y' + SELECT IFNULL(IF(difficulty=0, pow(2, (" . $this->config['difficulty'] . " - 16)), difficulty), 0) AS difficulty, username FROM " . $this->share->getTableName() . " WHERE time > DATE_SUB(now(), INTERVAL 10 MINUTE) AND our_result = 'Y' + UNION ALL + SELECT IFNULL(IF(difficulty=0, pow(2, (" . $this->config['difficulty'] . " - 16)), difficulty), 0) AS difficulty, username FROM " . $this->share->getArchiveTableName() ." WHERE time > DATE_SUB(now(), INTERVAL 10 MINUTE) AND our_result = 'Y' ) AS t1 LEFT JOIN " . $this->user->getTableName() . " AS a ON SUBSTRING_INDEX( t1.username, '.', 1 ) = a.username @@ -386,7 +383,7 @@ class Statistics { if ($data = $this->memcache->get(__FUNCTION__ . $account_id)) return $data; $stmt = $this->mysqli->prepare(" SELECT - ROUND(SUM(IF(s.difficulty=0, pow(2, (" . $this->config['difficulty'] . " - 16)) - 1, s.difficulty)) * 65536/3600/1000) AS hashrate, + IFNULL(ROUND(SUM(IF(s.difficulty=0, pow(2, (" . $this->config['difficulty'] . " - 16)), s.difficulty)) * 65536/3600/1000), 0) AS hashrate, HOUR(s.time) AS hour FROM " . $this->share->getArchiveTableName() . " AS s, accounts AS a WHERE time < NOW() - INTERVAL 1 HOUR @@ -396,7 +393,7 @@ class Statistics { GROUP BY HOUR(time) UNION ALL SELECT - ROUND(COUNT(s.id) * POW(2, " . $this->config['difficulty'] . ") / 3600 / 1000) AS hashrate, + IFNULL(ROUND(SUM(IF(s.difficulty=0, pow(2, (" . $this->config['difficulty'] . " - 16)), s.difficulty)) * 65536/3600/1000), 0) AS hashrate, HOUR(s.time) AS hour FROM " . $this->share->getArchiveTableName() . " AS s, accounts AS a WHERE time < NOW() - INTERVAL 1 HOUR @@ -426,7 +423,7 @@ class Statistics { if ($this->getGetCache() && $data = $this->memcache->get(__FUNCTION__)) return $data; $stmt = $this->mysqli->prepare(" SELECT - ROUND(SUM(IF(s.difficulty=0, pow(2, (" . $this->config['difficulty'] . " - 16)) - 1, s.difficulty)) * 65536/3600/1000) AS hashrate, + IFNULL(ROUND(SUM(IF(s.difficulty=0, pow(2, (" . $this->config['difficulty'] . " - 16)), s.difficulty)) * 65536/3600/1000), 0) AS hashrate, HOUR(s.time) AS hour FROM " . $this->share->getArchiveTableName() . " AS s WHERE time < NOW() - INTERVAL 1 HOUR @@ -434,7 +431,7 @@ class Statistics { GROUP BY HOUR(time) UNION ALL SELECT - IFNULL(ROUND(COUNT(s.id) * POW(2, " . $this->config['difficulty'] . ") / 3600 / 1000), 0) AS hashrate, + IFNULL(ROUND(SUM(IF(s.difficulty=0, pow(2, (" . $this->config['difficulty'] . " - 16)), s.difficulty)) * 65536/3600/1000), 0) AS hashrate, HOUR(s.time) AS hour FROM " . $this->share->getArchiveTableName() . " AS s WHERE time < NOW() - INTERVAL 1 HOUR diff --git a/public/include/classes/worker.class.php b/public/include/classes/worker.class.php index a107213b..b0f0a348 100644 --- a/public/include/classes/worker.class.php +++ b/public/include/classes/worker.class.php @@ -96,7 +96,7 @@ class Worker { $stmt = $this->mysqli->prepare(" SELECT id, username, password, monitor, ( SELECT SIGN(COUNT(id)) FROM " . $this->share->getTableName() . " WHERE username = $this->table.username AND time > DATE_SUB(now(), INTERVAL 10 MINUTE)) AS active, - ( SELECT ROUND(SUM(IF(difficulty=0, pow(2, (" . $this->config['difficulty'] . " - 16)) - 1, difficulty)) * 65536/600/1000) FROM " . $this->share->getTableName() . " WHERE username = $this->table.username AND time > DATE_SUB(now(), INTERVAL 10 MINUTE)) AS hashrate + ( SELECT ROUND(SUM(IF(difficulty=0, pow(2, (" . $this->config['difficulty'] . " - 16)), difficulty)) * 65536/600/1000) FROM " . $this->share->getTableName() . " WHERE username = $this->table.username AND time > DATE_SUB(now(), INTERVAL 10 MINUTE)) AS hashrate FROM $this->table WHERE id = ? "); @@ -117,7 +117,7 @@ class Worker { $stmt = $this->mysqli->prepare(" SELECT id, username, password, monitor, ( SELECT SIGN(COUNT(id)) FROM " . $this->share->getTableName() . " WHERE our_result = 'Y' AND username = $this->table.username AND time > DATE_SUB(now(), INTERVAL 10 MINUTE)) AS active, - ( SELECT ROUND(SUM(IF(difficulty=0, pow(2, (" . $this->config['difficulty'] . " - 16)) - 1, difficulty)) * 65536/600/1000) FROM " . $this->share->getTableName() . " WHERE our_result = 'Y' AND username = $this->table.username AND time > DATE_SUB(now(), INTERVAL 10 MINUTE)) AS hashrate + ( SELECT ROUND(SUM(IF(difficulty=0, pow(2, (" . $this->config['difficulty'] . " - 16)), difficulty)) * 65536/600/1000) FROM " . $this->share->getTableName() . " WHERE our_result = 'Y' AND username = $this->table.username AND time > DATE_SUB(now(), INTERVAL 10 MINUTE)) AS hashrate FROM $this->table WHERE account_id = ?"); if ($this->checkStmt($stmt) && $stmt->bind_param('i', $account_id) && $stmt->execute() && $result = $stmt->get_result()) diff --git a/public/include/config/global.inc.dist.php b/public/include/config/global.inc.dist.php index 359f74da..098f6ad0 100644 --- a/public/include/config/global.inc.dist.php +++ b/public/include/config/global.inc.dist.php @@ -347,6 +347,27 @@ $config['reward'] = 50; // Confirmations per block required to credit transactions, default: 120 $config['confirmations'] = 120; + /** + * Available pps options: + * reward_type: + * fixed : Fixed value according to `reward` setting + * blockavg : Dynamic value based on average of x number of block rewards + * block : Dynamic value based on LAST block amount + * reward: + * float value : Any value of your choice but should reflect base block values + * blockcount : amount of blocks to average, any integer + * Default: + * pps_reward_type = `fixed` default $config['pps']['reward']['default'] + * reward = 50 + * + **/ +$config['pps']['reward']['default'] = 50; +$config['pps']['reward']['type'] = 'blockavg'; +$config['pps']['blockavg']['blockcount'] = 10; + +// pps base payout target, default 16 = difficulty 1 shares for vardiff +// (1/(65536 * difficulty) * reward) = (reward / (pow(2,32) * difficulty) * pow(2, 16)) +$config['pps_target'] = 16; // do not change unless you know what it does /** * Memcache configuration diff --git a/public/include/smarty_globals.inc.php b/public/include/smarty_globals.inc.php index b3c5d3ee..cda4cd36 100644 --- a/public/include/smarty_globals.inc.php +++ b/public/include/smarty_globals.inc.php @@ -38,7 +38,6 @@ $aGlobal = array( 'hashrate' => $iCurrentPoolHashrate, 'nethashrate' => $dNetworkHashrate, 'sharerate' => $iCurrentPoolShareRate, - 'ppsvalue' => number_format(round((1/(65536 * $dDifficulty) * $config['reward']), 12) ,12), 'workers' => $iCurrentActiveWorkers, 'roundshares' => $aRoundShares, 'fees' => $config['fees'], @@ -65,18 +64,24 @@ $aGlobal = array( ) ); +// We support some dynamic reward targets but fall back to our fixed value // Special calculations for PPS Values based on reward_type setting and/or available blocks -if ($config['reward_type'] != 'block') { - $aGlobal['ppsvalue'] = number_format(round(50 / (pow(2,32) * $dDifficulty) * pow(2, $config['difficulty']), 12) ,12); +if ($config['pps']['reward']['type'] == 'blockavg' && $block->getBlockCount() > 0) { + $pps_reward = round($block->getAvgBlockReward($config['pps']['blockavg']['blockcount'])); } else { - // Try to find the last block value and use that for future payouts, revert to fixed reward if none found - if ($aLastBlock = $block->getLast()) { - $aGlobal['ppsvalue'] = number_format(round($aLastBlock['amount'] / (pow(2,32) * $dDifficulty) * pow(2, $config['difficulty']), 12) ,12); + if ($config['pps']['reward']['type'] == 'block') { + if ($aLastBlock = $block->getLast()) { + $pps_reward = $aLastBlock['amount']; + } else { + $pps_reward = $config['pps']['reward']['default']; + } } else { - $aGlobal['ppsvalue'] = number_format(round($config['reward'] / (pow(2,32) * $dDifficulty) * pow(2, $config['difficulty']), 12) ,12); + $pps_reward = $config['pps']['reward']['default']; } } +$aGlobal['ppsvalue'] = number_format(round($pps_reward / (pow(2,32) * $dDifficulty) * pow(2, $config['pps_target']), 12) ,12); + // We don't want these session infos cached if (@$_SESSION['USERDATA']['id']) { $aGlobal['userdata'] = $_SESSION['USERDATA']['id'] ? $user->getUserData($_SESSION['USERDATA']['id']) : array(); diff --git a/public/templates/mmcFE/statistics/blocks/default.tpl b/public/templates/mmcFE/statistics/blocks/default.tpl index c491a8dd..d77178d5 100644 --- a/public/templates/mmcFE/statistics/blocks/default.tpl +++ b/public/templates/mmcFE/statistics/blocks/default.tpl @@ -62,8 +62,8 @@ target and network difficulty and assuming a zero variance scenario. {$BLOCKSFOUND[block].difficulty|number_format:"2"} {$BLOCKSFOUND[block].amount|number_format:"2"} - {math assign="estshares" equation="(65536 * blockdiff)" targetdiff=$GLOBAL.config.targetdiff blockdiff=$BLOCKSFOUND[block].difficulty} - {$estshares} + {math assign="estshares" equation="(65536 * blockdiff)" blockdiff=$BLOCKSFOUND[block].difficulty} + {$estshares|number_format} {$BLOCKSFOUND[block].shares|number_format} diff --git a/public/templates/mobile/statistics/blocks/default.tpl b/public/templates/mobile/statistics/blocks/default.tpl index b4f29b00..512d7fce 100644 --- a/public/templates/mobile/statistics/blocks/default.tpl +++ b/public/templates/mobile/statistics/blocks/default.tpl @@ -56,9 +56,9 @@ target and network difficulty and assuming a zero variance scenario. {$BLOCKSFOUND[block].finder|default:"unknown"} {$BLOCKSFOUND[block].time|date_format:"%d/%m %H:%M:%S"} {$BLOCKSFOUND[block].difficulty|number_format:"2"} - {(pow(2,32 - $GLOBAL.config.targetdiff) * $BLOCKSFOUND[block].difficulty)|number_format} + {(65536 * $BLOCKSFOUND[block].difficulty)|number_format} {$BLOCKSFOUND[block].shares|number_format} - {($BLOCKSFOUND[block].shares / (pow(2,32 - $GLOBAL.config.targetdiff) * $BLOCKSFOUND[block].difficulty) * 100)|number_format:"2"} + {($BLOCKSFOUND[block].shares / (65536 * $BLOCKSFOUND[block].difficulty) * 100)|number_format:"2"} {/section} diff --git a/public/templates/mobile/statistics/pool/authenticated.tpl b/public/templates/mobile/statistics/pool/authenticated.tpl index 0d0252e6..d9e490b2 100644 --- a/public/templates/mobile/statistics/pool/authenticated.tpl +++ b/public/templates/mobile/statistics/pool/authenticated.tpl @@ -51,7 +51,7 @@ Est. Shares this Round - {(pow(2, 32 - $GLOBAL.config.targetdiff) * $DIFFICULTY)|number_format:"0"} (done: {(100 / (pow(2, 32 - $GLOBAL.config.targetdiff) * $DIFFICULTY) * $GLOBAL.roundshares.valid)|number_format:"2"} %) + {(65536 * $DIFFICULTY)|number_format:"0"} (done: {(100 / (65536 * $DIFFICULTY) * $GLOBAL.roundshares.valid)|number_format:"2"} %) Time Since Last Block diff --git a/sql/000_base_structure.sql b/sql/000_base_structure.sql index fc31343d..487a3d07 100644 --- a/sql/000_base_structure.sql +++ b/sql/000_base_structure.sql @@ -80,8 +80,8 @@ CREATE TABLE IF NOT EXISTS `pool_worker` ( `account_id` int(255) NOT NULL, `username` char(50) DEFAULT NULL, `password` char(255) DEFAULT NULL, + `difficulty` float NOT NULL DEFAULT '0', `monitor` tinyint(1) NOT NULL DEFAULT '0', - `difficulty` int(11) NOT NULL DEFAULT '0', PRIMARY KEY (`id`), UNIQUE KEY `username` (`username`), KEY `account_id` (`account_id`) @@ -102,8 +102,8 @@ CREATE TABLE IF NOT EXISTS `shares` ( `upstream_result` enum('Y','N') DEFAULT NULL, `reason` varchar(50) DEFAULT NULL, `solution` varchar(257) NOT NULL, + `difficulty` float NOT NULL DEFAULT '0', `time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, - `difficulty` int(11) NOT NULL DEFAULT '0', PRIMARY KEY (`id`), KEY `time` (`time`), KEY `upstream_result` (`upstream_result`), @@ -118,8 +118,8 @@ CREATE TABLE IF NOT EXISTS `shares_archive` ( `our_result` enum('Y','N') DEFAULT NULL, `upstream_result` enum('Y','N') DEFAULT NULL, `block_id` int(10) unsigned NOT NULL, + `difficulty` float NOT NULL DEFAULT '0', `time` datetime NOT NULL, - `difficulty` int(11) NOT NULL DEFAULT '0', PRIMARY KEY (`id`), UNIQUE KEY `share_id` (`share_id`), KEY `time` (`time`) From 691611eb13bdd0ee166c000baadbc583637dcf75 Mon Sep 17 00:00:00 2001 From: obigal Date: Tue, 2 Jul 2013 14:43:11 -0400 Subject: [PATCH 23/60] Update share.class.php --- public/include/classes/share.class.php | 1 + 1 file changed, 1 insertion(+) diff --git a/public/include/classes/share.class.php b/public/include/classes/share.class.php index e47b65d6..26eebb35 100644 --- a/public/include/classes/share.class.php +++ b/public/include/classes/share.class.php @@ -277,6 +277,7 @@ class Share { SUBSTRING_INDEX( `username` , '.', 1 ) AS account, id FROM $this->table WHERE upstream_result = 'Y' + AND UNIX_TIMESTAMP(time) BETWEEN (?) AND (? + 120) AND id > ? AND UNIX_TIMESTAMP(time) >= ? AND UNIX_TIMESTAMP(time) <= ( ? + 60 ) From f452f79f079cabf23be051ca52fa7e464c3a401d Mon Sep 17 00:00:00 2001 From: obigal Date: Tue, 2 Jul 2013 14:47:43 -0400 Subject: [PATCH 24/60] Update statistics.class.php --- public/include/classes/statistics.class.php | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/public/include/classes/statistics.class.php b/public/include/classes/statistics.class.php index e3e2f793..0550957e 100644 --- a/public/include/classes/statistics.class.php +++ b/public/include/classes/statistics.class.php @@ -353,13 +353,14 @@ class Statistics { SELECT a.donate_percent AS donate_percent, a.is_anonymous AS is_anonymous, - IFNULL(ROUND(SUM(t1.difficulty) * 65536/600/1000, 2), 0) AS hashrate, + IFNULL(ROUND(COUNT(t1.id) * POW(2," . $this->config['difficulty'] . ")/600/1000, 2), 0) AS hashrate, + ROUND(SUM(t1.difficulty) * 65536/600/1000) AS hashrate, SUBSTRING_INDEX( t1.username, '.', 1 ) AS account FROM ( - SELECT IFNULL(IF(difficulty=0, pow(2, (" . $this->config['difficulty'] . " - 16)), difficulty), 0) AS difficulty, username FROM " . $this->share->getTableName() . " WHERE time > DATE_SUB(now(), INTERVAL 10 MINUTE) AND our_result = 'Y' - UNION ALL - SELECT IFNULL(IF(difficulty=0, pow(2, (" . $this->config['difficulty'] . " - 16)), difficulty), 0) AS difficulty, username FROM " . $this->share->getArchiveTableName() ." WHERE time > DATE_SUB(now(), INTERVAL 10 MINUTE) AND our_result = 'Y' + SELECT id, username, difficulty FROM " . $this->share->getTableName() . " WHERE time > DATE_SUB(now(), INTERVAL 10 MINUTE) AND our_result = 'Y' + UNION + SELECT id, username, difficulty FROM " . $this->share->getArchiveTableName() ." WHERE time > DATE_SUB(now(), INTERVAL 10 MINUTE) AND our_result = 'Y' ) AS t1 LEFT JOIN " . $this->user->getTableName() . " AS a ON SUBSTRING_INDEX( t1.username, '.', 1 ) = a.username From 528c7ee70810d0e088f0e9ddddc4d2194530a046 Mon Sep 17 00:00:00 2001 From: obigal Date: Tue, 2 Jul 2013 14:58:44 -0400 Subject: [PATCH 25/60] Update mmcfe_ng_structure.sql --- sql/000_base_structure.sql | 3 +++ 1 file changed, 3 insertions(+) diff --git a/sql/000_base_structure.sql b/sql/000_base_structure.sql index 487a3d07..8749c578 100644 --- a/sql/000_base_structure.sql +++ b/sql/000_base_structure.sql @@ -82,6 +82,7 @@ CREATE TABLE IF NOT EXISTS `pool_worker` ( `password` char(255) DEFAULT NULL, `difficulty` float NOT NULL DEFAULT '0', `monitor` tinyint(1) NOT NULL DEFAULT '0', + `difficulty` int(11) NOT NULL DEFAULT '0', PRIMARY KEY (`id`), UNIQUE KEY `username` (`username`), KEY `account_id` (`account_id`) @@ -104,6 +105,7 @@ CREATE TABLE IF NOT EXISTS `shares` ( `solution` varchar(257) NOT NULL, `difficulty` float NOT NULL DEFAULT '0', `time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, + `difficulty` int(11) NOT NULL DEFAULT '0', PRIMARY KEY (`id`), KEY `time` (`time`), KEY `upstream_result` (`upstream_result`), @@ -120,6 +122,7 @@ CREATE TABLE IF NOT EXISTS `shares_archive` ( `block_id` int(10) unsigned NOT NULL, `difficulty` float NOT NULL DEFAULT '0', `time` datetime NOT NULL, + `difficulty` int(11) NOT NULL DEFAULT '0', PRIMARY KEY (`id`), UNIQUE KEY `share_id` (`share_id`), KEY `time` (`time`) From 2a94f49bf62e2be3c0fc66c09e4a964283ee3bc3 Mon Sep 17 00:00:00 2001 From: obigal Date: Wed, 3 Jul 2013 08:33:56 -0400 Subject: [PATCH 26/60] Update mmcfe_ng_structure.sql --- sql/000_base_structure.sql | 1 + 1 file changed, 1 insertion(+) diff --git a/sql/000_base_structure.sql b/sql/000_base_structure.sql index 8749c578..efdfef6f 100644 --- a/sql/000_base_structure.sql +++ b/sql/000_base_structure.sql @@ -82,6 +82,7 @@ CREATE TABLE IF NOT EXISTS `pool_worker` ( `password` char(255) DEFAULT NULL, `difficulty` float NOT NULL DEFAULT '0', `monitor` tinyint(1) NOT NULL DEFAULT '0', + `hashrate` int(11) DEFAULT NULL, `difficulty` int(11) NOT NULL DEFAULT '0', PRIMARY KEY (`id`), UNIQUE KEY `username` (`username`), From f4451aee1c994a27a3ddec3b38c2dd9b4ccd8c58 Mon Sep 17 00:00:00 2001 From: obigal Date: Wed, 3 Jul 2013 08:37:14 -0400 Subject: [PATCH 27/60] Update share.class.php --- public/include/classes/share.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/public/include/classes/share.class.php b/public/include/classes/share.class.php index 26eebb35..db17e9c6 100644 --- a/public/include/classes/share.class.php +++ b/public/include/classes/share.class.php @@ -277,7 +277,7 @@ class Share { SUBSTRING_INDEX( `username` , '.', 1 ) AS account, id FROM $this->table WHERE upstream_result = 'Y' - AND UNIX_TIMESTAMP(time) BETWEEN (?) AND (? + 120) + AND UNIX_TIMESTAMP(time) BETWEEN (?) AND (? + 20) AND id > ? AND UNIX_TIMESTAMP(time) >= ? AND UNIX_TIMESTAMP(time) <= ( ? + 60 ) From 86d4ec18cdbf2f23b2d0af08237bc90c4698bafd Mon Sep 17 00:00:00 2001 From: obigal Date: Wed, 3 Jul 2013 08:42:21 -0400 Subject: [PATCH 28/60] Update authenticated.tpl --- public/templates/mmcFE/statistics/pool/authenticated.tpl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/public/templates/mmcFE/statistics/pool/authenticated.tpl b/public/templates/mmcFE/statistics/pool/authenticated.tpl index 83ee505c..e9f8e95b 100644 --- a/public/templates/mmcFE/statistics/pool/authenticated.tpl +++ b/public/templates/mmcFE/statistics/pool/authenticated.tpl @@ -48,7 +48,7 @@ Est. Shares this Round - {(65536 * $DIFFICULTY)|number_format:"0"} (done: {(100 / (65536 * $DIFFICULTY) * $GLOBAL.roundshares.valid)|number_format:"2"} %) + {(65536 * $DIFFICULTY)|number_format:"0"} (done: {(100 / (pow(2, 32 - $GLOBAL.config.targetdiff) * $DIFFICULTY) * $GLOBAL.roundshares.valid)|number_format:"2"} %) Time Since Last Block From 45d5db65c8619c8bb0f8bacc1fc0adf52306a22c Mon Sep 17 00:00:00 2001 From: obigal Date: Wed, 3 Jul 2013 08:59:22 -0400 Subject: [PATCH 29/60] Update default.tpl --- public/templates/mmcFE/statistics/blocks/default.tpl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/public/templates/mmcFE/statistics/blocks/default.tpl b/public/templates/mmcFE/statistics/blocks/default.tpl index d77178d5..a0198c75 100644 --- a/public/templates/mmcFE/statistics/blocks/default.tpl +++ b/public/templates/mmcFE/statistics/blocks/default.tpl @@ -62,8 +62,8 @@ target and network difficulty and assuming a zero variance scenario. {$BLOCKSFOUND[block].difficulty|number_format:"2"} {$BLOCKSFOUND[block].amount|number_format:"2"} - {math assign="estshares" equation="(65536 * blockdiff)" blockdiff=$BLOCKSFOUND[block].difficulty} - {$estshares|number_format} + {math assign="estshares" equation="(65536 * blockdiff)" blockdiff=$BLOCKSFOUND[block].difficulty} + {$estshares|number_format} {$BLOCKSFOUND[block].shares|number_format} From a7278401b08e2c4de74d4729274f395a6f5f1480 Mon Sep 17 00:00:00 2001 From: obigal Date: Wed, 3 Jul 2013 09:09:47 -0400 Subject: [PATCH 30/60] Update smarty_globals.inc.php --- public/include/smarty_globals.inc.php | 1 + 1 file changed, 1 insertion(+) diff --git a/public/include/smarty_globals.inc.php b/public/include/smarty_globals.inc.php index cda4cd36..1fecac98 100644 --- a/public/include/smarty_globals.inc.php +++ b/public/include/smarty_globals.inc.php @@ -38,6 +38,7 @@ $aGlobal = array( 'hashrate' => $iCurrentPoolHashrate, 'nethashrate' => $dNetworkHashrate, 'sharerate' => $iCurrentPoolShareRate, + 'ppsvalue' => number_format(round(1/(65536 * $dDifficulty) * $config['reward']), 12), 'workers' => $iCurrentActiveWorkers, 'roundshares' => $aRoundShares, 'fees' => $config['fees'], From 53da013fab512398d1cccff0f41addd8c515e574 Mon Sep 17 00:00:00 2001 From: obigal Date: Wed, 3 Jul 2013 09:10:48 -0400 Subject: [PATCH 31/60] Update pps_payout.php --- cronjobs/pps_payout.php | 25 ------------------------- 1 file changed, 25 deletions(-) diff --git a/cronjobs/pps_payout.php b/cronjobs/pps_payout.php index 5585292c..58c9b870 100755 --- a/cronjobs/pps_payout.php +++ b/cronjobs/pps_payout.php @@ -71,31 +71,6 @@ if ($config['pps']['reward']['type'] == 'blockavg' && $block->getBlockCount() > $pps_value = number_format(round($pps_reward / (pow(2,32) * $dDifficulty) * pow(2, $config['pps_target']), 12) ,12); //$pps_value = number_format(round((1/(65536 * $dDifficulty) * $pps_reward), 12) ,12); -/** -if ($config['reward_type'] != 'block') { - $pps_value = number_format(round($config['reward'] / (pow(2,32) * $dDifficulty) * pow(2, $config['pps_target']), 12) ,12); -} else { - // Try to find the last block value and use that for future payouts, revert to fixed reward if none found - if ($aLastBlock = $block->getLast()) { - $pps_value = number_format(round($aLastBlock['amount'] / (pow(2,32) * $dDifficulty) * pow(2, $config['pps_target']), 12) ,12); - } else { - $pps_value = number_format(round($config['reward'] / (pow(2,32) * $dDifficulty) * pow(2, $config['pps_target']), 12) ,12); - } -} -**/ -/** -if ($config['reward_type'] != 'block') { - $pps_value = number_format(round((1/(65536 * $dDifficulty) * $config['reward']), 12) ,12); -} else { - // Try to find the last block value and use that for future payouts, revert to fixed reward if none found - if ($aLastBlock = $block->getLast()) { - $pps_value = number_format(round((1/(65536 * $dDifficulty) * $aLastBlock['amount']), 12) ,12); - } else { - $pps_value = number_format(round((1/(65536 * $dDifficulty) * $config['reward']), 12) ,12); - } -} -**/ - // Find our last share accounted and last inserted share for PPS calculations $iPreviousShareId = $setting->getValue('pps_last_share_id'); $iLastShareId = $share->getLastInsertedShareId(); From 84e22ae4a98763eacfd76b8ff0aa6eb31eac0f11 Mon Sep 17 00:00:00 2001 From: obigal Date: Wed, 3 Jul 2013 09:42:23 -0400 Subject: [PATCH 32/60] Update share.class.php --- public/include/classes/share.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/public/include/classes/share.class.php b/public/include/classes/share.class.php index db17e9c6..6ff03be3 100644 --- a/public/include/classes/share.class.php +++ b/public/include/classes/share.class.php @@ -277,7 +277,7 @@ class Share { SUBSTRING_INDEX( `username` , '.', 1 ) AS account, id FROM $this->table WHERE upstream_result = 'Y' - AND UNIX_TIMESTAMP(time) BETWEEN (?) AND (? + 20) + AND UNIX_TIMESTAMP(time) >= ? AND id > ? AND UNIX_TIMESTAMP(time) >= ? AND UNIX_TIMESTAMP(time) <= ( ? + 60 ) From 1f2bc294f27951449cfc4517692b06216b1d09cd Mon Sep 17 00:00:00 2001 From: obigal Date: Fri, 5 Jul 2013 05:51:02 -0400 Subject: [PATCH 33/60] Update for pushpool compatibility --- public/include/classes/statistics.class.php | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/public/include/classes/statistics.class.php b/public/include/classes/statistics.class.php index 0550957e..10faf83a 100644 --- a/public/include/classes/statistics.class.php +++ b/public/include/classes/statistics.class.php @@ -130,9 +130,12 @@ class Statistics { $this->debug->append("STA " . __METHOD__, 4); if ($data = $this->memcache->get(__FUNCTION__)) return $data; $stmt = $this->mysqli->prepare(" - SELECT ROUND(SUM(IF(difficulty=0, pow(2, (" . $this->config['difficulty'] . " - 16)), difficulty)) / 600, 2) AS sharerate - FROM " . $this->share->getTableName() . " - WHERE time > DATE_SUB(now(), INTERVAL 10 MINUTE)"); + SELECT ROUND(SUM(sharerate) / 600, 2) AS sharerate FROM + ( + SELECT SUM(IF(difficulty=0, pow(2, (" . $this->config['difficulty'] . " - 16)) - 1, difficulty)) AS sharerate FROM " . $this->share->getTableName() . " WHERE time > DATE_SUB(now(), INTERVAL 10 MINUTE) + UNION ALL + SELECT SUM(IF(difficulty=0, pow(2, (" . $this->config['difficulty'] . " - 16)) - 1, difficulty)) AS sharerate FROM " . $this->share->getArchiveTableName() . " WHERE time > DATE_SUB(now(), INTERVAL 10 MINUTE) + ) AS sum"); if ($this->checkStmt($stmt) && $stmt->execute() && $result = $stmt->get_result() ) return $this->memcache->setCache(__FUNCTION__, $result->fetch_object()->sharerate); // Catchall $this->debug->append("Failed to fetch share rate: " . $this->mysqli->error); @@ -354,7 +357,7 @@ class Statistics { a.donate_percent AS donate_percent, a.is_anonymous AS is_anonymous, IFNULL(ROUND(COUNT(t1.id) * POW(2," . $this->config['difficulty'] . ")/600/1000, 2), 0) AS hashrate, - ROUND(SUM(t1.difficulty) * 65536/600/1000) AS hashrate, + ROUND(SUM(IF(t1.difficulty=0, pow(2, (" . $this->config['difficulty'] . " - 16)) - 1, t1.difficulty)) * 65536/600/1000) AS hashrate, SUBSTRING_INDEX( t1.username, '.', 1 ) AS account FROM ( From 99bb4470f38ccf92647a57318db6cebfdbeff95f Mon Sep 17 00:00:00 2001 From: obigal Date: Fri, 5 Jul 2013 11:58:11 -0400 Subject: [PATCH 34/60] Update smarty_globals.inc.php --- public/include/smarty_globals.inc.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/public/include/smarty_globals.inc.php b/public/include/smarty_globals.inc.php index 1fecac98..a1a6946a 100644 --- a/public/include/smarty_globals.inc.php +++ b/public/include/smarty_globals.inc.php @@ -38,7 +38,7 @@ $aGlobal = array( 'hashrate' => $iCurrentPoolHashrate, 'nethashrate' => $dNetworkHashrate, 'sharerate' => $iCurrentPoolShareRate, - 'ppsvalue' => number_format(round(1/(65536 * $dDifficulty) * $config['reward']), 12), + 'ppsvalue' => number_format(round((1/(65536 * $dDifficulty) * $config['reward']), 12) ,12), 'workers' => $iCurrentActiveWorkers, 'roundshares' => $aRoundShares, 'fees' => $config['fees'], From 6f3a7c5b50c98cc660cd6618480cad6680641a9b Mon Sep 17 00:00:00 2001 From: obigal Date: Fri, 5 Jul 2013 14:00:36 -0400 Subject: [PATCH 35/60] Update share.class.php --- public/include/classes/share.class.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/public/include/classes/share.class.php b/public/include/classes/share.class.php index 6ff03be3..d9be9131 100644 --- a/public/include/classes/share.class.php +++ b/public/include/classes/share.class.php @@ -13,12 +13,19 @@ class Share { // This defines each share public $rem_host, $username, $our_result, $upstream_result, $reason, $solution, $time, $difficulty; +<<<<<<< HEAD public function __construct($debug, $mysqli, $user, $block, $config) { $this->debug = $debug; $this->mysqli = $mysqli; $this->user = $user; $this->config = $config; $this->block = $block; +======= + public function __construct($debug, $mysqli, $config, $salt) { + $this->debug = $debug; + $this->mysqli = $mysqli; + $this->config = $config; +>>>>>>> Update share.class.php $this->debug->append("Instantiated Share class", 2); } From fcb9ebd5294e2ce2af08cc09d463ffddad1796bb Mon Sep 17 00:00:00 2001 From: obigal Date: Fri, 5 Jul 2013 14:03:19 -0400 Subject: [PATCH 36/60] Update statistics.class.php --- public/include/classes/statistics.class.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/public/include/classes/statistics.class.php b/public/include/classes/statistics.class.php index 10faf83a..7e511749 100644 --- a/public/include/classes/statistics.class.php +++ b/public/include/classes/statistics.class.php @@ -152,8 +152,8 @@ class Statistics { if ($this->getGetCache() && $data = $this->memcache->get(__FUNCTION__)) return $data; $stmt = $this->mysqli->prepare(" SELECT - IFNULL(SUM(IF(our_result='Y', IF(difficulty=0, pow(2, (" . $this->config['difficulty'] . " - 16)), difficulty), 0)), 0) AS valid, - IFNULL(SUM(IF(our_result='N', IF(difficulty=0, pow(2, (" . $this->config['difficulty'] . " - 16)), difficulty), 0)), 0) AS invalid + IFNULL(SUM(IF(our_result='Y', IF(difficulty=0, pow(2, (" . $this->config['difficulty'] . " - 16)) - 1, difficulty), 0)), 0) AS valid, + IFNULL(SUM(IF(our_result='N', IF(difficulty=0, pow(2, (" . $this->config['difficulty'] . " - 16)) - 1, difficulty), 0)), 0) AS invalid FROM " . $this->share->getTableName() . " WHERE UNIX_TIMESTAMP(time) >IFNULL((SELECT MAX(time) FROM " . $this->block->getTableName() . "),0)"); if ( $this->checkStmt($stmt) && $stmt->execute() && $result = $stmt->get_result() ) @@ -174,8 +174,8 @@ class Statistics { if ($this->getGetCache() && $data = $this->memcache->get(__FUNCTION__)) return $data; $stmt = $this->mysqli->prepare(" SELECT - IFNULL(SUM(IF(our_result='Y', IF(s.difficulty=0, pow(2, (" . $this->config['difficulty'] . " - 16)), s.difficulty), 0)), 0) AS valid, - IFNULL(SUM(IF(our_result='N', IF(s.difficulty=0, pow(2, (" . $this->config['difficulty'] . " - 16)), s.difficulty), 0)), 0) AS invalid, + IFNULL(SUM(IF(our_result='Y', IF(difficulty=0, pow(2, (" . $this->config['difficulty'] . " - 16)) - 1, difficulty), 0)), 0) AS valid, + IFNULL(SUM(IF(our_result='N', IF(difficulty=0, pow(2, (" . $this->config['difficulty'] . " - 16)) - 1, difficulty), 0)), 0) AS invalid, u.id AS id, u.username AS username FROM " . $this->share->getTableName() . " AS s, @@ -200,8 +200,8 @@ class Statistics { if ($this->getGetCache() && $data = $this->memcache->get(__FUNCTION__ . $account_id)) return $data; $stmt = $this->mysqli->prepare(" SELECT - IFNULL(SUM(IF(our_result='Y', IF(s.difficulty=0, pow(2, (" . $this->config['difficulty'] . " - 16)), s.difficulty), 0)), 0) AS valid, - IFNULL(SUM(IF(our_result='N', IF(s.difficulty=0, pow(2, (" . $this->config['difficulty'] . " - 16)), s.difficulty), 0)), 0) AS invalid + IFNULL(SUM(IF(our_result='Y', IF(difficulty=0, pow(2, (" . $this->config['difficulty'] . " - 16)) - 1, difficulty), 0)), 0) AS valid, + IFNULL(SUM(IF(our_result='N', IF(difficulty=0, pow(2, (" . $this->config['difficulty'] . " - 16)) - 1, difficulty), 0)), 0) AS invalid FROM " . $this->share->getTableName() . " AS s, " . $this->user->getTableName() . " AS u WHERE From efc35bd2fc2ab8f84f91330f17550f772ca6227e Mon Sep 17 00:00:00 2001 From: obigal Date: Sat, 6 Jul 2013 09:23:15 -0400 Subject: [PATCH 37/60] Update mmcfe_ng_structure.sql --- sql/000_base_structure.sql | 1 - 1 file changed, 1 deletion(-) diff --git a/sql/000_base_structure.sql b/sql/000_base_structure.sql index efdfef6f..8749c578 100644 --- a/sql/000_base_structure.sql +++ b/sql/000_base_structure.sql @@ -82,7 +82,6 @@ CREATE TABLE IF NOT EXISTS `pool_worker` ( `password` char(255) DEFAULT NULL, `difficulty` float NOT NULL DEFAULT '0', `monitor` tinyint(1) NOT NULL DEFAULT '0', - `hashrate` int(11) DEFAULT NULL, `difficulty` int(11) NOT NULL DEFAULT '0', PRIMARY KEY (`id`), UNIQUE KEY `username` (`username`), From 360bd22dc622768886bb367df57096d9658ed7cb Mon Sep 17 00:00:00 2001 From: obigal Date: Sat, 6 Jul 2013 13:38:34 -0400 Subject: [PATCH 38/60] Updates --- public/include/classes/share.class.php | 10 +------- public/include/classes/statistics.class.php | 25 +++++++++---------- .../mmcFE/statistics/pool/authenticated.tpl | 2 +- 3 files changed, 14 insertions(+), 23 deletions(-) diff --git a/public/include/classes/share.class.php b/public/include/classes/share.class.php index d9be9131..a507adf4 100644 --- a/public/include/classes/share.class.php +++ b/public/include/classes/share.class.php @@ -13,19 +13,12 @@ class Share { // This defines each share public $rem_host, $username, $our_result, $upstream_result, $reason, $solution, $time, $difficulty; -<<<<<<< HEAD public function __construct($debug, $mysqli, $user, $block, $config) { $this->debug = $debug; $this->mysqli = $mysqli; $this->user = $user; $this->config = $config; $this->block = $block; -======= - public function __construct($debug, $mysqli, $config, $salt) { - $this->debug = $debug; - $this->mysqli = $mysqli; - $this->config = $config; ->>>>>>> Update share.class.php $this->debug->append("Instantiated Share class", 2); } @@ -77,7 +70,7 @@ class Share { **/ public function getRoundShares($previous_upstream=0, $current_upstream) { $stmt = $this->mysqli->prepare("SELECT - IFNULL(ROUND(SUM(IF(difficulty=0, pow(2, (" . $this->config['difficulty'] . " - 16)), difficulty)), 8), 0) as total + IFNULL(SUM(IF(difficulty=0, pow(2, (" . $this->config['difficulty'] . " - 16)) - 1, difficulty)), 0) as total FROM $this->table WHERE our_result = 'Y' AND id > ? AND id <= ? @@ -284,7 +277,6 @@ class Share { SUBSTRING_INDEX( `username` , '.', 1 ) AS account, id FROM $this->table WHERE upstream_result = 'Y' - AND UNIX_TIMESTAMP(time) >= ? AND id > ? AND UNIX_TIMESTAMP(time) >= ? AND UNIX_TIMESTAMP(time) <= ( ? + 60 ) diff --git a/public/include/classes/statistics.class.php b/public/include/classes/statistics.class.php index 7e511749..4ec8eae8 100644 --- a/public/include/classes/statistics.class.php +++ b/public/include/classes/statistics.class.php @@ -105,11 +105,11 @@ class Statistics { SELECT ( ( - SELECT IFNULL(ROUND(SUM(IF(difficulty=0, pow(2, (" . $this->config['difficulty'] . " - 16)), difficulty)) * 65536/600/1000), 0) AS hashrate + SELECT IFNULL(ROUND(SUM(IF(difficulty=0, pow(2, (" . $this->config['difficulty'] . " - 16)) - 1, difficulty)) * 65536/600/1000), 0) AS hashrate FROM " . $this->share->getTableName() . " WHERE time > DATE_SUB(now(), INTERVAL 10 MINUTE) ) + ( - SELECT IFNULL(ROUND(SUM(IF(difficulty=0, pow(2, (" . $this->config['difficulty'] . " - 16)), difficulty)) * 65536/600/1000), 0) AS hashrate + SELECT IFNULL(ROUND(SUM(IF(difficulty=0, pow(2, (" . $this->config['difficulty'] . " - 16)) - 1, difficulty)) * 65536/600/1000), 0) AS hashrate FROM " . $this->share->getArchiveTableName() . " WHERE time > DATE_SUB(now(), INTERVAL 10 MINUTE) ) @@ -132,9 +132,9 @@ class Statistics { $stmt = $this->mysqli->prepare(" SELECT ROUND(SUM(sharerate) / 600, 2) AS sharerate FROM ( - SELECT SUM(IF(difficulty=0, pow(2, (" . $this->config['difficulty'] . " - 16)) - 1, difficulty)) AS sharerate FROM " . $this->share->getTableName() . " WHERE time > DATE_SUB(now(), INTERVAL 10 MINUTE) + SELECT IFNULL(SUM(IF(difficulty=0, pow(2, (" . $this->config['difficulty'] . " - 16)) - 1, difficulty)), 0) AS sharerate FROM " . $this->share->getTableName() . " WHERE time > DATE_SUB(now(), INTERVAL 10 MINUTE) UNION ALL - SELECT SUM(IF(difficulty=0, pow(2, (" . $this->config['difficulty'] . " - 16)) - 1, difficulty)) AS sharerate FROM " . $this->share->getArchiveTableName() . " WHERE time > DATE_SUB(now(), INTERVAL 10 MINUTE) + SELECT IFNULL(SUM(IF(difficulty=0, pow(2, (" . $this->config['difficulty'] . " - 16)) - 1, difficulty)), 0) AS sharerate FROM " . $this->share->getArchiveTableName() . " WHERE time > DATE_SUB(now(), INTERVAL 10 MINUTE) ) AS sum"); if ($this->checkStmt($stmt) && $stmt->execute() && $result = $stmt->get_result() ) return $this->memcache->setCache(__FUNCTION__, $result->fetch_object()->sharerate); // Catchall @@ -174,8 +174,8 @@ class Statistics { if ($this->getGetCache() && $data = $this->memcache->get(__FUNCTION__)) return $data; $stmt = $this->mysqli->prepare(" SELECT - IFNULL(SUM(IF(our_result='Y', IF(difficulty=0, pow(2, (" . $this->config['difficulty'] . " - 16)) - 1, difficulty), 0)), 0) AS valid, - IFNULL(SUM(IF(our_result='N', IF(difficulty=0, pow(2, (" . $this->config['difficulty'] . " - 16)) - 1, difficulty), 0)), 0) AS invalid, + IFNULL(SUM(IF(our_result='Y', IF(s.difficulty=0, pow(2, (" . $this->config['difficulty'] . " - 16)) - 1, s.difficulty), 0)), 0) AS valid, + IFNULL(SUM(IF(our_result='N', IF(s.difficulty=0, pow(2, (" . $this->config['difficulty'] . " - 16)) - 1, s.difficulty), 0)), 0) AS invalid, u.id AS id, u.username AS username FROM " . $this->share->getTableName() . " AS s, @@ -200,8 +200,8 @@ class Statistics { if ($this->getGetCache() && $data = $this->memcache->get(__FUNCTION__ . $account_id)) return $data; $stmt = $this->mysqli->prepare(" SELECT - IFNULL(SUM(IF(our_result='Y', IF(difficulty=0, pow(2, (" . $this->config['difficulty'] . " - 16)) - 1, difficulty), 0)), 0) AS valid, - IFNULL(SUM(IF(our_result='N', IF(difficulty=0, pow(2, (" . $this->config['difficulty'] . " - 16)) - 1, difficulty), 0)), 0) AS invalid + IFNULL(SUM(IF(our_result='Y', IF(s.difficulty=0, pow(2, (" . $this->config['difficulty'] . " - 16)) - 1, s.difficulty), 0)), 0) AS valid, + IFNULL(SUM(IF(our_result='N', IF(s.difficulty=0, pow(2, (" . $this->config['difficulty'] . " - 16)) - 1, s.difficulty), 0)), 0) AS invalid FROM " . $this->share->getTableName() . " AS s, " . $this->user->getTableName() . " AS u WHERE @@ -286,7 +286,7 @@ class Statistics { $this->debug->append("STA " . __METHOD__, 4); if ($data = $this->memcache->get(__FUNCTION__ . $account_id)) return $data; $stmt = $this->mysqli->prepare(" - SELECT IFNULL(SUM(IF(difficulty=0, pow(2, (" . $this->config['difficulty'] . " - 16)), difficulty)), 0)/600 AS sharerate + SELECT IFNULL(SUM(IF(s.difficulty=0, pow(2, (" . $this->config['difficulty'] . " - 16)) - 1, s.difficulty)), 0)/600 AS sharerate FROM " . $this->share->getTableName() . " AS s, " . $this->user->getTableName() . " AS u WHERE u.username = SUBSTRING_INDEX( s.username, '.', 1 ) @@ -308,7 +308,7 @@ class Statistics { $this->debug->append("STA " . __METHOD__, 4); if ($data = $this->memcache->get(__FUNCTION__ . $worker_id)) return $data; $stmt = $this->mysqli->prepare(" - SELECT IFNULL(ROUND(SUM(IF(difficulty=0, pow(2, (" . $this->config['difficulty'] . " - 16)), difficulty)) * 65536/600/1000), 0) AS hashrate + SELECT IFNULL(ROUND(SUM(IF(s.difficulty=0, pow(2, (" . $this->config['difficulty'] . " - 16)) - 1, s.difficulty)) * 65536/600/1000), 0) AS hashrate FROM " . $this->share->getTableName() . " AS s, " . $this->user->getTableName() . " AS u WHERE u.username = SUBSTRING_INDEX( s.username, '.', 1 ) @@ -336,7 +336,7 @@ class Statistics { SELECT a.donate_percent AS donate_percent, a.is_anonymous AS is_anonymous, - IFNULL(SUM(IF(s.difficulty=0, pow(2, (" . $this->config['difficulty'] . " - 16)), s.difficulty)), 0) AS shares, + IFNULL(SUM(IF(difficulty=0, pow(2, (" . $this->config['difficulty'] . " - 16)) - 1, difficulty)), 0) AS shares, SUBSTRING_INDEX( s.username, '.', 1 ) AS account FROM " . $this->share->getTableName() . " AS s LEFT JOIN " . $this->user->getTableName() . " AS a @@ -356,8 +356,7 @@ class Statistics { SELECT a.donate_percent AS donate_percent, a.is_anonymous AS is_anonymous, - IFNULL(ROUND(COUNT(t1.id) * POW(2," . $this->config['difficulty'] . ")/600/1000, 2), 0) AS hashrate, - ROUND(SUM(IF(t1.difficulty=0, pow(2, (" . $this->config['difficulty'] . " - 16)) - 1, t1.difficulty)) * 65536/600/1000) AS hashrate, + IFNULL(ROUND(SUM(IF(t1.difficulty=0, pow(2, (" . $this->config['difficulty'] . " - 16)) - 1, t1.difficulty)) * 65536/600/1000), 0) AS hashrate, SUBSTRING_INDEX( t1.username, '.', 1 ) AS account FROM ( diff --git a/public/templates/mmcFE/statistics/pool/authenticated.tpl b/public/templates/mmcFE/statistics/pool/authenticated.tpl index e9f8e95b..83ee505c 100644 --- a/public/templates/mmcFE/statistics/pool/authenticated.tpl +++ b/public/templates/mmcFE/statistics/pool/authenticated.tpl @@ -48,7 +48,7 @@ Est. Shares this Round - {(65536 * $DIFFICULTY)|number_format:"0"} (done: {(100 / (pow(2, 32 - $GLOBAL.config.targetdiff) * $DIFFICULTY) * $GLOBAL.roundshares.valid)|number_format:"2"} %) + {(65536 * $DIFFICULTY)|number_format:"0"} (done: {(100 / (65536 * $DIFFICULTY) * $GLOBAL.roundshares.valid)|number_format:"2"} %) Time Since Last Block From 1819a47bf42d45e0a15291581afae24551daffa3 Mon Sep 17 00:00:00 2001 From: obigal Date: Sun, 4 Aug 2013 01:10:00 -0400 Subject: [PATCH 39/60] Vardiff/pushpool and pps payout support --- public/include/classes/share.class.php | 2 +- public/include/classes/statistics.class.php | 39 ++++++++++----------- public/include/smarty_globals.inc.php | 1 - sql/000_base_structure.sql | 3 -- 4 files changed, 19 insertions(+), 26 deletions(-) diff --git a/public/include/classes/share.class.php b/public/include/classes/share.class.php index a507adf4..e47b65d6 100644 --- a/public/include/classes/share.class.php +++ b/public/include/classes/share.class.php @@ -70,7 +70,7 @@ class Share { **/ public function getRoundShares($previous_upstream=0, $current_upstream) { $stmt = $this->mysqli->prepare("SELECT - IFNULL(SUM(IF(difficulty=0, pow(2, (" . $this->config['difficulty'] . " - 16)) - 1, difficulty)), 0) as total + IFNULL(ROUND(SUM(IF(difficulty=0, pow(2, (" . $this->config['difficulty'] . " - 16)), difficulty)), 8), 0) as total FROM $this->table WHERE our_result = 'Y' AND id > ? AND id <= ? diff --git a/public/include/classes/statistics.class.php b/public/include/classes/statistics.class.php index 4ec8eae8..e3e2f793 100644 --- a/public/include/classes/statistics.class.php +++ b/public/include/classes/statistics.class.php @@ -105,11 +105,11 @@ class Statistics { SELECT ( ( - SELECT IFNULL(ROUND(SUM(IF(difficulty=0, pow(2, (" . $this->config['difficulty'] . " - 16)) - 1, difficulty)) * 65536/600/1000), 0) AS hashrate + SELECT IFNULL(ROUND(SUM(IF(difficulty=0, pow(2, (" . $this->config['difficulty'] . " - 16)), difficulty)) * 65536/600/1000), 0) AS hashrate FROM " . $this->share->getTableName() . " WHERE time > DATE_SUB(now(), INTERVAL 10 MINUTE) ) + ( - SELECT IFNULL(ROUND(SUM(IF(difficulty=0, pow(2, (" . $this->config['difficulty'] . " - 16)) - 1, difficulty)) * 65536/600/1000), 0) AS hashrate + SELECT IFNULL(ROUND(SUM(IF(difficulty=0, pow(2, (" . $this->config['difficulty'] . " - 16)), difficulty)) * 65536/600/1000), 0) AS hashrate FROM " . $this->share->getArchiveTableName() . " WHERE time > DATE_SUB(now(), INTERVAL 10 MINUTE) ) @@ -130,12 +130,9 @@ class Statistics { $this->debug->append("STA " . __METHOD__, 4); if ($data = $this->memcache->get(__FUNCTION__)) return $data; $stmt = $this->mysqli->prepare(" - SELECT ROUND(SUM(sharerate) / 600, 2) AS sharerate FROM - ( - SELECT IFNULL(SUM(IF(difficulty=0, pow(2, (" . $this->config['difficulty'] . " - 16)) - 1, difficulty)), 0) AS sharerate FROM " . $this->share->getTableName() . " WHERE time > DATE_SUB(now(), INTERVAL 10 MINUTE) - UNION ALL - SELECT IFNULL(SUM(IF(difficulty=0, pow(2, (" . $this->config['difficulty'] . " - 16)) - 1, difficulty)), 0) AS sharerate FROM " . $this->share->getArchiveTableName() . " WHERE time > DATE_SUB(now(), INTERVAL 10 MINUTE) - ) AS sum"); + SELECT ROUND(SUM(IF(difficulty=0, pow(2, (" . $this->config['difficulty'] . " - 16)), difficulty)) / 600, 2) AS sharerate + FROM " . $this->share->getTableName() . " + WHERE time > DATE_SUB(now(), INTERVAL 10 MINUTE)"); if ($this->checkStmt($stmt) && $stmt->execute() && $result = $stmt->get_result() ) return $this->memcache->setCache(__FUNCTION__, $result->fetch_object()->sharerate); // Catchall $this->debug->append("Failed to fetch share rate: " . $this->mysqli->error); @@ -152,8 +149,8 @@ class Statistics { if ($this->getGetCache() && $data = $this->memcache->get(__FUNCTION__)) return $data; $stmt = $this->mysqli->prepare(" SELECT - IFNULL(SUM(IF(our_result='Y', IF(difficulty=0, pow(2, (" . $this->config['difficulty'] . " - 16)) - 1, difficulty), 0)), 0) AS valid, - IFNULL(SUM(IF(our_result='N', IF(difficulty=0, pow(2, (" . $this->config['difficulty'] . " - 16)) - 1, difficulty), 0)), 0) AS invalid + IFNULL(SUM(IF(our_result='Y', IF(difficulty=0, pow(2, (" . $this->config['difficulty'] . " - 16)), difficulty), 0)), 0) AS valid, + IFNULL(SUM(IF(our_result='N', IF(difficulty=0, pow(2, (" . $this->config['difficulty'] . " - 16)), difficulty), 0)), 0) AS invalid FROM " . $this->share->getTableName() . " WHERE UNIX_TIMESTAMP(time) >IFNULL((SELECT MAX(time) FROM " . $this->block->getTableName() . "),0)"); if ( $this->checkStmt($stmt) && $stmt->execute() && $result = $stmt->get_result() ) @@ -174,8 +171,8 @@ class Statistics { if ($this->getGetCache() && $data = $this->memcache->get(__FUNCTION__)) return $data; $stmt = $this->mysqli->prepare(" SELECT - IFNULL(SUM(IF(our_result='Y', IF(s.difficulty=0, pow(2, (" . $this->config['difficulty'] . " - 16)) - 1, s.difficulty), 0)), 0) AS valid, - IFNULL(SUM(IF(our_result='N', IF(s.difficulty=0, pow(2, (" . $this->config['difficulty'] . " - 16)) - 1, s.difficulty), 0)), 0) AS invalid, + IFNULL(SUM(IF(our_result='Y', IF(s.difficulty=0, pow(2, (" . $this->config['difficulty'] . " - 16)), s.difficulty), 0)), 0) AS valid, + IFNULL(SUM(IF(our_result='N', IF(s.difficulty=0, pow(2, (" . $this->config['difficulty'] . " - 16)), s.difficulty), 0)), 0) AS invalid, u.id AS id, u.username AS username FROM " . $this->share->getTableName() . " AS s, @@ -200,8 +197,8 @@ class Statistics { if ($this->getGetCache() && $data = $this->memcache->get(__FUNCTION__ . $account_id)) return $data; $stmt = $this->mysqli->prepare(" SELECT - IFNULL(SUM(IF(our_result='Y', IF(s.difficulty=0, pow(2, (" . $this->config['difficulty'] . " - 16)) - 1, s.difficulty), 0)), 0) AS valid, - IFNULL(SUM(IF(our_result='N', IF(s.difficulty=0, pow(2, (" . $this->config['difficulty'] . " - 16)) - 1, s.difficulty), 0)), 0) AS invalid + IFNULL(SUM(IF(our_result='Y', IF(s.difficulty=0, pow(2, (" . $this->config['difficulty'] . " - 16)), s.difficulty), 0)), 0) AS valid, + IFNULL(SUM(IF(our_result='N', IF(s.difficulty=0, pow(2, (" . $this->config['difficulty'] . " - 16)), s.difficulty), 0)), 0) AS invalid FROM " . $this->share->getTableName() . " AS s, " . $this->user->getTableName() . " AS u WHERE @@ -286,7 +283,7 @@ class Statistics { $this->debug->append("STA " . __METHOD__, 4); if ($data = $this->memcache->get(__FUNCTION__ . $account_id)) return $data; $stmt = $this->mysqli->prepare(" - SELECT IFNULL(SUM(IF(s.difficulty=0, pow(2, (" . $this->config['difficulty'] . " - 16)) - 1, s.difficulty)), 0)/600 AS sharerate + SELECT IFNULL(SUM(IF(difficulty=0, pow(2, (" . $this->config['difficulty'] . " - 16)), difficulty)), 0)/600 AS sharerate FROM " . $this->share->getTableName() . " AS s, " . $this->user->getTableName() . " AS u WHERE u.username = SUBSTRING_INDEX( s.username, '.', 1 ) @@ -308,7 +305,7 @@ class Statistics { $this->debug->append("STA " . __METHOD__, 4); if ($data = $this->memcache->get(__FUNCTION__ . $worker_id)) return $data; $stmt = $this->mysqli->prepare(" - SELECT IFNULL(ROUND(SUM(IF(s.difficulty=0, pow(2, (" . $this->config['difficulty'] . " - 16)) - 1, s.difficulty)) * 65536/600/1000), 0) AS hashrate + SELECT IFNULL(ROUND(SUM(IF(difficulty=0, pow(2, (" . $this->config['difficulty'] . " - 16)), difficulty)) * 65536/600/1000), 0) AS hashrate FROM " . $this->share->getTableName() . " AS s, " . $this->user->getTableName() . " AS u WHERE u.username = SUBSTRING_INDEX( s.username, '.', 1 ) @@ -336,7 +333,7 @@ class Statistics { SELECT a.donate_percent AS donate_percent, a.is_anonymous AS is_anonymous, - IFNULL(SUM(IF(difficulty=0, pow(2, (" . $this->config['difficulty'] . " - 16)) - 1, difficulty)), 0) AS shares, + IFNULL(SUM(IF(s.difficulty=0, pow(2, (" . $this->config['difficulty'] . " - 16)), s.difficulty)), 0) AS shares, SUBSTRING_INDEX( s.username, '.', 1 ) AS account FROM " . $this->share->getTableName() . " AS s LEFT JOIN " . $this->user->getTableName() . " AS a @@ -356,13 +353,13 @@ class Statistics { SELECT a.donate_percent AS donate_percent, a.is_anonymous AS is_anonymous, - IFNULL(ROUND(SUM(IF(t1.difficulty=0, pow(2, (" . $this->config['difficulty'] . " - 16)) - 1, t1.difficulty)) * 65536/600/1000), 0) AS hashrate, + IFNULL(ROUND(SUM(t1.difficulty) * 65536/600/1000, 2), 0) AS hashrate, SUBSTRING_INDEX( t1.username, '.', 1 ) AS account FROM ( - SELECT id, username, difficulty FROM " . $this->share->getTableName() . " WHERE time > DATE_SUB(now(), INTERVAL 10 MINUTE) AND our_result = 'Y' - UNION - SELECT id, username, difficulty FROM " . $this->share->getArchiveTableName() ." WHERE time > DATE_SUB(now(), INTERVAL 10 MINUTE) AND our_result = 'Y' + SELECT IFNULL(IF(difficulty=0, pow(2, (" . $this->config['difficulty'] . " - 16)), difficulty), 0) AS difficulty, username FROM " . $this->share->getTableName() . " WHERE time > DATE_SUB(now(), INTERVAL 10 MINUTE) AND our_result = 'Y' + UNION ALL + SELECT IFNULL(IF(difficulty=0, pow(2, (" . $this->config['difficulty'] . " - 16)), difficulty), 0) AS difficulty, username FROM " . $this->share->getArchiveTableName() ." WHERE time > DATE_SUB(now(), INTERVAL 10 MINUTE) AND our_result = 'Y' ) AS t1 LEFT JOIN " . $this->user->getTableName() . " AS a ON SUBSTRING_INDEX( t1.username, '.', 1 ) = a.username diff --git a/public/include/smarty_globals.inc.php b/public/include/smarty_globals.inc.php index a1a6946a..cda4cd36 100644 --- a/public/include/smarty_globals.inc.php +++ b/public/include/smarty_globals.inc.php @@ -38,7 +38,6 @@ $aGlobal = array( 'hashrate' => $iCurrentPoolHashrate, 'nethashrate' => $dNetworkHashrate, 'sharerate' => $iCurrentPoolShareRate, - 'ppsvalue' => number_format(round((1/(65536 * $dDifficulty) * $config['reward']), 12) ,12), 'workers' => $iCurrentActiveWorkers, 'roundshares' => $aRoundShares, 'fees' => $config['fees'], diff --git a/sql/000_base_structure.sql b/sql/000_base_structure.sql index 8749c578..487a3d07 100644 --- a/sql/000_base_structure.sql +++ b/sql/000_base_structure.sql @@ -82,7 +82,6 @@ CREATE TABLE IF NOT EXISTS `pool_worker` ( `password` char(255) DEFAULT NULL, `difficulty` float NOT NULL DEFAULT '0', `monitor` tinyint(1) NOT NULL DEFAULT '0', - `difficulty` int(11) NOT NULL DEFAULT '0', PRIMARY KEY (`id`), UNIQUE KEY `username` (`username`), KEY `account_id` (`account_id`) @@ -105,7 +104,6 @@ CREATE TABLE IF NOT EXISTS `shares` ( `solution` varchar(257) NOT NULL, `difficulty` float NOT NULL DEFAULT '0', `time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, - `difficulty` int(11) NOT NULL DEFAULT '0', PRIMARY KEY (`id`), KEY `time` (`time`), KEY `upstream_result` (`upstream_result`), @@ -122,7 +120,6 @@ CREATE TABLE IF NOT EXISTS `shares_archive` ( `block_id` int(10) unsigned NOT NULL, `difficulty` float NOT NULL DEFAULT '0', `time` datetime NOT NULL, - `difficulty` int(11) NOT NULL DEFAULT '0', PRIMARY KEY (`id`), UNIQUE KEY `share_id` (`share_id`), KEY `time` (`time`) From 4c3bf8f85f7bdeb971eee534b291aeef84a44877 Mon Sep 17 00:00:00 2001 From: Sebastian Grewe Date: Tue, 6 Aug 2013 09:54:50 +0200 Subject: [PATCH 40/60] adding missing column --- sql/issue_145_shares.sql | 1 + 1 file changed, 1 insertion(+) diff --git a/sql/issue_145_shares.sql b/sql/issue_145_shares.sql index c8367230..17c704c1 100644 --- a/sql/issue_145_shares.sql +++ b/sql/issue_145_shares.sql @@ -1,2 +1,3 @@ ALTER TABLE `shares` ADD `difficulty` FLOAT NOT NULL AFTER `solution` ; +ALTER TABLE `shares_archive` ADD `difficulty` FLOAT NOT NULL AFTER `time` ; ALTER TABLE `pool_worker` ADD `difficulty` FLOAT NOT NULL AFTER `password` ; From 8809e3df536c840fcda7d1369dc1cc1cc8d0ae5c Mon Sep 17 00:00:00 2001 From: Sebastian Grewe Date: Tue, 6 Aug 2013 10:26:27 +0200 Subject: [PATCH 41/60] Do not use number_format for inserting to DB This will fix an issue with very large payouts not being inserted to the DB properly. Moved number formatting to displaying output as it should be. --- cronjobs/pps_payout.php | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/cronjobs/pps_payout.php b/cronjobs/pps_payout.php index 58c9b870..840d931a 100755 --- a/cronjobs/pps_payout.php +++ b/cronjobs/pps_payout.php @@ -68,7 +68,7 @@ if ($config['pps']['reward']['type'] == 'blockavg' && $block->getBlockCount() > } } -$pps_value = number_format(round($pps_reward / (pow(2,32) * $dDifficulty) * pow(2, $config['pps_target']), 12) ,12); +$pps_value = round($pps_reward / (pow(2,32) * $dDifficulty) * pow(2, $config['pps_target']), 12); //$pps_value = number_format(round((1/(65536 * $dDifficulty) * $pps_reward), 12) ,12); // Find our last share accounted and last inserted share for PPS calculations @@ -82,7 +82,7 @@ $log->logInfo("ID\tUsername\tInvalid\tValid\t\tPPS Value\t\tPayout\t\tDonation\t foreach ($aAccountShares as $aData) { // Take our valid shares and multiply by per share value - $aData['payout'] = number_format(round($aData['valid'] * $pps_value, 8), 8); + $aData['payout'] = round($aData['valid'] * $pps_value, 8); // Defaults $aData['fee' ] = 0; @@ -90,18 +90,18 @@ foreach ($aAccountShares as $aData) { // Calculate block fees if ($config['fees'] > 0 && $aData['no_fees'] == 0) - $aData['fee'] = number_format(round($config['fees'] / 100 * $aData['payout'], 8), 8); + $aData['fee'] = round($config['fees'] / 100 * $aData['payout'], 8); // Calculate donation amount - $aData['donation'] = number_format(round($user->getDonatePercent($user->getUserId($aData['username'])) / 100 * ( $aData['payout'] - $aData['fee']), 8), 8); + $aData['donation'] = round($user->getDonatePercent($user->getUserId($aData['username'])) / 100 * ( $aData['payout'] - $aData['fee']), 8); $log->logInfo($aData['id'] . "\t" . $aData['username'] . "\t" . $aData['invalid'] . "\t" . $aData['valid'] . "\t*\t" . - $pps_value . "\t=\t" . - $aData['payout'] . "\t" . - $aData['donation'] . "\t" . - $aData['fee']); + number_format($pps_value, 12) . "\t=\t" . + number_format($aData['payout'], 8) . "\t" . + number_format($aData['donation'], 8) . "\t" . + number_format($aData['fee'], 8)); // Add new credit transaction if (!$transaction->addTransaction($aData['id'], $aData['payout'], 'Credit_PPS')) From 0dbe1ebe1182342eab5d7d900c592670b77bce52 Mon Sep 17 00:00:00 2001 From: Sebastian Grewe Date: Wed, 7 Aug 2013 09:45:40 +0200 Subject: [PATCH 42/60] fixing hashrate graphs --- public/include/classes/statistics.class.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/public/include/classes/statistics.class.php b/public/include/classes/statistics.class.php index e3e2f793..1bbedfc6 100644 --- a/public/include/classes/statistics.class.php +++ b/public/include/classes/statistics.class.php @@ -385,7 +385,7 @@ class Statistics { SELECT IFNULL(ROUND(SUM(IF(s.difficulty=0, pow(2, (" . $this->config['difficulty'] . " - 16)), s.difficulty)) * 65536/3600/1000), 0) AS hashrate, HOUR(s.time) AS hour - FROM " . $this->share->getArchiveTableName() . " AS s, accounts AS a + FROM " . $this->share->getTableName() . " AS s, accounts AS a WHERE time < NOW() - INTERVAL 1 HOUR AND time > NOW() - INTERVAL 25 HOUR AND a.username = SUBSTRING_INDEX( s.username, '.', 1 ) @@ -425,7 +425,7 @@ class Statistics { SELECT IFNULL(ROUND(SUM(IF(s.difficulty=0, pow(2, (" . $this->config['difficulty'] . " - 16)), s.difficulty)) * 65536/3600/1000), 0) AS hashrate, HOUR(s.time) AS hour - FROM " . $this->share->getArchiveTableName() . " AS s + FROM " . $this->share->getTableName() . " AS s WHERE time < NOW() - INTERVAL 1 HOUR AND time > NOW() - INTERVAL 25 HOUR GROUP BY HOUR(time) From 7769550f8919f63d2f9957ae080d9d98e72a38bd Mon Sep 17 00:00:00 2001 From: Sebastian Grewe Date: Tue, 20 Aug 2013 15:58:17 +0200 Subject: [PATCH 43/60] fixing missing network hashrate in this branch --- public/include/smarty_globals.inc.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/public/include/smarty_globals.inc.php b/public/include/smarty_globals.inc.php index cdeb6ebd..4ced2de7 100644 --- a/public/include/smarty_globals.inc.php +++ b/public/include/smarty_globals.inc.php @@ -20,7 +20,7 @@ if ($bitcoin->can_connect() === true) { } // Always fetch this since we need for ministats header -//$bitcoin->can_connect() === true ? $dNetworkHashrate = $bitcoin->query('getnetworkhashps') : $dNetworkHashrate = 0; +$bitcoin->can_connect() === true ? $dNetworkHashrate = $bitcoin->query('getnetworkhashps') : $dNetworkHashrate = 0; // Fetch some data if (!$iCurrentActiveWorkers = $worker->getCountAllActiveWorkers()) $iCurrentActiveWorkers = 0; From 96066993ac72d1e808d2c9a16d04eaa48bc7805c Mon Sep 17 00:00:00 2001 From: Sebastian Grewe Date: Tue, 20 Aug 2013 16:50:40 +0200 Subject: [PATCH 44/60] adding per-worker difficulty display --- public/include/classes/worker.class.php | 15 ++++++++++++--- .../templates/mmcFE/account/workers/default.tpl | 15 ++++++++------- .../templates/mobile/account/workers/default.tpl | 2 ++ 3 files changed, 22 insertions(+), 10 deletions(-) diff --git a/public/include/classes/worker.class.php b/public/include/classes/worker.class.php index 1388b730..d9b87945 100644 --- a/public/include/classes/worker.class.php +++ b/public/include/classes/worker.class.php @@ -136,14 +136,23 @@ class Worker { WHERE username = w.username AND time > DATE_SUB(now(), INTERVAL 10 MINUTE) - ) + ( - SELECT + ) + ( + SELECT IFNULL(IF(our_result='Y', ROUND(SUM(IF(difficulty=0, pow(2, (" . $this->config['difficulty'] . " - 16)), difficulty)) * 65536/600/1000), 0), 0) AS hashrate FROM " . $this->share->getArchiveTableName() . " WHERE username = w.username AND time > DATE_SUB(now(), INTERVAL 10 MINUTE) - ) AS hashrate + ) AS hashrate, + ( + SELECT IFNULL(IF(our_result='Y', ROUND(SUM(IF(difficulty=0, pow(2, (" . $this->config['difficulty'] . " - 16)), difficulty)) / COUNT(id), 2), 0), 0) + FROM " . $this->share->getTableName() . " + WHERE username = w.username AND time > DATE_SUB(now(), INTERVAL 10 MINUTE) + ) + ( + SELECT IFNULL(IF(our_result='Y', ROUND(SUM(IF(difficulty=0, pow(2, (" . $this->config['difficulty'] . " - 16)), difficulty)) / COUNT(id), 2), 0), 0) + FROM " . $this->share->getArchiveTableName() . " + WHERE username = w.username AND time > DATE_SUB(now(), INTERVAL 10 MINUTE) + ) AS difficulty FROM $this->table AS w WHERE account_id = ?"); if ($this->checkStmt($stmt) && $stmt->bind_param('i', $account_id) && $stmt->execute() && $result = $stmt->get_result()) diff --git a/public/templates/mmcFE/account/workers/default.tpl b/public/templates/mmcFE/account/workers/default.tpl index 65635b4b..2f35e617 100644 --- a/public/templates/mmcFE/account/workers/default.tpl +++ b/public/templates/mmcFE/account/workers/default.tpl @@ -7,13 +7,13 @@ - - - - {if $GLOBAL.config.disable_notifications != 1}{/if} - - - + + + + {if $GLOBAL.config.disable_notifications != 1}{/if} + + + {nocache} {section worker $WORKERS} @@ -29,6 +29,7 @@ {/if} + {/section} diff --git a/public/templates/mobile/account/workers/default.tpl b/public/templates/mobile/account/workers/default.tpl index 09ebf867..996c6467 100644 --- a/public/templates/mobile/account/workers/default.tpl +++ b/public/templates/mobile/account/workers/default.tpl @@ -4,6 +4,7 @@ + {section worker $WORKERS} {assign var="username" value="."|escape|explode:$WORKERS[worker].username:2} @@ -11,6 +12,7 @@ + {/section} From 56cfa24eb4036a8c3328e966daee305f5a46c5fb Mon Sep 17 00:00:00 2001 From: Sebastian Grewe Date: Tue, 20 Aug 2013 17:03:41 +0200 Subject: [PATCH 45/60] Include worker diff in API Addresses #145 --- public/include/classes/worker.class.php | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/public/include/classes/worker.class.php b/public/include/classes/worker.class.php index d9b87945..28dcc94a 100644 --- a/public/include/classes/worker.class.php +++ b/public/include/classes/worker.class.php @@ -110,7 +110,16 @@ class Worker { WHERE username = w.username AND time > DATE_SUB(now(), INTERVAL 10 MINUTE) - ) AS hashrate + ) AS hashrate, + ( + SELECT IFNULL(IF(our_result='Y', ROUND(SUM(IF(difficulty=0, pow(2, (" . $this->config['difficulty'] . " - 16)), difficulty)) / COUNT(id), 2), 0), 0) + FROM " . $this->share->getTableName() . " + WHERE username = w.username AND time > DATE_SUB(now(), INTERVAL 10 MINUTE) + ) + ( + SELECT IFNULL(IF(our_result='Y', ROUND(SUM(IF(difficulty=0, pow(2, (" . $this->config['difficulty'] . " - 16)), difficulty)) / COUNT(id), 2), 0), 0) + FROM " . $this->share->getArchiveTableName() . " + WHERE username = w.username AND time > DATE_SUB(now(), INTERVAL 10 MINUTE) + ) AS difficulty FROM $this->table AS w WHERE id = ? "); From 2aad605cf2893f5226f23a4159c51a2e3c2c964a Mon Sep 17 00:00:00 2001 From: Sebastian Grewe Date: Thu, 22 Aug 2013 11:27:09 +0200 Subject: [PATCH 46/60] minor cleanup --- cronjobs/pps_payout.php | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/cronjobs/pps_payout.php b/cronjobs/pps_payout.php index 840d931a..b993d29c 100755 --- a/cronjobs/pps_payout.php +++ b/cronjobs/pps_payout.php @@ -42,12 +42,6 @@ if ( $bitcoin->can_connect() === true ){ exit(1); } -// Value per share calculation -// We need to use this instead when running VARDIFF -// $pps_value = number_format(round((1/(65536 * $dDifficulty) * $config['reward']), 12) ,12); -// pps base payout target, default 16 = difficulty 1 shares for vardiff -// (1/(65536 * difficulty) * reward) = (reward / (pow(2,32) * difficulty) * pow(2, 16)) - // We support some dynamic reward targets but fall back to our fixed value // Re-calculate after each run due to re-targets in this loop if ($config['pps']['reward']['type'] == 'blockavg' && $block->getBlockCount() > 0) { @@ -59,8 +53,8 @@ if ($config['pps']['reward']['type'] == 'blockavg' && $block->getBlockCount() > $pps_reward = $aLastBlock['amount']; $log->logInfo("PPS reward using last block, amount: " . $pps_reward . "\tdifficulty: " . $dDifficulty); } else { - $pps_reward = $config['pps']['reward']['default']; - $log->logInfo("PPS reward using default, amount: " . $pps_reward . "\tdifficulty: " . $dDifficulty); + $pps_reward = $config['pps']['reward']['default']; + $log->logInfo("PPS reward using default, amount: " . $pps_reward . "\tdifficulty: " . $dDifficulty); } } else { $pps_reward = $config['pps']['reward']['default']; @@ -68,8 +62,8 @@ if ($config['pps']['reward']['type'] == 'blockavg' && $block->getBlockCount() > } } +// Per-share value to be paid out to users $pps_value = round($pps_reward / (pow(2,32) * $dDifficulty) * pow(2, $config['pps_target']), 12); -//$pps_value = number_format(round((1/(65536 * $dDifficulty) * $pps_reward), 12) ,12); // Find our last share accounted and last inserted share for PPS calculations $iPreviousShareId = $setting->getValue('pps_last_share_id'); @@ -121,9 +115,7 @@ $setting->setValue('pps_last_share_id', $iLastShareId); // Fetch all unaccounted blocks $aAllBlocks = $block->getAllUnaccounted('ASC'); -if (empty($aAllBlocks)) { - $log->logDebug("No new unaccounted blocks found"); -} +if (empty($aAllBlocks)) $log->logDebug("No new unaccounted blocks found"); // Go through blocks and archive/delete shares that have been accounted for foreach ($aAllBlocks as $iIndex => $aBlock) { From 36d64b27fd8d66f807bef381155501cff80c891e Mon Sep 17 00:00:00 2001 From: Sebastian Grewe Date: Thu, 22 Aug 2013 11:28:01 +0200 Subject: [PATCH 47/60] adding share rate to prop sidebar --- public/templates/mmcFE/global/sidebar_prop.tpl | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/public/templates/mmcFE/global/sidebar_prop.tpl b/public/templates/mmcFE/global/sidebar_prop.tpl index 69afe6ee..6f59b50c 100644 --- a/public/templates/mmcFE/global/sidebar_prop.tpl +++ b/public/templates/mmcFE/global/sidebar_prop.tpl @@ -13,6 +13,10 @@ + + + + From d28e728d6ca8d74e8d3024ee2a0421d83a061d7b Mon Sep 17 00:00:00 2001 From: Sebastian Grewe Date: Thu, 22 Aug 2013 11:28:18 +0200 Subject: [PATCH 48/60] minor cleanup --- public/include/smarty_globals.inc.php | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/public/include/smarty_globals.inc.php b/public/include/smarty_globals.inc.php index 4ced2de7..27d980e6 100644 --- a/public/include/smarty_globals.inc.php +++ b/public/include/smarty_globals.inc.php @@ -9,10 +9,12 @@ $debug->append('Global smarty variables', 3); $debug->append('No cached page detected, loading smarty globals', 3); // Defaults to get rid of PHP Notice warnings $dDifficulty = 1; -$aRoundShares = 1; -// Only run these if the user is logged in -$aRoundShares = $statistics->getRoundShares(); +// Fetch round shares +if (!$aRoundShares = $statistics->getRoundShares()) { + $aRoundShares = array('valid' => 0, 'invalid' => 0); +} + if ($bitcoin->can_connect() === true) { $dDifficulty = $bitcoin->query('getdifficulty'); if (is_array($dDifficulty) && array_key_exists('proof-of-work', $dDifficulty)) From b23dd56bc8269cd745c8bee8cb2f44137161424e Mon Sep 17 00:00:00 2001 From: Sebastian Grewe Date: Thu, 22 Aug 2013 11:29:26 +0200 Subject: [PATCH 49/60] Adding baseline shares to statistics class * Calculate shares towards our base diff * Calculate share rate based on actual shares not diff --- public/include/classes/statistics.class.php | 47 +++++++++++---------- 1 file changed, 24 insertions(+), 23 deletions(-) diff --git a/public/include/classes/statistics.class.php b/public/include/classes/statistics.class.php index 31d64fba..e3fb62e9 100644 --- a/public/include/classes/statistics.class.php +++ b/public/include/classes/statistics.class.php @@ -64,7 +64,8 @@ class Statistics { SELECT b.*, a.username AS finder, - a.is_anonymous AS is_anonymous + a.is_anonymous AS is_anonymous, + ROUND((difficulty * 65535) / POW(2, (" . $this->config['difficulty'] . " -16)), 0) AS estshares FROM " . $this->block->getTableName() . " AS b LEFT JOIN " . $this->user->getTableName() . " AS a ON b.account_id = a.id @@ -105,13 +106,13 @@ class Statistics { SELECT ( ( - SELECT IFNULL(ROUND(SUM(IF(difficulty=0, pow(2, (" . $this->config['difficulty'] . " - 16)), difficulty)) * 65536/600/1000), 0) AS hashrate + SELECT IFNULL(ROUND(SUM(IF(difficulty=0, POW(2, (" . $this->config['difficulty'] . " - 16)), difficulty)) * 65536 / 600 / 1000), 0) AS hashrate FROM " . $this->share->getTableName() . " - WHERE time > DATE_SUB(now(), INTERVAL 10 MINUTE) + WHERE time > DATE_SUB(now(), INTERVAL 600 SECOND) ) + ( - SELECT IFNULL(ROUND(SUM(IF(difficulty=0, pow(2, (" . $this->config['difficulty'] . " - 16)), difficulty)) * 65536/600/1000), 0) AS hashrate + SELECT IFNULL(ROUND(SUM(IF(difficulty=0, POW(2, (" . $this->config['difficulty'] . " - 16)), difficulty)) * 65536 / 600 / 1000), 0) AS hashrate FROM " . $this->share->getArchiveTableName() . " - WHERE time > DATE_SUB(now(), INTERVAL 10 MINUTE) + WHERE time > DATE_SUB(now(), INTERVAL 600 SECOND) ) ) AS hashrate FROM DUAL"); @@ -130,7 +131,7 @@ class Statistics { $this->debug->append("STA " . __METHOD__, 4); if ($data = $this->memcache->get(__FUNCTION__)) return $data; $stmt = $this->mysqli->prepare(" - SELECT ROUND(SUM(IF(difficulty=0, pow(2, (" . $this->config['difficulty'] . " - 16)), difficulty)) / 600, 2) AS sharerate + SELECT ROUND(SUM(IF(difficulty=0, POW(2, (" . $this->config['difficulty'] . " - 16)), difficulty)) / POW(2, (" . $this->config['difficulty'] . " - 16)) / 600, 2) AS sharerate FROM " . $this->share->getTableName() . " WHERE time > DATE_SUB(now(), INTERVAL 10 MINUTE)"); if ($this->checkStmt($stmt) && $stmt->execute() && $result = $stmt->get_result() ) return $this->memcache->setCache(__FUNCTION__, $result->fetch_object()->sharerate); @@ -149,10 +150,10 @@ class Statistics { if ($this->getGetCache() && $data = $this->memcache->get(__FUNCTION__)) return $data; $stmt = $this->mysqli->prepare(" SELECT - IFNULL(SUM(IF(our_result='Y', IF(difficulty=0, pow(2, (" . $this->config['difficulty'] . " - 16)), difficulty), 0)), 0) AS valid, - IFNULL(SUM(IF(our_result='N', IF(difficulty=0, pow(2, (" . $this->config['difficulty'] . " - 16)), difficulty), 0)), 0) AS invalid + ROUND(IFNULL(SUM(IF(our_result='Y', IF(difficulty=0, POW(2, (" . $this->config['difficulty'] . " - 16)), difficulty), 0)), 0) / POW(2, (" . $this->config['difficulty'] . " - 16)), 0) AS valid, + ROUND(IFNULL(SUM(IF(our_result='N', IF(difficulty=0, POW(2, (" . $this->config['difficulty'] . " - 16)), difficulty), 0)), 0) / POW(2, (" . $this->config['difficulty'] . " - 16)), 0) AS invalid FROM " . $this->share->getTableName() . " - WHERE UNIX_TIMESTAMP(time) >IFNULL((SELECT MAX(time) FROM " . $this->block->getTableName() . "),0)"); + WHERE UNIX_TIMESTAMP(time) > IFNULL((SELECT MAX(time) FROM " . $this->block->getTableName() . "), 0)"); if ( $this->checkStmt($stmt) && $stmt->execute() && $result = $stmt->get_result() ) return $this->memcache->setCache(__FUNCTION__, $result->fetch_assoc()); // Catchall @@ -171,8 +172,8 @@ class Statistics { if ($this->getGetCache() && $data = $this->memcache->get(__FUNCTION__)) return $data; $stmt = $this->mysqli->prepare(" SELECT - IFNULL(SUM(IF(our_result='Y', IF(s.difficulty=0, pow(2, (" . $this->config['difficulty'] . " - 16)), s.difficulty), 0)), 0) AS valid, - IFNULL(SUM(IF(our_result='N', IF(s.difficulty=0, pow(2, (" . $this->config['difficulty'] . " - 16)), s.difficulty), 0)), 0) AS invalid, + ROUND(IFNULL(SUM(IF(our_result='Y', IF(s.difficulty=0, POW(2, (" . $this->config['difficulty'] . " - 16)), s.difficulty), 0)), 0) / POW(2, (" . $this->config['difficulty'] . " - 16)), 0) AS valid, + ROUND(IFNULL(SUM(IF(our_result='N', IF(s.difficulty=0, POW(2, (" . $this->config['difficulty'] . " - 16)), s.difficulty), 0)), 0) / POW(2, (" . $this->config['difficulty'] . " - 16)), 0) AS invalid, u.id AS id, u.username AS username FROM " . $this->share->getTableName() . " AS s, @@ -197,8 +198,8 @@ class Statistics { if ($this->getGetCache() && $data = $this->memcache->get(__FUNCTION__ . $account_id)) return $data; $stmt = $this->mysqli->prepare(" SELECT - IFNULL(SUM(IF(our_result='Y', IF(s.difficulty=0, pow(2, (" . $this->config['difficulty'] . " - 16)), s.difficulty), 0)), 0) AS valid, - IFNULL(SUM(IF(our_result='N', IF(s.difficulty=0, pow(2, (" . $this->config['difficulty'] . " - 16)), s.difficulty), 0)), 0) AS invalid + ROUND(IFNULL(SUM(IF(our_result='Y', IF(s.difficulty=0, POW(2, (" . $this->config['difficulty'] . " - 16)), s.difficulty), 0)), 0) / POW(2, (" . $this->config['difficulty'] . " - 16)), 0) AS valid, + ROUND(IFNULL(SUM(IF(our_result='N', IF(s.difficulty=0, POW(2, (" . $this->config['difficulty'] . " - 16)), s.difficulty), 0)), 0) / POW(2, (" . $this->config['difficulty'] . " - 16)), 0) AS invalid FROM " . $this->share->getTableName() . " AS s, " . $this->user->getTableName() . " AS u WHERE @@ -228,7 +229,7 @@ class Statistics { a.username AS username, a.donate_percent AS donate_percent, a.email AS email, - IFNULL(SUM(IF(s.difficulty=0, pow(2, (" . $this->config['difficulty'] . " - 16)), s.difficulty)), 0) AS shares + IFNULL(SUM(IF(s.difficulty=0, POW(2, (" . $this->config['difficulty'] . " - 16)), s.difficulty)), 0) AS shares FROM " . $this->user->getTableName() . " AS a LEFT JOIN " . $this->share->getTableName() . " AS s ON a.username = SUBSTRING_INDEX( s.username, '.', 1 ) @@ -252,18 +253,18 @@ class Statistics { $stmt = $this->mysqli->prepare(" SELECT ( - SELECT IFNULL(ROUND(SUM(IF(difficulty=0, pow(2, (" . $this->config['difficulty'] . " - 16)), difficulty)) * 65536/600/1000), 0) AS hashrate + SELECT IFNULL(ROUND(SUM(IF(difficulty=0, POW(2, (" . $this->config['difficulty'] . " - 16)), difficulty)) * 65536 / 600 / 1000), 0) AS hashrate FROM " . $this->share->getTableName() . " AS s, " . $this->user->getTableName() . " AS u WHERE u.username = SUBSTRING_INDEX( s.username, '.', 1 ) - AND s.time > DATE_SUB(now(), INTERVAL 10 MINUTE) + AND s.time > DATE_SUB(now(), INTERVAL 600 SECOND) AND u.id = ? ) + ( - SELECT IFNULL(ROUND(SUM(IF(difficulty=0, pow(2, (" . $this->config['difficulty'] . " - 16)), difficulty)) * 65536/600/1000), 0) AS hashrate + SELECT IFNULL(ROUND(SUM(IF(difficulty=0, POW(2, (" . $this->config['difficulty'] . " - 16)), difficulty)) * 65536 / 600 / 1000), 0) AS hashrate FROM " . $this->share->getArchiveTableName() . " AS s, " . $this->user->getTableName() . " AS u WHERE u.username = SUBSTRING_INDEX( s.username, '.', 1 ) - AND s.time > DATE_SUB(now(), INTERVAL 10 MINUTE) + AND s.time > DATE_SUB(now(), INTERVAL 600 SECOND) AND u.id = ? ) AS hashrate FROM DUAL"); @@ -283,11 +284,11 @@ class Statistics { $this->debug->append("STA " . __METHOD__, 4); if ($data = $this->memcache->get(__FUNCTION__ . $account_id)) return $data; $stmt = $this->mysqli->prepare(" - SELECT IFNULL(SUM(IF(difficulty=0, pow(2, (" . $this->config['difficulty'] . " - 16)), difficulty)), 0)/600 AS sharerate + SELECT COUNT(s.id) / 600 AS sharerate FROM " . $this->share->getTableName() . " AS s, " . $this->user->getTableName() . " AS u WHERE u.username = SUBSTRING_INDEX( s.username, '.', 1 ) - AND s.time > DATE_SUB(now(), INTERVAL 10 MINUTE) + AND s.time > DATE_SUB(now(), INTERVAL 600 SECOND) AND u.id = ?"); if ($this->checkStmt($stmt) && $stmt->bind_param("i", $account_id) && $stmt->execute() && $result = $stmt->get_result() ) return $this->memcache->setCache(__FUNCTION__ . $account_id, $result->fetch_object()->sharerate); @@ -305,11 +306,11 @@ class Statistics { $this->debug->append("STA " . __METHOD__, 4); if ($data = $this->memcache->get(__FUNCTION__ . $worker_id)) return $data; $stmt = $this->mysqli->prepare(" - SELECT IFNULL(ROUND(SUM(IF(difficulty=0, pow(2, (" . $this->config['difficulty'] . " - 16)), difficulty)) * 65536/600/1000), 0) AS hashrate + SELECT IFNULL(ROUND(SUM(IF(difficulty=0, POW(2, (" . $this->config['difficulty'] . " - 16)), difficulty)) * 65536 / 600 / 1000), 0) AS hashrate FROM " . $this->share->getTableName() . " AS s, " . $this->user->getTableName() . " AS u WHERE u.username = SUBSTRING_INDEX( s.username, '.', 1 ) - AND s.time > DATE_SUB(now(), INTERVAL 10 MINUTE) + AND s.time > DATE_SUB(now(), INTERVAL 600 SECOND) AND u.id = ?"); if ($this->checkStmt($stmt) && $stmt->bind_param("i", $account_id) && $stmt->execute() && $result = $stmt->get_result() ) return $this->memcache->setCache(__FUNCTION__ . $worker_id, $result->fetch_object()->hashrate); @@ -333,7 +334,7 @@ class Statistics { SELECT a.donate_percent AS donate_percent, a.is_anonymous AS is_anonymous, - IFNULL(SUM(IF(s.difficulty=0, pow(2, (" . $this->config['difficulty'] . " - 16)), s.difficulty)), 0) AS shares, + ROUND(IFNULL(SUM(IF(s.difficulty=0, POW(2, (" . $this->config['difficulty'] . " - 16)), s.difficulty)), 0) / POW(2, (" . $this->config['difficulty'] . " - 16)), 0) AS shares, SUBSTRING_INDEX( s.username, '.', 1 ) AS account FROM " . $this->share->getTableName() . " AS s LEFT JOIN " . $this->user->getTableName() . " AS a From ae1a5c8ed38d1ac79badd0cdae75b68684712b45 Mon Sep 17 00:00:00 2001 From: Sebastian Grewe Date: Thu, 22 Aug 2013 11:30:13 +0200 Subject: [PATCH 50/60] Use baseline shares for share class --- public/include/classes/share.class.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/public/include/classes/share.class.php b/public/include/classes/share.class.php index e47b65d6..d3b88759 100644 --- a/public/include/classes/share.class.php +++ b/public/include/classes/share.class.php @@ -70,7 +70,7 @@ class Share { **/ public function getRoundShares($previous_upstream=0, $current_upstream) { $stmt = $this->mysqli->prepare("SELECT - IFNULL(ROUND(SUM(IF(difficulty=0, pow(2, (" . $this->config['difficulty'] . " - 16)), difficulty)), 8), 0) as total + ROUND(IFNULL(SUM(IF(difficulty=0, POW(2, (" . $this->config['difficulty'] . " - 16)), difficulty)), 0) / POW(2, (" . $this->config['difficulty'] . " - 16)), 0) AS total FROM $this->table WHERE our_result = 'Y' AND id > ? AND id <= ? @@ -98,8 +98,8 @@ class Share { a.id, SUBSTRING_INDEX( s.username , '.', 1 ) as username, a.no_fees AS no_fees, - IFNULL(ROUND(SUM(IF(our_result='Y', IF(s.difficulty=0, pow(2, (" . $this->config['difficulty'] . " - 16)), s.difficulty), 0)), 8), 0) AS valid, - IFNULL(ROUND(SUM(IF(our_result='N', IF(s.difficulty=0, pow(2, (" . $this->config['difficulty'] . " - 16)), s.difficulty), 0)), 8), 0) AS invalid + ROUND(IFNULL(SUM(IF(our_result='Y', IF(s.difficulty=0, POW(2, (" . $this->config['difficulty'] . " - 16)), s.difficulty), 0)), 0) / POW(2, (" . $this->config['difficulty'] . " - 16)), 8) AS valid, + ROUND(IFNULL(SUM(IF(our_result='N', IF(s.difficulty=0, POW(2, (" . $this->config['difficulty'] . " - 16)), s.difficulty), 0)), 0) / POW(2, (" . $this->config['difficulty'] . " - 16)), 8) AS invalid FROM $this->table AS s LEFT JOIN " . $this->user->getTableName() . " AS a ON a.username = SUBSTRING_INDEX( s.username , '.', 1 ) @@ -137,8 +137,8 @@ class Share { a.id, SUBSTRING_INDEX( s.username , '.', 1 ) as account, a.no_fees AS no_fees, - IFNULL(ROUND(SUM(IF(our_result='Y', IF(s.difficulty=0, pow(2, (" . $this->config['difficulty'] . " - 16)), s.difficulty), 0)), 8), 0) AS valid, - IFNULL(ROUND(SUM(IF(our_result='N', IF(s.difficulty=0, pow(2, (" . $this->config['difficulty'] . " - 16)), s.difficulty), 0)), 8), 0) AS invalid + ROUND(IFNULL(SUM(IF(our_result='Y', IF(s.difficulty=0, pow(2, (" . $this->config['difficulty'] . " - 16)), s.difficulty), 0)), 0) / POW(2, (" . $this->config['difficulty'] . " - 16)), 8) AS valid, + ROUND(IFNULL(SUM(IF(our_result='N', IF(s.difficulty=0, pow(2, (" . $this->config['difficulty'] . " - 16)), s.difficulty), 0)), 0) / POW(2, (" . $this->config['difficulty'] . " - 16)), 8) AS invalid FROM $this->tableArchive AS s LEFT JOIN " . $this->user->getTableName() . " AS a ON a.username = SUBSTRING_INDEX( s.username , '.', 1 ) From eacb8dff03b2fb6da935990a295ccbf3dbc5634d Mon Sep 17 00:00:00 2001 From: Sebastian Grewe Date: Thu, 22 Aug 2013 11:30:27 +0200 Subject: [PATCH 51/60] updated templates --- public/templates/mmcFE/statistics/blocks/default.tpl | 11 +++++------ .../templates/mmcFE/statistics/pool/authenticated.tpl | 3 ++- .../mobile/statistics/pool/authenticated.tpl | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/public/templates/mmcFE/statistics/blocks/default.tpl b/public/templates/mmcFE/statistics/blocks/default.tpl index 240b4a00..c1eac127 100644 --- a/public/templates/mmcFE/statistics/blocks/default.tpl +++ b/public/templates/mmcFE/statistics/blocks/default.tpl @@ -12,7 +12,7 @@ {section block $BLOCKSFOUND step=-1} - + {/section} @@ -64,16 +64,15 @@ target and network difficulty and assuming a zero variance scenario. {else}{$GLOBAL.confirmations - $BLOCKSFOUND[block].confirmations} left{/if} - + diff --git a/public/templates/mmcFE/statistics/pool/authenticated.tpl b/public/templates/mmcFE/statistics/pool/authenticated.tpl index 83ee505c..ff87137a 100644 --- a/public/templates/mmcFE/statistics/pool/authenticated.tpl +++ b/public/templates/mmcFE/statistics/pool/authenticated.tpl @@ -48,7 +48,8 @@ - + {assign var=estshares value=(65536 * $DIFFICULTY) / pow(2, ($GLOBAL.config.targetdiff - 16))} + diff --git a/public/templates/mobile/statistics/pool/authenticated.tpl b/public/templates/mobile/statistics/pool/authenticated.tpl index d9e490b2..69588d9f 100644 --- a/public/templates/mobile/statistics/pool/authenticated.tpl +++ b/public/templates/mobile/statistics/pool/authenticated.tpl @@ -51,7 +51,7 @@ - + From eb435b4072d17f48f7a107b0079d546bfd00624e Mon Sep 17 00:00:00 2001 From: Sebastian Grewe Date: Thu, 22 Aug 2013 12:33:29 +0200 Subject: [PATCH 52/60] fixing difficulty per worker value --- public/include/classes/worker.class.php | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/public/include/classes/worker.class.php b/public/include/classes/worker.class.php index 28dcc94a..cb959f38 100644 --- a/public/include/classes/worker.class.php +++ b/public/include/classes/worker.class.php @@ -96,6 +96,8 @@ class Worker { $this->debug->append("STA " . __METHOD__, 4); $stmt = $this->mysqli->prepare(" SELECT id, username, password, monitor, + ( SELECT COUNT(id) FROM " . $this->share->getTableName() . " WHERE username = w.username AND time > DATE_SUB(now(), INTERVAL 10 MINUTE)) AS count_all, + ( SELECT COUNT(id) FROM " . $this->share->getArchiveTableName() . " WHERE username = w.username AND time > DATE_SUB(now(), INTERVAL 10 MINUTE)) AS count_all_archive, ( SELECT IFNULL(IF(our_result='Y', ROUND(SUM(IF(difficulty=0, pow(2, (" . $this->config['difficulty'] . " - 16)), difficulty)) * 65536/600/1000), 0), 0) AS hashrate @@ -112,11 +114,11 @@ class Worker { AND time > DATE_SUB(now(), INTERVAL 10 MINUTE) ) AS hashrate, ( - SELECT IFNULL(IF(our_result='Y', ROUND(SUM(IF(difficulty=0, pow(2, (" . $this->config['difficulty'] . " - 16)), difficulty)) / COUNT(id), 2), 0), 0) + SELECT IFNULL(ROUND(SUM(IF(difficulty=0, pow(2, (" . $this->config['difficulty'] . " - 16)), difficulty)) / count_all, 2), 0) FROM " . $this->share->getTableName() . " WHERE username = w.username AND time > DATE_SUB(now(), INTERVAL 10 MINUTE) ) + ( - SELECT IFNULL(IF(our_result='Y', ROUND(SUM(IF(difficulty=0, pow(2, (" . $this->config['difficulty'] . " - 16)), difficulty)) / COUNT(id), 2), 0), 0) + SELECT IFNULL(ROUND(SUM(IF(difficulty=0, pow(2, (" . $this->config['difficulty'] . " - 16)), difficulty)) / count_all_archive, 2), 0) FROM " . $this->share->getArchiveTableName() . " WHERE username = w.username AND time > DATE_SUB(now(), INTERVAL 10 MINUTE) ) AS difficulty @@ -138,6 +140,8 @@ class Worker { $this->debug->append("STA " . __METHOD__, 4); $stmt = $this->mysqli->prepare(" SELECT id, username, password, monitor, + ( SELECT COUNT(id) FROM " . $this->share->getTableName() . " WHERE username = w.username AND time > DATE_SUB(now(), INTERVAL 10 MINUTE)) AS count_all, + ( SELECT COUNT(id) FROM " . $this->share->getArchiveTableName() . " WHERE username = w.username AND time > DATE_SUB(now(), INTERVAL 10 MINUTE)) AS count_all_archive, ( SELECT IFNULL(IF(our_result='Y', ROUND(SUM(IF(difficulty=0, pow(2, (" . $this->config['difficulty'] . " - 16)), difficulty)) * 65536/600/1000), 0), 0) AS hashrate @@ -154,11 +158,11 @@ class Worker { AND time > DATE_SUB(now(), INTERVAL 10 MINUTE) ) AS hashrate, ( - SELECT IFNULL(IF(our_result='Y', ROUND(SUM(IF(difficulty=0, pow(2, (" . $this->config['difficulty'] . " - 16)), difficulty)) / COUNT(id), 2), 0), 0) + SELECT IFNULL(ROUND(SUM(IF(difficulty=0, pow(2, (" . $this->config['difficulty'] . " - 16)), difficulty)) / count_all, 2), 0) FROM " . $this->share->getTableName() . " WHERE username = w.username AND time > DATE_SUB(now(), INTERVAL 10 MINUTE) ) + ( - SELECT IFNULL(IF(our_result='Y', ROUND(SUM(IF(difficulty=0, pow(2, (" . $this->config['difficulty'] . " - 16)), difficulty)) / COUNT(id), 2), 0), 0) + SELECT IFNULL(ROUND(SUM(IF(difficulty=0, pow(2, (" . $this->config['difficulty'] . " - 16)), difficulty)) / count_all_archive, 2), 0) FROM " . $this->share->getArchiveTableName() . " WHERE username = w.username AND time > DATE_SUB(now(), INTERVAL 10 MINUTE) ) AS difficulty From 75d0dfe5f72b7e0522087e46112d6bdfed5c1c53 Mon Sep 17 00:00:00 2001 From: Sebastian Grewe Date: Thu, 22 Aug 2013 14:18:04 +0200 Subject: [PATCH 53/60] adding share rate to all sidebars --- public/templates/mmcFE/global/sidebar_pplns.tpl | 4 ++++ public/templates/mobile/global/sidebar_pplns.tpl | 4 ++++ public/templates/mobile/global/sidebar_prop.tpl | 4 ++++ 3 files changed, 12 insertions(+) diff --git a/public/templates/mmcFE/global/sidebar_pplns.tpl b/public/templates/mmcFE/global/sidebar_pplns.tpl index a39bce8d..71dc11bf 100644 --- a/public/templates/mmcFE/global/sidebar_pplns.tpl +++ b/public/templates/mmcFE/global/sidebar_pplns.tpl @@ -18,6 +18,10 @@ + + + + diff --git a/public/templates/mobile/global/sidebar_pplns.tpl b/public/templates/mobile/global/sidebar_pplns.tpl index c60359b7..c56a968f 100644 --- a/public/templates/mobile/global/sidebar_pplns.tpl +++ b/public/templates/mobile/global/sidebar_pplns.tpl @@ -11,6 +11,10 @@ + + + + diff --git a/public/templates/mobile/global/sidebar_prop.tpl b/public/templates/mobile/global/sidebar_prop.tpl index f685171e..7ef6db53 100644 --- a/public/templates/mobile/global/sidebar_prop.tpl +++ b/public/templates/mobile/global/sidebar_prop.tpl @@ -7,6 +7,10 @@ + + + + From c9a8f8dc65f06fbc3d14695716ff511a58df6c2a Mon Sep 17 00:00:00 2001 From: Sebastian Grewe Date: Thu, 22 Aug 2013 14:39:46 +0200 Subject: [PATCH 54/60] adjusting pplns target to baseline shares --- cronjobs/pplns_payout.php | 13 ++++++-- public/include/classes/share.class.php | 42 +++++++++++++++++++++++++- 2 files changed, 51 insertions(+), 4 deletions(-) diff --git a/cronjobs/pplns_payout.php b/cronjobs/pplns_payout.php index c71f5659..6d718870 100755 --- a/cronjobs/pplns_payout.php +++ b/cronjobs/pplns_payout.php @@ -45,9 +45,12 @@ foreach ($aAllBlocks as $iIndex => $aBlock) { if ($config['pplns']['shares']['type'] == 'blockavg' && $block->getBlockCount() > 0) { $pplns_target = round($block->getAvgBlockShares($config['pplns']['blockavg']['blockcount'])); } else { - $pplns_target = $config['pplns']['shares']['default'] ; + $pplns_target = $config['pplns']['shares']['default']; } + // We use baseline shares, so we have to calculate back to diff shares + $pplns_target = $pplns_target * pow(2, ($config['difficulty'] - 16)); + if (!$aBlock['accounted']) { $iPreviousShareId = @$aAllBlocks[$iIndex - 1]['share_id'] ? $aAllBlocks[$iIndex - 1]['share_id'] : 0; $iCurrentUpstreamId = $aBlock['share_id']; @@ -65,7 +68,8 @@ foreach ($aAllBlocks as $iIndex => $aBlock) { if ($iRoundShares >= $pplns_target) { $log->logDebug("Matching or exceeding PPLNS target of $pplns_target with $iRoundShares"); - $aAccountShares = $share->getSharesForAccounts($aBlock['share_id'] - $pplns_target, $aBlock['share_id']); + $iMinimumShareId = $share->getMinimumShareId($pplns_target, $aBlock['share_id']); + $aAccountShares = $share->getSharesForAccounts($iMinimumShareId, $aBlock['share_id']); if (empty($aAccountShares)) { $log->logFatal("No shares found for this block, aborted! Block Height : " . $aBlock['height']); $monitoring->setStatus($cron_name . "_active", "yesno", 0); @@ -73,8 +77,11 @@ foreach ($aAllBlocks as $iIndex => $aBlock) { $monitoring->setStatus($cron_name . "_status", "okerror", 1); exit(1); } + foreach($aAccountShares as $key => $aData) { + $iNewRoundShares += $aData['valid']; + } $log->logInfo('Adjusting round target to PPLNS target ' . $pplns_target); - $iRoundShares = $pplns_target; + $iRoundShares = $iNewRoundShares; } else { $log->logDebug("Not able to match PPLNS target of $pplns_target with $iRoundShares"); // We need to fill up with archived shares diff --git a/public/include/classes/share.class.php b/public/include/classes/share.class.php index d3b88759..85a005de 100644 --- a/public/include/classes/share.class.php +++ b/public/include/classes/share.class.php @@ -130,7 +130,7 @@ class Share { * return array data Returns an array with usernames as keys for easy access **/ function getArchiveShares($iCount) { - $iMinId = $this->getMaxArchiveShareId() - $iCount; + $iMinId = $this->getMinArchiveShareId($iCount); $iMaxId = $this->getMaxArchiveShareId(); $stmt = $this->mysqli->prepare(" SELECT @@ -307,6 +307,46 @@ class Share { return false; } + /** + * Fetch the lowest needed share ID from shares + **/ + function getMinimumShareId($iCount, $current_upstream) { + $stmt = $this->mysqli->prepare(" + SELECT MIN(b.id) AS id FROM + ( + SELECT id, @total := @total + IF(difficulty=0, POW(2, (" . $this->config['difficulty'] . " - 16)), difficulty) AS total + FROM $this->table, (SELECT @total := 0) AS a + WHERE our_result = 'Y' + AND id <= ? AND @total < ? + ORDER BY id DESC + ) AS b + WHERE total <= ? + "); + if ($this->checkStmt($stmt) && $stmt->bind_param('iii', $current_upstream, $iCount, $iCount) && $stmt->execute() && $result = $stmt->get_result()) + return $result->fetch_object()->id; + return false; + } + + /** + * Fetch the lowest needed share ID from archive + **/ + function getMinArchiveShareId($iCount) { + $stmt = $this->mysqli->prepare(" + SELECT MIN(b.share_id) AS share_id FROM + ( + SELECT share_id, @total := @total + IF(difficulty=0, pow(2, (" . $this->config['difficulty'] . " - 16)), difficulty) AS total + FROM $this->tableArchive, (SELECT @total := 0) AS a + WHERE our_result = 'Y' + AND @total < ? + ORDER BY share_id DESC + ) AS b + WHERE total <= ? + "); + if ($this->checkStmt($stmt) && $stmt->bind_param('ii', $iCount, $iCount) && $stmt->execute() && $result = $stmt->get_result()) + return $result->fetch_object()->share_id; + return false; + } + /** * Helper function **/ From 2d271327252f8a623c883024ef951fe82a2f0c03 Mon Sep 17 00:00:00 2001 From: Sebastian Grewe Date: Thu, 22 Aug 2013 14:51:30 +0200 Subject: [PATCH 55/60] Revert "adjusting pplns target to baseline shares" * Shares are already baselined when calculating rounds This reverts commit c9a8f8dc65f06fbc3d14695716ff511a58df6c2a. --- cronjobs/pplns_payout.php | 13 ++------ public/include/classes/share.class.php | 42 +------------------------- 2 files changed, 4 insertions(+), 51 deletions(-) diff --git a/cronjobs/pplns_payout.php b/cronjobs/pplns_payout.php index 6d718870..c71f5659 100755 --- a/cronjobs/pplns_payout.php +++ b/cronjobs/pplns_payout.php @@ -45,12 +45,9 @@ foreach ($aAllBlocks as $iIndex => $aBlock) { if ($config['pplns']['shares']['type'] == 'blockavg' && $block->getBlockCount() > 0) { $pplns_target = round($block->getAvgBlockShares($config['pplns']['blockavg']['blockcount'])); } else { - $pplns_target = $config['pplns']['shares']['default']; + $pplns_target = $config['pplns']['shares']['default'] ; } - // We use baseline shares, so we have to calculate back to diff shares - $pplns_target = $pplns_target * pow(2, ($config['difficulty'] - 16)); - if (!$aBlock['accounted']) { $iPreviousShareId = @$aAllBlocks[$iIndex - 1]['share_id'] ? $aAllBlocks[$iIndex - 1]['share_id'] : 0; $iCurrentUpstreamId = $aBlock['share_id']; @@ -68,8 +65,7 @@ foreach ($aAllBlocks as $iIndex => $aBlock) { if ($iRoundShares >= $pplns_target) { $log->logDebug("Matching or exceeding PPLNS target of $pplns_target with $iRoundShares"); - $iMinimumShareId = $share->getMinimumShareId($pplns_target, $aBlock['share_id']); - $aAccountShares = $share->getSharesForAccounts($iMinimumShareId, $aBlock['share_id']); + $aAccountShares = $share->getSharesForAccounts($aBlock['share_id'] - $pplns_target, $aBlock['share_id']); if (empty($aAccountShares)) { $log->logFatal("No shares found for this block, aborted! Block Height : " . $aBlock['height']); $monitoring->setStatus($cron_name . "_active", "yesno", 0); @@ -77,11 +73,8 @@ foreach ($aAllBlocks as $iIndex => $aBlock) { $monitoring->setStatus($cron_name . "_status", "okerror", 1); exit(1); } - foreach($aAccountShares as $key => $aData) { - $iNewRoundShares += $aData['valid']; - } $log->logInfo('Adjusting round target to PPLNS target ' . $pplns_target); - $iRoundShares = $iNewRoundShares; + $iRoundShares = $pplns_target; } else { $log->logDebug("Not able to match PPLNS target of $pplns_target with $iRoundShares"); // We need to fill up with archived shares diff --git a/public/include/classes/share.class.php b/public/include/classes/share.class.php index 85a005de..d3b88759 100644 --- a/public/include/classes/share.class.php +++ b/public/include/classes/share.class.php @@ -130,7 +130,7 @@ class Share { * return array data Returns an array with usernames as keys for easy access **/ function getArchiveShares($iCount) { - $iMinId = $this->getMinArchiveShareId($iCount); + $iMinId = $this->getMaxArchiveShareId() - $iCount; $iMaxId = $this->getMaxArchiveShareId(); $stmt = $this->mysqli->prepare(" SELECT @@ -307,46 +307,6 @@ class Share { return false; } - /** - * Fetch the lowest needed share ID from shares - **/ - function getMinimumShareId($iCount, $current_upstream) { - $stmt = $this->mysqli->prepare(" - SELECT MIN(b.id) AS id FROM - ( - SELECT id, @total := @total + IF(difficulty=0, POW(2, (" . $this->config['difficulty'] . " - 16)), difficulty) AS total - FROM $this->table, (SELECT @total := 0) AS a - WHERE our_result = 'Y' - AND id <= ? AND @total < ? - ORDER BY id DESC - ) AS b - WHERE total <= ? - "); - if ($this->checkStmt($stmt) && $stmt->bind_param('iii', $current_upstream, $iCount, $iCount) && $stmt->execute() && $result = $stmt->get_result()) - return $result->fetch_object()->id; - return false; - } - - /** - * Fetch the lowest needed share ID from archive - **/ - function getMinArchiveShareId($iCount) { - $stmt = $this->mysqli->prepare(" - SELECT MIN(b.share_id) AS share_id FROM - ( - SELECT share_id, @total := @total + IF(difficulty=0, pow(2, (" . $this->config['difficulty'] . " - 16)), difficulty) AS total - FROM $this->tableArchive, (SELECT @total := 0) AS a - WHERE our_result = 'Y' - AND @total < ? - ORDER BY share_id DESC - ) AS b - WHERE total <= ? - "); - if ($this->checkStmt($stmt) && $stmt->bind_param('ii', $iCount, $iCount) && $stmt->execute() && $result = $stmt->get_result()) - return $result->fetch_object()->share_id; - return false; - } - /** * Helper function **/ From 927fc12cb388f5f50d3232bfc909c588d94d66ac Mon Sep 17 00:00:00 2001 From: Sebastian Grewe Date: Thu, 22 Aug 2013 15:01:00 +0200 Subject: [PATCH 56/60] fixing admin panel user info --- public/include/classes/statistics.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/public/include/classes/statistics.class.php b/public/include/classes/statistics.class.php index cca66283..000e5b02 100644 --- a/public/include/classes/statistics.class.php +++ b/public/include/classes/statistics.class.php @@ -229,7 +229,7 @@ class Statistics { a.username AS username, a.donate_percent AS donate_percent, a.email AS email, - IFNULL(SUM(IF(s.difficulty=0, POW(2, (" . $this->config['difficulty'] . " - 16)), s.difficulty)), 0) AS shares + ROUND(IFNULL(SUM(IF(s.difficulty=0, POW(2, (" . $this->config['difficulty'] . " - 16)), s.difficulty)), 0) / POW(2, (" . $this->config['difficulty'] . " - 16)), 0) AS shares FROM " . $this->user->getTableName() . " AS a LEFT JOIN " . $this->share->getTableName() . " AS s ON a.username = SUBSTRING_INDEX( s.username, '.', 1 ) From db754c146edcc5a83054a09f648d0ace7bb46358 Mon Sep 17 00:00:00 2001 From: Sebastian Grewe Date: Thu, 22 Aug 2013 15:20:46 +0200 Subject: [PATCH 57/60] Revert "Revert "adjusting pplns target to baseline shares"" Reverting the revert .... :-/ This reverts commit 2d271327252f8a623c883024ef951fe82a2f0c03. --- cronjobs/pplns_payout.php | 13 ++++++-- public/include/classes/share.class.php | 42 +++++++++++++++++++++++++- 2 files changed, 51 insertions(+), 4 deletions(-) diff --git a/cronjobs/pplns_payout.php b/cronjobs/pplns_payout.php index c71f5659..6d718870 100755 --- a/cronjobs/pplns_payout.php +++ b/cronjobs/pplns_payout.php @@ -45,9 +45,12 @@ foreach ($aAllBlocks as $iIndex => $aBlock) { if ($config['pplns']['shares']['type'] == 'blockavg' && $block->getBlockCount() > 0) { $pplns_target = round($block->getAvgBlockShares($config['pplns']['blockavg']['blockcount'])); } else { - $pplns_target = $config['pplns']['shares']['default'] ; + $pplns_target = $config['pplns']['shares']['default']; } + // We use baseline shares, so we have to calculate back to diff shares + $pplns_target = $pplns_target * pow(2, ($config['difficulty'] - 16)); + if (!$aBlock['accounted']) { $iPreviousShareId = @$aAllBlocks[$iIndex - 1]['share_id'] ? $aAllBlocks[$iIndex - 1]['share_id'] : 0; $iCurrentUpstreamId = $aBlock['share_id']; @@ -65,7 +68,8 @@ foreach ($aAllBlocks as $iIndex => $aBlock) { if ($iRoundShares >= $pplns_target) { $log->logDebug("Matching or exceeding PPLNS target of $pplns_target with $iRoundShares"); - $aAccountShares = $share->getSharesForAccounts($aBlock['share_id'] - $pplns_target, $aBlock['share_id']); + $iMinimumShareId = $share->getMinimumShareId($pplns_target, $aBlock['share_id']); + $aAccountShares = $share->getSharesForAccounts($iMinimumShareId, $aBlock['share_id']); if (empty($aAccountShares)) { $log->logFatal("No shares found for this block, aborted! Block Height : " . $aBlock['height']); $monitoring->setStatus($cron_name . "_active", "yesno", 0); @@ -73,8 +77,11 @@ foreach ($aAllBlocks as $iIndex => $aBlock) { $monitoring->setStatus($cron_name . "_status", "okerror", 1); exit(1); } + foreach($aAccountShares as $key => $aData) { + $iNewRoundShares += $aData['valid']; + } $log->logInfo('Adjusting round target to PPLNS target ' . $pplns_target); - $iRoundShares = $pplns_target; + $iRoundShares = $iNewRoundShares; } else { $log->logDebug("Not able to match PPLNS target of $pplns_target with $iRoundShares"); // We need to fill up with archived shares diff --git a/public/include/classes/share.class.php b/public/include/classes/share.class.php index d3b88759..85a005de 100644 --- a/public/include/classes/share.class.php +++ b/public/include/classes/share.class.php @@ -130,7 +130,7 @@ class Share { * return array data Returns an array with usernames as keys for easy access **/ function getArchiveShares($iCount) { - $iMinId = $this->getMaxArchiveShareId() - $iCount; + $iMinId = $this->getMinArchiveShareId($iCount); $iMaxId = $this->getMaxArchiveShareId(); $stmt = $this->mysqli->prepare(" SELECT @@ -307,6 +307,46 @@ class Share { return false; } + /** + * Fetch the lowest needed share ID from shares + **/ + function getMinimumShareId($iCount, $current_upstream) { + $stmt = $this->mysqli->prepare(" + SELECT MIN(b.id) AS id FROM + ( + SELECT id, @total := @total + IF(difficulty=0, POW(2, (" . $this->config['difficulty'] . " - 16)), difficulty) AS total + FROM $this->table, (SELECT @total := 0) AS a + WHERE our_result = 'Y' + AND id <= ? AND @total < ? + ORDER BY id DESC + ) AS b + WHERE total <= ? + "); + if ($this->checkStmt($stmt) && $stmt->bind_param('iii', $current_upstream, $iCount, $iCount) && $stmt->execute() && $result = $stmt->get_result()) + return $result->fetch_object()->id; + return false; + } + + /** + * Fetch the lowest needed share ID from archive + **/ + function getMinArchiveShareId($iCount) { + $stmt = $this->mysqli->prepare(" + SELECT MIN(b.share_id) AS share_id FROM + ( + SELECT share_id, @total := @total + IF(difficulty=0, pow(2, (" . $this->config['difficulty'] . " - 16)), difficulty) AS total + FROM $this->tableArchive, (SELECT @total := 0) AS a + WHERE our_result = 'Y' + AND @total < ? + ORDER BY share_id DESC + ) AS b + WHERE total <= ? + "); + if ($this->checkStmt($stmt) && $stmt->bind_param('ii', $iCount, $iCount) && $stmt->execute() && $result = $stmt->get_result()) + return $result->fetch_object()->share_id; + return false; + } + /** * Helper function **/ From 6eec747be6f0c2d6ad707048eb3e4d5f5f5d913a Mon Sep 17 00:00:00 2001 From: Sebastian Grewe Date: Thu, 22 Aug 2013 16:16:04 +0200 Subject: [PATCH 58/60] fixing PPLNS payouts one last time --- cronjobs/pplns_payout.php | 9 ++++----- public/include/classes/share.class.php | 4 +++- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/cronjobs/pplns_payout.php b/cronjobs/pplns_payout.php index 6d718870..6f661021 100755 --- a/cronjobs/pplns_payout.php +++ b/cronjobs/pplns_payout.php @@ -48,9 +48,6 @@ foreach ($aAllBlocks as $iIndex => $aBlock) { $pplns_target = $config['pplns']['shares']['default']; } - // We use baseline shares, so we have to calculate back to diff shares - $pplns_target = $pplns_target * pow(2, ($config['difficulty'] - 16)); - if (!$aBlock['accounted']) { $iPreviousShareId = @$aAllBlocks[$iIndex - 1]['share_id'] ? $aAllBlocks[$iIndex - 1]['share_id'] : 0; $iCurrentUpstreamId = $aBlock['share_id']; @@ -69,7 +66,8 @@ foreach ($aAllBlocks as $iIndex => $aBlock) { if ($iRoundShares >= $pplns_target) { $log->logDebug("Matching or exceeding PPLNS target of $pplns_target with $iRoundShares"); $iMinimumShareId = $share->getMinimumShareId($pplns_target, $aBlock['share_id']); - $aAccountShares = $share->getSharesForAccounts($iMinimumShareId, $aBlock['share_id']); + // We need to go one ID lower due to `id >` or we won't match if minimum share ID == $aBlock['share_id'] + $aAccountShares = $share->getSharesForAccounts($iMinimumShareId - 1, $aBlock['share_id']); if (empty($aAccountShares)) { $log->logFatal("No shares found for this block, aborted! Block Height : " . $aBlock['height']); $monitoring->setStatus($cron_name . "_active", "yesno", 0); @@ -80,7 +78,7 @@ foreach ($aAllBlocks as $iIndex => $aBlock) { foreach($aAccountShares as $key => $aData) { $iNewRoundShares += $aData['valid']; } - $log->logInfo('Adjusting round target to PPLNS target ' . $pplns_target); + $log->logInfo('Adjusting round target to PPLNS target ' . $iNewRoundShares); $iRoundShares = $iNewRoundShares; } else { $log->logDebug("Not able to match PPLNS target of $pplns_target with $iRoundShares"); @@ -160,6 +158,7 @@ foreach ($aAllBlocks as $iIndex => $aBlock) { if (!$statistics->updateShareStatistics($aRoundData, $aBlock['id'])) $log->logError('Failed to update share statistics for ' . $aData['username']); } + // Add new credit transaction if (!$transaction->addTransaction($aData['id'], $aData['payout'], 'Credit', $aBlock['id'])) $log->logFatal('Failed to insert new Credit transaction to database for ' . $aData['username']); diff --git a/public/include/classes/share.class.php b/public/include/classes/share.class.php index 85a005de..4184acb7 100644 --- a/public/include/classes/share.class.php +++ b/public/include/classes/share.class.php @@ -311,6 +311,8 @@ class Share { * Fetch the lowest needed share ID from shares **/ function getMinimumShareId($iCount, $current_upstream) { + // We don't use baseline here to be more accurate + $iCount = $iCount * pow(2, ($this->config['difficulty'] - 16)); $stmt = $this->mysqli->prepare(" SELECT MIN(b.id) AS id FROM ( @@ -334,7 +336,7 @@ class Share { $stmt = $this->mysqli->prepare(" SELECT MIN(b.share_id) AS share_id FROM ( - SELECT share_id, @total := @total + IF(difficulty=0, pow(2, (" . $this->config['difficulty'] . " - 16)), difficulty) AS total + SELECT share_id, @total := @total + (IF(difficulty=0, POW(2, (" . $this->config['difficulty'] . " - 16)), difficulty) / POW(2, (" . $this->config['difficulty'] . " - 16))) AS total FROM $this->tableArchive, (SELECT @total := 0) AS a WHERE our_result = 'Y' AND @total < ? From 5e1c3ae3726d021d3c64a587797ed5570028c364 Mon Sep 17 00:00:00 2001 From: Sebastian Grewe Date: Thu, 12 Sep 2013 13:22:39 +0200 Subject: [PATCH 59/60] fixing issue mentioned in #145 with payouts --- public/include/classes/share.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/public/include/classes/share.class.php b/public/include/classes/share.class.php index 4184acb7..05fb8d0b 100644 --- a/public/include/classes/share.class.php +++ b/public/include/classes/share.class.php @@ -70,7 +70,7 @@ class Share { **/ public function getRoundShares($previous_upstream=0, $current_upstream) { $stmt = $this->mysqli->prepare("SELECT - ROUND(IFNULL(SUM(IF(difficulty=0, POW(2, (" . $this->config['difficulty'] . " - 16)), difficulty)), 0) / POW(2, (" . $this->config['difficulty'] . " - 16)), 0) AS total + ROUND(IFNULL(SUM(IF(difficulty=0, POW(2, (" . $this->config['difficulty'] . " - 16)), difficulty)), 0) / POW(2, (" . $this->config['difficulty'] . " - 16)), 8) AS total FROM $this->table WHERE our_result = 'Y' AND id > ? AND id <= ? From 34b95d6312959925f9eeaeb17f699d71b38d3b9a Mon Sep 17 00:00:00 2001 From: Sebastian Grewe Date: Fri, 13 Sep 2013 13:57:45 +0200 Subject: [PATCH 60/60] renaming SQL file --- sql/{issue_145_shares.sql => 008_vardiff_support.sql} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename sql/{issue_145_shares.sql => 008_vardiff_support.sql} (100%) diff --git a/sql/issue_145_shares.sql b/sql/008_vardiff_support.sql similarity index 100% rename from sql/issue_145_shares.sql rename to sql/008_vardiff_support.sql
Worker NamePasswordActiveMonitorKhash/s  Worker NamePasswordActiveMonitorKhash/sDifficultyAction
{$WORKERS[worker].hashrate|number_format}{$WORKERS[worker].difficulty|number_format:"2"}
Worker Name Active Khash/sDifficulty
{$username.0|escape}.{$username.1|escape} {$WORKERS[worker].hashrate|number_format}{$WORKERS[worker].hashrate|number_format}
Hashrate {$GLOBAL.userdata.hashrate|number_format} KH/s
Share Rate{$GLOBAL.userdata.sharerate|number_format:"2"} S/s
Unpaid Shares
Expected{round(65536 * $BLOCKSFOUND[block].difficulty)}{$BLOCKSFOUND[block].estshares}
{if $BLOCKSFOUND[block].is_anonymous|default:"0" == 1}anonymous{else}{$BLOCKSFOUND[block].finder|default:"unknown"|escape}{/if} {$BLOCKSFOUND[block].time|date_format:"%d/%m %H:%M:%S"}{$BLOCKSFOUND[block].difficulty|number_format:"2"}{$BLOCKSFOUND[block].difficulty|number_format:"8"} {$BLOCKSFOUND[block].amount|number_format:"2"} - {math assign="estshares" equation="(65536 * blockdiff)" blockdiff=$BLOCKSFOUND[block].difficulty} - {assign var="totalexpectedshares" value=$totalexpectedshares+$estshares} - {$estshares|number_format} + {$BLOCKSFOUND[block].estshares|number_format} + {assign var="totalexpectedshares" value=$totalexpectedshares+$BLOCKSFOUND[block].estshares} {$BLOCKSFOUND[block].shares|number_format} - {math assign="percentage" equation="shares / estshares * 100" shares=$BLOCKSFOUND[block].shares estshares=$estshares} + {math assign="percentage" equation="shares / estshares * 100" shares=$BLOCKSFOUND[block].shares estshares=$BLOCKSFOUND[block].estshares} {assign var="totalpercentage" value=$totalpercentage+$percentage} {$percentage|number_format:"2"}
Est. Shares this Round{(65536 * $DIFFICULTY)|number_format:"0"} (done: {(100 / (65536 * $DIFFICULTY) * $GLOBAL.roundshares.valid)|number_format:"2"} %){$estshares|number_format:"0"} (done: {(100 / $estshares * $GLOBAL.roundshares.valid)|number_format:"2"} %)
Time Since Last Block
Est. Shares this Round{(65536 * $DIFFICULTY)|number_format:"0"} (done: {(100 / (65536 * $DIFFICULTY) * $GLOBAL.roundshares.valid)|number_format:"2"} %){((65536 * $DIFFICULTY) / pow(2, ($GLOBAL.config.targetdiff - 16)))|number_format:"0"} (done: {(100 / ((65536 * $DIFFICULTY) / pow(2, ($GLOBAL.config.targetdiff - 16))) * $GLOBAL.roundshares.valid)|number_format:"2"} %)
Time Since Last BlockHashrate {$GLOBAL.userdata.hashrate|number_format} KH/s
Share Rate{$GLOBAL.userdata.sharerate|number_format:"2"} S/s
Unpaid Shares
Hashrate {$GLOBAL.userdata.hashrate|number_format} KH/s
Share Rate{$GLOBAL.userdata.sharerate|number_format:"2"} S/s
Unpaid Shares
Hashrate {$GLOBAL.userdata.hashrate|number_format} KH/s
Share Rate{$GLOBAL.userdata.sharerate|number_format:"2"} S/s
 
Round Shares