Skip to content
This repository has been archived by the owner on Dec 2, 2020. It is now read-only.

Commit

Permalink
PPLNT fix for multiple instances.
Browse files Browse the repository at this point in the history
  • Loading branch information
crutched committed Mar 24, 2018
1 parent 53e9fdb commit ed76b45
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 21 deletions.
2 changes: 1 addition & 1 deletion init.js
Expand Up @@ -289,7 +289,7 @@ var spawnPoolWorkers = function(){
//var timeChangeTotal = roundTo(Math.max(now - lastStartTime, 0) / 1000, 4);
if (timeChangeSec < 900) {
// loyal miner keeps mining :)
redisCommands.push(['hincrbyfloat', msg.coin + ':shares:timesCurrent', workerAddress, timeChangeSec]);
redisCommands.push(['hincrbyfloat', msg.coin + ':shares:timesCurrent', workerAddress + "." + poolConfigs[msg.coin].poolId, timeChangeSec]);
//logger.debug('PPLNT', msg.coin, 'Thread '+msg.thread, workerAddress+':{totalTimeSec:'+timeChangeTotal+', timeChangeSec:'+timeChangeSec+'}');
connection.multi(redisCommands).exec(function(err, replies){
if (err)
Expand Down
39 changes: 25 additions & 14 deletions libs/paymentProcessor.js
Expand Up @@ -908,8 +908,31 @@ function SetupForPool(logger, poolOptions, setupFinished){
logger.error(logSystem, logComponent, 'No worker shares for round: ' + round.height + ' blockHash: ' + round.blockHash);
return;
}
var workerTimes = allWorkerTimes[i];

var workerTimesWithPoolIds = allWorkerTimes[i];
var workerTimes = {};
var maxTime = 0;
if (pplntEnabled === true) {
for (var workerAddressWithPoolId in workerTimesWithPoolIds){
var workerWithoutPoolId = workerAddressWithPoolId.split('.')[0];
var workerTimeFloat = parseFloat(workerTimesWithPoolIds[workerAddressWithPoolId]);
if (maxTime < workerTimeFloat) {
maxTime = workerTimeFloat;
}
if (!(workerWithoutPoolId in workerTimes)) {
workerTimes[workerWithoutPoolId] = workerTimeFloat;
} else {
// add time from other instances with penalty
if (workerTimes[workerWithoutPoolId] < workerTimeFloat) {
workerTimes[workerWithoutPoolId] = workerTimes[workerWithoutPoolId] * 0.5 + workerTimeFloat;
} else {
workerTimes[workerWithoutPoolId] = workerTimes[workerWithoutPoolId] + workerTimeFloat * 0.5;
}
if (workerTimes[workerWithoutPoolId] > maxTime) {
workerTimes[workerWithoutPoolId] = maxTime;
}
}
}
}
switch (round.category){
case 'kicked':
case 'orphan':
Expand All @@ -926,12 +949,6 @@ function SetupForPool(logger, poolOptions, setupFinished){
// adjust block immature .. tx fees
immature = Math.round(immature - feeSatoshi);

// find most time spent in this round by single worker
maxTime = 0;
for (var workerAddress in workerTimes){
if (maxTime < parseFloat(workerTimes[workerAddress]))
maxTime = parseFloat(workerTimes[workerAddress]);
}
// total up shares for round
for (var workerAddress in workerShares){
var worker = workers[workerAddress] = (workers[workerAddress] || {});
Expand Down Expand Up @@ -984,12 +1001,6 @@ function SetupForPool(logger, poolOptions, setupFinished){
// adjust block reward .. tx fees
reward = Math.round(reward - feeSatoshi);

// find most time spent in this round by single worker
maxTime = 0;
for (var workerAddress in workerTimes){
if (maxTime < parseFloat(workerTimes[workerAddress]))
maxTime = parseFloat(workerTimes[workerAddress]);
}
// total up shares for round
for (var workerAddress in workerShares){
var worker = workers[workerAddress] = (workers[workerAddress] || {});
Expand Down
14 changes: 8 additions & 6 deletions libs/stats.js
Expand Up @@ -616,12 +616,10 @@ module.exports = function(logger, portalConfig, poolConfigs){
}
for (var worker in coinStats.currentRoundTimes) {
var time = parseFloat(coinStats.currentRoundTimes[worker]);
if (_maxTimeShare < time)
_maxTimeShare = time;

var miner = worker.split(".")[0];
if (miner in coinStats.miners) {
coinStats.miners[miner].currRoundTime += parseFloat(coinStats.currentRoundTimes[worker]);
if (_maxTimeShare < time) { _maxTimeShare = time; }
var miner = worker.split(".")[0]; // split poolId from minerAddress
if (miner in coinStats.miners && coinStats.miners[miner].currRoundTime < time) {
coinStats.miners[miner].currRoundTime = time;
}
}

Expand All @@ -636,6 +634,10 @@ module.exports = function(logger, portalConfig, poolConfigs){
coinStats.workers[worker].luckHours = ((_networkHashRate / _wHashRate * _blocktime) / (60 * 60)).toFixed(3);
coinStats.workers[worker].hashrate = _workerRate;
coinStats.workers[worker].hashrateString = _this.getReadableHashRateString(_workerRate);
var miner = worker.split('.')[0];
if (miner in coinStats.miners) {
coinStats.workers[worker].currRoundTime = coinStats.miners[miner].currRoundTime;
}
}
for (var miner in coinStats.miners) {
var _workerRate = shareMultiplier * coinStats.miners[miner].shares / portalConfig.website.stats.hashrateWindow;
Expand Down
3 changes: 3 additions & 0 deletions pool_configs/zen_example.json
Expand Up @@ -54,6 +54,9 @@
}
}
},

"poolId": "main",
"_comment_poolId": "use it for region identification: eu, us, asia or keep default if you have one stratum instance for one coin",

"daemons": [
{
Expand Down

0 comments on commit ed76b45

Please sign in to comment.