Better logging
This commit is contained in:
parent
2857773553
commit
32dc22944e
73
lib/pool.js
73
lib/pool.js
@ -31,12 +31,12 @@ var pool = module.exports = function pool(options, authorizeFn){
|
|||||||
var blockPollingIntervalId;
|
var blockPollingIntervalId;
|
||||||
|
|
||||||
|
|
||||||
var emitLog = function(key, text) { _this.emit('log', 'debug' , key, text); };
|
var emitLog = function(text) { _this.emit('log', 'debug' , text); };
|
||||||
var emitWarningLog = function(key, text) { _this.emit('log', 'warning', key, text); };
|
var emitWarningLog = function(text) { _this.emit('log', 'warning', text); };
|
||||||
var emitErrorLog = function(key, text) { _this.emit('log', 'error' , key, text); };
|
var emitErrorLog = function(text) { _this.emit('log', 'error' , text); };
|
||||||
|
|
||||||
this.start = function(){
|
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();
|
SetupJobManager();
|
||||||
SetupVarDiff();
|
SetupVarDiff();
|
||||||
SetupDaemonInterface(function (err, newDaemon) {
|
SetupDaemonInterface(function (err, newDaemon) {
|
||||||
@ -63,13 +63,13 @@ var pool = module.exports = function pool(options, authorizeFn){
|
|||||||
return;
|
return;
|
||||||
_this.peer = new peer(options.p2p);
|
_this.peer = new peer(options.p2p);
|
||||||
_this.peer.on('connected', function(){
|
_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(){
|
}).on('disconnected', function(){
|
||||||
emitWarningLog('system', 'peer node disconnected - attempting reconnection...');
|
emitWarningLog('peer node disconnected - attempting reconnection...');
|
||||||
}).on('connectionFailed', function(){
|
}).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){
|
}).on('error', function(msg){
|
||||||
emitWarningLog('p2p', msg);
|
emitWarningLog(msg);
|
||||||
}).on('blockFound', function(hash){
|
}).on('blockFound', function(hash){
|
||||||
this.processBlockNotify(hash);
|
this.processBlockNotify(hash);
|
||||||
});
|
});
|
||||||
@ -103,12 +103,12 @@ var pool = module.exports = function pool(options, authorizeFn){
|
|||||||
function(results){
|
function(results){
|
||||||
results.forEach(function(result){
|
results.forEach(function(result){
|
||||||
if (result.error)
|
if (result.error)
|
||||||
emitErrorLog('submitblock', 'rpc error with daemon instance ' +
|
emitErrorLog('rpc error with daemon instance ' +
|
||||||
result.instance.index + ' when submitting block with ' + rpcCommand + ' ' +
|
result.instance.index + ' when submitting block with ' + rpcCommand + ' ' +
|
||||||
JSON.stringify(result.error)
|
JSON.stringify(result.error)
|
||||||
);
|
);
|
||||||
else
|
else
|
||||||
emitLog('submitblock', 'Submitted Block using ' + rpcCommand + ' to daemon instance ' +
|
emitLog('Submitted Block using ' + rpcCommand + ' to daemon instance ' +
|
||||||
result.instance.index
|
result.instance.index
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
@ -130,13 +130,13 @@ var pool = module.exports = function pool(options, authorizeFn){
|
|||||||
_this.jobManager.on('newBlock', function(blockTemplate){
|
_this.jobManager.on('newBlock', function(blockTemplate){
|
||||||
//Check if stratumServer has been initialized yet
|
//Check if stratumServer has been initialized yet
|
||||||
if ( typeof(_this.stratumServer ) !== 'undefined') {
|
if ( typeof(_this.stratumServer ) !== 'undefined') {
|
||||||
emitLog('system', 'Detected new block');
|
emitLog('Detected new block');
|
||||||
_this.stratumServer.broadcastMiningJobs(blockTemplate.getJobParams());
|
_this.stratumServer.broadcastMiningJobs(blockTemplate.getJobParams());
|
||||||
}
|
}
|
||||||
}).on('updatedBlock', function(blockTemplate){
|
}).on('updatedBlock', function(blockTemplate){
|
||||||
//Check if stratumServer has been initialized yet
|
//Check if stratumServer has been initialized yet
|
||||||
if ( typeof(_this.stratumServer ) !== 'undefined') {
|
if ( typeof(_this.stratumServer ) !== 'undefined') {
|
||||||
emitLog('system', 'Detected updated block transactions');
|
emitLog('Detected updated block transactions');
|
||||||
var job = blockTemplate.getJobParams();
|
var job = blockTemplate.getJobParams();
|
||||||
job[8] = false;
|
job[8] = false;
|
||||||
_this.stratumServer.broadcastMiningJobs(job);
|
_this.stratumServer.broadcastMiningJobs(job);
|
||||||
@ -165,13 +165,12 @@ var pool = module.exports = function pool(options, authorizeFn){
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
}).on('debugBlockShare', function(debugData) {
|
}).on('debugBlockShare', function(debugData) {
|
||||||
emitLog('debugBlockSubmit', JSON.stringify(debugData));
|
//emitLog(JSON.stringify(debugData));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function SetupDaemonInterface(cback){
|
function SetupDaemonInterface(cback){
|
||||||
emitLog('system', 'Connecting to daemon(s)');
|
|
||||||
var newDaemon = new daemon.interface(options.daemons);
|
var newDaemon = new daemon.interface(options.daemons);
|
||||||
newDaemon.once('online', function(){
|
newDaemon.once('online', function(){
|
||||||
async.parallel({
|
async.parallel({
|
||||||
@ -181,11 +180,11 @@ var pool = module.exports = function pool(options, authorizeFn){
|
|||||||
//Make sure address is valid with each daemon
|
//Make sure address is valid with each daemon
|
||||||
var allValid = results.every(function(result){
|
var allValid = results.every(function(result){
|
||||||
if (result.error || !result.response){
|
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));
|
result.instance.index + ', error +' + JSON.stringify(result.error));
|
||||||
}
|
}
|
||||||
else if (!result.response.isvalid)
|
else if (!result.response.isvalid)
|
||||||
emitErrorLog('system', 'Daemon instance ' + result.instance.index +
|
emitErrorLog('Daemon instance ' + result.instance.index +
|
||||||
' reports address is not valid');
|
' reports address is not valid');
|
||||||
return result.response && result.response.isvalid;
|
return result.response && result.response.isvalid;
|
||||||
});
|
});
|
||||||
@ -207,21 +206,21 @@ var pool = module.exports = function pool(options, authorizeFn){
|
|||||||
var allValid = results.every(function(result){
|
var allValid = results.every(function(result){
|
||||||
|
|
||||||
if (result.error){
|
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)
|
result.instance.index + ', error ' + JSON.stringify(result.error)
|
||||||
);
|
);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
var network = result.response.testnet ? 'testnet' : 'live blockchain';
|
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'){
|
if (typeof isTestnet === 'undefined'){
|
||||||
isTestnet = result.response.testnet;
|
isTestnet = result.response.testnet;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
else if (isTestnet !== result.response.testnet){
|
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;
|
return false;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -260,26 +259,26 @@ var pool = module.exports = function pool(options, authorizeFn){
|
|||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
if (couldNotDetectMethod){
|
if (couldNotDetectMethod){
|
||||||
emitErrorLog('system', 'Could not detect block submission RPC method');
|
emitErrorLog('Could not detect block submission RPC method');
|
||||||
callback('block submission detection failed');
|
callback('block submission detection failed');
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}, function(err, results){
|
}, function(err, results){
|
||||||
if (err){
|
if (err){
|
||||||
emitErrorLog('system', 'Could not start pool, ' + JSON.stringify(err));
|
emitErrorLog('Could not start pool, ' + JSON.stringify(err));
|
||||||
cback(err);
|
cback(err);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
emitLog('system','Connected to daemon via RPC');
|
emitLog('Connected to daemon via RPC');
|
||||||
|
|
||||||
|
|
||||||
options.hasSubmitMethod = results.submitMethod;
|
options.hasSubmitMethod = results.submitMethod;
|
||||||
|
|
||||||
if (options.coin.reward === 'POS' && typeof(results.addressInfo.pubkey) == 'undefined') {
|
if (options.coin.reward === 'POS' && typeof(results.addressInfo.pubkey) == 'undefined') {
|
||||||
// address provided is not of the wallet.
|
// 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);
|
cback(err);
|
||||||
return;
|
return;
|
||||||
} else {
|
} else {
|
||||||
@ -293,18 +292,18 @@ var pool = module.exports = function pool(options, authorizeFn){
|
|||||||
|
|
||||||
GetBlockTemplate(newDaemon, function(error, result){
|
GetBlockTemplate(newDaemon, function(error, result){
|
||||||
if (error) {
|
if (error) {
|
||||||
emitErrorLog('system', 'Error with getblocktemplate on initializing');
|
emitErrorLog('Error with getblocktemplate on initializing');
|
||||||
cback(error);
|
cback(error);
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
var networkDifficulty = _this.jobManager.currentJob.difficulty;
|
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);
|
' with block difficulty of ' + networkDifficulty);
|
||||||
|
|
||||||
Object.keys(options.ports).forEach(function(port){
|
Object.keys(options.ports).forEach(function(port){
|
||||||
var portDiff = options.ports[port].diff;
|
var portDiff = options.ports[port].diff;
|
||||||
if (portDiff > networkDifficulty)
|
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);
|
' was set higher than network difficulty of ' + networkDifficulty);
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -316,9 +315,9 @@ var pool = module.exports = function pool(options, authorizeFn){
|
|||||||
});
|
});
|
||||||
|
|
||||||
}).on('connectionFailed', function(error){
|
}).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){
|
}).on('error', function(message){
|
||||||
emitErrorLog('system', message);
|
emitErrorLog(message);
|
||||||
});
|
});
|
||||||
|
|
||||||
newDaemon.init();
|
newDaemon.init();
|
||||||
@ -328,7 +327,7 @@ var pool = module.exports = function pool(options, authorizeFn){
|
|||||||
function StartStratumServer(){
|
function StartStratumServer(){
|
||||||
_this.stratumServer = new stratum.Server(options.ports, options.connectionTimeout, options.banning, authorizeFn);
|
_this.stratumServer = new stratum.Server(options.ports, options.connectionTimeout, options.banning, authorizeFn);
|
||||||
_this.stratumServer.on('started', function(){
|
_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');
|
_this.emit('started');
|
||||||
}).on('client.connected', function(client){
|
}).on('client.connected', function(client){
|
||||||
if (typeof(_this.varDiff[client.socket.localPort]) !== 'undefined') {
|
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);
|
resultCallback(result.error, result.result ? true : null);
|
||||||
|
|
||||||
}).on('malformedMessage', function (message) {
|
}).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) {
|
}).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() {
|
}).on('socketDisconnect', function() {
|
||||||
emitLog('client', "Client '" + client.workerName + "' disconnected!");
|
emitLog("Client '" + client.workerName + "' disconnected!");
|
||||||
}).on('unknownStratumMethod', function(fullMessage) {
|
}).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(){
|
}).on('socketFlooded', function(){
|
||||||
emitWarningLog('client', 'Detected socket flooding and purged buffer');
|
emitWarningLog('Detected socket flooding and purged buffer');
|
||||||
}).on('ban', function(ipAddress){
|
}).on('ban', function(ipAddress){
|
||||||
_this.emit('banIP', 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(){
|
function SetupBlockPolling(){
|
||||||
|
|
||||||
if (typeof options.blockRefreshInterval !== "number" || options.blockRefreshInterval <= 0){
|
if (typeof options.blockRefreshInterval !== "number" || options.blockRefreshInterval <= 0){
|
||||||
emitLog('system', 'Block template polling has been disabled');
|
emitLog('Block template polling has been disabled');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -398,7 +397,7 @@ var pool = module.exports = function pool(options, authorizeFn){
|
|||||||
blockPollingIntervalId = setInterval(function () {
|
blockPollingIntervalId = setInterval(function () {
|
||||||
GetBlockTemplate(function(error, result){});
|
GetBlockTemplate(function(error, result){});
|
||||||
}, pollingInterval);
|
}, pollingInterval);
|
||||||
emitLog('system', 'Block polling every ' + pollingInterval + ' milliseconds');
|
emitLog('Block polling every ' + pollingInterval + ' milliseconds');
|
||||||
}
|
}
|
||||||
|
|
||||||
function GetBlockTemplate(daemonObj, callback){
|
function GetBlockTemplate(daemonObj, callback){
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user