Skip to content

Commit 1552fc2

Browse files
committed
Merge pull request #2290 from MPOS/coin-rounding-setting
Coin rounding setting
2 parents 8cf7c99 + 4147ef5 commit 1552fc2

File tree

16 files changed

+260
-111
lines changed

16 files changed

+260
-111
lines changed

cronjobs/pplns_payout.php

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@
3838
$monitoring->endCronjob($cron_name, 'E0011', 0, true, false);
3939
}
4040

41+
// Fetch precision
42+
$precision = $coin->getCoinValuePrevision();
43+
$table_precision = $coin->getCoinValuePrevision() + 3;
44+
4145
$log->logDebug('Starting PPLNS payout process');
4246
$count = 0;
4347
foreach ($aAllBlocks as $iIndex => $aBlock) {
@@ -181,7 +185,7 @@
181185
}
182186

183187
// Table header for account shares
184-
$strLogMask = "| %5.5s | %-15.15s | %15.15s | %15.15s | %12.12s | %15.15s | %15.15s | %15.15s | %15.15s |";
188+
$strLogMask = "| %5.5s | %-15.15s | %15.15s | %15.15s | %12.12s | %${table_precision}.${table_precision}s | %${table_precision}.${table_precision}s | %${table_precision}.${table_precision}s | %${table_precision}.${table_precision}s |";
185189
$log->logInfo(sprintf($strLogMask, 'ID', 'Username', 'Valid', 'Invalid', 'Percentage', 'Payout', 'Donation', 'Fee', 'Bonus'));
186190

187191
// Loop through all accounts that have found shares for this round
@@ -197,27 +201,27 @@
197201

198202
// Payout based on PPLNS target shares, proportional payout for all users
199203
$aData['percentage'] = round(( 100 / $iRoundShares) * $aData['pplns_valid'], 8);
200-
$aData['payout'] = round(( $aData['percentage'] / 100 ) * $dReward, 8);
204+
$aData['payout'] = ( $aData['percentage'] / 100 ) * $dReward;
201205
// Defaults
202206
$aData['fee' ] = 0;
203207
$aData['donation'] = 0;
204208
$aData['pool_bonus'] = 0;
205209

206210
// Calculate pool fees
207211
if ($config['fees'] > 0 && $aData['no_fees'] == 0)
208-
$aData['fee'] = round($config['fees'] / 100 * $aData['payout'], 8);
212+
$aData['fee'] = $config['fees'] / 100 * $aData['payout'];
209213

210214
// Calculate pool bonus if it applies, will be paid from liquid assets!
211215
if ($config['pool_bonus'] > 0) {
212216
if ($config['pool_bonus_type'] == 'block') {
213-
$aData['pool_bonus'] = round(( $config['pool_bonus'] / 100 ) * $dReward, 8);
217+
$aData['pool_bonus'] = ( $config['pool_bonus'] / 100 ) * $dReward;
214218
} else {
215-
$aData['pool_bonus'] = round(( $config['pool_bonus'] / 100 ) * $aData['payout'], 8);
219+
$aData['pool_bonus'] = ( $config['pool_bonus'] / 100 ) * $aData['payout'];
216220
}
217221
}
218222

219223
// Calculate donation amount, fees not included
220-
$aData['donation'] = round($user->getDonatePercent($user->getUserId($aData['username'])) / 100 * ( $aData['payout'] - $aData['fee']), 8);
224+
$aData['donation'] = $user->getDonatePercent($user->getUserId($aData['username'])) / 100 * ( $aData['payout'] - $aData['fee']);
221225

222226
// Verbose output of this users calculations
223227
$log->logInfo(

cronjobs/pps_payout.php

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@
6363
}
6464

6565
// Per-share value to be paid out to users
66-
$pps_value = round($coin->calcPPSValue($pps_reward, $dDifficulty), 12);
66+
$pps_value = $coin->calcPPSValue($pps_reward, $dDifficulty);
6767

6868
// Find our last share accounted and last inserted share for PPS calculations
6969
if (!$iPreviousShareId = $setting->getValue('pps_last_share_id')) {
@@ -89,13 +89,15 @@
8989

9090
if (!empty($aAccountShares)) {
9191
// Runtime information for this payout
92+
$precision = $coin->getCoinValuePrevision();
93+
$table_precision = $coin->getCoinValuePrevision() + 3;
9294
$log->logInfo('Runtime information for this payout');
93-
$strLogMask = "| %-15.15s | %15.15s | %15.15s | %15.15s |";
94-
$log->logInfo(sprintf($strLogMask, 'PPS reward type', 'Reward Base', 'Difficulty', 'PPS Value'));
95-
$log->logInfo(sprintf($strLogMask, $strRewardType, $pps_reward, $dDifficulty, $pps_value));
95+
$strLogMask = "| %-15.15s | %15.15s | %15.15s | %${table_precision}.${table_precision}s | %3.3s |";
96+
$log->logInfo(sprintf($strLogMask, 'PPS reward type', 'Reward Base', 'Difficulty', 'PPS Value', 'Precision'));
97+
$log->logInfo(sprintf($strLogMask, $strRewardType, $pps_reward, $dDifficulty, $pps_value, $precision));
9698
$log->logInfo('Per-user payout information');
97-
$strLogMask = "| %8.8s | %25.25s | %15.15s | %15.15s | %18.18s | %18.18s | %18.18s |";
98-
$log->logInfo(sprintf($strLogMask, 'User ID', 'Username', 'Invalid', 'Valid', ' * PPS Value', ' = Payout', 'Donation', 'Fee'));
99+
$strLogMask = "| %8.8s | %25.25s | %15.15s | %${table_precision}.${table_precision}s | %${table_precision}.${table_precision}s | %${table_precision}.${table_precision}s | %${table_precision}.${table_precision}s |";
100+
$log->logInfo(sprintf($strLogMask, 'User ID', 'Username', 'Invalid', 'Valid', '* PPS Value', ' = Payout', 'Donation', 'Fee'));
99101
}
100102

101103
foreach ($aAccountShares as $aData) {
@@ -106,21 +108,21 @@
106108
}
107109

108110
// Payout for this user
109-
$aData['payout'] = round($aData['valid'] * $pps_value, 12);
111+
$aData['payout'] = $aData['valid'] * $pps_value;
110112

111113
// Defaults
112114
$aData['fee' ] = 0;
113115
$aData['donation'] = 0;
114116

115117
// Calculate block fees
116118
if ($config['fees'] > 0 && $aData['no_fees'] == 0)
117-
$aData['fee'] = round($config['fees'] / 100 * $aData['payout'], 12);
119+
$aData['fee'] = $config['fees'] / 100 * $aData['payout'];
118120
// Calculate donation amount
119-
$aData['donation'] = round($user->getDonatePercent($user->getUserId($aData['username'])) / 100 * ( $aData['payout'] - $aData['fee']), 12);
121+
$aData['donation'] = $user->getDonatePercent($user->getUserId($aData['username'])) / 100 * ( $aData['payout'] - $aData['fee']);
120122

121123
$log->logInfo(sprintf(
122124
$strLogMask, $aData['id'], $aData['username'], $aData['invalid'], $aData['valid'],
123-
number_format($pps_value, 12), number_format($aData['payout'], 12), number_format($aData['donation'], 12), number_format($aData['fee'], 12)
125+
number_format($pps_value, $precision), number_format($aData['payout'], $precision), number_format($aData['donation'], $precision), number_format($aData['fee'], $precision)
124126
));
125127

126128
// Add new credit transaction

cronjobs/proportional_payout.php

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,13 @@
3838
$monitoring->endCronjob($cron_name, 'E0011', 0, true, false);
3939
}
4040

41+
// Fetch precision
42+
$precision = $coin->getCoinValuePrevision();
43+
$table_precision = $coin->getCoinValuePrevision() + 3;
44+
4145
$count = 0;
4246
// Table header for account shares
43-
$strLogMask = "| %10.10s | %-5.5s | %15.15s | %15.15s | %12.12s | %12.12s | %15.15s | %15.15s | %15.15s | %15.15s |";
47+
$strLogMask = "| %10.10s | %-5.5s | %15.15s | %15.15s | %12.12s | %12.12s | %${table_precision}.${table_precision}s | %${table_precision}.${table_precision}s | %${table_precision}.${table_precision}s | %${table_precision}.${table_precision}s |";
4448
$log->logInfo(sprintf($strLogMask, 'Block', 'ID', 'Username', 'Valid', 'Invalid', 'Percentage', 'Payout', 'Donation', 'Fee', 'Bonus'));
4549
foreach ($aAllBlocks as $iIndex => $aBlock) {
4650
// If we have unaccounted blocks without share_ids, they might not have been inserted yet
@@ -87,29 +91,29 @@
8791
$aData['fee' ] = 0;
8892
$aData['donation'] = 0;
8993
$aData['pool_bonus'] = 0;
90-
$aData['percentage'] = round(( 100 / $iRoundShares ) * $aData['valid'], 8);
91-
$aData['payout'] = round(( $aData['percentage'] / 100 ) * $dReward, 8);
94+
$aData['percentage'] = ( 100 / $iRoundShares ) * $aData['valid'];
95+
$aData['payout'] = ( $aData['percentage'] / 100 ) * $dReward;
9296

9397
// Calculate pool fees if they apply
9498
if ($config['fees'] > 0 && $aData['no_fees'] == 0)
95-
$aData['fee'] = round($config['fees'] / 100 * $aData['payout'], 8);
99+
$aData['fee'] = $config['fees'] / 100 * $aData['payout'];
96100

97101
// Calculate pool bonus if it applies, will be paid from liquid assets!
98102
if ($config['pool_bonus'] > 0) {
99103
if ($config['pool_bonus_type'] == 'block') {
100-
$aData['pool_bonus'] = round(( $config['pool_bonus'] / 100 ) * $dReward, 8);
104+
$aData['pool_bonus'] = ( $config['pool_bonus'] / 100 ) * $dReward;
101105
} else {
102-
$aData['pool_bonus'] = round(( $config['pool_bonus'] / 100 ) * $aData['payout'], 8);
106+
$aData['pool_bonus'] = ( $config['pool_bonus'] / 100 ) * $aData['payout'];
103107
}
104108
}
105109

106110
// Calculate donation amount, fees not included
107-
$aData['donation'] = round($user->getDonatePercent($user->getUserId($aData['username'])) / 100 * ( $aData['payout'] - $aData['fee']), 8);
111+
$aData['donation'] = $user->getDonatePercent($user->getUserId($aData['username'])) / 100 * ( $aData['payout'] - $aData['fee']);
108112

109113
// Verbose output of this users calculations
110114
$log->logInfo(
111115
sprintf($strLogMask, $aBlock['height'], $aData['id'], $aData['username'], $aData['valid'], $aData['invalid'],
112-
number_format($aData['percentage'], 8), number_format($aData['payout'], 8), number_format($aData['donation'], 8), number_format($aData['fee'], 8), number_format($aData['pool_bonus'], 8))
116+
number_format($aData['percentage'], $precision), number_format($aData['payout'], $precision), number_format($aData['donation'], $precision), number_format($aData['fee'], $precision), number_format($aData['pool_bonus'], $precision))
113117
);
114118

115119
// Update user share statistics

include/classes/coins/coin_base.class.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,23 @@ class CoinBase extends Base {
1515
// Our coins share difficulty precision
1616
protected $share_difficulty_precision = 0;
1717

18+
// Our coin value precision, mostly used on frontend
19+
protected $coin_value_precision = 8;
20+
1821
/**
1922
* Read our target bits
2023
**/
2124
public function getTargetBits() {
2225
return $this->target_bits;
2326
}
2427

28+
/**
29+
* Read our coin value precision
30+
**/
31+
public function getCoinValuePrevision() {
32+
return $this->coin_value_precision;
33+
}
34+
2535
/**
2636
* Read our share difficulty precision
2737
**/

include/classes/coins/coin_sha256d.class.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
**/
99
class Coin extends CoinBase {
1010
protected $target_bits = 32;
11+
protected $coin_value_precision = 20;
1112
}
1213

1314
?>

include/classes/transaction.class.php

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,9 @@ class Transaction extends Base {
1616
* @return bool
1717
**/
1818
public function addTransaction($account_id, $amount, $type='Credit', $block_id=NULL, $coin_address=NULL, $txid=NULL) {
19+
$amount = number_format($amount, $this->coin->getCoinValuePrevision(), '.', '');
1920
$stmt = $this->mysqli->prepare("INSERT INTO $this->table (account_id, amount, block_id, type, coin_address, txid) VALUES (?, ?, ?, ?, ?, ?)");
20-
if ($this->checkStmt($stmt) && $stmt->bind_param("idisss", $account_id, $amount, $block_id, $type, $coin_address, $txid) && $stmt->execute()) {
21+
if ($this->checkStmt($stmt) && $stmt->bind_param("isisss", $account_id, $amount, $block_id, $type, $coin_address, $txid) && $stmt->execute()) {
2122
$this->insert_id = $stmt->insert_id;
2223
return true;
2324
}
@@ -296,11 +297,11 @@ public function getLockedBalance() {
296297
$this->debug->append("STA " . __METHOD__, 4);
297298
$stmt = $this->mysqli->prepare("
298299
SELECT
299-
ROUND((
300+
(
300301
SUM( IF( ( t.type IN ('Credit','Bonus') AND b.confirmations >= ? ) OR t.type = 'Credit_PPS', t.amount, 0 ) ) -
301302
SUM( IF( t.type IN ('Debit_MP', 'Debit_AP'), t.amount, 0 ) ) -
302303
SUM( IF( ( t.type IN ('Donation','Fee') AND b.confirmations >= ? ) OR ( t.type IN ('Donation_PPS', 'Fee_PPS', 'TXFee') ), t.amount, 0 ) )
303-
), 8) AS balance
304+
) AS balance
304305
FROM $this->table AS t
305306
LEFT JOIN " . $this->block->getTableName() . " AS b
306307
ON t.block_id = b.id
@@ -319,19 +320,19 @@ public function getBalance($account_id) {
319320
$this->debug->append("STA " . __METHOD__, 4);
320321
$stmt = $this->mysqli->prepare("
321322
SELECT
322-
IFNULL(ROUND((
323+
IFNULL((
323324
SUM( IF( ( t.type IN ('Credit','Bonus') AND b.confirmations >= ? ) OR t.type = 'Credit_PPS', t.amount, 0 ) ) -
324325
SUM( IF( t.type IN ('Debit_MP', 'Debit_AP'), t.amount, 0 ) ) -
325326
SUM( IF( ( t.type IN ('Donation','Fee') AND b.confirmations >= ? ) OR ( t.type IN ('Donation_PPS', 'Fee_PPS', 'TXFee') ), t.amount, 0 ) )
326-
), 8), 0) AS confirmed,
327-
IFNULL(ROUND((
327+
), 0) AS confirmed,
328+
IFNULL((
328329
SUM( IF( t.type IN ('Credit','Bonus') AND b.confirmations < ? AND b.confirmations >= 0, t.amount, 0 ) ) -
329330
SUM( IF( t.type IN ('Donation','Fee') AND b.confirmations < ? AND b.confirmations >= 0, t.amount, 0 ) )
330-
), 8), 0) AS unconfirmed,
331-
IFNULL(ROUND((
331+
), 0) AS unconfirmed,
332+
IFNULL((
332333
SUM( IF( t.type IN ('Credit','Bonus') AND b.confirmations = -1, t.amount, 0) ) -
333334
SUM( IF( t.type IN ('Donation','Fee') AND b.confirmations = -1, t.amount, 0) )
334-
), 8), 0) AS orphaned
335+
), 0) AS orphaned
335336
FROM $this->table AS t
336337
LEFT JOIN " . $this->block->getTableName() . " AS b
337338
ON t.block_id = b.id
@@ -357,12 +358,10 @@ public function getAPQueue($limit=250) {
357358
a.ap_threshold,
358359
ca.coin_address,
359360
IFNULL(
360-
ROUND(
361361
(
362362
SUM( IF( ( t.type IN ('Credit','Bonus') AND b.confirmations >= " . $this->config['confirmations'] . ") OR t.type = 'Credit_PPS', t.amount, 0 ) ) -
363363
SUM( IF( t.type IN ('Debit_MP', 'Debit_AP'), t.amount, 0 ) ) -
364364
SUM( IF( ( t.type IN ('Donation','Fee') AND b.confirmations >= " . $this->config['confirmations'] . ") OR ( t.type IN ('Donation_PPS', 'Fee_PPS', 'TXFee') ), t.amount, 0 ) )
365-
), 8
366365
), 0
367366
) AS confirmed
368367
FROM $this->table AS t
@@ -451,12 +450,10 @@ public function getMPQueue($limit=250) {
451450
ca.coin_address,
452451
p.id AS payout_id,
453452
IFNULL(
454-
ROUND(
455453
(
456454
SUM( IF( ( t.type IN ('Credit','Bonus') AND b.confirmations >= " . $this->config['confirmations'] . ") OR t.type = 'Credit_PPS', t.amount, 0 ) ) -
457455
SUM( IF( t.type IN ('Debit_MP', 'Debit_AP'), t.amount, 0 ) ) -
458456
SUM( IF( ( t.type IN ('Donation','Fee') AND b.confirmations >= " . $this->config['confirmations'] . ") OR ( t.type IN ('Donation_PPS', 'Fee_PPS', 'TXFee') ), t.amount, 0 ) )
459-
), 8
460457
), 0
461458
) AS confirmed
462459
FROM " . $this->payout->getTableName() . " AS p
@@ -481,7 +478,9 @@ public function getMPQueue($limit=250) {
481478
$transaction = new Transaction();
482479
$transaction->setMemcache($memcache);
483480
$transaction->setNotification($notification);
481+
$transaction->setSetting($setting);
484482
$transaction->setDebug($debug);
483+
$transaction->setCoin($coin);
485484
$transaction->setCoinAddress($coin_address);
486485
$transaction->setMysql($mysqli);
487486
$transaction->setConfig($config);

include/config/admin_settings.inc.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,7 @@
324324
);
325325
$aSettings['system'][] = array(
326326
'display' => 'Date format string', 'type' => 'text',
327-
'site' => 25,
327+
'size' => 25,
328328
'default' => '%m/%d/%Y %H:%M:%S',
329329
'name' => 'system_date_format', 'value' => $setting->getValue('system_date_format'),
330330
'tooltip' => 'Date format to be used throughout the site. Please check PHP strftime for details.'

include/pages/dashboard.inc.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
}
5050

5151
// Make it available in Smarty
52+
$smarty->assign('PRECISION', $coin->getCoinValuePrevision());
5253
$smarty->assign('BLOCKSFOUND', $aLastBlocks);
5354
$smarty->assign('DISABLED_DASHBOARD', $setting->getValue('disable_dashboard'));
5455
$smarty->assign('DISABLED_DASHBOARD_API', $setting->getValue('disable_dashboard_api'));

include/smarty_globals.inc.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,8 @@
176176
break;
177177
case 'pps':
178178
$aGlobal['userdata']['pps']['unpaidshares'] = $statistics->getUserUnpaidPPSShares($_SESSION['USERDATA']['username'], $_SESSION['USERDATA']['id'], $setting->getValue('pps_last_share_id'));
179-
$aGlobal['ppsvalue'] = number_format($statistics->getPPSValue(), 12);
179+
// We use coin precision + 8 to display PPS value
180+
$aGlobal['ppsvalue'] = number_format($statistics->getPPSValue(), $coin->getCoinValuePrevision() + 8);
180181
$aGlobal['poolppsvalue'] = $aGlobal['ppsvalue'] * pow(2, $config['difficulty'] - 16);
181182
$aGlobal['userdata']['estimates'] = $statistics->getUserEstimates($aGlobal['userdata']['sharerate'], $aGlobal['userdata']['sharedifficulty'], $aGlobal['userdata']['donate_percent'], $aGlobal['userdata']['no_fees'], $aGlobal['ppsvalue']);
182183
break;

include/version.inc.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
$defflip = (!cfip()) ? exit(header('HTTP/1.1 401 Unauthorized')) : 1;
33

44
define('MPOS_VERSION', '0.0.4');
5-
define('DB_VERSION', '0.0.14');
5+
define('DB_VERSION', '0.0.15');
66
define('CONFIG_VERSION', '0.0.8');
77
define('HASH_VERSION', 1);
88

0 commit comments

Comments
 (0)