Browse Source

pool-side algorithm suggestion improvement

pull/123/head
notgiven688 3 years ago
parent
commit
b9c7796a3d
4 changed files with 48 additions and 43 deletions
  1. +39
    -15
      server/Server/AlgorithmHelper.cs
  2. +4
    -28
      server/Server/PoolConnection.cs
  3. +5
    -0
      server/Server/Server.csproj
  4. +0
    -0
      server/Server/pools.json

+ 39
- 15
server/Server/AlgorithmHelper.cs View File

@ -18,27 +18,51 @@
// COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
// IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
using System;
using System.Collections.Generic;
using JsonData = System.Collections.Generic.Dictionary<string, object>;
namespace Server {
public class AlgorithmHelper {
// we could create a lookup table but keep it simple stupid for now,
// since we only support cn and cn_lite.
public static bool Normalize (string algo, out string normalized) {
algo = algo.ToLower ();
if (algo == "cn" || algo == "cryptonight") {
normalized = "cn";
return true;
} else if (algo == "cn-lite" || algo == "cryptonight-lite") {
normalized = "cn-lite";
return true;
} else {
normalized = string.Empty;
return false;
// quite a mess
// https://github.com/xmrig/xmrig-proxy/blob/dev/doc/STRATUM_EXT.md#mining-algorithm-negotiation
private static Dictionary<string, Tuple<string, int>> lookup = new Dictionary<string, Tuple<string, int>>
{
{ "cryptonight/0", new Tuple<string, int>("cn", 0) },
{ "cryptonight/1", new Tuple<string, int>("cn", 1) },
{ "cryptonight-lite/0", new Tuple<string, int>("cn-lite", 0) },
{ "cryptonight-lite/1", new Tuple<string, int>("cn-lite", 1) },
{ "cn/0", new Tuple<string, int>("cn", 0) },
{ "cn/1", new Tuple<string, int>("cn", 1) },
{ "cn-lite/0", new Tuple<string, int>("cn-lite", 0) },
{ "cn-lite/1", new Tuple<string, int>("cn-lite", 1) }
};
public static bool NormalizeAlgorithmAndVariant (JsonData job) {
string algo = job["algo"].GetString().ToLower();
if (lookup.ContainsKey(algo))
{
var tuple = lookup[algo];
job["algo"] = tuple.Item1;
job["variant"] = tuple.Item2;
}
else
{
if (algo == "cn" || algo == "cryptonight")
job["algo"] = "cn";
else if (algo == "cn-lite" || algo == "cryptonight-lite")
job["algo"] = "cn-lite";
else return false;
}
return true;
}
}

+ 4
- 28
server/Server/PoolConnection.cs View File

@ -196,20 +196,8 @@ namespace Server {
// extended stratum
if(!lastjob.ContainsKey("variant")) lastjob.Add("variant",mypc.DefaultVariant);
if(!lastjob.ContainsKey("algo")) lastjob.Add("algo",mypc.DefaultAlgorithm);
string normalized;
if(!AlgorithmHelper.Normalize(lastjob["algo"].GetString(), out normalized))
{
CConsole.ColorAlert(() => {
Console.WriteLine("Pool " + mypc.Url + " requests unknown algorithm: "+ lastjob["algo"].GetString());
Console.WriteLine("Job ignored!");
});
return;
}
lastjob["algo"] = normalized;
if(!lastjob.ContainsKey("algo")) lastjob.Add("algo",mypc.DefaultAlgorithm);
AlgorithmHelper.NormalizeAlgorithmAndVariant(lastjob);
mypc.LastJob = lastjob;
mypc.LastInteraction = DateTime.Now;
@ -229,26 +217,14 @@ namespace Server {
if (!VerifyJob (lastjob)) {
CConsole.ColorWarning(() =>
Console.WriteLine ("Failed to verify job: {0}", json));
Console.WriteLine ("Failed to verify job: {0}", json));
return;
}
// extended stratum
if (!lastjob.ContainsKey("variant")) lastjob.Add("variant", mypc.DefaultVariant);
if (!lastjob.ContainsKey("algo")) lastjob.Add("algo", mypc.DefaultAlgorithm);
string normalized;
if (!AlgorithmHelper.Normalize(lastjob["algo"].GetString(), out normalized))
{
CConsole.ColorAlert(() => {
Console.WriteLine("Pool " + mypc.Url + " requests unknown algorithm: " + lastjob["algo"].GetString());
Console.WriteLine("Job ignored!");
});
return;
}
lastjob["algo"] = normalized;
AlgorithmHelper.NormalizeAlgorithmAndVariant(lastjob);
mypc.LastJob = lastjob;
mypc.LastInteraction = DateTime.Now;

+ 5
- 0
server/Server/Server.csproj View File

@ -87,5 +87,10 @@
<Compile Include="Random2.cs" />
<Compile Include="AlgorithmHelper.cs" />
</ItemGroup>
<ItemGroup>
<None Include="pools.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
</Project>

server/Server/bin/Release_Server/pools.json → server/Server/pools.json View File


Loading…
Cancel
Save