forked from drkskwlkr/NiceHashMinerLegacy
-
Notifications
You must be signed in to change notification settings - Fork 18
/
lolMiner.cs
758 lines (691 loc) · 35.6 KB
/
lolMiner.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
using System;
using System.IO;
using System.Collections.Generic;
using System.Text;
using System.Diagnostics;
using System.Globalization;
using System.Net;
using System.Net.Sockets;
using System.Windows.Forms;
using System.Management;
using NiceHashMiner.Configs;
using NiceHashMiner.Devices;
using NiceHashMiner.Miners.Grouping;
using NiceHashMiner.Miners.Parsing;
using System.Threading;
using System.Threading.Tasks;
using NiceHashMiner.Algorithms;
using NiceHashMiner.Switching;
using NiceHashMinerLegacy.Common.Enums;
using Newtonsoft.Json;
using System.Linq;
using System.Text.RegularExpressions;
using static NiceHashMiner.Devices.ComputeDeviceManager;
namespace NiceHashMiner.Miners
{
class lolMiner : Miner
{
private readonly int GPUPlatformNumber;
Stopwatch _benchmarkTimer = new Stopwatch();
private int _benchmarkTimeWait = 180;
public lolMiner()
: base("lolMiner")
{
GPUPlatformNumber = ComputeDeviceManager.Available.AmdOpenCLPlatformNum;
IsKillAllUsedMinerProcs = true;
IsNeverHideMiningWindow = true;
}
protected override int GetMaxCooldownTimeInMilliseconds() {
return 60*1000;
}
protected override void _Stop(MinerStopType willswitch) {
Stop_cpu_ccminer_sgminer_nheqminer(willswitch);
}
public override void Start(string url, string btcAdress, string worker)
{
if (!IsInit)
{
Helpers.ConsolePrint(MinerTag(), "MiningSetup is not initialized exiting Start()");
return;
}
string username = GetUsername(btcAdress, worker);
//IsApiReadException = MiningSetup.MinerPath == MinerPaths.Data.lolMiner;
IsApiReadException = false;
//add failover
string alg = url.Substring(url.IndexOf("://") + 3, url.IndexOf(".") - url.IndexOf("://") - 3);
string port = url.Substring(url.IndexOf(".com:") + 5, url.Length - url.IndexOf(".com:") - 5);
//var algo = "";
url = url.Replace("stratum+tcp://", "");
//url = url.Substring(0, url.IndexOf(":"));
var apiBind = " --apiport " + ApiPort;
if (MiningSetup.CurrentAlgorithmType == AlgorithmType.ZHash)
{
LastCommandLine = "--coin AUTO144_5 --pool " + url + " --user " + username + " --pass x" +
" --pool zhash." + Form_Main.myServers[1, 0] + ".nicehash.com:3369 " +" --user " + username + " --pass x" +
" --pool zhash." + Form_Main.myServers[2, 0] + ".nicehash.com:3369 " +" --user " + username + " --pass x" +
" --pool zhash." + Form_Main.myServers[3, 0] + ".nicehash.com:3369 " +" --user " + username + " --pass x" +
apiBind + " " +
ExtraLaunchParametersParser.ParseForMiningSetup(
MiningSetup,
DeviceType.AMD) +
" --devices ";
}
if (MiningSetup.CurrentAlgorithmType == AlgorithmType.BeamV2)
{
LastCommandLine = "--algo BEAM-II --pool " + url + " --user " + username + " --pass x --tls 0" +
" --pool beamv2." + Form_Main.myServers[1, 0] + ".nicehash.com:3378 " + " --user " + username + " --pass x --tls 0" +
" --pool beamv2." + Form_Main.myServers[2, 0] + ".nicehash.com:3378 " + " --user " + username + " --pass x --tls 0" +
" --pool beamv2." + Form_Main.myServers[3, 0] + ".nicehash.com:3378 " + " --user " + username + " --pass x --tls 0" +
apiBind + " " +
ExtraLaunchParametersParser.ParseForMiningSetup(
MiningSetup,
DeviceType.AMD) +
" --devices ";
}
if (MiningSetup.CurrentAlgorithmType == AlgorithmType.BeamV3)
{
LastCommandLine = "--algo BEAM-III --pool " + url + " --user " + username + " --pass x --tls 0" +
" --pool beamv3." + Form_Main.myServers[1, 0] + ".nicehash.com:3387 " + " --user " + username + " --pass x --tls 0" +
" --pool beamv3." + Form_Main.myServers[2, 0] + ".nicehash.com:3387 " + " --user " + username + " --pass x --tls 0" +
" --pool beamv3." + Form_Main.myServers[3, 0] + ".nicehash.com:3387 " + " --user " + username + " --pass x --tls 0" +
apiBind + " " +
ExtraLaunchParametersParser.ParseForMiningSetup(
MiningSetup,
DeviceType.AMD) +
" --devices ";
}
if (MiningSetup.CurrentAlgorithmType == AlgorithmType.GrinCuckatoo31)
{
LastCommandLine = "--coin MWC-C31 --pool " + url + " --user " + username + " --pass x" +
" --pool grincuckatoo31." + Form_Main.myServers[1, 0] + ".nicehash.com:3372 " + " --user " + username + " --pass x" +
" --pool grincuckatoo31." + Form_Main.myServers[2, 0] + ".nicehash.com:3372 " + " --user " + username + " --pass x" +
" --pool grincuckatoo31." + Form_Main.myServers[3, 0] + ".nicehash.com:3372 " + " --user " + username + " --pass x" +
apiBind + " " +
ExtraLaunchParametersParser.ParseForMiningSetup(
MiningSetup,
DeviceType.AMD) +
" --devices ";
}
if (MiningSetup.CurrentAlgorithmType == AlgorithmType.GrinCuckatoo32)
{
LastCommandLine = "--coin GRIN-C32 --pool " + url + " --user " + username + " --pass x" +
" --pool grincuckatoo32." + Form_Main.myServers[1, 0] + ".nicehash.com:3383 " + " --user " + username + " --pass x" +
" --pool grincuckatoo32." + Form_Main.myServers[2, 0] + ".nicehash.com:3383 " + " --user " + username + " --pass x" +
" --pool grincuckatoo32." + Form_Main.myServers[3, 0] + ".nicehash.com:3383 " + " --user " + username + " --pass x" +
apiBind + " " +
ExtraLaunchParametersParser.ParseForMiningSetup(
MiningSetup,
DeviceType.AMD) +
" --devices ";
}
if (MiningSetup.CurrentAlgorithmType == AlgorithmType.GrinCuckarood29)
{
LastCommandLine = "--coin MWC-C29D --pool " + url + " --user " + username + " --pass x" +
" --pool grincuckarood29." + Form_Main.myServers[1, 0] + ".nicehash.com:3377 " + " --user " + username + " --pass x" +
" --pool grincuckarood29." + Form_Main.myServers[2, 0] + ".nicehash.com:3377 " + " --user " + username + " --pass x" +
" --pool grincuckarood29." + Form_Main.myServers[3, 0] + ".nicehash.com:3377 " + " --user " + username + " --pass x" +
apiBind + " " +
ExtraLaunchParametersParser.ParseForMiningSetup(
MiningSetup,
DeviceType.AMD) +
" --devices ";
}
if (MiningSetup.CurrentAlgorithmType == AlgorithmType.CuckooCycle)
{
LastCommandLine = "--algo C29AE --pool " + url + " --user " + username + " --pass x" +
" --pool cuckoocycle." + Form_Main.myServers[1, 0] + ".nicehash.com:3376 " + " --user " + username + " --pass x" +
" --pool cuckoocycle." + Form_Main.myServers[2, 0] + ".nicehash.com:3376 " + " --user " + username + " --pass x" +
" --pool cuckoocycle." + Form_Main.myServers[3, 0] + ".nicehash.com:3376 " + " --user " + username + " --pass x" +
apiBind + " " +
ExtraLaunchParametersParser.ParseForMiningSetup(
MiningSetup,
DeviceType.AMD) +
" --devices ";
}
if (MiningSetup.CurrentAlgorithmType == AlgorithmType.DaggerHashimoto)
{
LastCommandLine = "--algo ETHASH --ethstratum=ETHV1 --pool " + url + " --user " + username + " --pass x" +
" --pool daggerhashimoto." + Form_Main.myServers[1, 0] + ".nicehash.com:3353 " + " --user " + username + " --pass x" +
" --pool daggerhashimoto." + Form_Main.myServers[2, 0] + ".nicehash.com:3353 " + " --user " + username + " --pass x" +
" --pool daggerhashimoto." + Form_Main.myServers[3, 0] + ".nicehash.com:3353 " + " --user " + username + " --pass x" +
apiBind + " " +
ExtraLaunchParametersParser.ParseForMiningSetup(
MiningSetup,
DeviceType.AMD) +
" --devices ";
}
if (MiningSetup.CurrentAlgorithmType == AlgorithmType.Autolykos)
{
LastCommandLine = "--algo AUTOLYKOS2 --pool " + url + " --user " + username + " --pass x" +
" --pool autolykos." + Form_Main.myServers[1, 0] + ".nicehash.com:3390 " + " --user " + username + " --pass x" +
" --pool autolykos." + Form_Main.myServers[2, 0] + ".nicehash.com:3390 " + " --user " + username + " --pass x" +
" --pool autolykos." + Form_Main.myServers[3, 0] + ".nicehash.com:3390 " + " --user " + username + " --pass x" +
apiBind + " " +
ExtraLaunchParametersParser.ParseForMiningSetup(
MiningSetup,
DeviceType.AMD) +
" --devices ";
}
LastCommandLine += GetDevicesCommandString() + " ";//
LastCommandLine = LastCommandLine.Replace("--asm 1", "");
string sColor = "";
if (GetWinVer(Environment.OSVersion.Version) < 8)
{
sColor = " --nocolor";
}
LastCommandLine += sColor;
ProcessHandle = _Start();
}
static int GetWinVer(Version ver)
{
if (ver.Major == 6 & ver.Minor == 1)
return 7;
else if (ver.Major == 6 & ver.Minor == 2)
return 8;
else
return 10;
}
// new decoupled benchmarking routines
#region Decoupled benchmarking routines
protected override string BenchmarkCreateCommandLine(Algorithm algorithm, int time) {
var apiBind = " --apiport " + ApiPort;
var CommandLine = "";
string url = Globals.GetLocationUrl(algorithm.NiceHashID, Globals.MiningLocation[ConfigManager.GeneralConfig.ServiceLocation], this.ConectionType);
string port = url.Substring(url.IndexOf(".com:") + 5, url.Length - url.IndexOf(".com:") - 5);
// demo for benchmark
var btcAddress = Globals.GetBitcoinUser();
var worker = ConfigManager.GeneralConfig.WorkerName.Trim();
string username = GetUsername(btcAddress, worker);
if (MiningSetup.CurrentAlgorithmType == AlgorithmType.BeamV2)
{
CommandLine = "--algo BEAM-II " +
" --pool beamv2.eu-north.nicehash.com:3378 --user " + username + " --pass x --tls 0" +
ExtraLaunchParametersParser.ParseForMiningSetup(
MiningSetup,
DeviceType.AMD) +
" --devices ";
}
if (MiningSetup.CurrentAlgorithmType == AlgorithmType.BeamV3)
{
CommandLine = "--algo BEAM-III " +
" --pool beam-eu.sparkpool.com:2222 --user 2c20485d95e81037ec2d0312b000b922f444c650496d600d64b256bdafa362bafc9.lolMiner --pass x" +
" --pool beam-asia.sparkpool.com:12222 --user 2c20485d95e81037ec2d0312b000b922f444c650496d600d64b256bdafa362bafc9.lolMiner --pass x" +
// " --pass x;x;x;x --tls 1;1;0;0 " +
ExtraLaunchParametersParser.ParseForMiningSetup(
MiningSetup,
DeviceType.AMD) +
" --devices ";
}
if (MiningSetup.CurrentAlgorithmType == AlgorithmType.ZHash)
{
CommandLine = "--algo EQUI144_5 --pers BgoldPoW" +
" --pool europe.equihash-hub.miningpoolhub.com:20595 --user angelbbs.lol --pass x" +
ExtraLaunchParametersParser.ParseForMiningSetup(
MiningSetup,
DeviceType.AMD) +
" --devices ";
}
if (MiningSetup.CurrentAlgorithmType == AlgorithmType.GrinCuckatoo31)
{
CommandLine = "--coin MWC-C31 " +
" --pool mwc.2miners.com:1111 --user 2aHR0cHM6Ly9td2MuaG90Yml0LmlvLzcyOTkyMw.lolMiner --pass x " +
"--pool grincuckatoo31.eu-north.nicehash.com:3372 --user " + username + " --pass x" +
ExtraLaunchParametersParser.ParseForMiningSetup(
MiningSetup,
DeviceType.AMD) +
" --devices ";
}
if (MiningSetup.CurrentAlgorithmType == AlgorithmType.GrinCuckatoo32)
{
CommandLine = "--coin GRIN-C32" +
" --pool grin.2miners.com:3030 --user grin16ek8qgx29ssku0q2cxez7830gh9ndw3ek5yzxe26x34s09528d2sldl6td.lolMiner --pass x" +
" --pool grincuckatoo32.eu-north.nicehash.com:3383 --user " + username + " --pass x" +
ExtraLaunchParametersParser.ParseForMiningSetup(
MiningSetup,
DeviceType.AMD) +
" --devices ";
}
if (MiningSetup.CurrentAlgorithmType == AlgorithmType.GrinCuckarood29)
{
CommandLine = "--coin MWC-C29D " +
" --pool mwc.2miners.com:1111 --user 2aHR0cHM6Ly9td2MuaG90Yml0LmlvLzcyOTkyMw.lolMiner --pass x" +
" --pool grincuckaroo29.eu-north.nicehash.com:3372 --user " + username + " --pass x" +
ExtraLaunchParametersParser.ParseForMiningSetup(
MiningSetup,
DeviceType.AMD) +
" --devices ";
}
if (MiningSetup.CurrentAlgorithmType == AlgorithmType.CuckooCycle)
{
CommandLine = "--algo C29AE " +
" --pool ae.2miners.com:4040 --user ak_2f9AMwztStKs5roPmT592wTbUEeTyqRgYVZNrc5TyZfr94m7fM.lolMiner --pass x" +
" --pool cuckoocycle.eu-north.nicehash.com:3376 --user " + username + " --pass x" +
ExtraLaunchParametersParser.ParseForMiningSetup(
MiningSetup,
DeviceType.AMD) +
" --devices ";
}
if (MiningSetup.CurrentAlgorithmType == AlgorithmType.DaggerHashimoto)
{
CommandLine = "--algo ETHASH " +
" --pool eu1.ethermine.org:4444 --user 0x9290e50e7ccf1bdc90da8248a2bbacc5063aeee1.lolMiner --pass x" +
" --pool daggerhashimoto.eu-north.nicehash.com:3353 --user " + username + " --pass x" +
ExtraLaunchParametersParser.ParseForMiningSetup(
MiningSetup,
DeviceType.AMD) +
" --devices ";
}
if (MiningSetup.CurrentAlgorithmType == AlgorithmType.Autolykos)
{
CommandLine = "--algo AUTOLYKOS2 " +
" --pool pool.eu.woolypooly.com:3100 --user 9gnVDaLeFa4ETwtrceHepPe9JeaCBGV1PxV5tdNGAvqEmjWF2Lt.lolMiner --pass x" +
ExtraLaunchParametersParser.ParseForMiningSetup(
MiningSetup,
DeviceType.AMD) +
" --devices ";
}
CommandLine += GetDevicesCommandString() + " "; //amd карты перечисляются первыми
_benchmarkTimeWait = time;
CommandLine = CommandLine.Replace("--asm 1", "");
string sColor = "";
if (GetWinVer(Environment.OSVersion.Version) < 8)
{
sColor = " --nocolor";
}
CommandLine += sColor;
CommandLine += apiBind;
return CommandLine;
}
protected void GetEnimeration()
{
var btcAddress = Globals.GetBitcoinUser();
var worker = ConfigManager.GeneralConfig.WorkerName.Trim();
string username = GetUsername(btcAddress, worker);
int edevice = 0;
double edeviceBus = 0;
var EnimerationHandle = new Process
{
StartInfo =
{
FileName = MiningSetup.MinerPath
}
};
{
Helpers.ConsolePrint(MinerTag(), "Using miner for enumeration: " + EnimerationHandle.StartInfo.FileName);
EnimerationHandle.StartInfo.WorkingDirectory = WorkingDirectory;
}
if (MinersSettingsManager.MinerSystemVariables.ContainsKey(Path))
{
foreach (var kvp in MinersSettingsManager.MinerSystemVariables[Path])
{
var envName = kvp.Key;
var envValue = kvp.Value;
EnimerationHandle.StartInfo.EnvironmentVariables[envName] = envValue;
}
}
var CommandLine = " --coin BEAM-II " +
" --pool localhost --port fake --user " + username + " --pass x --tls 0 --devices 999";//fake port for enumeration
EnimerationHandle.StartInfo.Arguments = CommandLine;
EnimerationHandle.StartInfo.UseShellExecute = false;
EnimerationHandle.StartInfo.RedirectStandardError = true;
EnimerationHandle.StartInfo.RedirectStandardOutput = true;
EnimerationHandle.StartInfo.CreateNoWindow = true;
Thread.Sleep(250);
Helpers.ConsolePrint(MinerTag(), "Start enumeration: " + EnimerationHandle.StartInfo.FileName + EnimerationHandle.StartInfo.Arguments);
EnimerationHandle.Start();
var allDeviceCount = ComputeDeviceManager.Query.GpuCount;
var allDevices = Available.Devices;
try
{
string outdata = "";
while (IsActiveProcess(EnimerationHandle.Id))
{
outdata = EnimerationHandle.StandardOutput.ReadLine();
Helpers.ConsolePrint(MinerTag(), outdata);
if (outdata.Contains("Device"))
{
string cdevice = Regex.Match(outdata, @"\d+").Value;
if (int.TryParse(cdevice, out edevice))
{
Helpers.ConsolePrint(MinerTag(), edevice.ToString());
}
}
if (outdata.Contains("Address:"))
{
string cdeviceBus = Regex.Match(outdata, @"\d+").Value;
if (double.TryParse(cdeviceBus, out edeviceBus))
{
Helpers.ConsolePrint(MinerTag(), edeviceBus.ToString());
// for (var i = 0; i < allDevices.Count; i++)
var sortedMinerPairs = MiningSetup.MiningPairs.OrderBy(pair => pair.Device.ID).ToList();
foreach (var mPair in sortedMinerPairs)
{
Helpers.ConsolePrint(MinerTag(), " IDByBus=" + mPair.Device.IDByBus.ToString() + " ID=" + mPair.Device.ID.ToString() + " edevice=" + edevice.ToString() + " edeviceBus=" + edeviceBus.ToString());
if (mPair.Device.IDByBus == edeviceBus)
{
// mPair.Device.lolMinerBusID = edevice;
}
}
// allDevices[edevice].lolMinerBusID = edeviceBus;
}
}
}
}
catch (Exception ex)
{
}
try
{
if (!EnimerationHandle.WaitForExit(10 * 1000))
{
EnimerationHandle.Kill();
EnimerationHandle.WaitForExit(5 * 1000);
EnimerationHandle.Close();
}
}
catch { }
Thread.Sleep(50);
}
protected override string GetDevicesCommandString()
{
var deviceStringCommand = " ";
var ids = new List<string>();
var amdDeviceCount = ComputeDeviceManager.Query.AmdDevices.Count;
var allDeviceCount = ComputeDeviceManager.Query.GpuCount;
Helpers.ConsolePrint("lolMinerIndexing", $"Found {allDeviceCount} Total GPU devices");
Helpers.ConsolePrint("lolMinerIndexing", $"Found {amdDeviceCount} AMD devices");
// var ids = MiningSetup.MiningPairs.Select(mPair => mPair.Device.ID.ToString()).ToList();
//var sortedMinerPairs = MiningSetup.MiningPairs.OrderBy(pair => pair.Device.DeviceType).ToList();
var sortedMinerPairs = MiningSetup.MiningPairs.OrderBy(pair => pair.Device.lolMinerBusID).ToList();
foreach (var mPair in sortedMinerPairs)
{
Helpers.ConsolePrint("lolMinerIndexing", "Index: " + mPair.Device.Index);
Helpers.ConsolePrint("lolMinerIndexing", "Name: " + mPair.Device.Name);
Helpers.ConsolePrint("lolMinerIndexing", "ID: " + mPair.Device.ID);
Helpers.ConsolePrint("lolMinerIndexing", "IDbybus: " + mPair.Device.IDByBus);
Helpers.ConsolePrint("lolMinerIndexing", "busid: " + mPair.Device.BusID);
Helpers.ConsolePrint("lolMinerIndexing", "lol: " + mPair.Device.lolMinerBusID);
//список карт выводить --devices 999
//double id = mPair.Device.IDByBus + allDeviceCount - amdDeviceCount;
int id = (int)mPair.Device.lolMinerBusID;
if (id < 0)
{
Helpers.ConsolePrint("lolMinerIndexing", "ID too low: " + id + " skipping device");
continue;
}
/*
if (mPair.Device.DeviceType == DeviceType.NVIDIA)
{
Helpers.ConsolePrint("lolMinerIndexing", "NVIDIA found. Increasing index");
id ++;
}
*/
Helpers.ConsolePrint("lolMinerIndexing", "Minind ID: " + id );
{
ids.Add(id.ToString());
}
}
deviceStringCommand += string.Join(",", ids);
return deviceStringCommand;
}
protected override bool BenchmarkParseLine(string outdata)
{
return true;
}
protected override void BenchmarkThreadRoutine(object commandLine)
{
BenchmarkSignalQuit = false;
BenchmarkSignalHanged = false;
BenchmarkSignalFinnished = false;
BenchmarkException = null;
double repeats = 0.0d;
double summspeed = 0.0d;
int delay_before_calc_hashrate = 10;
int MinerStartDelay = 10;
Thread.Sleep(ConfigManager.GeneralConfig.MinerRestartDelayMS);
try
{
if (MiningSetup.CurrentAlgorithmType.Equals(AlgorithmType.DaggerHashimoto))
{
_benchmarkTimeWait = _benchmarkTimeWait + 60;
}
if (MiningSetup.CurrentAlgorithmType.Equals(AlgorithmType.Autolykos))
{
_benchmarkTimeWait = _benchmarkTimeWait + 20;
}
if (MiningSetup.CurrentAlgorithmType.Equals(AlgorithmType.CuckooCycle))
{
_benchmarkTimeWait = _benchmarkTimeWait + 15;
}
Helpers.ConsolePrint("BENCHMARK", "Benchmark starts");
Helpers.ConsolePrint(MinerTag(), "Benchmark should end in: " + _benchmarkTimeWait + " seconds");
BenchmarkHandle = BenchmarkStartProcess((string)commandLine);
//BenchmarkHandle.WaitForExit(_benchmarkTimeWait + 2);
var benchmarkTimer = new Stopwatch();
benchmarkTimer.Reset();
benchmarkTimer.Start();
BenchmarkProcessStatus = BenchmarkProcessStatus.Running;
BenchmarkThreadRoutineStartSettup(); //need for benchmark log
while (IsActiveProcess(BenchmarkHandle.Id))
{
if (benchmarkTimer.Elapsed.TotalSeconds >= (_benchmarkTimeWait + 60)
|| BenchmarkSignalQuit
|| BenchmarkSignalFinnished
|| BenchmarkSignalHanged
|| BenchmarkSignalTimedout
|| BenchmarkException != null)
{
var imageName = MinerExeName.Replace(".exe", "");
// maybe will have to KILL process
EndBenchmarkProcces();
// KillMinerBase(imageName);
if (BenchmarkSignalTimedout)
{
throw new Exception("Benchmark timedout");
}
if (BenchmarkException != null)
{
throw BenchmarkException;
}
if (BenchmarkSignalQuit)
{
throw new Exception("Termined by user request");
}
if (BenchmarkSignalFinnished)
{
break;
}
//keepRunning = false;
break;
}
// wait a second due api request
Thread.Sleep(1000);
if (MiningSetup.CurrentAlgorithmType.Equals(AlgorithmType.DaggerHashimoto))
{
delay_before_calc_hashrate = 60;
MinerStartDelay = 20;
}
if (MiningSetup.CurrentAlgorithmType.Equals(AlgorithmType.Autolykos))
{
delay_before_calc_hashrate = 30;
MinerStartDelay = 20;
}
if (MiningSetup.CurrentAlgorithmType.Equals(AlgorithmType.ZHash))
{
delay_before_calc_hashrate = 10;
MinerStartDelay = 30;
}
if (MiningSetup.CurrentAlgorithmType.Equals(AlgorithmType.GrinCuckatoo31))
{
delay_before_calc_hashrate = 20;
MinerStartDelay = 10;
}
if (MiningSetup.CurrentAlgorithmType.Equals(AlgorithmType.GrinCuckatoo32))
{
delay_before_calc_hashrate = 10;
MinerStartDelay = 30;
}
if (MiningSetup.CurrentAlgorithmType.Equals(AlgorithmType.BeamV3))
{
delay_before_calc_hashrate = 20;
MinerStartDelay = 20;
}
if (MiningSetup.CurrentAlgorithmType.Equals(AlgorithmType.CuckooCycle))
{
delay_before_calc_hashrate = 40;
MinerStartDelay = 5;
}
var ad = GetSummaryAsync();
if (ad.Result != null && ad.Result.Speed > 0)
{
repeats++;
double benchProgress = repeats / (_benchmarkTimeWait - MinerStartDelay - 15);
BenchmarkAlgorithm.BenchmarkProgressPercent = (int)(benchProgress * 100);
if (repeats > delay_before_calc_hashrate)
{
Helpers.ConsolePrint(MinerTag(), "Useful API Speed: " + ad.Result.Speed.ToString());
if (MiningSetup.CurrentAlgorithmType.Equals(AlgorithmType.DaggerHashimoto))
{
summspeed = Math.Max(summspeed, ad.Result.Speed);
}
else
{
summspeed += ad.Result.Speed;
}
}
else
{
Helpers.ConsolePrint(MinerTag(), "Delayed API Speed: " + ad.Result.Speed.ToString());
}
if (repeats >= _benchmarkTimeWait - MinerStartDelay - 15)
{
Helpers.ConsolePrint(MinerTag(), "Benchmark ended");
ad.Dispose();
benchmarkTimer.Stop();
BenchmarkHandle.Kill();
BenchmarkHandle.Dispose();
EndBenchmarkProcces();
break;
}
}
}
if (MiningSetup.CurrentAlgorithmType.Equals(AlgorithmType.DaggerHashimoto))
{
BenchmarkAlgorithm.BenchmarkSpeed = summspeed;
}
else
{
BenchmarkAlgorithm.BenchmarkSpeed = Math.Round(summspeed / (repeats - delay_before_calc_hashrate), 2);
}
}
catch (Exception ex)
{
BenchmarkThreadRoutineCatch(ex);
}
finally
{
BenchmarkThreadRoutineFinish();
}
}
protected override void BenchmarkOutputErrorDataReceivedImpl(string outdata)
{
CheckOutdata(outdata);
}
#endregion // Decoupled benchmarking routines
public class lolResponse
{
public List<lolGpuResult> result { get; set; }
}
public class lolGpuResult
{
public double sol_ps { get; set; } = 0;
}
// TODO _currentMinerReadStatus
public override async Task<ApiData> GetSummaryAsync()
{
var ad = new ApiData(MiningSetup.CurrentAlgorithmType);
string ResponseFromlolMiner;
double total = 0;
try
{
HttpWebRequest WR = (HttpWebRequest)WebRequest.Create("http://127.0.0.1:" + ApiPort.ToString() + "/summary");
WR.UserAgent = "GET / HTTP/1.1\r\n\r\n";
WR.Timeout = 3 * 1000;
WR.Credentials = CredentialCache.DefaultCredentials;
WebResponse Response = WR.GetResponse();
Stream SS = Response.GetResponseStream();
SS.ReadTimeout = 2 * 1000;
StreamReader Reader = new StreamReader(SS);
ResponseFromlolMiner = await Reader.ReadToEndAsync();
//Helpers.ConsolePrint("API: ", ResponseFromlolMiner);
//if (ResponseFromlolMiner.Length == 0 || (ResponseFromlolMiner[0] != '{' && ResponseFromlolMiner[0] != '['))
// throw new Exception("Not JSON!");
Reader.Close();
Response.Close();
}
catch (Exception ex)
{
return null;
}
if (ResponseFromlolMiner == null)
{
CurrentMinerReadStatus = MinerApiReadStatus.NONE;
return null;
}
try
{
dynamic resp = JsonConvert.DeserializeObject(ResponseFromlolMiner);
int mult = 1;
if (resp != null)
{
int gpus = resp.Session.Active_GPUs;
double totals = resp.Session.Performance_Summary;
if (MiningSetup.CurrentAlgorithmType == AlgorithmType.DaggerHashimoto || MiningSetup.CurrentAlgorithmType == AlgorithmType.Autolykos)
{
mult = 1000000;
}
else
{
mult = 1;
}
ad.Speed = totals * mult;
if (gpus > 0)
{
double[] hashrates = new double[gpus];
for (var i = 0; i < gpus; i++)
{
hashrates[i] = resp.GPUs[i].Performance;
}
int dev = 0;
var sortedMinerPairs = MiningSetup.MiningPairs.OrderBy(pair => pair.Device.BusID).ToList();
if (Form_Main.NVIDIA_orderBug)
{
sortedMinerPairs.Sort((a, b) => a.Device.ID.CompareTo(b.Device.ID));
}
foreach (var mPair in sortedMinerPairs)
{
mPair.Device.MiningHashrate = hashrates[dev] * mult;
dev++;
}
if (ad.Speed == 0)
{
CurrentMinerReadStatus = MinerApiReadStatus.READ_SPEED_ZERO;
}
else
{
CurrentMinerReadStatus = MinerApiReadStatus.GOT_READ;
}
}
}
} catch (Exception e)
{
Helpers.ConsolePrint(MinerTag(), e.ToString());
}
Thread.Sleep(100);
//CurrentMinerReadStatus = MinerApiReadStatus.GOT_READ;
// check if speed zero
if (ad.Speed == 0) CurrentMinerReadStatus = MinerApiReadStatus.READ_SPEED_ZERO;
return ad;
}
}
}