diff --git a/lib/pool.js b/lib/pool.js index e914ba4..b169640 100644 --- a/lib/pool.js +++ b/lib/pool.js @@ -31,12 +31,12 @@ var pool = module.exports = function pool(options, authorizeFn){ var blockPollingIntervalId; - var emitLog = function(key, text) { _this.emit('log', 'debug' , key, text); }; - var emitWarningLog = function(key, text) { _this.emit('log', 'warning', key, text); }; - var emitErrorLog = function(key, text) { _this.emit('log', 'error' , key, text); }; + var emitLog = function(text) { _this.emit('log', 'debug' , text); }; + var emitWarningLog = function(text) { _this.emit('log', 'warning', text); }; + var emitErrorLog = function(text) { _this.emit('log', 'error' , text); }; this.start = function(){ - emitLog('system', 'Starting pool for ' + options.coin.name + ' [' + options.coin.symbol.toUpperCase() + ']'); + emitLog('Starting pool for ' + options.coin.name + ' [' + options.coin.symbol.toUpperCase() + ']'); SetupJobManager(); SetupVarDiff(); SetupDaemonInterface(function (err, newDaemon) { @@ -63,13 +63,13 @@ var pool = module.exports = function pool(options, authorizeFn){ return; _this.peer = new peer(options.p2p); _this.peer.on('connected', function(){ - emitLog('system', 'connected to daemon as a peer node'); + emitLog('connected to daemon as a peer node'); }).on('disconnected', function(){ - emitWarningLog('system', 'peer node disconnected - attempting reconnection...'); + emitWarningLog('peer node disconnected - attempting reconnection...'); }).on('connectionFailed', function(){ - emitErrorLog('system', 'failed to connect to daemon as a peer node'); + emitErrorLog('failed to connect to daemon as a peer node'); }).on('error', function(msg){ - emitWarningLog('p2p', msg); + emitWarningLog(msg); }).on('blockFound', function(hash){ this.processBlockNotify(hash); }); @@ -103,12 +103,12 @@ var pool = module.exports = function pool(options, authorizeFn){ function(results){ results.forEach(function(result){ if (result.error) - emitErrorLog('submitblock', 'rpc error with daemon instance ' + + emitErrorLog('rpc error with daemon instance ' + result.instance.index + ' when submitting block with ' + rpcCommand + ' ' + JSON.stringify(result.error) ); else - emitLog('submitblock', 'Submitted Block using ' + rpcCommand + ' to daemon instance ' + + emitLog('Submitted Block using ' + rpcCommand + ' to daemon instance ' + result.instance.index ); }); @@ -130,13 +130,13 @@ var pool = module.exports = function pool(options, authorizeFn){ _this.jobManager.on('newBlock', function(blockTemplate){ //Check if stratumServer has been initialized yet if ( typeof(_this.stratumServer ) !== 'undefined') { - emitLog('system', 'Detected new block'); + emitLog('Detected new block'); _this.stratumServer.broadcastMiningJobs(blockTemplate.getJobParams()); } }).on('updatedBlock', function(blockTemplate){ //Check if stratumServer has been initialized yet if ( typeof(_this.stratumServer ) !== 'undefined') { - emitLog('system', 'Detected updated block transactions'); + emitLog('Detected updated block transactions'); var job = blockTemplate.getJobParams(); job[8] = false; _this.stratumServer.broadcastMiningJobs(job); @@ -165,13 +165,12 @@ var pool = module.exports = function pool(options, authorizeFn){ }); } }).on('debugBlockShare', function(debugData) { - emitLog('debugBlockSubmit', JSON.stringify(debugData)); + //emitLog(JSON.stringify(debugData)); }); } function SetupDaemonInterface(cback){ - emitLog('system', 'Connecting to daemon(s)'); var newDaemon = new daemon.interface(options.daemons); newDaemon.once('online', function(){ async.parallel({ @@ -181,11 +180,11 @@ var pool = module.exports = function pool(options, authorizeFn){ //Make sure address is valid with each daemon var allValid = results.every(function(result){ if (result.error || !result.response){ - emitErrorLog('system','validateaddress rpc error on daemon instance ' + + emitErrorLog('validateaddress rpc error on daemon instance ' + result.instance.index + ', error +' + JSON.stringify(result.error)); } else if (!result.response.isvalid) - emitErrorLog('system', 'Daemon instance ' + result.instance.index + + emitErrorLog('Daemon instance ' + result.instance.index + ' reports address is not valid'); return result.response && result.response.isvalid; }); @@ -207,21 +206,21 @@ var pool = module.exports = function pool(options, authorizeFn){ var allValid = results.every(function(result){ if (result.error){ - emitErrorLog('system', 'getmininginfo on init failed with daemon instance ' + + emitErrorLog('getmininginfo on init failed with daemon instance ' + result.instance.index + ', error ' + JSON.stringify(result.error) ); return false; } var network = result.response.testnet ? 'testnet' : 'live blockchain'; - emitLog('system', 'Daemon instance ' + result.instance.index + ' is running on ' + network); + emitLog('Daemon instance ' + result.instance.index + ' is running on ' + network); if (typeof isTestnet === 'undefined'){ isTestnet = result.response.testnet; return true; } else if (isTestnet !== result.response.testnet){ - emitErrorLog('system', 'not all daemons are on same network'); + emitErrorLog('not all daemons are on same network'); return false; } else @@ -260,26 +259,26 @@ var pool = module.exports = function pool(options, authorizeFn){ return true; }); if (couldNotDetectMethod){ - emitErrorLog('system', 'Could not detect block submission RPC method'); + emitErrorLog('Could not detect block submission RPC method'); callback('block submission detection failed'); } }); } }, function(err, results){ if (err){ - emitErrorLog('system', 'Could not start pool, ' + JSON.stringify(err)); + emitErrorLog('Could not start pool, ' + JSON.stringify(err)); cback(err); return; } - emitLog('system','Connected to daemon via RPC'); + emitLog('Connected to daemon via RPC'); options.hasSubmitMethod = results.submitMethod; if (options.coin.reward === 'POS' && typeof(results.addressInfo.pubkey) == 'undefined') { // address provided is not of the wallet. - emitErrorLog('system', 'The address provided is not from the daemon wallet.'); + emitErrorLog('The address provided is not from the daemon wallet.'); cback(err); return; } else { @@ -293,18 +292,18 @@ var pool = module.exports = function pool(options, authorizeFn){ GetBlockTemplate(newDaemon, function(error, result){ if (error) { - emitErrorLog('system', 'Error with getblocktemplate on initializing'); + emitErrorLog('Error with getblocktemplate on initializing'); cback(error); } else { var networkDifficulty = _this.jobManager.currentJob.difficulty; - emitLog('network', 'Current block height at ' + results.miningInfo.blocks + + emitLog('Current block height at ' + results.miningInfo.blocks + ' with block difficulty of ' + networkDifficulty); Object.keys(options.ports).forEach(function(port){ var portDiff = options.ports[port].diff; if (portDiff > networkDifficulty) - emitWarningLog('system', 'diff of ' + portDiff + ' on port ' + port + + emitWarningLog('diff of ' + portDiff + ' on port ' + port + ' was set higher than network difficulty of ' + networkDifficulty); }); @@ -316,9 +315,9 @@ var pool = module.exports = function pool(options, authorizeFn){ }); }).on('connectionFailed', function(error){ - emitErrorLog('system','Failed to connect daemon(s): ' + JSON.stringify(error)); + emitErrorLog('Failed to connect daemon(s): ' + JSON.stringify(error)); }).on('error', function(message){ - emitErrorLog('system', message); + emitErrorLog(message); }); newDaemon.init(); @@ -328,7 +327,7 @@ var pool = module.exports = function pool(options, authorizeFn){ function StartStratumServer(){ _this.stratumServer = new stratum.Server(options.ports, options.connectionTimeout, options.banning, authorizeFn); _this.stratumServer.on('started', function(){ - emitLog('system','Stratum server started on port(s): ' + Object.keys(options.ports).join(', ')); + emitLog('Stratum server started on port(s): ' + Object.keys(options.ports).join(', ')); _this.emit('started'); }).on('client.connected', function(client){ if (typeof(_this.varDiff[client.socket.localPort]) !== 'undefined') { @@ -370,18 +369,18 @@ var pool = module.exports = function pool(options, authorizeFn){ resultCallback(result.error, result.result ? true : null); }).on('malformedMessage', function (message) { - emitWarningLog('client', client.workerName + " has sent us a malformed message: " + message); + emitWarningLog(client.workerName + " has sent us a malformed message: " + message); }).on('socketError', function(err) { - emitWarningLog('client', client.workerName + " has somehow had a socket error: " + JSON.stringify(err)); + emitWarningLog(client.workerName + " has somehow had a socket error: " + JSON.stringify(err)); }).on('socketDisconnect', function() { - emitLog('client', "Client '" + client.workerName + "' disconnected!"); + emitLog("Client '" + client.workerName + "' disconnected!"); }).on('unknownStratumMethod', function(fullMessage) { - emitLog('client', "Client '" + client.workerName + "' has sent us an unknown stratum method: " + fullMessage.method); + emitLog("Client '" + client.workerName + "' has sent us an unknown stratum method: " + fullMessage.method); }).on('socketFlooded', function(){ - emitWarningLog('client', 'Detected socket flooding and purged buffer'); + emitWarningLog('Detected socket flooding and purged buffer'); }).on('ban', function(ipAddress){ _this.emit('banIP', ipAddress); - emitWarningLog('client', 'banned IP ' + ipAddress); + emitWarningLog('banned IP ' + ipAddress); }); }); } @@ -389,7 +388,7 @@ var pool = module.exports = function pool(options, authorizeFn){ function SetupBlockPolling(){ if (typeof options.blockRefreshInterval !== "number" || options.blockRefreshInterval <= 0){ - emitLog('system', 'Block template polling has been disabled'); + emitLog('Block template polling has been disabled'); return; } @@ -398,7 +397,7 @@ var pool = module.exports = function pool(options, authorizeFn){ blockPollingIntervalId = setInterval(function () { GetBlockTemplate(function(error, result){}); }, pollingInterval); - emitLog('system', 'Block polling every ' + pollingInterval + ' milliseconds'); + emitLog('Block polling every ' + pollingInterval + ' milliseconds'); } function GetBlockTemplate(daemonObj, callback){