From b0f70f840f4992fc932596bf3818b8de6b9ebb59 Mon Sep 17 00:00:00 2001 From: Matt Date: Tue, 4 Mar 2014 13:25:23 -0700 Subject: [PATCH 1/3] readme typo --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index c4b142a..f5e03fc 100644 --- a/README.md +++ b/README.md @@ -137,7 +137,7 @@ Description of options: /* For when miner's authenticate: set to "password" for both worker name and password to be checked for in the database, set to "worker" for only work name to be checked, or don't use this option (set to "none") for no auth checks */ - "stratumAuth": "password"' + "stratumAuth": "password" } }, From c7e61d681ba45217f8073a2fa368f2d50d42ebca Mon Sep 17 00:00:00 2001 From: Andrea Baccega Date: Tue, 4 Mar 2014 22:58:00 +0100 Subject: [PATCH 2/3] Fixed mpos compatibility layer --- libs/mposCompatibility.js | 18 ++++++++++++++---- libs/poolWorker.js | 12 +++++++----- 2 files changed, 21 insertions(+), 9 deletions(-) diff --git a/libs/mposCompatibility.js b/libs/mposCompatibility.js index ae240d8..d139be0 100644 --- a/libs/mposCompatibility.js +++ b/libs/mposCompatibility.js @@ -1,5 +1,5 @@ var mysql = require('mysql'); - +var cluster = require('cluster'); module.exports = function(logger, poolConfigs){ var dbConnections = (function(){ @@ -92,14 +92,24 @@ module.exports = function(logger, poolConfigs){ }; - this.handleShare = function(isValidShare, isValidBlock, data){ - + this.handleShare = function(data){ + var isValidShare = data.isValidShare; + var isValidBlock = data.isValidBlock; if ((!data.coin in dbConnections)) return; var connection = dbConnections[data.coin]; + var dbData = [ + data.share.ip, + data.share.worker, + isValidShare ? 'Y' : 'N', + isValidBlock ? 'Y' : 'N', + data.share.difficulty, + typeof(data.share.error)==='undefined'?null:data.share.error, + typeof(data.solution)==='undefined'?'':data.solution // solution? + ]; connection.query( 'INSERT INTO `shares` SET time = NOW(), rem_host = ?, username = ?, our_result = ?, upstream_result = ?, difficulty = ?, reason = ?, solution = ?', - [data.ip, data.worker, isValidShare ? 'Y' : 'N', isValidBlock ? 'Y' : 'N', data.difficulty, data.error, data.solution], + dbData, function(err, result) { if (err) logger.logError('shareProcessor', 'mysql', 'MySQL insert error when adding share: ' + diff --git a/libs/poolWorker.js b/libs/poolWorker.js index beb429a..c280b6c 100644 --- a/libs/poolWorker.js +++ b/libs/poolWorker.js @@ -28,8 +28,9 @@ module.exports = function(logger){ break; case 'mposAuth': var callbackId = message.callbackId; - if (callbackId in mposAuthCallbacks) + if (callbackId in mposAuthCallbacks) { mposAuthCallbacks[callbackId](message.authorized); + } break; } }); @@ -93,7 +94,7 @@ module.exports = function(logger){ var pool = Stratum.createPool(poolOptions, authorizeFN); - pool.on('share', function(isValidShare, isValidBlock, data){ + pool.on('share', function(isValidShare, isValidBlock, data, blockHex){ var shareData = JSON.stringify(data); @@ -107,17 +108,18 @@ module.exports = function(logger){ logDebug(logIdentify, 'client', 'Valid share submitted, share data: ' + shareData); process.send({ type: 'share', - share: shareData, + share: data, coin: poolOptions.coin.name, isValidShare: isValidShare, - isValidBlock: isValidBlock + isValidBlock: isValidBlock, + solution: blockHex }); if (isValidBlock){ logDebug(logIdentify, 'client', 'Block found, solution: ' + shareData.solution); process.send({ type: 'block', - share: shareData, + share: data, coin: poolOptions.coin.name }); } From 1c6f7c4f5013c5062bf06ea15e77b4f81c4212b4 Mon Sep 17 00:00:00 2001 From: Andrea Baccega Date: Tue, 4 Mar 2014 23:35:43 +0100 Subject: [PATCH 3/3] First and raw api support + mposcompatibility fixes/codereadability improvements --- libs/apis.js | 18 +++++++++++++ libs/mposCompatibility.js | 6 ++--- libs/poolWorker.js | 41 ++++++++++++++-------------- libs/workerapi.js | 56 +++++++++++++++++++++++++++++++++++++++ 4 files changed, 98 insertions(+), 23 deletions(-) create mode 100644 libs/apis.js create mode 100644 libs/workerapi.js diff --git a/libs/apis.js b/libs/apis.js new file mode 100644 index 0000000..966fc12 --- /dev/null +++ b/libs/apis.js @@ -0,0 +1,18 @@ +var express = require('express'); +var os = require('os'); +var app = express(); + +app.get('/getstatus', function (req, res) { + res.send({ + 'loadavg': os.loadavg(), + 'freemem': os.freemem(), + }); +}); + + +module.exports = { + start: function () { + app.listen(9000); + } +} + diff --git a/libs/mposCompatibility.js b/libs/mposCompatibility.js index d139be0..51d9834 100644 --- a/libs/mposCompatibility.js +++ b/libs/mposCompatibility.js @@ -63,9 +63,9 @@ module.exports = function(logger, poolConfigs){ var sendResult = function(authorized){ cluster.workers[data.workerId].send({ - type: 'mposAuth', - callbackId: data.callbackId, - authorized: authorized + type : 'mposAuth', + callbackId : data.callbackId, + authorized : authorized }); }; diff --git a/libs/poolWorker.js b/libs/poolWorker.js index c280b6c..1469ed4 100644 --- a/libs/poolWorker.js +++ b/libs/poolWorker.js @@ -74,16 +74,17 @@ module.exports = function(logger){ clearTimeout(authTimeout); }; process.send({ - type: 'mposAuth', - coin: poolOptions.coin.name, - callbackId: callbackId, - workerId: cluster.worker.id, - workerName: workerName, - password: password, - authLevel: mposAuthLevel + type : 'mposAuth', + coin : poolOptions.coin.name, + callbackId : callbackId, + workerId : cluster.worker.id, + workerName : workerName, + password : password, + authLevel : mposAuthLevel }); } else{ + // if we're here than it means we're on stratumAuth: "none" or something unrecognized by the system! callback({ error: null, authorized: true, @@ -107,30 +108,30 @@ module.exports = function(logger){ logDebug(logIdentify, 'client', 'Valid share submitted, share data: ' + shareData); process.send({ - type: 'share', - share: data, - coin: poolOptions.coin.name, - isValidShare: isValidShare, - isValidBlock: isValidBlock, - solution: blockHex + type : 'share', + share : data, + coin : poolOptions.coin.name, + isValidShare : isValidShare, + isValidBlock : isValidBlock, + solution : blockHex // blockHex is undefined is this was not a valid block. }); if (isValidBlock){ logDebug(logIdentify, 'client', 'Block found, solution: ' + shareData.solution); process.send({ - type: 'block', - share: data, - coin: poolOptions.coin.name + type : 'block', + share : data, + coin : poolOptions.coin.name }); } }).on('difficultyUpdate', function(workerName, diff){ if (poolOptions.shareProcessing.mpos.enabled){ process.send({ - type: 'difficultyUpdate', - workerName: workerName, - diff: diff, - coin: poolOptions.coin.name + type : 'difficultyUpdate', + workerName : workerName, + diff : diff, + coin : poolOptions.coin.name }); } }).on('log', function(severity, logKey, logText) { diff --git a/libs/workerapi.js b/libs/workerapi.js new file mode 100644 index 0000000..9e1f732 --- /dev/null +++ b/libs/workerapi.js @@ -0,0 +1,56 @@ +var express = require('express'); +var os = require('os'); + + +function workerapi(listen) { + var _this = this; + var app = express(); + var counters = { + validShares : 0, + validBlocks : 0, + invalidShares : 0 + }; + + var lastEvents = { + lastValidShare : 0 , + lastValidBlock : 0, + lastInvalidShare : 0 + }; + + app.get('/stats', function (req, res) { + res.send({ + "clients" : Object.keys(_this.poolObj.stratumServer.getStratumClients()).length, + "counters" : counters, + "lastEvents" : lastEvents + }); + }); + + + this.start = function (poolObj) { + this.poolObj = poolObj; + this.poolObj.once('started', function () { + app.listen(listen, function (lol) { + console.log("LISTENING "); + }); + }) + .on('share', function(isValidShare, isValidBlock, shareData) { + var now = Date.now(); + if (isValidShare) { + counters.validShares ++; + lastEvents.lastValidShare = now; + if (isValidBlock) { + counters.validBlocks ++; + lastEvents.lastValidBlock = now; + } + } else { + counters.invalidShares ++; + lastEvents.lastInvalidShare = now; + } + }); + } +} + + + +module.exports = workerapi; +