mirror of https://github.com/BTCPrivate/z-nomp.git
Betting logging. Payment processing fixes.
This commit is contained in:
parent
ae2bc98675
commit
ad1f4ce3d0
30
init.js
30
init.js
|
@ -17,19 +17,17 @@ JSON.minify = JSON.minify || require("node-json-minify");
|
|||
var portalConfig = JSON.parse(JSON.minify(fs.readFileSync("config.json", {encoding: 'utf8'})));
|
||||
|
||||
|
||||
var loggerInstance = new PoolLogger({
|
||||
var logger = new PoolLogger({
|
||||
logLevel: portalConfig.logLevel
|
||||
});
|
||||
|
||||
var logDebug = loggerInstance.logDebug;
|
||||
var logWarning = loggerInstance.logWarning;
|
||||
var logError = loggerInstance.logError;
|
||||
|
||||
|
||||
|
||||
try {
|
||||
require('newrelic');
|
||||
if (cluster.isMaster)
|
||||
logDebug('newrelic', 'system', 'New Relic initiated');
|
||||
logger.debug('NewRelic', 'Monitor', 'New Relic initiated');
|
||||
} catch(e) {}
|
||||
|
||||
|
||||
|
@ -38,7 +36,7 @@ try{
|
|||
posix.setrlimit('nofile', { soft: 100000, hard: 100000 });
|
||||
}
|
||||
catch(e){
|
||||
logWarning('posix', 'system', '(Safe to ignore) Must be ran as root to increase resource limits');
|
||||
logger.warning('POSIX', 'Connection Limit', '(Safe to ignore) Must be ran as root to increase resource limits');
|
||||
}
|
||||
|
||||
|
||||
|
@ -47,13 +45,13 @@ if (cluster.isWorker){
|
|||
|
||||
switch(process.env.workerType){
|
||||
case 'pool':
|
||||
new PoolWorker(loggerInstance);
|
||||
new PoolWorker(logger);
|
||||
break;
|
||||
case 'paymentProcessor':
|
||||
new PaymentProcessor(loggerInstance);
|
||||
new PaymentProcessor(logger);
|
||||
break;
|
||||
case 'website':
|
||||
new Website(loggerInstance);
|
||||
new Website(logger);
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -81,7 +79,7 @@ var buildPoolConfigs = function(){
|
|||
if (poolOptions.disabled) return;
|
||||
var coinFilePath = 'coins/' + poolOptions.coin;
|
||||
if (!fs.existsSync(coinFilePath)){
|
||||
logError(poolOptions.coin, 'system', 'could not find file: ' + coinFilePath);
|
||||
logger.error('Master', poolOptions.coin, 'could not find file: ' + coinFilePath);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -117,7 +115,7 @@ var spawnPoolWorkers = function(portalConfig, poolConfigs){
|
|||
portalConfig : JSON.stringify(portalConfig),
|
||||
});
|
||||
worker.on('exit', function(code, signal){
|
||||
logError('poolWorker', 'system', 'Fork ' + forkId + ' died, spawning replacement worker...');
|
||||
logger.error('Master', 'Pool Worker', 'Fork ' + forkId + ' died, spawning replacement worker...');
|
||||
setTimeout(function(){
|
||||
createPoolWorker(forkId);
|
||||
}, 2000);
|
||||
|
@ -132,7 +130,7 @@ var spawnPoolWorkers = function(portalConfig, poolConfigs){
|
|||
|
||||
|
||||
var startWorkerListener = function(poolConfigs){
|
||||
var workerListener = new WorkerListener(loggerInstance, poolConfigs);
|
||||
var workerListener = new WorkerListener(logger, poolConfigs);
|
||||
workerListener.init();
|
||||
};
|
||||
|
||||
|
@ -142,7 +140,7 @@ var startBlockListener = function(portalConfig){
|
|||
//setup block notify here and use IPC to tell appropriate pools
|
||||
var listener = new BlocknotifyListener(portalConfig.blockNotifyListener);
|
||||
listener.on('log', function(text){
|
||||
logDebug('blocknotify', 'system', text);
|
||||
logger.debug('Master', 'Blocknotify', text);
|
||||
});
|
||||
listener.on('hash', function(message){
|
||||
|
||||
|
@ -163,7 +161,7 @@ var startRedisBlockListener = function(portalConfig){
|
|||
|
||||
var listener = new RedisBlocknotifyListener(portalConfig.redisBlockNotifyListener);
|
||||
listener.on('log', function(text){
|
||||
logDebug('blocknotify', 'system', text);
|
||||
logger.debug('Master', 'blocknotify', text);
|
||||
}).on('hash', function (message) {
|
||||
var ipcMessage = {type:'blocknotify', coin: message.coin, hash: message.hash};
|
||||
Object.keys(cluster.workers).forEach(function(id) {
|
||||
|
@ -180,7 +178,7 @@ var startPaymentProcessor = function(poolConfigs){
|
|||
pools: JSON.stringify(poolConfigs)
|
||||
});
|
||||
worker.on('exit', function(code, signal){
|
||||
logError('paymentProcessor', 'system', 'Payment processor died, spawning replacement...');
|
||||
logger.error('Master', 'Payment Processor', 'Payment processor died, spawning replacement...');
|
||||
setTimeout(function(){
|
||||
startPaymentProcessor(poolConfigs);
|
||||
}, 2000);
|
||||
|
@ -198,7 +196,7 @@ var startWebsite = function(portalConfig, poolConfigs){
|
|||
portalConfig: JSON.stringify(portalConfig)
|
||||
});
|
||||
worker.on('exit', function(code, signal){
|
||||
logError('website', 'system', 'Website process died, spawning replacement...');
|
||||
logger.error('Master', 'Website', 'Website process died, spawning replacement...');
|
||||
setTimeout(function(){
|
||||
startWebsite(portalConfig, poolConfigs);
|
||||
}, 2000);
|
||||
|
|
123
libs/logUtil.js
123
libs/logUtil.js
|
@ -1,78 +1,73 @@
|
|||
var dateFormat = require('dateformat');
|
||||
/*
|
||||
var defaultConfiguration = {
|
||||
'default': true,
|
||||
'keys': {
|
||||
'client' : 'warning',
|
||||
'system' : true,
|
||||
'submitblock' : true,
|
||||
var colors = require('colors');
|
||||
|
||||
|
||||
var severityToColor = function(severity, text) {
|
||||
switch(severity) {
|
||||
case 'debug':
|
||||
return text.green;
|
||||
case 'warning':
|
||||
return text.yellow;
|
||||
case 'error':
|
||||
return text.red;
|
||||
default:
|
||||
console.log("Unknown severity " + severity);
|
||||
return text.italic;
|
||||
}
|
||||
};
|
||||
*/
|
||||
|
||||
var severityToInt = function(severity) {
|
||||
switch(severity) {
|
||||
case 'debug':
|
||||
return 10;
|
||||
case 'warning':
|
||||
return 20;
|
||||
case 'error':
|
||||
return 30;
|
||||
default:
|
||||
console.log("Unknown severity "+severity);
|
||||
return 1000;
|
||||
}
|
||||
}
|
||||
var getSeverityColor = function(severity) {
|
||||
switch(severity) {
|
||||
case 'debug':
|
||||
return 32;
|
||||
case 'warning':
|
||||
return 33;
|
||||
case 'error':
|
||||
return 31;
|
||||
default:
|
||||
console.log("Unknown severity "+severity);
|
||||
return 31;
|
||||
}
|
||||
}
|
||||
var severityValues = {
|
||||
'debug': 1,
|
||||
'warning': 2,
|
||||
'error': 3
|
||||
};
|
||||
|
||||
|
||||
var PoolLogger = function (configuration) {
|
||||
|
||||
var logLevelInt = severityToInt(configuration.logLevel);
|
||||
|
||||
// privates
|
||||
var shouldLog = function(key, severity) {
|
||||
var severity = severityToInt(severity);
|
||||
return severity >= logLevelInt;
|
||||
var logLevelInt = severityValues[configuration.logLevel];
|
||||
|
||||
|
||||
|
||||
var log = function(severity, system, component, text, subcat) {
|
||||
|
||||
if (severityValues[severity] < logLevelInt) return;
|
||||
|
||||
if (subcat){
|
||||
var realText = subcat;
|
||||
var realSubCat = text;
|
||||
text = realText;
|
||||
subcat = realSubCat;
|
||||
}
|
||||
|
||||
var entryDesc = dateFormat(new Date(), 'yyyy-mm-dd HH:MM:ss') + ' [' + system + ']\t';
|
||||
entryDesc = severityToColor(severity, entryDesc);
|
||||
|
||||
var logString =
|
||||
entryDesc +
|
||||
('[' + component + '] ').italic;
|
||||
|
||||
if (subcat)
|
||||
logString += ('(' + subcat + ') ').bold.grey
|
||||
|
||||
logString += text.grey;
|
||||
|
||||
console.log(logString);
|
||||
|
||||
|
||||
};
|
||||
|
||||
var log = function(severity, key, poolName, text) {
|
||||
if (!shouldLog(key, severity))
|
||||
return;
|
||||
|
||||
var desc = poolName ? '[' + poolName + '] ' : '';
|
||||
console.log(
|
||||
'\u001b[' + getSeverityColor(severity) + 'm' +
|
||||
dateFormat(new Date(), 'yyyy-mm-dd HH:MM:ss') +
|
||||
" [" + key + "]" + '\u001b[39m: ' + "\t" +
|
||||
desc + text
|
||||
);
|
||||
}
|
||||
|
||||
// public
|
||||
|
||||
this.logDebug = function(poolName, logKey, text){
|
||||
log('debug', logKey, poolName, text);
|
||||
}
|
||||
|
||||
this.logWarning = function(poolName, logKey, text) {
|
||||
log('warning', logKey, poolName, text);
|
||||
}
|
||||
|
||||
this.logError = function(poolName, logKey, text) {
|
||||
log('error', logKey, poolName, text);
|
||||
}
|
||||
}
|
||||
var _this = this;
|
||||
Object.keys(severityValues).forEach(function(logType){
|
||||
_this[logType] = function(){
|
||||
var args = Array.prototype.slice.call(arguments, 0);
|
||||
args.unshift(logType);
|
||||
log.apply(this, args);
|
||||
};
|
||||
});
|
||||
};
|
||||
|
||||
module.exports = PoolLogger;
|
|
@ -7,6 +7,8 @@ module.exports = function(logger, poolConfig){
|
|||
|
||||
var connection;
|
||||
|
||||
var logIdentify = 'MPOS';
|
||||
|
||||
function connect(){
|
||||
connection = mysql.createConnection({
|
||||
host: mposConfig.host,
|
||||
|
@ -17,18 +19,18 @@ module.exports = function(logger, poolConfig){
|
|||
});
|
||||
connection.connect(function(err){
|
||||
if (err)
|
||||
logger.error('mysql', 'Could not connect to mysql database: ' + JSON.stringify(err))
|
||||
logger.error(logIdentify, 'mysql', 'Could not connect to mysql database: ' + JSON.stringify(err))
|
||||
else{
|
||||
logger.debug('mysql', 'Successful connection to MySQL database');
|
||||
logger.debug(logIdentify, 'mysql', 'Successful connection to MySQL database');
|
||||
}
|
||||
});
|
||||
connection.on('error', function(err){
|
||||
if(err.code === 'PROTOCOL_CONNECTION_LOST') {
|
||||
logger.warning('mysql', 'Lost connection to MySQL database, attempting reconnection...');
|
||||
logger.warning(logIdentify, 'mysql', 'Lost connection to MySQL database, attempting reconnection...');
|
||||
connect();
|
||||
}
|
||||
else{
|
||||
logger.error('mysql', 'Database error: ' + JSON.stringify(err))
|
||||
logger.error(logIdentify, 'mysql', 'Database error: ' + JSON.stringify(err))
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -41,7 +43,7 @@ module.exports = function(logger, poolConfig){
|
|||
[workerName],
|
||||
function(err, result){
|
||||
if (err){
|
||||
logger.error('mysql', 'Database error when authenticating worker: ' +
|
||||
logger.error(logIdentify, 'mysql', 'Database error when authenticating worker: ' +
|
||||
JSON.stringify(err));
|
||||
authCallback(false);
|
||||
}
|
||||
|
@ -74,8 +76,9 @@ module.exports = function(logger, poolConfig){
|
|||
dbData,
|
||||
function(err, result) {
|
||||
if (err)
|
||||
logger.error('mysql', 'Insert error when adding share: ' +
|
||||
JSON.stringify(err));
|
||||
logger.error(logIdentify, 'mysql', 'Insert error when adding share: ' + JSON.stringify(err));
|
||||
else
|
||||
logger.debug(logIdentify, 'mysql', 'Share inserted');
|
||||
}
|
||||
);
|
||||
};
|
||||
|
@ -86,7 +89,7 @@ module.exports = function(logger, poolConfig){
|
|||
'UPDATE `pool_worker` SET `difficulty` = ' + diff + ' WHERE `username` = ' + connection.escape(workerName),
|
||||
function(err, result){
|
||||
if (err)
|
||||
logger.error('mysql', 'Error when updating worker diff: ' +
|
||||
logger.error(logIdentify, 'mysql', 'Error when updating worker diff: ' +
|
||||
JSON.stringify(err));
|
||||
else if (result.affectedRows === 0){
|
||||
connection.query('INSERT INTO `pool_worker` SET ?', {username: workerName, difficulty: diff});
|
||||
|
|
|
@ -25,33 +25,23 @@ function SetupForPool(logger, poolOptions){
|
|||
|
||||
if (!processingConfig.enabled) return;
|
||||
|
||||
var logIdentify = 'Payment Processor (' + coin + ')';
|
||||
var logSystem = 'Payments';
|
||||
var logComponent = coin;
|
||||
|
||||
var paymentLogger = {
|
||||
debug: function(key, text){
|
||||
logger.logDebug(logIdentify, key, text);
|
||||
},
|
||||
warning: function(key, text){
|
||||
logger.logWarning(logIdentify, key, text);
|
||||
},
|
||||
error: function(key, text){
|
||||
logger.logError(logIdentify, key, text);
|
||||
}
|
||||
};
|
||||
|
||||
var daemon = new Stratum.daemon.interface([processingConfig.daemon]);
|
||||
daemon.once('online', function(){
|
||||
paymentLogger.debug('system', 'Connected to daemon for payment processing');
|
||||
logger.debug(logSystem, logComponent, 'Connected to daemon for payment processing');
|
||||
|
||||
daemon.cmd('validateaddress', [poolOptions.address], function(result){
|
||||
if (!result[0].response.ismine){
|
||||
paymentLogger.error('system', 'Daemon does not own pool address - payment processing can not be done with this daemon');
|
||||
logger.error(logSystem, logComponent, 'Daemon does not own pool address - payment processing can not be done with this daemon');
|
||||
}
|
||||
});
|
||||
}).once('connectionFailed', function(error){
|
||||
paymentLogger.error('system', 'Failed to connect to daemon for payment processing: ' + JSON.stringify(error));
|
||||
logger.error(logSystem, logComponent, 'Failed to connect to daemon for payment processing: ' + JSON.stringify(error));
|
||||
}).on('error', function(error){
|
||||
paymentLogger.error('system', error);
|
||||
logger.error(logSystem, logComponent);
|
||||
}).init();
|
||||
|
||||
|
||||
|
@ -64,12 +54,12 @@ function SetupForPool(logger, poolOptions){
|
|||
redisClient = redis.createClient(processingConfig.redis.port, processingConfig.redis.host);
|
||||
redisClient.on('ready', function(){
|
||||
clearTimeout(reconnectTimeout);
|
||||
paymentLogger.debug('redis', 'Successfully connected to redis database');
|
||||
logger.debug(logSystem, logComponent, 'Successfully connected to redis database');
|
||||
}).on('error', function(err){
|
||||
paymentLogger.error('redis', 'Redis client had an error: ' + JSON.stringify(err))
|
||||
}).on('end', function(){
|
||||
paymentLogger.error('redis', 'Connection to redis database as been ended');
|
||||
paymentLogger.warning('redis', 'Trying reconnection in 3 seconds...');
|
||||
logger.error(logSystem, logComponent, 'Connection to redis database as been ended');
|
||||
logger.warning(logSystem, logComponent, 'Trying reconnection to redis in 3 seconds...');
|
||||
reconnectTimeout = setTimeout(function(){
|
||||
connectToRedis();
|
||||
}, 3000);
|
||||
|
@ -89,12 +79,12 @@ function SetupForPool(logger, poolOptions){
|
|||
redisClient.smembers(coin + '_blocksPending', function(error, results){
|
||||
|
||||
if (error){
|
||||
paymentLogger.error('redis', 'Could get blocks from redis ' + JSON.stringify(error));
|
||||
callback('done - redis error for getting blocks');
|
||||
logger.error(logSystem, logComponent, 'Could get blocks from redis ' + JSON.stringify(error));
|
||||
callback('check finished - redis error for getting blocks');
|
||||
return;
|
||||
}
|
||||
if (results.length === 0){
|
||||
callback('done - no pending blocks in redis');
|
||||
callback('check finished - no pending blocks in redis');
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -125,13 +115,13 @@ function SetupForPool(logger, poolOptions){
|
|||
daemon.batchCmd(batchRPCcommand, function(error, txDetails){
|
||||
|
||||
if (error || !txDetails){
|
||||
callback('done - daemon rpc error with batch gettransactions ' + JSON.stringify(error));
|
||||
callback('check finished - daemon rpc error with batch gettransactions ' + JSON.stringify(error));
|
||||
return;
|
||||
}
|
||||
|
||||
txDetails = txDetails.filter(function(tx){
|
||||
if (tx.error || !tx.result){
|
||||
paymentLogger.error('error with requesting transaction from block daemon: ' + JSON.stringify(t));
|
||||
logger.error(logSystem, logComponent, 'error with requesting transaction from block daemon: ' + JSON.stringify(t));
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
|
@ -144,7 +134,7 @@ function SetupForPool(logger, poolOptions){
|
|||
var tx = txDetails.filter(function(tx){return tx.result.txid === r.txHash})[0];
|
||||
|
||||
if (!tx){
|
||||
paymentLogger.error('system', 'daemon did not give us back a transaction that we asked for: ' + r.txHash);
|
||||
logger.error(logSystem, logComponent, 'daemon did not give us back a transaction that we asked for: ' + r.txHash);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -158,10 +148,10 @@ function SetupForPool(logger, poolOptions){
|
|||
magnitude = roundMagnitude;
|
||||
|
||||
if (roundMagnitude % 10 !== 0)
|
||||
paymentLogger.error('system', 'Satosihis in coin is not divisible by 10 which is very odd');
|
||||
logger.error(logSystem, logComponent, 'Satosihis in coin is not divisible by 10 which is very odd');
|
||||
}
|
||||
else if (magnitude != roundMagnitude){
|
||||
paymentLogger.error('system', 'Magnitude in a round was different than in another round. HUGE PROBLEM.');
|
||||
logger.error(logSystem, logComponent, 'Magnitude in a round was different than in another round. HUGE PROBLEM.');
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
@ -172,7 +162,7 @@ function SetupForPool(logger, poolOptions){
|
|||
|
||||
|
||||
if (rounds.length === 0){
|
||||
callback('done - no confirmed or orphaned rounds');
|
||||
callback('check finished - no confirmed or orphaned blocks found');
|
||||
}
|
||||
else{
|
||||
callback(null, rounds, magnitude);
|
||||
|
@ -193,7 +183,7 @@ function SetupForPool(logger, poolOptions){
|
|||
|
||||
redisClient.multi(shareLookups).exec(function(error, allWorkerShares){
|
||||
if (error){
|
||||
callback('done - redis error with multi get rounds share')
|
||||
callback('check finished - redis error with multi get rounds share')
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -238,7 +228,7 @@ function SetupForPool(logger, poolOptions){
|
|||
|
||||
redisClient.hmget([coin + '_balances'].concat(workers), function(error, results){
|
||||
if (error && workers.length !== 0){
|
||||
callback('done - redis error with multi get balances ' + JSON.stringify(error));
|
||||
callback('check finished - redis error with multi get balances ' + JSON.stringify(error));
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -246,7 +236,7 @@ function SetupForPool(logger, poolOptions){
|
|||
var workerBalances = {};
|
||||
|
||||
for (var i = 0; i < workers.length; i++){
|
||||
workerBalances[workers[i]] = (parseInt(results[i]) || 0) * magnitude;
|
||||
workerBalances[workers[i]] = (parseInt(results[i]) || 0);
|
||||
}
|
||||
|
||||
|
||||
|
@ -307,7 +297,7 @@ function SetupForPool(logger, poolOptions){
|
|||
var minReserveSatoshis = processingConfig.minimumReserve * magnitude;
|
||||
if (balanceLeftOver < minReserveSatoshis){
|
||||
|
||||
callback('done - payments would wipe out minimum reserve, tried to pay out ' + toBePaid +
|
||||
callback('check finished - payments would wipe out minimum reserve, tried to pay out ' + toBePaid +
|
||||
' but only have ' + totalBalance + '. Left over balance would be ' + balanceLeftOver +
|
||||
', needs to be at least ' + minReserveSatoshis);
|
||||
return;
|
||||
|
@ -355,12 +345,11 @@ function SetupForPool(logger, poolOptions){
|
|||
|
||||
function(magnitude, workerPayments, finalRedisCommands, callback){
|
||||
|
||||
|
||||
//This does the final all-or-nothing atom transaction if block deamon sent payments
|
||||
var finalizeRedisTx = function(){
|
||||
redisClient.multi(finalRedisCommands).exec(function(error, results){
|
||||
if (error){
|
||||
callback('done - error with final redis commands for cleaning up ' + JSON.stringify(error));
|
||||
callback('check finished - error with final redis commands for cleaning up ' + JSON.stringify(error));
|
||||
return;
|
||||
}
|
||||
callback(null, 'Payments processing performed an interval');
|
||||
|
@ -372,36 +361,35 @@ function SetupForPool(logger, poolOptions){
|
|||
}
|
||||
else{
|
||||
|
||||
|
||||
var coinPrecision = magnitude.toString().length - 1;
|
||||
var addressAmounts = {};
|
||||
var totalAmountUnits = 0;
|
||||
for (var address in workerPayments){
|
||||
addressAmounts[address] = parseFloat((workerPayments[address] / magnitude).toFixed(coinPrecision));
|
||||
var coiUnits = parseFloat((workerPayments[address] / magnitude).toFixed(coinPrecision));;
|
||||
addressAmounts[address] = coiUnits;
|
||||
totalAmountUnits += coiUnits;
|
||||
}
|
||||
|
||||
paymentLogger.debug('system', 'Payments about to be sent to: ' + JSON.stringify(addressAmounts));
|
||||
logger.debug(logSystem, logComponent, 'Payments about to be sent to: ' + JSON.stringify(addressAmounts));
|
||||
daemon.cmd('sendmany', ['', addressAmounts], function(results){
|
||||
if (results[0].error){
|
||||
callback('done - error with sendmany ' + JSON.stringify(results[0].error));
|
||||
callback('check finished - error with sendmany ' + JSON.stringify(results[0].error));
|
||||
return;
|
||||
}
|
||||
finalizeRedisTx();
|
||||
var totalWorkers = Object.keys(workerPayments).length;
|
||||
var totalAmount = Object.keys(workerPayments).reduce(function(p, c){return p + workerPayments[c]}, 0);
|
||||
paymentLogger.debug('system', 'Payments sent, a total of ' + totalAmount +
|
||||
logger.debug(logSystem, logComponent, 'Payments sent, a total of ' + totalAmountUnits +
|
||||
' was sent to ' + totalWorkers + ' miners');
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
], function(error, result){
|
||||
if (error)
|
||||
paymentLogger.debug('system', error)
|
||||
logger.debug(logSystem, logComponent, error);
|
||||
|
||||
else{
|
||||
paymentLogger.debug('system', result);
|
||||
logger.debug(logSystem, logComponent, result);
|
||||
withdrawalProfit();
|
||||
}
|
||||
});
|
||||
|
@ -420,11 +408,11 @@ function SetupForPool(logger, poolOptions){
|
|||
|
||||
|
||||
if (leftOverBalance < processingConfig.minimumReserve || withdrawalAmount < processingConfig.feeWithdrawalThreshold){
|
||||
paymentLogger.debug('system', 'Not enough profit to withdrawal yet');
|
||||
logger.debug(logSystem, logComponent, 'Not enough profit to withdrawal yet');
|
||||
}
|
||||
else{
|
||||
//Need to figure out how much of the balance is profit... ???
|
||||
paymentLogger.debug('system', 'Can send profit');
|
||||
logger.debug(logSystem, logComponent, 'Can send profit');
|
||||
}
|
||||
|
||||
});
|
||||
|
|
|
@ -16,7 +16,6 @@ module.exports = function(logger){
|
|||
var forkId = process.env.forkId;
|
||||
|
||||
var pools = {};
|
||||
var varDiffsInstances = {}; // contains all the vardiffs for the profit switching pool
|
||||
|
||||
var proxyStuff = {}
|
||||
//Handle messages from master process sent via IPC
|
||||
|
@ -51,19 +50,10 @@ module.exports = function(logger){
|
|||
|
||||
var poolOptions = poolConfigs[coin];
|
||||
|
||||
var logIdentify = 'Pool Fork ' + forkId + ' (' + coin + ')';
|
||||
var logSystem = 'Pool';
|
||||
var logComponent = coin;
|
||||
var logSubCat = 'Fork ' + forkId;
|
||||
|
||||
var poolLogger = {
|
||||
debug: function(key, text){
|
||||
logger.logDebug(logIdentify, key, text);
|
||||
},
|
||||
warning: function(key, text){
|
||||
logger.logWarning(logIdentify, key, text);
|
||||
},
|
||||
error: function(key, text){
|
||||
logger.logError(logIdentify, key, text);
|
||||
}
|
||||
};
|
||||
|
||||
var handlers = {
|
||||
auth: function(){},
|
||||
|
@ -75,7 +65,7 @@ module.exports = function(logger){
|
|||
|
||||
//Functions required for MPOS compatibility
|
||||
if (shareProcessing.mpos && shareProcessing.mpos.enabled){
|
||||
var mposCompat = new MposCompatibility(poolLogger, poolOptions)
|
||||
var mposCompat = new MposCompatibility(logger, poolOptions)
|
||||
|
||||
handlers.auth = function(workerName, password, authCallback){
|
||||
mposCompat.handleAuth(workerName, password, authCallback);
|
||||
|
@ -93,7 +83,7 @@ module.exports = function(logger){
|
|||
//Functions required for internal payment processing
|
||||
else if (shareProcessing.internal && shareProcessing.internal.enabled){
|
||||
|
||||
var shareProcessor = new ShareProcessor(poolLogger, poolOptions)
|
||||
var shareProcessor = new ShareProcessor(logger, poolOptions)
|
||||
|
||||
handlers.auth = function(workerName, password, authCallback){
|
||||
pool.daemon.cmd('validateaddress', [workerName], function(results){
|
||||
|
@ -112,7 +102,7 @@ module.exports = function(logger){
|
|||
|
||||
var authString = authorized ? 'Authorized' : 'Unauthorized ';
|
||||
|
||||
poolLogger.debug('client', authString + ' [' + ip + '] ' + workerName + ':' + password);
|
||||
logger.debug(logSystem, logComponent, logSubCat, authString + ' ' + workerName + ':' + password + ' [' + ip + ']');
|
||||
callback({
|
||||
error: null,
|
||||
authorized: authorized,
|
||||
|
@ -122,20 +112,20 @@ module.exports = function(logger){
|
|||
};
|
||||
|
||||
|
||||
var pool = Stratum.createPool(poolOptions, authorizeFN);
|
||||
var pool = Stratum.createPool(poolOptions, authorizeFN, logger);
|
||||
pool.on('share', function(isValidShare, isValidBlock, data){
|
||||
|
||||
var shareData = JSON.stringify(data);
|
||||
|
||||
if (data.solution && !isValidBlock)
|
||||
poolLogger.debug('client', 'We thought a block solution was found but it was rejected by the daemon, share data: ' + shareData);
|
||||
logger.debug(logSystem, logComponent, logSubCat, 'We thought a block solution was found but it was rejected by the daemon, share data: ' + shareData);
|
||||
else if (isValidBlock)
|
||||
poolLogger.debug('client', 'Block found, solution: ' + data.solution);
|
||||
logger.debug(logSystem, logComponent, logSubCat, 'Block found, solution: ' + data.solution);
|
||||
|
||||
if (isValidShare)
|
||||
poolLogger.debug('client', 'Valid share submitted, share data: ' + shareData);
|
||||
logger.debug(logSystem, logComponent, logSubCat, 'Valid share submitted, share data: ' + shareData);
|
||||
else if (!isValidShare)
|
||||
poolLogger.debug('client', 'Invalid share submitted, share data: ' + shareData)
|
||||
logger.debug(logSystem, logComponent, logSubCat, 'Invalid share submitted, share data: ' + shareData)
|
||||
|
||||
|
||||
handlers.share(isValidShare, isValidBlock, data)
|
||||
|
@ -143,14 +133,8 @@ module.exports = function(logger){
|
|||
|
||||
}).on('difficultyUpdate', function(workerName, diff){
|
||||
handlers.diff(workerName, diff);
|
||||
}).on('log', function(severity, logKey, logText) {
|
||||
if (severity == 'debug') {
|
||||
poolLogger.debug(logKey, logText);
|
||||
} else if (severity == 'warning') {
|
||||
poolLogger.warning(logKey, logText);
|
||||
} else if (severity == 'error') {
|
||||
poolLogger.error(logKey, logText);
|
||||
}
|
||||
}).on('log', function(severity, text) {
|
||||
logger[severity](logSystem, logComponent, logSubCat, text);
|
||||
});
|
||||
pool.start();
|
||||
pools[poolOptions.coin.name.toLowerCase()] = pool;
|
||||
|
|
|
@ -20,6 +20,8 @@ module.exports = function(logger, poolConfig){
|
|||
var redisConfig = internalConfig.redis;
|
||||
var coin = poolConfig.coin.name;
|
||||
|
||||
var logSystem = 'Shares';
|
||||
|
||||
var connection;
|
||||
|
||||
function connect(){
|
||||
|
@ -29,14 +31,14 @@ module.exports = function(logger, poolConfig){
|
|||
connection = redis.createClient(redisConfig.port, redisConfig.host);
|
||||
connection.on('ready', function(){
|
||||
clearTimeout(reconnectTimeout);
|
||||
logger.debug('redis', 'Successfully connected to redis database');
|
||||
logger.debug(logSystem, 'redis', 'Successfully connected to redis database');
|
||||
});
|
||||
connection.on('error', function(err){
|
||||
logger.error('redis', 'Redis client had an error: ' + JSON.stringify(err))
|
||||
logger.error(logSystem, 'redis', 'Redis client had an error: ' + JSON.stringify(err))
|
||||
});
|
||||
connection.on('end', function(){
|
||||
logger.error('redis', 'Connection to redis database as been ended');
|
||||
logger.warning('redis', 'Trying reconnection in 3 seconds...');
|
||||
logger.error(logSystem, 'redis', 'Connection to redis database as been ended');
|
||||
logger.warning(logSystem, 'redis', 'Trying reconnection in 3 seconds...');
|
||||
reconnectTimeout = setTimeout(function(){
|
||||
connect();
|
||||
}, 3000);
|
||||
|
@ -75,7 +77,9 @@ module.exports = function(logger, poolConfig){
|
|||
|
||||
connection.multi(redisCommands).exec(function(err, replies){
|
||||
if (err)
|
||||
logger.error('redis', 'error with share processor multi ' + JSON.stringify(err));
|
||||
logger.error(logSystem, 'redis', 'error with share processor multi ' + JSON.stringify(err));
|
||||
else
|
||||
logger.debug(logSystem, 'redis', 'share related data recorded');
|
||||
});
|
||||
|
||||
|
||||
|
|
|
@ -43,19 +43,7 @@ module.exports = function(logger){
|
|||
|
||||
var portalStats = new stats(logger, portalConfig, poolConfigs);
|
||||
|
||||
var logIdentify = 'Website';
|
||||
|
||||
var websiteLogger = {
|
||||
debug: function(key, text){
|
||||
logger.logDebug(logIdentify, key, text);
|
||||
},
|
||||
warning: function(key, text){
|
||||
logger.logWarning(logIdentify, key, text);
|
||||
},
|
||||
error: function(key, text){
|
||||
logger.logError(logIdentify, key, text);
|
||||
}
|
||||
};
|
||||
var logSystem = 'Website';
|
||||
|
||||
|
||||
var pageFiles = {
|
||||
|
@ -89,6 +77,7 @@ module.exports = function(logger){
|
|||
portalConfig: portalConfig
|
||||
});
|
||||
}
|
||||
logger.debug(logSystem, 'Stats', 'Website updated to latest stats');
|
||||
};
|
||||
|
||||
|
||||
|
@ -148,17 +137,6 @@ module.exports = function(logger){
|
|||
|
||||
var route = function(req, res, next){
|
||||
var pageId = req.params.page || '';
|
||||
/*var requestedPage = getPage(pageId);
|
||||
if (requestedPage){
|
||||
var data = pageTemplates.index({
|
||||
page: requestedPage,
|
||||
selected: pageId,
|
||||
stats: portalStats.stats,
|
||||
poolConfigs: poolConfigs,
|
||||
portalConfig: portalConfig
|
||||
});
|
||||
res.end(data);
|
||||
}*/
|
||||
if (pageId in indexesProcessed){
|
||||
res.end(indexesProcessed[pageId]);
|
||||
}
|
||||
|
@ -215,7 +193,7 @@ module.exports = function(logger){
|
|||
});
|
||||
|
||||
app.listen(portalConfig.website.port, function(){
|
||||
websiteLogger.debug('system', 'Website started on port ' + portalConfig.website.port);
|
||||
logger.debug(logSystem, 'Server', 'Website started on port ' + portalConfig.website.port);
|
||||
});
|
||||
|
||||
|
||||
|
|
|
@ -39,7 +39,8 @@
|
|||
"mysql": "*",
|
||||
"async": "*",
|
||||
"express": "*",
|
||||
"dot": "*"
|
||||
"dot": "*",
|
||||
"colors": "*"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=0.10"
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
"enabled": true,
|
||||
"validateWorkerAddress": true,
|
||||
"paymentInterval": 10,
|
||||
"minimumPayment": 0.001,
|
||||
"minimumPayment": 100.001,
|
||||
"minimumReserve": 10,
|
||||
"feePercent": 0.02,
|
||||
"feeReceiveAddress": "LZz44iyF4zLCXJTU8RxztyyJZBntdS6fvv",
|
||||
|
|
Loading…
Reference in New Issue