mirror of https://github.com/BTCPrivate/z-nomp.git
[REDIS BREAKING UPDATE] Changed coins to use redis branching for cleaner management
This commit is contained in:
parent
04f769a5a6
commit
e6556d416e
|
@ -152,8 +152,8 @@ function SetupForPool(logger, poolOptions, setupFinished){
|
||||||
|
|
||||||
startRedisTimer();
|
startRedisTimer();
|
||||||
redisClient.multi([
|
redisClient.multi([
|
||||||
['hgetall', coin + '_balances'],
|
['hgetall', coin + ':balances'],
|
||||||
['smembers', coin + '_blocksPending']
|
['smembers', coin + ':blocksPending']
|
||||||
]).exec(function(error, results){
|
]).exec(function(error, results){
|
||||||
endRedisTimer();
|
endRedisTimer();
|
||||||
|
|
||||||
|
@ -294,7 +294,7 @@ function SetupForPool(logger, poolOptions, setupFinished){
|
||||||
|
|
||||||
|
|
||||||
var shareLookups = rounds.map(function(r){
|
var shareLookups = rounds.map(function(r){
|
||||||
return ['hgetall', coin + '_shares:round' + r.height]
|
return ['hgetall', coin + ':shares:round' + r.height]
|
||||||
});
|
});
|
||||||
|
|
||||||
startRedisTimer();
|
startRedisTimer();
|
||||||
|
@ -419,13 +419,13 @@ function SetupForPool(logger, poolOptions, setupFinished){
|
||||||
if (worker.balanceChange !== 0){
|
if (worker.balanceChange !== 0){
|
||||||
balanceUpdateCommands.push([
|
balanceUpdateCommands.push([
|
||||||
'hincrbyfloat',
|
'hincrbyfloat',
|
||||||
coin + '_balances',
|
coin + ':balances',
|
||||||
w,
|
w,
|
||||||
satoshisToCoins(worker.balanceChange)
|
satoshisToCoins(worker.balanceChange)
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
if (worker.sent !== 0){
|
if (worker.sent !== 0){
|
||||||
workerPayoutsCommand.push(['hincrbyfloat', coin + '_payouts', w, worker.sent]);
|
workerPayoutsCommand.push(['hincrbyfloat', coin + ':payouts', w, worker.sent]);
|
||||||
totalPaid += worker.sent;
|
totalPaid += worker.sent;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -439,7 +439,7 @@ function SetupForPool(logger, poolOptions, setupFinished){
|
||||||
var moveSharesToCurrent = function(r){
|
var moveSharesToCurrent = function(r){
|
||||||
var workerShares = r.workerShares;
|
var workerShares = r.workerShares;
|
||||||
Object.keys(workerShares).forEach(function(worker){
|
Object.keys(workerShares).forEach(function(worker){
|
||||||
orphanMergeCommands.push(['hincrby', coin + '_shares:roundCurrent',
|
orphanMergeCommands.push(['hincrby', coin + ':shares:roundCurrent',
|
||||||
worker, workerShares[worker]]);
|
worker, workerShares[worker]]);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
@ -448,17 +448,17 @@ function SetupForPool(logger, poolOptions, setupFinished){
|
||||||
|
|
||||||
switch(r.category){
|
switch(r.category){
|
||||||
case 'kicked':
|
case 'kicked':
|
||||||
movePendingCommands.push(['smove', coin + '_blocksPending', coin + '_blocksKicked', r.serialized]);
|
movePendingCommands.push(['smove', coin + ':blocksPending', coin + ':blocksKicked', r.serialized]);
|
||||||
case 'orphan':
|
case 'orphan':
|
||||||
movePendingCommands.push(['smove', coin + '_blocksPending', coin + '_blocksOrphaned', r.serialized]);
|
movePendingCommands.push(['smove', coin + ':blocksPending', coin + ':blocksOrphaned', r.serialized]);
|
||||||
if (r.canDeleteShares){
|
if (r.canDeleteShares){
|
||||||
moveSharesToCurrent(r);
|
moveSharesToCurrent(r);
|
||||||
roundsToDelete.push(coin + '_shares:round' + r.height);
|
roundsToDelete.push(coin + ':shares:round' + r.height);
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
case 'generate':
|
case 'generate':
|
||||||
movePendingCommands.push(['smove', coin + '_blocksPending', coin + '_blocksConfirmed', r.serialized]);
|
movePendingCommands.push(['smove', coin + ':blocksPending', coin + ':blocksConfirmed', r.serialized]);
|
||||||
roundsToDelete.push(coin + '_shares:round' + r.height);
|
roundsToDelete.push(coin + ':shares:round' + r.height);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -482,7 +482,7 @@ function SetupForPool(logger, poolOptions, setupFinished){
|
||||||
finalRedisCommands.push(['del'].concat(roundsToDelete));
|
finalRedisCommands.push(['del'].concat(roundsToDelete));
|
||||||
|
|
||||||
if (totalPaid !== 0)
|
if (totalPaid !== 0)
|
||||||
finalRedisCommands.push(['hincrbyfloat', coin + '_stats', 'totalPaid', totalPaid]);
|
finalRedisCommands.push(['hincrbyfloat', coin + ':stats', 'totalPaid', totalPaid]);
|
||||||
|
|
||||||
if (finalRedisCommands.length === 0){
|
if (finalRedisCommands.length === 0){
|
||||||
callback();
|
callback();
|
||||||
|
|
|
@ -45,27 +45,27 @@ module.exports = function(logger, poolConfig){
|
||||||
var redisCommands = [];
|
var redisCommands = [];
|
||||||
|
|
||||||
if (isValidShare){
|
if (isValidShare){
|
||||||
redisCommands.push(['hincrbyfloat', coin + '_shares:roundCurrent', shareData.worker, shareData.difficulty]);
|
redisCommands.push(['hincrbyfloat', coin + ':shares:roundCurrent', shareData.worker, shareData.difficulty]);
|
||||||
redisCommands.push(['hincrby', coin + '_stats', 'validShares', 1]);
|
redisCommands.push(['hincrby', coin + ':stats', 'validShares', 1]);
|
||||||
|
|
||||||
/* Stores share diff, worker, and unique value with a score that is the timestamp. Unique value ensures it
|
/* Stores share diff, worker, and unique value with a score that is the timestamp. Unique value ensures it
|
||||||
doesn't overwrite an existing entry, and timestamp as score lets us query shares from last X minutes to
|
doesn't overwrite an existing entry, and timestamp as score lets us query shares from last X minutes to
|
||||||
generate hashrate for each worker and pool. */
|
generate hashrate for each worker and pool. */
|
||||||
var dateNow = Date.now();
|
var dateNow = Date.now();
|
||||||
var hashrateData = [shareData.difficulty, shareData.worker, dateNow];
|
var hashrateData = [shareData.difficulty, shareData.worker, dateNow];
|
||||||
redisCommands.push(['zadd', coin + '_hashrate', dateNow / 1000 | 0, hashrateData.join(':')]);
|
redisCommands.push(['zadd', coin + ':hashrate', dateNow / 1000 | 0, hashrateData.join(':')]);
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
redisCommands.push(['hincrby', coin + '_stats', 'invalidShares', 1]);
|
redisCommands.push(['hincrby', coin + ':stats', 'invalidShares', 1]);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isValidBlock){
|
if (isValidBlock){
|
||||||
redisCommands.push(['rename', coin + '_shares:roundCurrent', coin + '_shares:round' + shareData.height]);
|
redisCommands.push(['rename', coin + ':shares:roundCurrent', coin + '_shares:round' + shareData.height]);
|
||||||
redisCommands.push(['sadd', coin + '_blocksPending', [shareData.blockHash, shareData.txHash, shareData.height].join(':')]);
|
redisCommands.push(['sadd', coin + ':blocksPending', [shareData.blockHash, shareData.txHash, shareData.height].join(':')]);
|
||||||
redisCommands.push(['hincrby', coin + '_stats', 'validBlocks', 1]);
|
redisCommands.push(['hincrby', coin + ':stats', 'validBlocks', 1]);
|
||||||
}
|
}
|
||||||
else if (shareData.blockHash){
|
else if (shareData.blockHash){
|
||||||
redisCommands.push(['hincrby', coin + '_stats', 'invalidBlocks', 1]);
|
redisCommands.push(['hincrby', coin + ':stats', 'invalidBlocks', 1]);
|
||||||
}
|
}
|
||||||
|
|
||||||
connection.multi(redisCommands).exec(function(err, replies){
|
connection.multi(redisCommands).exec(function(err, replies){
|
||||||
|
|
|
@ -109,12 +109,12 @@ module.exports = function(logger, portalConfig, poolConfigs){
|
||||||
|
|
||||||
|
|
||||||
var redisCommandTemplates = [
|
var redisCommandTemplates = [
|
||||||
['zremrangebyscore', '_hashrate', '-inf', '(' + windowTime],
|
['zremrangebyscore', ':hashrate', '-inf', '(' + windowTime],
|
||||||
['zrangebyscore', '_hashrate', windowTime, '+inf'],
|
['zrangebyscore', ':hashrate', windowTime, '+inf'],
|
||||||
['hgetall', '_stats'],
|
['hgetall', ':stats'],
|
||||||
['scard', '_blocksPending'],
|
['scard', ':blocksPending'],
|
||||||
['scard', '_blocksConfirmed'],
|
['scard', ':blocksConfirmed'],
|
||||||
['scard', '_blocksOrphaned']
|
['scard', ':blocksOrphaned']
|
||||||
];
|
];
|
||||||
|
|
||||||
var commandsPerCoin = redisCommandTemplates.length;
|
var commandsPerCoin = redisCommandTemplates.length;
|
||||||
|
|
Loading…
Reference in New Issue