Skip to content

Commit 1be0f65

Browse files
author
ceedii
committed
Add support for Goldshell AL BOX (I & II)
Add support for IceRiver ALPH AL0 Improves ALPH stratum handling of "mining.notify" & "mining.set_difficulty"
1 parent c913fb3 commit 1be0f65

File tree

4 files changed

+54
-11
lines changed

4 files changed

+54
-11
lines changed

examples/alephium_pool.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,18 @@
109109
"variancePercent": 100,
110110
"maxDelta": 512
111111
}
112+
},
113+
"3096": {
114+
"listenAddress": "0.0.0.0",
115+
"difficulty": 256,
116+
"varDiff": {
117+
"minDiff": 256,
118+
"maxDiff": null,
119+
"targetTime": 15,
120+
"retargetTime": 90,
121+
"variancePercent": 30,
122+
"maxDelta": 2048
123+
}
112124
}
113125
},
114126
"daemons": [

src/Miningcore/Blockchain/Alephium/AlephiumConstants.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ public static class AlephiumConstants
2222

2323
public const string BlockTypeUncle = "uncle";
2424
public const string BlockTypeBlock = "block";
25+
26+
public static readonly Regex RegexUserAgentGoldShell = new("goldshell", RegexOptions.Compiled | RegexOptions.IgnoreCase);
27+
public static readonly Regex RegexUserAgentIceRiverMiner = new("iceriverminer", RegexOptions.Compiled | RegexOptions.IgnoreCase);
2528

2629
// Socket miner API
2730
public const int MessageHeaderSize = 4; // 4 bytes body length

src/Miningcore/Blockchain/Alephium/AlephiumJobManager.cs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
using System.Reactive.Linq;
88
using System.Security.Cryptography;
99
using System.Text;
10+
using System.Text.RegularExpressions;
1011
using System.IO;
1112
using System.Net;
1213
using System.Net.Sockets;
@@ -573,6 +574,26 @@ public async Task<bool> ValidateAddress(string address, CancellationToken ct)
573574
return validity?.Group1 >= 0;
574575
}
575576

577+
public bool ValidateIsGoldShell(string userAgent)
578+
{
579+
if(string.IsNullOrEmpty(userAgent))
580+
return false;
581+
582+
// Find matches
583+
MatchCollection matchesUserAgentGoldShell = AlephiumConstants.RegexUserAgentGoldShell.Matches(userAgent);
584+
return (matchesUserAgentGoldShell.Count > 0);
585+
}
586+
587+
public bool ValidateIsIceRiverMiner(string userAgent)
588+
{
589+
if(string.IsNullOrEmpty(userAgent))
590+
return false;
591+
592+
// Find matches
593+
MatchCollection matchesUserAgentIceRiverMiner = AlephiumConstants.RegexUserAgentIceRiverMiner.Matches(userAgent);
594+
return (matchesUserAgentIceRiverMiner.Count > 0);
595+
}
596+
576597
#endregion // API-Surface
577598

578599
#region Overrides

src/Miningcore/Blockchain/Alephium/AlephiumPool.cs

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ protected virtual async Task OnHelloAsync(StratumConnection connection, Timestam
7171
// [Respect the goddamn standards Nicehack :(]
7272
var response = new JsonRpcResponse<object[]>(data, request.Id);
7373

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

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

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

201201
logger.Info(() => $"[{connection.ConnectionId}] Setting static difficulty of {staticDiff.Value}");
202202
}
203-
203+
204+
// send initial difficulty
205+
await connection.NotifyAsync(AlephiumStratumMethods.SetDifficulty, new object[] { context.Difficulty });
206+
204207
// send intial job
205208
await SendJob(connection, context, currentJobParams);
206209
}
@@ -259,7 +262,7 @@ protected virtual async Task OnSubmitAsync(StratumConnection connection, Timesta
259262
// [Respect the goddamn standards Nicehack :(]
260263
var response = new JsonRpcResponse<object>(true, request.Id);
261264

262-
if(context.IsNicehash)
265+
if(context.IsNicehash || manager.ValidateIsGoldShell(context.UserAgent) || manager.ValidateIsIceRiverMiner(context.UserAgent))
263266
{
264267
response.Extra = new Dictionary<string, object>();
265268
response.Extra["error"] = null;
@@ -311,15 +314,19 @@ protected virtual async Task OnNewJobAsync(AlephiumJobParams jobParams)
311314
await Guard(() => ForEachMinerAsync(async (connection, ct) =>
312315
{
313316
var context = connection.ContextAs<AlephiumWorkerContext>();
314-
317+
318+
// varDiff: if the client has a pending difficulty change, apply it now
319+
if(context.ApplyPendingDifficulty())
320+
await connection.NotifyAsync(AlephiumStratumMethods.SetDifficulty, new object[] { context.Difficulty });
321+
315322
await SendJob(connection, context, currentJobParams);
316323
}));
317324
}
318325

319326
private async Task SendJob(StratumConnection connection, AlephiumWorkerContext context, AlephiumJobParams jobParams)
320327
{
321328
var target = EncodeTarget(context.Difficulty);
322-
329+
323330
// clone job params
324331
var jobParamsActual = new AlephiumJobParams
325332
{
@@ -330,10 +337,7 @@ private async Task SendJob(StratumConnection connection, AlephiumWorkerContext c
330337
TxsBlob = jobParams.TxsBlob,
331338
TargetBlob = target,
332339
};
333-
334-
// send difficulty
335-
await connection.NotifyAsync(AlephiumStratumMethods.SetDifficulty, new object[] { context.Difficulty });
336-
340+
337341
// send job
338342
await connection.NotifyAsync(AlephiumStratumMethods.MiningNotify, new object[] { jobParamsActual });
339343
}
@@ -480,6 +484,9 @@ protected override async Task OnVarDiffUpdateAsync(StratumConnection connection,
480484

481485
if(context.ApplyPendingDifficulty())
482486
{
487+
// send difficulty
488+
await connection.NotifyAsync(AlephiumStratumMethods.SetDifficulty, new object[] { context.Difficulty });
489+
483490
// send job
484491
await SendJob(connection, context, currentJobParams);
485492
}

0 commit comments

Comments
 (0)