From 116983fc85b9b1e6db47fa7a7dd810d5ebdb428f Mon Sep 17 00:00:00 2001 From: Jerry Brady Date: Wed, 28 May 2014 20:56:56 +0000 Subject: [PATCH] Fixed starting difficulty issues for proxy ports, including X11 --- config_example.json | 9 +++++++- libs/poolWorker.js | 50 +++++++++++++++++++++++++++++++++------------ 2 files changed, 45 insertions(+), 14 deletions(-) diff --git a/config_example.json b/config_example.json index 9534651..9083c59 100644 --- a/config_example.json +++ b/config_example.json @@ -88,7 +88,14 @@ "algorithm": "x11", "ports": { "5555": { - "diff": 0.001 + "diff": 0.001, + "varDiff": { + "minDiff": 0.001, + "maxDiff": 1, + "targetTime": 15, + "retargetTime": 60, + "variancePercent": 30 + } } } } diff --git a/libs/poolWorker.js b/libs/poolWorker.js index dc48282..d85d016 100644 --- a/libs/poolWorker.js +++ b/libs/poolWorker.js @@ -202,6 +202,8 @@ module.exports = function(logger){ logger[severity](logSystem, logComponent, logSubCat, text); }).on('banIP', function(ip, worker){ process.send({type: 'banIP', ip: ip}); + }).on('started', function(){ + _this.setDifficultyForProxyPort(pool, poolOptions.coin.name, poolOptions.coin.algorithm); }); pool.start(); @@ -259,17 +261,6 @@ module.exports = function(logger){ }; - Object.keys(pools).forEach(function (coinName) { - var p = pools[coinName]; - if (poolConfigs[coinName].coin.algorithm === algorithm) { - for (var port in portalConfig.switching[switchName].ports) { - if (portalConfig.switching[switchName].ports[port].varDiff) - p.setVarDiff(port, portalConfig.switching[switchName].ports[port].varDiff); - } - } - }); - - Object.keys(proxySwitch[switchName].ports).forEach(function(port){ var f = net.createServer(function(socket) { var currentPool = proxySwitch[switchName].currentPool; @@ -278,8 +269,11 @@ module.exports = function(logger){ + switchName + ' from ' + socket.remoteAddress + ' on ' + port + ' routing to ' + currentPool); - - pools[currentPool].getStratumServer().handleNewClient(socket); + + if (pools[currentPool]) + pools[currentPool].getStratumServer().handleNewClient(socket); + else + pools[initialPool].getStratumServer().handleNewClient(socket); }).listen(parseInt(port), function() { logger.debug(logSystem, logComponent, logSubCat, 'Switching "' + switchName @@ -304,4 +298,34 @@ module.exports = function(logger){ }); return foundCoin; }; + + // + // Called when stratum pool emits its 'started' event to copy the initial diff and vardiff + // configuation for any proxy switching ports configured into the stratum pool object. + // + this.setDifficultyForProxyPort = function(pool, coin, algo) { + + logger.debug(logSystem, logComponent, algo, 'Setting proxy difficulties after pool start'); + + Object.keys(portalConfig.switching).forEach(function(switchName) { + if (!portalConfig.switching[switchName].enabled) return; + + var switchAlgo = portalConfig.switching[switchName].algorithm; + if (pool.options.coin.algorithm !== switchAlgo) return; + + // we know the switch configuration matches the pool's algo, so setup the diff and + // vardiff for each of the switch's ports + for (var port in portalConfig.switching[switchName].ports) { + + if (portalConfig.switching[switchName].ports[port].varDiff) + pool.setVarDiff(port, portalConfig.switching[switchName].ports[port].varDiff); + + if (portalConfig.switching[switchName].ports[port].diff){ + if (!pool.options.ports.hasOwnProperty(port)) + pool.options.ports[port] = {}; + pool.options.ports[port].diff = portalConfig.switching[switchName].ports[port].diff; + } + } + }); + }; };