Skip to content

Commit

Permalink
Add support for Goldshell AL BOX (I & II)
Browse files Browse the repository at this point in the history
Add support for IceRiver ALPH AL0
Improves ALPH stratum handling of "mining.notify" & "mining.set_difficulty"
  • Loading branch information
ceedii committed Aug 29, 2024
1 parent c913fb3 commit 1be0f65
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 11 deletions.
12 changes: 12 additions & 0 deletions examples/alephium_pool.json
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,18 @@
"variancePercent": 100,
"maxDelta": 512
}
},
"3096": {
"listenAddress": "0.0.0.0",
"difficulty": 256,
"varDiff": {
"minDiff": 256,
"maxDiff": null,
"targetTime": 15,
"retargetTime": 90,
"variancePercent": 30,
"maxDelta": 2048
}
}
},
"daemons": [
Expand Down
3 changes: 3 additions & 0 deletions src/Miningcore/Blockchain/Alephium/AlephiumConstants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ public static class AlephiumConstants

public const string BlockTypeUncle = "uncle";
public const string BlockTypeBlock = "block";

public static readonly Regex RegexUserAgentGoldShell = new("goldshell", RegexOptions.Compiled | RegexOptions.IgnoreCase);
public static readonly Regex RegexUserAgentIceRiverMiner = new("iceriverminer", RegexOptions.Compiled | RegexOptions.IgnoreCase);

// Socket miner API
public const int MessageHeaderSize = 4; // 4 bytes body length
Expand Down
21 changes: 21 additions & 0 deletions src/Miningcore/Blockchain/Alephium/AlephiumJobManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using System.Reactive.Linq;
using System.Security.Cryptography;
using System.Text;
using System.Text.RegularExpressions;
using System.IO;
using System.Net;
using System.Net.Sockets;
Expand Down Expand Up @@ -573,6 +574,26 @@ public async Task<bool> ValidateAddress(string address, CancellationToken ct)
return validity?.Group1 >= 0;
}

public bool ValidateIsGoldShell(string userAgent)
{
if(string.IsNullOrEmpty(userAgent))
return false;

// Find matches
MatchCollection matchesUserAgentGoldShell = AlephiumConstants.RegexUserAgentGoldShell.Matches(userAgent);
return (matchesUserAgentGoldShell.Count > 0);
}

public bool ValidateIsIceRiverMiner(string userAgent)
{
if(string.IsNullOrEmpty(userAgent))
return false;

// Find matches
MatchCollection matchesUserAgentIceRiverMiner = AlephiumConstants.RegexUserAgentIceRiverMiner.Matches(userAgent);
return (matchesUserAgentIceRiverMiner.Count > 0);
}

#endregion // API-Surface

#region Overrides
Expand Down
29 changes: 18 additions & 11 deletions src/Miningcore/Blockchain/Alephium/AlephiumPool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ protected virtual async Task OnHelloAsync(StratumConnection connection, Timestam
// [Respect the goddamn standards Nicehack :(]
var response = new JsonRpcResponse<object[]>(data, request.Id);

if(context.IsNicehash)
if(context.IsNicehash || manager.ValidateIsGoldShell(context.UserAgent) || manager.ValidateIsIceRiverMiner(context.UserAgent))
{
response.Extra = new Dictionary<string, object>();
response.Extra["error"] = null;
Expand Down Expand Up @@ -105,7 +105,7 @@ protected virtual async Task OnSubscribeAsync(StratumConnection connection, Time
// [Respect the goddamn standards Nicehack :(]
var response = new JsonRpcResponse<object>(connection.ConnectionId, request.Id);

if(context.IsNicehash)
if(context.IsNicehash || manager.ValidateIsGoldShell(context.UserAgent) || manager.ValidateIsIceRiverMiner(context.UserAgent))
{
response.Extra = new Dictionary<string, object>();
response.Extra["error"] = null;
Expand Down Expand Up @@ -156,7 +156,7 @@ protected virtual async Task OnAuthorizeAsync(StratumConnection connection, Time
// [Respect the goddamn standards Nicehack :(]
var response = new JsonRpcResponse<object>(context.IsAuthorized, request.Id);

if(context.IsNicehash)
if(context.IsNicehash || manager.ValidateIsGoldShell(context.UserAgent) || manager.ValidateIsIceRiverMiner(context.UserAgent))
{
response.Extra = new Dictionary<string, object>();
response.Extra["error"] = null;
Expand Down Expand Up @@ -200,7 +200,10 @@ protected virtual async Task OnAuthorizeAsync(StratumConnection connection, Time

logger.Info(() => $"[{connection.ConnectionId}] Setting static difficulty of {staticDiff.Value}");
}


// send initial difficulty
await connection.NotifyAsync(AlephiumStratumMethods.SetDifficulty, new object[] { context.Difficulty });

// send intial job
await SendJob(connection, context, currentJobParams);
}
Expand Down Expand Up @@ -259,7 +262,7 @@ protected virtual async Task OnSubmitAsync(StratumConnection connection, Timesta
// [Respect the goddamn standards Nicehack :(]
var response = new JsonRpcResponse<object>(true, request.Id);

if(context.IsNicehash)
if(context.IsNicehash || manager.ValidateIsGoldShell(context.UserAgent) || manager.ValidateIsIceRiverMiner(context.UserAgent))
{
response.Extra = new Dictionary<string, object>();
response.Extra["error"] = null;
Expand Down Expand Up @@ -311,15 +314,19 @@ protected virtual async Task OnNewJobAsync(AlephiumJobParams jobParams)
await Guard(() => ForEachMinerAsync(async (connection, ct) =>
{
var context = connection.ContextAs<AlephiumWorkerContext>();
// varDiff: if the client has a pending difficulty change, apply it now
if(context.ApplyPendingDifficulty())
await connection.NotifyAsync(AlephiumStratumMethods.SetDifficulty, new object[] { context.Difficulty });
await SendJob(connection, context, currentJobParams);
}));
}

private async Task SendJob(StratumConnection connection, AlephiumWorkerContext context, AlephiumJobParams jobParams)
{
var target = EncodeTarget(context.Difficulty);

// clone job params
var jobParamsActual = new AlephiumJobParams
{
Expand All @@ -330,10 +337,7 @@ private async Task SendJob(StratumConnection connection, AlephiumWorkerContext c
TxsBlob = jobParams.TxsBlob,
TargetBlob = target,
};

// send difficulty
await connection.NotifyAsync(AlephiumStratumMethods.SetDifficulty, new object[] { context.Difficulty });


// send job
await connection.NotifyAsync(AlephiumStratumMethods.MiningNotify, new object[] { jobParamsActual });
}
Expand Down Expand Up @@ -480,6 +484,9 @@ protected override async Task OnVarDiffUpdateAsync(StratumConnection connection,

if(context.ApplyPendingDifficulty())
{
// send difficulty
await connection.NotifyAsync(AlephiumStratumMethods.SetDifficulty, new object[] { context.Difficulty });

// send job
await SendJob(connection, context, currentJobParams);
}
Expand Down

0 comments on commit 1be0f65

Please sign in to comment.