forknote / forknote-pool

Mining pool for Bytecoin/Forknote based coins such as Bytecoin and Dashcoin.
https://github.com/forknote/forknote-pool
GNU General Public License v2.0
123 stars 185 forks source link

collectUsersHashrate #47

Open DiscoTim opened 6 years ago

DiscoTim commented 6 years ago

Hi looking at this function, a few things:

function collectUsersHashrate(chartName, settings) {
    var redisBaseKey = getStatsRedisKey(chartName) + ':';
    redisClient.keys(redisBaseKey + '*', function(keys) {
        var hashrates = {};
        for(var i in keys) {
            hashrates[keys[i].substr(keys[i].length)] = 0;
        }
        getUsersHashrates(function(newHashrates) {
            for(var address in newHashrates) {
                hashrates[address] = newHashrates[address];
            }
            storeCollectedValues(chartName, hashrates, settings);
        });
    });
}

I think...

redisClient.keys(redisBaseKey + '*', function(keys) {

should be:

redisClient.keys(redisBaseKey + '*', function(err, keys) {

The way it is 'keys' will be the error and null, and the for loop does not execute.

This line:

hashrates[keys[i].substr(keys[i].length)] = 0;

the statement

keys[i].substr(keys[i].length) will always equal ""

I think it was intended to be:

hashrates[keys[i].substr(redisBaseKey.length)] = 0

in order to write a hashrate of 0 to all inactive miners, however i am not sure if that is even necessary.