Merge branch 'drop-baseline-shares' of https://github.com/MPOS/php-mpos into development

This commit is contained in:
iAmShorty 2014-03-21 13:00:31 +01:00
commit 9a79363aba
8 changed files with 109 additions and 22 deletions

View File

@ -105,9 +105,8 @@ foreach ($aAccountShares as $aData) {
continue; continue;
} }
// MPOS uses a base difficulty setting to avoid showing weightened shares // Payout for this user
// Since we need weightened shares here, we go back to the proper value for payouts $aData['payout'] = round($aData['valid'] * $pps_value, 12);
$aData['payout'] = round($aData['valid'] * pow(2, ($config['difficulty'] - 16)) * $pps_value, 12);
// Defaults // Defaults
$aData['fee' ] = 0; $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); $aData['donation'] = round($user->getDonatePercent($user->getUserId($aData['username'])) / 100 * ( $aData['payout'] - $aData['fee']), 12);
$log->logInfo(sprintf( $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) number_format($pps_value, 12), number_format($aData['payout'], 12), number_format($aData['donation'], 12), number_format($aData['fee'], 12)
)); ));

View File

@ -40,7 +40,7 @@ class CoinBase extends Base {
* according to our configuration difficulty * according to our configuration difficulty
**/ **/
public function calcEstaimtedShares($dDifficulty) { 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);
} }
/** /**

View File

@ -78,7 +78,7 @@ class RoundStats extends Base {
SELECT SELECT
b.id, height, blockhash, amount, confirmations, difficulty, FROM_UNIXTIME(time) as time, shares, b.id, height, blockhash, amount, confirmations, difficulty, FROM_UNIXTIME(time) as time, shares,
IF(a.is_anonymous, 'anonymous', a.username) AS finder, 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 (time - (SELECT time FROM $this->tableBlocks WHERE height < ? ORDER BY height DESC LIMIT 1)) AS round_time
FROM " . $this->block->getTableName() . " as b FROM " . $this->block->getTableName() . " as b
LEFT JOIN " . $this->user->getTableName() . " AS a ON b.account_id = a.id LEFT JOIN " . $this->user->getTableName() . " AS a ON b.account_id = a.id
@ -288,3 +288,4 @@ $roundstats->setUser($user);
$roundstats->setStatistics($statistics); $roundstats->setStatistics($statistics);
$roundstats->setBlock($block); $roundstats->setBlock($block);
$roundstats->setTransaction($transaction); $roundstats->setTransaction($transaction);
$roundstats->setCoin($coin);

View File

@ -75,7 +75,7 @@ class Share Extends Base {
**/ **/
public function getRoundShares($previous_upstream=0, $current_upstream) { public function getRoundShares($previous_upstream=0, $current_upstream) {
$stmt = $this->mysqli->prepare("SELECT $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 FROM $this->table AS s
LEFT JOIN " . $this->user->getTableName() . " AS a LEFT JOIN " . $this->user->getTableName() . " AS a
ON a.username = SUBSTRING_INDEX( s.username , '.', 1 ) ON a.username = SUBSTRING_INDEX( s.username , '.', 1 )
@ -99,8 +99,8 @@ class Share Extends Base {
a.id, a.id,
SUBSTRING_INDEX( s.username , '.', 1 ) as username, SUBSTRING_INDEX( s.username , '.', 1 ) as username,
a.no_fees AS no_fees, 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, IFNULL(SUM(IF(our_result='Y', IF(s.difficulty=0, POW(2, (" . $this->config['difficulty'] . " - 16)), s.difficulty), 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) / POW(2, (" . $this->config['difficulty'] . " - 16)), 8) AS invalid 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 FROM $this->table AS s
LEFT JOIN " . $this->user->getTableName() . " AS a LEFT JOIN " . $this->user->getTableName() . " AS a
ON a.username = SUBSTRING_INDEX( s.username , '.', 1 ) ON a.username = SUBSTRING_INDEX( s.username , '.', 1 )
@ -146,8 +146,8 @@ class Share Extends Base {
a.id, a.id,
SUBSTRING_INDEX( s.username , '.', 1 ) as account, SUBSTRING_INDEX( s.username , '.', 1 ) as account,
a.no_fees AS no_fees, 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, IFNULL(SUM(IF(our_result='Y', IF(s.difficulty=0, pow(2, (" . $this->config['difficulty'] . " - 16)), s.difficulty), 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) / POW(2, (" . $this->config['difficulty'] . " - 16)), 8) AS invalid 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 FROM $this->tableArchive AS s
LEFT JOIN " . $this->user->getTableName() . " AS a LEFT JOIN " . $this->user->getTableName() . " AS a
ON a.username = SUBSTRING_INDEX( s.username , '.', 1 ) ON a.username = SUBSTRING_INDEX( s.username , '.', 1 )

View File

@ -104,7 +104,7 @@ class Statistics extends Base {
b.*, b.*,
a.username AS finder, a.username AS finder,
a.is_anonymous AS is_anonymous, 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 FROM " . $this->block->getTableName() . " AS b
LEFT JOIN " . $this->user->getTableName() . " AS a LEFT JOIN " . $this->user->getTableName() . " AS a
ON b.account_id = a.id ON b.account_id = a.id
@ -127,7 +127,7 @@ class Statistics extends Base {
b.*, b.*,
a.username AS finder, a.username AS finder,
a.is_anonymous AS is_anonymous, 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 FROM " . $this->block->getTableName() . " AS b
LEFT JOIN " . $this->user->getTableName() . " AS a LEFT JOIN " . $this->user->getTableName() . " AS a
ON b.account_id = a.id ON b.account_id = a.id
@ -293,8 +293,8 @@ class Statistics extends Base {
} }
$stmt = $this->mysqli->prepare(" $stmt = $this->mysqli->prepare("
SELECT 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='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) / POW(2, (" . $this->config['difficulty'] . " - 16)), 0) AS invalid 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() . " 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() ) if ( $this->checkStmt($stmt) && $stmt->execute() && $result = $stmt->get_result() )
@ -316,8 +316,8 @@ class Statistics extends Base {
} }
$stmt = $this->mysqli->prepare(" $stmt = $this->mysqli->prepare("
SELECT 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='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) / POW(2, (" . $this->config['difficulty'] . " - 16)), 0) AS invalid, 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.id AS id,
u.donate_percent AS donate_percent, u.donate_percent AS donate_percent,
u.is_anonymous AS is_anonymous, u.is_anonymous AS is_anonymous,
@ -368,8 +368,8 @@ class Statistics extends Base {
if ($data = $this->memcache->get(__FUNCTION__ . $account_id)) return $data; if ($data = $this->memcache->get(__FUNCTION__ . $account_id)) return $data;
$stmt = $this->mysqli->prepare(" $stmt = $this->mysqli->prepare("
SELECT 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='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) / POW(2, (" . $this->config['difficulty'] . " - 16)), 0) AS invalid 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() . " FROM " . $this->share->getTableName() . "
WHERE username LIKE ? WHERE username LIKE ?
AND UNIX_TIMESTAMP(time) >IFNULL((SELECT MAX(b.time) FROM " . $this->block->getTableName() . " AS b),0)"); 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; if ($this->getGetCache() && $data = $this->memcache->get(__FUNCTION__ . $account_id)) return $data;
$stmt = $this->mysqli->prepare(" $stmt = $this->mysqli->prepare("
SELECT 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() . " FROM " . $this->share->getTableName() . "
WHERE username LIKE ? WHERE username LIKE ?
AND id > ? AND id > ?
@ -603,7 +603,7 @@ class Statistics extends Base {
a.username AS account, a.username AS account,
a.donate_percent AS donate_percent, a.donate_percent AS donate_percent,
a.is_anonymous AS is_anonymous, 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 FROM " . $this->share->getTableName() . " AS s
LEFT JOIN " . $this->user->getTableName() . " AS a LEFT JOIN " . $this->user->getTableName() . " AS a
ON SUBSTRING_INDEX( s.username, '.', 1 ) = a.username ON SUBSTRING_INDEX( s.username, '.', 1 ) = a.username

View File

@ -2,7 +2,7 @@
$defflip = (!cfip()) ? exit(header('HTTP/1.1 401 Unauthorized')) : 1; $defflip = (!cfip()) ? exit(header('HTTP/1.1 401 Unauthorized')) : 1;
define('MPOS_VERSION', '0.0.4'); define('MPOS_VERSION', '0.0.4');
define('DB_VERSION', '0.0.7'); define('DB_VERSION', '0.0.8');
define('CONFIG_VERSION', '0.0.7'); define('CONFIG_VERSION', '0.0.7');
// Fetch installed database version // Fetch installed database version

36
upgrade/db_version_0.0.8.php Executable file
View File

@ -0,0 +1,36 @@
#!/usr/bin/php
<?php
/* Upgarde script for https://github.com/MPOS/php-mpos/issues/1981 */
// Change to working directory
chdir(dirname(__FILE__));
// Include all settings and classes
require_once('shared.inc.php');
// Version information
$db_version_old = '0.0.7'; // What version do we expect
$db_version_new = '0.0.8'; // What is the new version we wish to upgrade to
$db_version_now = $setting->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);
}
}
}
?>

51
upgrade/shared.inc.php Normal file
View File

@ -0,0 +1,51 @@
<?php
/*
Copyright:: 2013, Sebastian Grewe
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
// MODIFY THIS
// We need to find our include files so set this properly
define("BASEPATH", "../public/");
/*****************************************************
* No need to change beyond this point *
*****************************************************/
define('SECURITY', '*)WT#&YHfd');
// Whether or not to check SECHASH for validity, still checks if SECURITY defined as before if disabled
define('SECHASH_CHECK', false);
// change SECHASH every second, we allow up to 3 sec back for slow servers
if (SECHASH_CHECK) {
function fip($tr=0) { return md5(SECURITY.(time()-$tr).SECURITY); }
define('SECHASH', fip());
function cfip() { return (fip()==SECHASH||fip(1)==SECHASH||fip(2)==SECHASH) ? 1 : 0; }
} else {
function cfip() { return (@defined('SECURITY')) ? 1 : 0; }
}
// Include our configuration (holding defines for the requires)
require_once(BASEPATH . 'include/config/global.inc.dist.php');
require_once(BASEPATH . 'include/config/global.inc.php');
require_once(BASEPATH . 'include/config/security.inc.dist.php');
@include_once(BASEPATH . 'include/config/security.inc.php');
require_once(BASEPATH . 'include/bootstrap.php');
require_once(BASEPATH . 'include/version.inc.php');
?>