Skip to content

Commit

Permalink
Fixed the hashrate error.
Browse files Browse the repository at this point in the history
  • Loading branch information
daliwangi committed Dec 24, 2016
1 parent b933fa0 commit 088755d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
using CoiniumServ.Persistance.Blocks;
using CoiniumServ.Shares;
using CoiniumServ.Utils.Helpers;
using CoiniumServ.Server.Mining.Stratum;

namespace CoiniumServ.Persistance.Layers.Hybrid
{
Expand All @@ -44,7 +45,8 @@ public void AddShare(IShare share)

// add the share to round
var currentKey = string.Format("{0}:shares:round:current", _coin);
_redisProvider.Client.HIncrByFloat(currentKey, share.Miner.Username, share.Difficulty);
var miner = (IStratumMiner)share.Miner;
_redisProvider.Client.HIncrByFloat(currentKey, miner.Username, (double)miner.Difficulty);

// increment shares stats.
var statsKey = string.Format("{0}:stats", _coin);
Expand All @@ -54,7 +56,9 @@ public void AddShare(IShare share)
if (share.IsValid)
{
var hashrateKey = string.Format("{0}:hashrate", _coin);
var entry = string.Format("{0}:{1}", share.Difficulty, share.Miner.Username);
var randomModifier = Convert.ToString(miner.ValidShareCount, 16).PadLeft(8, '0');
string modifiedUsername = miner.Username + randomModifier;
var entry = string.Format("{0}:{1}", (double)miner.Difficulty, modifiedUsername);
_redisProvider.Client.ZAdd(hashrateKey, Tuple.Create(TimeHelpers.NowInUnixTimestamp(), entry));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using CoiniumServ.Utils.Helpers;

namespace CoiniumServ.Persistance.Layers.Hybrid
{
Expand All @@ -46,7 +47,7 @@ public IDictionary<string, double> GetHashrateData(int since)
{
var data = result.Split(':');
var share = double.Parse(data[0].Replace(',', '.'), CultureInfo.InvariantCulture);
var worker = data[1];
var worker = data[1].Substring(0, data[1].Length - 8);

if (!hashrates.ContainsKey(worker))
hashrates.Add(worker, 0);
Expand Down

0 comments on commit 088755d

Please sign in to comment.