Skip to content

Commit

Permalink
Merge pull request #1 from ConcealNetwork/v2
Browse files Browse the repository at this point in the history
Pool upgrade
  • Loading branch information
cryptokatz authored Sep 11, 2019
2 parents 835b61f + e4ea733 commit 34e9ecd
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 5 deletions.
30 changes: 25 additions & 5 deletions lib/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -538,18 +538,21 @@ function broadcastLiveStats(){
function extractAverageHashrates(chartdata) {
var now = new Date() / 1000 | 0;

var sums = [0, 0, 0]; // 1h, 6h, 24h
var counts = [0, 0, 0];
var sums = [0, 0, 0, 0, 0, 0]; // 1h, 6h, 24h, 5m, 15m, 12h
var counts = [0, 0, 0, 0, 0, 0];

var sets = JSON.parse(chartdata); // [time, avgValue, updateCount]
for (var j in sets) {
var hr = sets[j][1];
if (now - sets[j][0] <= 1*60*60) { sums[0] += hr; counts[0]++; }
if (now - sets[j][0] <= 6*60*60) { sums[1] += hr; counts[1]++; }
if (now - sets[j][0] <= 24*60*60) { sums[2] += hr; counts[2]++; }
if (now - sets[j][0] <= 5*60) { sums[3] += hr; counts[3]++; }
if (now - sets[j][0] <= 15*60) { sums[4] += hr; counts[4]++; }
if (now - sets[j][0] <= 12*60*60) { sums[5] += hr; counts[5]++; }
}

return [sums[0] * 1.0 / (counts[0] || 1), sums[1] * 1.0 / (counts[1] || 1), sums[2] * 1.0 / (counts[2] || 1)];
return [sums[0] * 1.0 / (counts[0] || 1), sums[1] * 1.0 / (counts[1] || 1), sums[2] * 1.0 / (counts[2] || 1), sums[3] * 1.0 / (counts[3] || 1), sums[4] * 1.0 / (counts[4] || 1), sums[5] * 1.0 / (counts[5] || 1)];
}

/**
Expand Down Expand Up @@ -706,7 +709,10 @@ function handleMinerStats(urlParts, response){
['hgetall', config.coin + ':workers:' + address],
['zrevrange', config.coin + ':payments:' + address, 0, config.api.payments - 1, 'WITHSCORES'],
['keys', config.coin + ':unique_workers:' + address + '~*'],
['get', config.coin + ':charts:hashrate:' + address]
['get', config.coin + ':charts:hashrate:' + address],
['zrevrange', config.coin + ':blocksMiner:matured:' + address, 0, -1, 'WITHSCORES'],
['zrevrange', config.coin + ':blocksMiner:found:' + address, 0, -1, 'WITHSCORES'],
['zcard', config.coin + ':blocksMiner:found:' + address]
]).exec(function(error, replies){
if (error || !replies[0]){
var dataJSON = JSON.stringify({error: 'Not found'});
Expand All @@ -726,12 +732,18 @@ function handleMinerStats(urlParts, response){
stats.roundHashes = minerStats[address] && minerStats[address]['roundHashes'] ? minerStats[address]['roundHashes'] : 0;
if (replies[3]) {
var hr_avg = extractAverageHashrates(replies[3]);
stats.hashrate_5m = hr_avg[3];
stats.hashrate_15m = hr_avg[4];
stats.hashrate_1h = hr_avg[0];
stats.hashrate_6h = hr_avg[1];
stats.hashrate_12h = hr_avg[5];
stats.hashrate_24h = hr_avg[2];
}

var paymentsData = replies[1];
var blocksShareData = replies[4];
var blocksFoundData = replies[5];
var totalBlocksFoundData = replies[6];

var workersData = [];
for (var i=0; i<replies[2].length; i++) {
Expand Down Expand Up @@ -761,11 +773,16 @@ function handleMinerStats(urlParts, response){
if (replies[wi]) {
workersData[i].lastShare = replies[wi]['lastShare'] ? parseInt(replies[wi]['lastShare']) : 0;
workersData[i].hashes = replies[wi]['hashes'] ? parseInt(replies[wi]['hashes']) : 0;
workersData[i].validShares = replies[wi]['validShares'] ? parseInt(replies[wi]['validShares']) : 0;
workersData[i].invalidShares = replies[wi]['invalidShares'] ? parseInt(replies[wi]['invalidShares']) : 0;
}
if (replies[hi]) {
var avgs = extractAverageHashrates(replies[hi]);
workersData[i]['hashrate_5m'] = avgs[3];
workersData[i]['hashrate_15m'] = avgs[4];
workersData[i]['hashrate_1h'] = avgs[0];
workersData[i]['hashrate_6h'] = avgs[1];
workersData[i]['hashrate_12h'] = avgs[5];
workersData[i]['hashrate_24h'] = avgs[2];
}
}
Expand All @@ -774,7 +791,10 @@ function handleMinerStats(urlParts, response){
stats: stats,
payments: paymentsData,
charts: chartsData,
workers: workersData
workers: workersData,
blocksShare: blocksShareData,
blocksFound: blocksFoundData,
totalBlocksFound: totalBlocksFoundData
}

var dataJSON = JSON.stringify(data);
Expand Down
11 changes: 11 additions & 0 deletions lib/blockUnlocker.js
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,17 @@ function runInterval(){
var workerReward = Math.round(reward * percent);
payments[worker] = (payments[worker] || 0) + workerReward;
log('info', logSystem, 'Block %d payment to %s for %d%% of total block score: %d', [block.height, worker, percent*100, payments[worker]]);
redisClient.zadd(config.coin + ':blocksMiner:matured:' + worker, block.height, [
block.hash,
block.time,
block.difficulty,
block.shares,
block.orphaned,
block.reward,
percent*100,
payments[worker]
].join(':'));

});
}

Expand Down
11 changes: 11 additions & 0 deletions lib/pool.js
Original file line number Diff line number Diff line change
Expand Up @@ -819,6 +819,11 @@ function recordShareData(miner, job, shareDiff, blockCandidate, hashHex, shareTy
}
});

redisClient.zadd(config.coin + ':blocksMiner:found:' + miner.login, job.height, [
hashHex,
blockTemplate.difficulty
].join(':'));

notifications.sendToAll('blockFound', {
'HEIGHT': job.height,
'HASH': hashHex,
Expand All @@ -828,8 +833,12 @@ function recordShareData(miner, job, shareDiff, blockCandidate, hashHex, shareTy
});
}

redisClient.hincrby(config.coin + ':unique_workers:' + miner.login + '~' + miner.workerName, 'validShares', 1);


});


log('info', logSystem, 'Accepted %s share at difficulty %d/%d from %s@%s', [shareType, job.difficulty, shareDiff, miner.login, miner.ip]);
}

Expand Down Expand Up @@ -869,6 +878,7 @@ function processShare(miner, job, blockTemplate, params){

if (hash.toString('hex') !== resultHash) {
log('warn', logSystem, 'Bad hash from miner %s@%s', [miner.login, miner.ip]);
redisClient.hincrby(config.coin + ':unique_workers:' + miner.login + '~' + miner.workerName, 'invalidShares', 1);
return false;
}

Expand Down Expand Up @@ -897,6 +907,7 @@ function processShare(miner, job, blockTemplate, params){

else if (hashDiff.lt(job.difficulty)){
log('warn', logSystem, 'Rejected low difficulty share of %s from %s@%s', [hashDiff.toString(), miner.login, miner.ip]);
redisClient.hincrby(config.coin + ':unique_workers:' + miner.login + '~' + miner.workerName, 'invalidShares', 1);
return false;
}
else{
Expand Down

0 comments on commit 34e9ecd

Please sign in to comment.