Skip to content

Commit

Permalink
Bug fix
Browse files Browse the repository at this point in the history
Fixed a crucial cpuminer bug and linux compile bug
  • Loading branch information
archit120 committed May 28, 2014
1 parent fb8dec3 commit ddc77fa
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 5 deletions.
4 changes: 4 additions & 0 deletions CryptoNight/oaes_lib.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ static const char _NR[] = {
#include <unistd.h>
#endif

#ifdef __GNUC__
#define _getpid getpid
#endif

#include "oaes_config.h"
#include "oaes_lib.h"

Expand Down
15 changes: 14 additions & 1 deletion MoneroPool/BackgroundStaticUpdater.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@ public async void Start()
.IniReadValue(
"wallet-address")))))
["result"];
if (Statics.CurrentBlockTemplate == null || Statics.CurrentBlockHeight == 0)
{
Logger.Log(Logger.LogLevel.Error, "Failed to get block template and height. Shutting down!");
Environment.Exit(-1);
}
Statics.HashRate.Begin = DateTime.Now;
Statics.HashRate.Difficulty = 0;
Logger.Log(Logger.LogLevel.General, "Acquired block template and height, miners can connet now!");
Expand Down Expand Up @@ -109,7 +114,15 @@ public async void Start()
if (connectedClient.Value.TcpClient != null)
{
JObject response = new JObject();
CryptoNightPool.GenerateGetJobResponse(ref response, connectedClient.Key);

response["jsonrpc"] = "2.0";

response["method"] = "job";

JObject bluffResponse = new JObject();
CryptoNightPool.GenerateGetJobResponse(ref bluffResponse, connectedClient.Key);

response["params"] = bluffResponse["result"];
string s = JsonConvert.SerializeObject(response);
s += "\n";
byte[] byteArray = Encoding.UTF8.GetBytes(s);
Expand Down
11 changes: 11 additions & 0 deletions MoneroPool/ConnectedWorker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,17 @@ public ulong CurrentDifficulty
_currentDifficulty = value;
}
}
private List<int> _submittedShares;

public List<int> SubmittedShares
{
get
{
if(_submittedShares==null)
_submittedShares = new List<int>();
return _submittedShares;
}
}
}
public class ConnectedWorker
{
Expand Down
35 changes: 31 additions & 4 deletions MoneroPool/CryptoNightPool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -148,9 +148,22 @@ public bool GenerateSubmitResponse(ref JObject response, string jobId, string gu
Statics.TotalShares++;
JObject result = new JObject();

if (nonce == null || nonce.Length == 0)
{
response["error"] = "Invalid arguments!";
return false;
}

try
{
ShareJob shareJob = worker.JobSeed.First(x => x.Key == jobId).Value;
if (!shareJob.SubmittedShares.Contains(BitConverter.ToInt32(nonce, 0)))
shareJob.SubmittedShares.Add(BitConverter.ToInt32(nonce, 0));
else
{
response["error"] = "Duplicate share";
return false;
}
int jobSeed = shareJob.Seed;
worker.ShareRequest(shareJob.CurrentDifficulty);
Statics.RedisDb.MinerWorkers.First(x => x.Identifier == guid).ShareRequest(shareJob.CurrentDifficulty);
Expand Down Expand Up @@ -234,7 +247,7 @@ public bool GenerateSubmitResponse(ref JObject response, string jobId, string gu
}
catch
{
result["status"] = "Invalid job id";
result["error"] = "Invalid job id";
}
response["result"] = result;

Expand All @@ -249,16 +262,16 @@ public static void GenerateGetJobResponse(ref JObject response, string guid)
worker.LastSeen = DateTime.Now;
/*if (worker.ShareDifficulty.Count >= 4)
worker.LastDifficulty = Helpers.WorkerVardiffDifficulty(worker); */
worker.CurrentBlock = Statics.CurrentBlockHeight;


Logger.Log(Logger.LogLevel.General, "Getwork request from {0}", guid);

//result["id"] = guid;

int seed = 0;
if (worker.PendingDifficulty != worker.LastDifficulty)
if (worker.PendingDifficulty != worker.LastDifficulty || worker.CurrentBlock != Statics.CurrentBlockHeight)
{
worker.CurrentBlock = Statics.CurrentBlockHeight;
worker.LastDifficulty = worker.PendingDifficulty;
job["blob"] = Helpers.GenerateUniqueWork(ref seed);

Expand Down Expand Up @@ -296,12 +309,13 @@ public static void GenerateGetJobResponse(ref JObject response, string guid)

public void GenerateLoginResponse(ref JObject response, string guid, string address)
{

JObject result = new JObject();
JObject job = new JObject();

if (!Helpers.IsValidAddress(address, uint.Parse(Statics.Config.IniReadValue("base58-prefix"))))
{
result["status"] = "Invalid Address";
result["error"] = "Invalid Address";
return;
}

Expand Down Expand Up @@ -457,10 +471,22 @@ public string AcceptClient(string sRequest, string ipAddress, ref bool abort, re

response["error"] = null;
if ((string) request["method"] == "login")
{
guid = Guid.NewGuid().ToString();

}

else
{
guid = (string) request["params"]["id"];

if (!Statics.ConnectedClients.ContainsKey(guid))
{
response["error"] = "Not authenticated yet!";
return JsonConvert.SerializeObject(response);
}

}
switch ((string) request["method"])
{
case "login":
Expand All @@ -478,6 +504,7 @@ public string AcceptClient(string sRequest, string ipAddress, ref bool abort, re

return JsonConvert.SerializeObject(response);
}

catch (Exception e)
{
Logger.Log(Logger.LogLevel.Error, e.ToString());
Expand Down

0 comments on commit ddc77fa

Please sign in to comment.