Skip to content
This repository has been archived by the owner on Oct 28, 2023. It is now read-only.

Commit

Permalink
Will now autodetect if it's best to mine on Nicehash or Westhash
Browse files Browse the repository at this point in the history
Pings to their stratum 4 times, best average result is the winner. Can
be disabled by setting "detectstratum" under "nichash" or "westhash" to
false, but does detect it by default.
  • Loading branch information
KBomba committed Feb 15, 2015
1 parent d6ce081 commit 2418d58
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 2 deletions.
2 changes: 1 addition & 1 deletion MinerControl/MinerControl.conf
Expand Up @@ -36,7 +36,7 @@
{ "name": "keccak", "display": "Keccak", "hashrate": 301500, "power": 50, "aparam1": "", "aparam2": "TestMiner.exe", "aparam3": "-a keccak" },
{ "name": "qubit", "display": "Qubit", "hashrate": 7500, "power": 50, "aparam1": "", "aparam2": "TestMiner.exe", "aparam3": "-a qubit" },
{ "name": "lyra2", "display": "Lyra2RE", "hashrate": 1401, "power": 50, "aparam1": "", "aparam2": "TestMiner.exe", "aparam3": "-a lyra2re" },
{ "name": "fresh", "display": "Fresh", "hashrate": 1401, "power": 50, "aparam1": "", "aparam2": "TestMiner.exe", "aparam3": "-a fresh" },
{ "name": "fresh", "display": "Fresh", "hashrate": 1401, "power": 50, "aparam1": "", "aparam2": "TestMiner.exe", "aparam3": "-a fresh" },
{ "name": "sha256", "display": "SHA256", "hashrate": 10000, "power": 50, "aparam1": "c:\\windows\\system32", "aparam2": "cmd.exe", "aparam3": "/c test-run.bat -a sha256 -batch" }
],
"nicehash": {
Expand Down
65 changes: 64 additions & 1 deletion MinerControl/MiningEngine.cs
Expand Up @@ -4,6 +4,7 @@
using System.IO;
using System.Linq;
using System.Net;
using System.Net.NetworkInformation;
using System.Threading;
using System.Web.Script.Serialization;
using System.Windows.Forms;
Expand Down Expand Up @@ -384,9 +385,18 @@ private string GetConfigPath()
private void LoadService(IService service, IDictionary<string, object> data, string name)
{
if (!data.ContainsKey(name)) return;

Dictionary<string, object> serviceData = data[name] as Dictionary<string, object>;
if (serviceData != null && (name == "nicehash" || name == "westhash") &&
(!serviceData.ContainsKey("detectstratum") || (bool) serviceData["detectstratum"]))
{
service = GetBestNiceWestHashService();
if (_services.Any(o => o.ServiceEnum == service.ServiceEnum)) return;
}

service.MiningEngine = this;
_services.Add(service);
service.Initialize(data[name] as Dictionary<string, object>);
service.Initialize(serviceData);
}

private void LoadConfigGeneral(IDictionary<string, object> data)
Expand Down Expand Up @@ -483,6 +493,59 @@ private void LoadConfigAlgorithms(object[] data)
}
}

private IService GetBestNiceWestHashService()
{
const int tries = 4;
Ping pinger = new Ping();
PingReply replyWestHash = null;
long[] westRtt = new long[tries];
PingReply replyNiceHash = null;
long[] niceRtt = new long[tries];

try
{
for (int i = 0; i < tries; i++)
{
replyWestHash = pinger.Send("speedtest.sea01.softlayer.com", 1000);
if (replyWestHash != null)
{
westRtt[i] = replyWestHash.RoundtripTime;
}
else
{
westRtt[i] = 500;
}
}
}
catch { }
if (replyWestHash == null || replyWestHash.Status != IPStatus.Success) return new NiceHashService();

try
{
for (int i = 0; i < tries; i++)
{
replyNiceHash = pinger.Send("speedtest.ams01.softlayer.com", 1000);
if (replyNiceHash != null)
{
niceRtt[i] = replyNiceHash.RoundtripTime;
}
else
{
niceRtt[i] = 500;
}
}
}
catch { }
if (replyNiceHash == null || replyNiceHash.Status != IPStatus.Success) return new WestHashService();

if (niceRtt.Average() > westRtt.Average())
{
return new WestHashService();
}

return new NiceHashService();
}

public void StopMiner()
{
if (!_process.IsRunning())
Expand Down

0 comments on commit 2418d58

Please sign in to comment.