From 67a4713cf025afc419ae7309ada53a52c7009334 Mon Sep 17 00:00:00 2001 From: Sebastian Grewe Date: Fri, 21 Mar 2014 11:51:34 +0100 Subject: [PATCH 1/4] [REMOVED] Baseline Share calculations * We now track diff1 shares instead of converting into a baselined value * PPS has been adjusted to payout shares directly * Estimated Shares in coin_base adjusted --- cronjobs/pps_payout.php | 7 +++---- public/include/classes/coins/coin_base.class.php | 2 +- public/include/classes/share.class.php | 10 +++++----- 3 files changed, 9 insertions(+), 10 deletions(-) diff --git a/cronjobs/pps_payout.php b/cronjobs/pps_payout.php index cc1cbad1..509176d2 100755 --- a/cronjobs/pps_payout.php +++ b/cronjobs/pps_payout.php @@ -105,9 +105,8 @@ foreach ($aAccountShares as $aData) { continue; } - // MPOS uses a base difficulty setting to avoid showing weightened shares - // Since we need weightened shares here, we go back to the proper value for payouts - $aData['payout'] = round($aData['valid'] * pow(2, ($config['difficulty'] - 16)) * $pps_value, 12); + // Payout for this user + $aData['payout'] = round($aData['valid'] * $pps_value, 12); // Defaults $aData['fee' ] = 0; @@ -120,7 +119,7 @@ foreach ($aAccountShares as $aData) { $aData['donation'] = round($user->getDonatePercent($user->getUserId($aData['username'])) / 100 * ( $aData['payout'] - $aData['fee']), 12); $log->logInfo(sprintf( - $strLogMask, $aData['id'], $aData['username'], $aData['invalid'], $aData['valid'] * pow(2, ($config['difficulty'] - 16)), + $strLogMask, $aData['id'], $aData['username'], $aData['invalid'], $aData['valid'], number_format($pps_value, 12), number_format($aData['payout'], 12), number_format($aData['donation'], 12), number_format($aData['fee'], 12) )); diff --git a/public/include/classes/coins/coin_base.class.php b/public/include/classes/coins/coin_base.class.php index 64e412e2..1eb5470c 100644 --- a/public/include/classes/coins/coin_base.class.php +++ b/public/include/classes/coins/coin_base.class.php @@ -40,7 +40,7 @@ class CoinBase extends Base { * according to our configuration difficulty **/ public function calcEstaimtedShares($dDifficulty) { - return (int)round((pow(2, (32 - $this->target_bits)) * $dDifficulty) / pow(2, ($this->config['difficulty'] - 16))); + return (int)round(pow(2, (32 - $this->target_bits)) * $dDifficulty, 0); } /** diff --git a/public/include/classes/share.class.php b/public/include/classes/share.class.php index 0d11c4d5..3dd0e573 100644 --- a/public/include/classes/share.class.php +++ b/public/include/classes/share.class.php @@ -75,7 +75,7 @@ class Share Extends Base { **/ public function getRoundShares($previous_upstream=0, $current_upstream) { $stmt = $this->mysqli->prepare("SELECT - ROUND(IFNULL(SUM(IF(s.difficulty=0, POW(2, (" . $this->config['difficulty'] . " - 16)), s.difficulty)), 0) / POW(2, (" . $this->config['difficulty'] . " - 16)), 8) AS total + IFNULL(SUM(IF(s.difficulty=0, POW(2, (" . $this->config['difficulty'] . " - 16)), s.difficulty)), 0) AS total FROM $this->table AS s LEFT JOIN " . $this->user->getTableName() . " AS a ON a.username = SUBSTRING_INDEX( s.username , '.', 1 ) @@ -99,8 +99,8 @@ class Share Extends Base { a.id, SUBSTRING_INDEX( s.username , '.', 1 ) as username, a.no_fees AS no_fees, - 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 + 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->table AS s LEFT JOIN " . $this->user->getTableName() . " AS a ON a.username = SUBSTRING_INDEX( s.username , '.', 1 ) @@ -146,8 +146,8 @@ class Share Extends Base { a.id, SUBSTRING_INDEX( s.username , '.', 1 ) as account, a.no_fees AS no_fees, - 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 + 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->tableArchive AS s LEFT JOIN " . $this->user->getTableName() . " AS a ON a.username = SUBSTRING_INDEX( s.username , '.', 1 ) From 1f6ef81b9c3f690b180bf088d00a66840bec235f Mon Sep 17 00:00:00 2001 From: Sebastian Grewe Date: Fri, 21 Mar 2014 12:47:24 +0100 Subject: [PATCH 2/4] [ADDED] SQL Upgrade Script --- public/include/version.inc.php | 2 +- upgrade/db_version_0.0.8.php | 36 ++++++++++++++++++++++++ upgrade/shared.inc.php | 51 ++++++++++++++++++++++++++++++++++ 3 files changed, 88 insertions(+), 1 deletion(-) create mode 100755 upgrade/db_version_0.0.8.php create mode 100644 upgrade/shared.inc.php diff --git a/public/include/version.inc.php b/public/include/version.inc.php index 7244eb91..a9065e8c 100644 --- a/public/include/version.inc.php +++ b/public/include/version.inc.php @@ -2,7 +2,7 @@ $defflip = (!cfip()) ? exit(header('HTTP/1.1 401 Unauthorized')) : 1; define('MPOS_VERSION', '0.0.4'); -define('DB_VERSION', '0.0.7'); +define('DB_VERSION', '0.0.8'); define('CONFIG_VERSION', '0.0.7'); // Fetch installed database version diff --git a/upgrade/db_version_0.0.8.php b/upgrade/db_version_0.0.8.php new file mode 100755 index 00000000..de58dd30 --- /dev/null +++ b/upgrade/db_version_0.0.8.php @@ -0,0 +1,36 @@ +#!/usr/bin/php +getValue('DB_VERSION'); // Our actual version installed + +// Upgrade specific variables +$dDifficulty = POW(2, ($config['difficulty'] - 16)); +$aSql[] = "UPDATE " . $statistics->getTableName() . " SET valid = valid * $dDifficulty, invalid = invalid * $dDifficulty, pplns_valid = pplns_valid * $dDifficulty, pplns_invalid = pplns_invalid * $dDifficulty"; +$aSql[] = "UPDATE " . $block->getTableName() . " SET shares = shares * $dDifficulty"; +$aSql[] = "UPDATE " . $setting->getTableName() . " SET value = '0.0.8' WHERE name = 'DB_VERSION'"; + +if ($db_version_now == $db_version_old && version_compare($db_version_now, DB_VERSION, '<')) { + // Run the upgrade + echo 'Starting database migration to version ' . $db_version_new . PHP_EOL; + foreach ($aSql as $sql) { + echo ' Preparing: ' . $sql . PHP_EOL; + $stmt = $mysqli->prepare($sql); + if ($stmt && $stmt->execute()) { + echo ' success' . PHP_EOL; + } else { + echo ' failed: ' . $mysqli->error . PHP_EOL; + exit(1); + } + } +} +?> diff --git a/upgrade/shared.inc.php b/upgrade/shared.inc.php new file mode 100644 index 00000000..0f0638cb --- /dev/null +++ b/upgrade/shared.inc.php @@ -0,0 +1,51 @@ + From 055e4259e15516466a57e95249df7208b34a4373 Mon Sep 17 00:00:00 2001 From: Sebastian Grewe Date: Fri, 21 Mar 2014 12:54:29 +0100 Subject: [PATCH 3/4] [REMOVED] Baseline shares from statistics --- public/include/classes/statistics.class.php | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/public/include/classes/statistics.class.php b/public/include/classes/statistics.class.php index d368afe4..c9de9d24 100644 --- a/public/include/classes/statistics.class.php +++ b/public/include/classes/statistics.class.php @@ -104,7 +104,7 @@ class Statistics extends Base { b.*, a.username AS finder, a.is_anonymous AS is_anonymous, - ROUND((difficulty * POW(2, 32 - " . $this->coin->getTargetBits() . ")) / POW(2, (" . $this->config['difficulty'] . " -16)), 0) AS estshares + ROUND(difficulty * POW(2, 32 - " . $this->coin->getTargetBits() . "), 0) AS estshares FROM " . $this->block->getTableName() . " AS b LEFT JOIN " . $this->user->getTableName() . " AS a ON b.account_id = a.id @@ -127,7 +127,7 @@ class Statistics extends Base { b.*, a.username AS finder, a.is_anonymous AS is_anonymous, - ROUND((difficulty * POW(2, 32 - " . $this->coin->getTargetBits() . ")) / POW(2, (" . $this->config['difficulty'] . " -16)), 0) AS estshares + ROUND(difficulty * POW(2, 32 - " . $this->coin->getTargetBits() . "), 0) AS estshares FROM " . $this->block->getTableName() . " AS b LEFT JOIN " . $this->user->getTableName() . " AS a ON b.account_id = a.id @@ -293,8 +293,8 @@ class Statistics extends Base { } $stmt = $this->mysqli->prepare(" SELECT - 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 + ROUND(IFNULL(SUM(IF(our_result='Y', IF(difficulty=0, POW(2, (" . $this->config['difficulty'] . " - 16)), difficulty), 0)), 0), 0) AS valid, + ROUND(IFNULL(SUM(IF(our_result='N', IF(difficulty=0, POW(2, (" . $this->config['difficulty'] . " - 16)), difficulty), 0)), 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() ) @@ -316,8 +316,8 @@ class Statistics extends Base { } $stmt = $this->mysqli->prepare(" SELECT - 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, + ROUND(IFNULL(SUM(IF(our_result='Y', IF(s.difficulty=0, POW(2, (" . $this->config['difficulty'] . " - 16)), s.difficulty), 0)), 0), 0) AS valid, + ROUND(IFNULL(SUM(IF(our_result='N', IF(s.difficulty=0, POW(2, (" . $this->config['difficulty'] . " - 16)), s.difficulty), 0)), 0), 0) AS invalid, u.id AS id, u.donate_percent AS donate_percent, u.is_anonymous AS is_anonymous, @@ -368,8 +368,8 @@ class Statistics extends Base { if ($data = $this->memcache->get(__FUNCTION__ . $account_id)) return $data; $stmt = $this->mysqli->prepare(" SELECT - 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 + ROUND(IFNULL(SUM(IF(our_result='Y', IF(difficulty=0, POW(2, (" . $this->config['difficulty'] . " - 16)), difficulty), 0)), 0), 0) AS valid, + ROUND(IFNULL(SUM(IF(our_result='N', IF(difficulty=0, POW(2, (" . $this->config['difficulty'] . " - 16)), difficulty), 0)), 0), 0) AS invalid FROM " . $this->share->getTableName() . " WHERE username LIKE ? AND UNIX_TIMESTAMP(time) >IFNULL((SELECT MAX(b.time) FROM " . $this->block->getTableName() . " AS b),0)"); @@ -500,7 +500,7 @@ class Statistics extends Base { if ($this->getGetCache() && $data = $this->memcache->get(__FUNCTION__ . $account_id)) return $data; $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), 0) AS total FROM " . $this->share->getTableName() . " WHERE username LIKE ? AND id > ? @@ -603,7 +603,7 @@ class Statistics extends Base { a.username AS account, a.donate_percent AS donate_percent, a.is_anonymous AS is_anonymous, - 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 + ROUND(IFNULL(SUM(IF(s.difficulty=0, POW(2, (" . $this->config['difficulty'] . " - 16)), s.difficulty)), 0), 0) AS shares FROM " . $this->share->getTableName() . " AS s LEFT JOIN " . $this->user->getTableName() . " AS a ON SUBSTRING_INDEX( s.username, '.', 1 ) = a.username From d72b4f6a51656c97347736aee940d89adc027308 Mon Sep 17 00:00:00 2001 From: Sebastian Grewe Date: Fri, 21 Mar 2014 12:56:31 +0100 Subject: [PATCH 4/4] [REMOVED] Baseline from roundstats --- public/include/classes/roundstats.class.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/public/include/classes/roundstats.class.php b/public/include/classes/roundstats.class.php index 81c8f1d1..8c3f0315 100644 --- a/public/include/classes/roundstats.class.php +++ b/public/include/classes/roundstats.class.php @@ -78,7 +78,7 @@ class RoundStats extends Base { SELECT b.id, height, blockhash, amount, confirmations, difficulty, FROM_UNIXTIME(time) as time, shares, IF(a.is_anonymous, 'anonymous', a.username) AS finder, - ROUND((difficulty * 65535) / POW(2, (" . $this->config['difficulty'] . " -16)), 0) AS estshares, + ROUND(difficulty * POW(2, 32 - " . $this->coin->getTargetBits() . "), 0) AS estshares, (time - (SELECT time FROM $this->tableBlocks WHERE height < ? ORDER BY height DESC LIMIT 1)) AS round_time FROM " . $this->block->getTableName() . " as b LEFT JOIN " . $this->user->getTableName() . " AS a ON b.account_id = a.id @@ -288,3 +288,4 @@ $roundstats->setUser($user); $roundstats->setStatistics($statistics); $roundstats->setBlock($block); $roundstats->setTransaction($transaction); +$roundstats->setCoin($coin);