Skip to content

Commit bef24e7

Browse files
committed
Closes #10: Compatibility with xmr-stak 2.3.0 and newer
1 parent 47f957a commit bef24e7

File tree

14 files changed

+184
-47
lines changed

14 files changed

+184
-47
lines changed

xmr-stak-bootstrap/Core/Job/Generator/SampleConfigurationGenerator.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ public void Generate(string path)
1717
WriteAllText(configuration.PathsConfiguration.CpuTemplate, Resources.cpu_source);
1818
WriteAllText(configuration.PathsConfiguration.NvidiaTemplate, Resources.nvidia_source);
1919
WriteAllText(configuration.PathsConfiguration.AmdTemplate, Resources.amd_source);
20+
WriteAllText(configuration.PathsConfiguration.PoolsTemplate, Resources.pools_source);
2021
}
2122

2223
private static void WriteAllText(string path, string content)

xmr-stak-bootstrap/Core/Job/Miner/MinerRunner.cs

Lines changed: 63 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,13 @@ public void Run(MasterConfigurationModel configuration)
3636
continue;
3737
}
3838

39-
var configArgument = GetConfigurationArgument(configuration.PathsConfiguration.ConfigTemplate, outputPools);
39+
var currency = GetPoolCurrency(outputPools);
40+
if (string.IsNullOrWhiteSpace(currency))
41+
{
42+
Console.WriteLine(@"Instance {0}.{1} does not contain valid currency. Make sure currency for all pools is set to the same value.", RunConfigurationModel.ActiveSolutionConfiguration, i);
43+
continue;
44+
}
45+
4046
var utilizedHardware = instances.Hardware.Select(x => new UtilizedHardware
4147
{
4248
Hardware = configuration.Hardware.GetValue(x),
@@ -47,7 +53,10 @@ public void Run(MasterConfigurationModel configuration)
4753
var amdArgument = GetAmdArgument(configuration.PathsConfiguration.AmdTemplate, configuration.AmdProfiles, utilizedHardware.Where(x => x.Hardware.Type == "amd").ToList());
4854
var nvidiaArgument = GetNvidiaArgument(configuration.PathsConfiguration.NvidiaTemplate, configuration.NvidiaProfiles, utilizedHardware.Where(x => x.Hardware.Type == "nvidia").ToList());
4955

50-
RunMiner($"{configArgument} {cpuArgument} {amdArgument} {nvidiaArgument}");
56+
var configArgument = GetConfigurationArgument(configuration.PathsConfiguration.ConfigTemplate);
57+
var poolsArgument = GetPoolsArgument(configuration.PathsConfiguration.PoolsTemplate, outputPools, currency);
58+
59+
RunMiner($"{configArgument} {poolsArgument} {cpuArgument} {amdArgument} {nvidiaArgument}");
5160
}
5261
}
5362

@@ -64,11 +73,19 @@ private static List<PrioritizedPoolEntry> GetOutputPools(IDictionary<string, Poo
6473
TlsFingerprint = x.TlsFingerprint,
6574
WalletAddress = x.WalletAddress,
6675
UseNiceHash = x.UseNiceHash,
67-
UseTls = x.UseTls
76+
UseTls = x.UseTls,
77+
RigId = x.RigId,
78+
Currency = x.Currency
6879
})
6980
.ToList();
7081
}
7182

83+
private static string GetPoolCurrency(IEnumerable<PrioritizedPoolEntry> pools)
84+
{
85+
var currencies = pools.Select(x => (x.Currency ?? string.Empty).ToLower()).Distinct().ToList();
86+
return currencies.Count != 1 ? null : currencies.First();
87+
}
88+
7289
private static void RunMiner(string arguments)
7390
{
7491
var startInfo = new ProcessStartInfo(Path.GetFullPath("xmr-stak.exe"), arguments)
@@ -81,14 +98,29 @@ private static void RunMiner(string arguments)
8198
Process.Start(startInfo);
8299
}
83100

84-
private string GetConfigurationArgument(string configurationTemplatePath, IReadOnlyCollection<PrioritizedPoolEntry> pools)
101+
private string GetConfigurationArgument(string configurationTemplatePath)
85102
{
86-
var configPath = CreateTemporaryConfiguration(configurationTemplatePath, "config", "%POOLS%", pools);
103+
var configPath = CreateTemporaryConfiguration(configurationTemplatePath, "config");
87104
ScheduleFileDelete(configPath);
88105

89106
return $"--config \"{configPath}\"";
90107
}
91108

109+
private string GetPoolsArgument(string poolsTemplatePath, IReadOnlyCollection<PrioritizedPoolEntry> pools, string currency)
110+
{
111+
foreach (var prioritizedPoolEntry in pools)
112+
{
113+
prioritizedPoolEntry.Currency = null;
114+
}
115+
116+
var configPath = CreateTemporaryConfiguration(poolsTemplatePath, "pools",
117+
new VariableReplacement("%POOLS%", pools),
118+
new VariableReplacement("%CURRENCY%", currency));
119+
ScheduleFileDelete(configPath);
120+
121+
return $"--poolconf \"{configPath}\"";
122+
}
123+
92124
private string GetCpuArgument(string cpuTemplatePath, IDictionary<string, IList<CpuThreadEntry>> cpuConfiguration, ICollection<UtilizedHardware> entry)
93125
{
94126
if (entry.Count == 0)
@@ -97,7 +129,7 @@ private string GetCpuArgument(string cpuTemplatePath, IDictionary<string, IList<
97129
}
98130

99131
var cpuProfile = entry.SelectMany(x => cpuConfiguration.GetValue(x.Profile)).ToList();
100-
var path = CreateTemporaryConfiguration(cpuTemplatePath, "cpu", "%THREADS%", cpuProfile);
132+
var path = CreateTemporaryConfiguration(cpuTemplatePath, "cpu", new VariableReplacement("%THREADS%", cpuProfile));
101133
ScheduleFileDelete(path);
102134

103135
return $"--cpu \"{path}\"";
@@ -124,7 +156,7 @@ private string GetAmdArgument(string amdTemplatePath, IDictionary<string, IList<
124156
}))
125157
.ToList();
126158

127-
var path = CreateTemporaryConfiguration(amdTemplatePath, "amd", "%THREADS%", amdProfile);
159+
var path = CreateTemporaryConfiguration(amdTemplatePath, "amd", new VariableReplacement("%THREADS%", amdProfile));
128160
ScheduleFileDelete(path);
129161

130162
return $"--amd \"{path}\"";
@@ -153,21 +185,40 @@ private string GetNvidiaArgument(string nvidiaTemplatePath, IDictionary<string,
153185
}))
154186
.ToList();
155187

156-
var path = CreateTemporaryConfiguration(nvidiaTemplatePath, "nvidia", "%THREADS%", nvidiaProfile);
188+
var path = CreateTemporaryConfiguration(nvidiaTemplatePath, "nvidia", new VariableReplacement("%THREADS%", nvidiaProfile));
157189
ScheduleFileDelete(path);
158190

159191
return $"--nvidia \"{path}\"";
160192
}
161193

162-
private static string CreateTemporaryConfiguration(string templatePath, string type, string variable, object value)
194+
private static string CreateTemporaryConfiguration(string templatePath, string type, params VariableReplacement[] variables)
163195
{
164-
var configTemplateContent = File.ReadAllText(templatePath);
165-
var configContent = configTemplateContent.Replace(variable, JsonConvert.SerializeObject(value, Formatting.Indented));
196+
var content = File.ReadAllText(templatePath);
197+
if (variables != null)
198+
{
199+
foreach(var variable in variables)
200+
{
201+
content = content.Replace(variable.Variable, JsonConvert.SerializeObject(variable.Value, Formatting.Indented));
202+
}
203+
}
204+
166205
var configPath = $"{Guid.NewGuid()}.{type}.txt";
167-
File.WriteAllText(configPath, configContent);
206+
File.WriteAllText(configPath, content);
168207
return configPath;
169208
}
170209

210+
private class VariableReplacement
211+
{
212+
public string Variable { get; set; }
213+
public object Value { get; set; }
214+
215+
public VariableReplacement(string variable, object value)
216+
{
217+
Variable = variable;
218+
Value = value;
219+
}
220+
}
221+
171222
private void ScheduleFileDelete(string file)
172223
{
173224
Finalizer.ScheduleFinalization(() =>

xmr-stak-bootstrap/MasterConfiguration/Model/AmdThreadEntry.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,20 @@ public class AmdThreadEntry
1919
[DataMember(Name = "strided_index", EmitDefaultValue = true, IsRequired = true, Order = 50)]
2020
public bool StridedIndex { get; set; }
2121

22+
[DataMember(Name = "mem_chunk", EmitDefaultValue = true, IsRequired = true, Order = 60)]
23+
public int MemChunk { get; set; }
24+
25+
[DataMember(Name = "comp_mode", EmitDefaultValue = true, IsRequired = true, Order = 70)]
26+
public bool CompMode { get; set; }
27+
2228
public AmdThreadEntry()
2329
{
2430
Intensity = 1000;
2531
Worksize = 8;
2632
AffineToCpu = false;
2733
StridedIndex = true;
34+
MemChunk = 2;
35+
CompMode = true;
2836
}
2937
}
3038
}

xmr-stak-bootstrap/MasterConfiguration/Model/PathsConfiguration.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,16 @@ public class PathsConfiguration
1717
[DataMember(Name = "amd_template_path", EmitDefaultValue = true, IsRequired = true, Order = 40)]
1818
public string AmdTemplate { get; set; }
1919

20+
[DataMember(Name = "pools_template_path", EmitDefaultValue = true, IsRequired = true, Order = 50)]
21+
public string PoolsTemplate { get; set; }
22+
2023
public PathsConfiguration()
2124
{
2225
ConfigTemplate = "config.source.txt";
2326
NvidiaTemplate = "nvidia.source.txt";
2427
CpuTemplate = "cpu.source.txt";
2528
AmdTemplate = "amd.source.txt";
29+
PoolsTemplate = "pools.source.txt";
2630
}
2731
}
2832
}

xmr-stak-bootstrap/MasterConfiguration/Model/PoolEntry.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ public class PoolEntry
1111
[DataMember(Name = "wallet_address", EmitDefaultValue = true, IsRequired = true, Order = 20)]
1212
public string WalletAddress { get; set; }
1313

14+
[DataMember(Name = "rig_id", EmitDefaultValue = true, IsRequired = true, Order = 25)]
15+
public string RigId { get; set; }
16+
1417
[DataMember(Name = "pool_password", EmitDefaultValue = true, IsRequired = true, Order = 30)]
1518
public string PoolPassword { get; set; }
1619

@@ -23,6 +26,9 @@ public class PoolEntry
2326
[DataMember(Name = "tls_fingerprint", EmitDefaultValue = true, IsRequired = true, Order = 60)]
2427
public string TlsFingerprint { get; set; }
2528

29+
[DataMember(Name = "currency", EmitDefaultValue = false, IsRequired = true, Order = 70)]
30+
public string Currency { get; set; }
31+
2632
public PoolEntry()
2733
{
2834
PoolAddress = "pool.address.tld:1234";
@@ -31,6 +37,8 @@ public PoolEntry()
3137
UseNiceHash = false;
3238
UseTls = false;
3339
WalletAddress = "your_wallet_address";
40+
RigId = string.Empty;
41+
Currency = "electroneum";
3442
}
3543
}
3644
}

xmr-stak-bootstrap/MasterConfiguration/Templates/amd.source.txt

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,28 @@
11
/*
22
* GPU configuration. You should play around with intensity and worksize as the fastest settings will vary.
3-
* index - GPU index number usually starts from 0
4-
* intensity - Number of parallel GPU threads (nothing to do with CPU threads)
5-
* worksize - Number of local GPU threads (nothing to do with CPU threads)
3+
* index - GPU index number usually starts from 0
4+
* intensity - Number of parallel GPU threads (nothing to do with CPU threads)
5+
* worksize - Number of local GPU threads (nothing to do with CPU threads)
66
* affine_to_cpu - This will affine the thread to a CPU. This can make a GPU miner play along nicer with a CPU miner.
77
* strided_index - switch memory pattern used for the scratch pad memory
8-
* true = use 16byte contiguous memory per thread, the next memory block has offset of intensity blocks
9-
* false = use a contiguous block of memory per thread
8+
* 2 = chunked memory, chunk size is controlled by 'mem_chunk'
9+
* required: intensity must be a multiple of worksize
10+
* 1 or true = use 16byte contiguous memory per thread, the next memory block has offset of intensity blocks
11+
* 0 or false = use a contiguous block of memory per thread
12+
* mem_chunk - range 0 to 18: set the number of elements (16byte) per chunk
13+
* this value is only used if 'strided_index' == 2
14+
* element count is computed with the equation: 2 to the power of 'mem_chunk' e.g. 4 means a chunk of 16 elements(256byte)
15+
* comp_mode - Compatibility enable/disable the automatic guard around compute kernel which allows
16+
* to use a intensity which is not the multiple of the worksize.
17+
* If you set false and the intensity is not multiple of the worksize the miner can crash:
18+
* in this case set the intensity to a multiple of the worksize or activate comp_mode.
1019
* "gpu_threads_conf" :
1120
* [
12-
* { "index" : 0, "intensity" : 1000, "worksize" : 8, "affine_to_cpu" : false, "strided_index" : true },
21+
* { "index" : 0, "intensity" : 1000, "worksize" : 8, "affine_to_cpu" : false, "strided_index" : true, "mem_chunk" : 2, "comp_mode" : true },
1322
* ],
23+
* If you do not wish to mine with your AMD GPU(s) then use:
24+
* "gpu_threads_conf" :
25+
* null,
1426
*/
1527

1628
"gpu_threads_conf" : %THREADS%,

xmr-stak-bootstrap/MasterConfiguration/Templates/config.source.txt

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,4 @@
11

2-
/*
3-
* pool_address - Pool address should be in the form "pool.supportxmr.com:3333". Only stratum pools are supported.
4-
* wallet_address - Your wallet, or pool login.
5-
* pool_password - Can be empty in most cases or "x".
6-
* use_nicehash - Limit the nonce to 3 bytes as required by nicehash.
7-
* use_tls - This option will make us connect using Transport Layer Security.
8-
* tls_fingerprint - Server's SHA256 fingerprint. If this string is non-empty then we will check the server's cert against it.
9-
* pool_weight - Pool weight is a number telling the miner how important the pool is. Miner will mine mostly at the pool
10-
* with the highest weight, unless the pool fails. Weight must be an integer larger than 0.
11-
*
12-
* We feature pools up to 1MH/s. For a more complete list see M5M400's pool list at www.moneropools.com
13-
*/
14-
"pool_list" : %POOLS%,
15-
16-
/*
17-
* currency to mine
18-
* allowed values: 'monero' or 'aeon'
19-
*/
20-
"currency" : "monero",
21-
222
/*
233
* Network timeouts.
244
* Because of the way this client is written it doesn't need to constantly talk (keep-alive) to the server to make

xmr-stak-bootstrap/Program.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ private bool ConsoleEventCallback(int eventType)
4949

5050
public void Run()
5151
{
52-
if (ConfigurationModel == null) return;
52+
if (!ConfigurationModel.IsValid) return;
5353

5454
_handler = ConsoleEventCallback;
5555
SetConsoleCtrlHandler(_handler, true);
@@ -61,6 +61,7 @@ public void Run()
6161
Job.Execute();
6262

6363
if (ConfigurationModel.ContinuousMode) continue;
64+
if (ConfigurationModel.GenerateConfigurationOnly) break;
6465

6566
Console.WriteLine(@"Waiting 30 seconds before finalization.");
6667
Thread.Sleep(30000);

xmr-stak-bootstrap/ProgramBootstrapper.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ private static RunConfigurationModel ParseRunConfiguration(IUnityContainer unity
3939
{
4040
var parser = unityContainer.Resolve<IRunConfigurationParser>();
4141
var config = parser.Parse(args);
42-
return config.Errors.Any() ? null : config.Value;
42+
return config.Errors.Any() ? RunConfigurationModel.InvalidModel : config.Value;
4343
}
4444
}
4545
}

xmr-stak-bootstrap/Properties/Resources.Designer.cs

Lines changed: 24 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

xmr-stak-bootstrap/Properties/Resources.resx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,4 +130,7 @@
130130
<data name="nvidia_source" type="System.Resources.ResXFileRef, System.Windows.Forms">
131131
<value>..\MasterConfiguration\Templates\nvidia.source.txt;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;windows-1250</value>
132132
</data>
133+
<data name="pools_source" type="System.Resources.ResXFileRef, System.Windows.Forms">
134+
<value>..\Resources\pools_source.txt;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;windows-1250</value>
135+
</data>
133136
</root>

0 commit comments

Comments
 (0)