forked from tutulino/Megaminer
-
Notifications
You must be signed in to change notification settings - Fork 14
/
Core.ps1
1740 lines (1489 loc) · 88.8 KB
/
Core.ps1
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
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
param(
[parameter(mandatory = $true)]
[validateset('Automatic', 'Automatic24h', 'Manual')]
[string]$MiningMode,
[parameter(mandatory = $true)]
[array]$PoolsName,
[parameter(mandatory = $false)]
[array]$Algorithm,
[parameter(mandatory = $false)]
[array]$CoinsName,
[parameter(mandatory = $false)]
[array]$GroupNames
)
# Requires -Version 5.0
$Error.Clear()
Import-Module ./Include.psm1
Set-OsFlags
$Global:IsAdmin = Test-Admin
if ($IsWindows) {
try { Set-WindowSize 170 50 } catch { }
}
# Start log file
$LogPath = "./Logs/"
if (-not (Test-Path $LogPath)) { $null = New-Item -Path $LogPath -ItemType directory}
$LogName = $LogPath + "forager-$(Get-Date -Format "yyyyMMdd-HHmmss").log"
Start-Transcript $LogName #for start log msg
$null = Stop-Transcript
$global:LogFile = [System.IO.StreamWriter]::new( $LogName, $true )
$LogFile.AutoFlush = $true
Clear-Files
if ([Net.ServicePointManager]::SecurityProtocol -notmatch [Net.SecurityProtocolType]::Tls12) {
[Net.ServicePointManager]::SecurityProtocol += [Net.SecurityProtocolType]::Tls12
}
# Force Culture to en-US
$culture = [System.Globalization.CultureInfo]::CreateSpecificCulture("en-US")
$culture.NumberFormat.NumberDecimalSeparator = "."
$culture.NumberFormat.NumberGroupSeparator = ","
[System.Threading.Thread]::CurrentThread.CurrentCulture = $culture
$ErrorActionPreference = "Continue"
$Global:Release = @{
Application = "Forager"
Version = "20.04"
}
Log "$($Release.Application) v$($Release.Version)"
$Global:SystemInfo = Get-SystemInfo
Log "System Info: $($SystemInfo | ConvertTo-Json -Depth 1)" -Severity Debug
$Host.UI.RawUI.WindowTitle = "$($Release.Application) v$($Release.Version)"
if ($env:CUDA_DEVICE_ORDER -ne 'PCI_BUS_ID') { $env:CUDA_DEVICE_ORDER = 'PCI_BUS_ID' } # Align CUDA id with nvidia-smi order
if ($env:GPU_FORCE_64BIT_PTR -ne 1) { $env:GPU_FORCE_64BIT_PTR = 1 } # For AMD
if ($env:GPU_MAX_HEAP_SIZE -ne 100) { $env:GPU_MAX_HEAP_SIZE = 100 } # For AMD
if ($env:GPU_USE_SYNC_OBJECTS -ne 1) { $env:GPU_USE_SYNC_OBJECTS = 1 } # For AMD
if ($env:GPU_MAX_ALLOC_PERCENT -ne 100) { $env:GPU_MAX_ALLOC_PERCENT = 100 } # For AMD
if ($env:GPU_SINGLE_ALLOC_PERCENT -ne 100) { $env:GPU_SINGLE_ALLOC_PERCENT = 100 } # For AMD
if ($env:GPU_MAX_WORKGROUP_SIZE -ne 256) { $env:GPU_MAX_WORKGROUP_SIZE = 256 } # For AMD
# Set process priority to BelowNormal to avoid hash rate drops on systems with weak CPUs
(Get-Process -Id $PID).PriorityClass = "BelowNormal"
if ($IsWindows) {
Import-Module NetSecurity -ErrorAction SilentlyContinue
Import-Module Defender -ErrorAction SilentlyContinue
Import-Module "$env:Windir\System32\WindowsPowerShell\v1.0\Modules\NetSecurity\NetSecurity.psd1" -ErrorAction SilentlyContinue
Import-Module "$env:Windir\System32\WindowsPowerShell\v1.0\Modules\Defender\Defender.psd1" -ErrorAction SilentlyContinue
if ($PSEdition -eq 'core') { Import-Module -SkipEditionCheck NetTCPIP -ErrorAction SilentlyContinue }
if (Get-Command "Unblock-File" -ErrorAction SilentlyContinue) { Get-ChildItem . -Recurse | Unblock-File }
if ((Get-Command "Get-MpPreference" -ErrorAction SilentlyContinue) -and (Get-MpPreference).ExclusionPath -notcontains (Convert-Path .)) {
Start-Process (@{desktop = "powershell"; core = "pwsh" }.$PSEdition) "-Command Import-Module '$env:Windir\System32\WindowsPowerShell\v1.0\Modules\Defender\Defender.psd1'; Add-MpPreference -ExclusionPath '$(Convert-Path .)'" -Verb runAs
}
}
$ActiveMiners = @()
$ShowBestMinersOnly = $true
$Interval = @{
Current = $null
Last = $null
Duration = $null
LastTime = $null
Benchmark = $null
StartTime = Get-Date # First initialization
}
$Global:Config = Get-Config
$Params = @{
Querymode = "Info"
PoolsFilterList = $PoolsName
CoinFilterList = $CoinsName
Location = $Config.Location
AlgoFilterList = $Algorithm
}
$PoolsChecking = Get-Pools @Params
$PoolsErrors = $PoolsChecking | Where-Object "ActiveOn$($MiningMode)Mode" -eq $false
if ($PoolsErrors) {
$PoolsErrors | ForEach-Object {
Log "$MiningMode MiningMode is not valid for pool $($_.Name)" -Severity Warn
}
Exit
}
if ($MiningMode -eq 'Manual' -and ($CoinsName -split ',').Count -ne 1) {
Log "On manual mode one coin must be selected" -Severity Warn
Exit
}
if ($MiningMode -eq 'Manual' -and ($Algorithm -split ',').Count -ne 1) {
Log "On manual mode one algorithm must be selected" -Severity Warn
Exit
}
# Initial Parameters
$InitialParams = @{
Algorithm = $Algorithm
PoolsName = $PoolsName
CoinsName = $CoinsName
MiningMode = $MiningMode
}
$Msg = @("Initial Parameters: "
"Algorithm: " + [string]($Algorithm -join ",")
"PoolsName: " + [string]($PoolsName -join ",")
"CoinsName: " + [string]($CoinsName -join ",")
"MiningMode: " + $MiningMode
"GroupNames: " + [string]($GroupNames -join ",")
) -join ' //'
Log $Msg -Severity Debug
Start-Autoexec
# Initialize MSI Afterburner
if ($Config.Afterburner -and $IsWindows) {
. "$PSScriptRoot/Includes/Afterburner.ps1"
}
$Screen = 'Profits'
$StatsPath = "./Stats/"
$BinPath = $(if ($IsLinux) { "./BinLinux/" } else { "./Bin/" })
$MinersPath = $(if ($IsLinux) { "./MinersLinux/" } else { "./Miners/" })
if (-not (Test-Path $BinPath)) { $null = New-Item -Path $BinPath -ItemType directory -Force }
if (-not (Test-Path $StatsPath)) { $null = New-Item -Path $StatsPath -ItemType directory -Force }
Send-ErrorsToLog $LogFile
# This loop will be running forever
while ($Quit -ne $true) {
$Global:Config = Get-Config
Log "Config File: $($Config | ConvertTo-Json -Depth 1)" -Severity Debug
$Global:MinerParameters = Get-MinerParameters
Clear-Host
$RepaintScreen = $true
Get-Updates
# Get mining types
$DeviceGroupsConfig = Get-MiningTypes -Filter $GroupNames
Test-DeviceGroupsConfig $DeviceGroupsConfig
if ($null -ne $DeviceGroups) {
$DeviceGroupsConfig | ForEach-Object {
if ($DeviceGroups.GroupName -contains $_.GroupName) {
$_.Enabled = $DeviceGroups | Where-Object GroupName -eq $_.GroupName | Select-Object -ExpandProperty Enabled -First 1
}
}
} else {
Log "Device List: $($DeviceGroupsConfig | ConvertTo-Json -Depth 1)" -Severity Debug
Log "Device Information: $(Get-DevicesInformation $DeviceGroupsConfig | ConvertTo-Json -Depth 1)" -Severity Debug
}
$DeviceGroups = $DeviceGroupsConfig
$DeviceGroupsCount = $DeviceGroups | Measure-Object | Select-Object -ExpandProperty Count
if ($DeviceGroupsCount -gt 0) {
$InitialProfitsScreenLimit = [Math]::Floor(30 / $DeviceGroupsCount) - 5
}
if ($null -eq $ProfitsScreenLimit) {
$ProfitsScreenLimit = $InitialProfitsScreenLimit
}
# Get electricity cost for current time
($Config.ElectricityCost | ConvertFrom-Json) | ForEach-Object {
if ((
$_.HourStart -lt $_.HourEnd -and
@(($_.HourStart)..($_.HourEnd)) -contains (Get-Date).Hour
) -or (
$_.HourStart -gt $_.HourEnd -and (
@(($_.HourStart)..23) -contains (Get-Date).Hour -or
@(0..($_.HourEnd)) -contains (Get-Date).Hour
)
)
) {
$PowerCost = [decimal]$_.CostKwh
}
}
Log "New interval starting"
$Interval.Last = $Interval.Current
$Interval.LastTime = (Get-Date) - $Interval.StartTime
$Interval.StartTime = Get-Date
# Donation
$DonationsFile = "./Data/donations.json"
$DonationStat = if (Test-Path $DonationsFile) { Get-FileContent $DonationsFile | ConvertFrom-Json } else { @(0, 0) }
$Config.DonateMinutes = [math]::Max($Config.DonateMinutes, 10)
$MiningTime = $DonationStat[0]
$DonatedTime = $DonationStat[1]
switch ($Interval.Last) {
"Mining" { $MiningTime += $Interval.LastTime.TotalMinutes }
"Donate" { $DonatedTime += $Interval.LastTime.TotalMinutes }
}
if ($DonatedTime -ge $Config.DonateMinutes) {
$MiningTime = 0
$DonatedTime = 0
}
@($MiningTime, $DonatedTime) | ConvertTo-Json | Set-Content $DonationsFile
# Activate or deactivate donation
if ($MiningTime -gt 24 * 60) {
# Donation interval
$Interval.Current = "Donate"
$Global:Config.UserName = "ffwd"
$Global:Config.WorkerName = "Donate"
$Global:Wallets = @{
BTC = "3NoVvkGSNjPX8xBMWbP2HioWYK395wSzGL"
BTC_NH = "37YdKzKSibrEmE3XmsgmV14Mey3gmy4wGg"
LTC = "MXCsACfauv4zAub3jcM64weqEpG979uArm"
}
$Global:Config.Currency_Zergpool = "LTC"
$DonateInterval = [math]::min(($Config.DonateMinutes - $DonatedTime), 5) * 60
$Algorithm = $null
$PoolsName = @("NiceHash", "Zergpool")
$CoinsName = $null
$MiningMode = "Automatic"
$PowerCost = 0
Log "Next interval you will be donating for $DonateInterval seconds, thanks for your support"
} else {
# Mining interval
$Interval.Current = "Mining"
$Algorithm = $InitialParams.Algorithm
$PoolsName = $InitialParams.PoolsName
$CoinsName = $InitialParams.CoinsName
$MiningMode = $InitialParams.MiningMode
if (-not $Config.WorkerName) { $Config.WorkerName = $SystemInfo.ComputerName }
$Global:Wallets = Get-Wallets
}
Send-ErrorsToLog $LogFile
Log "Loading Pools Information"
# Load information about the Pools
do {
$Params = @{
Querymode = "Core"
PoolsFilterList = $PoolsName
CoinFilterList = $CoinsName
Location = $Config.Location
AlgoFilterList = $Algorithm
}
$AllPools = Get-Pools @Params
if ($AllPools.Count -eq 0) {
Log "NO POOLS! Retry in 30 seconds" -Severity Warn
Log "If you are mining on anonymous pool without exchage, like YIIMP, NANOPOOL or similar, you must set wallet for at least one pool coin in config.ini" -Severity Warn
Start-Sleep 30
}
} while ($AllPools.Count -eq 0)
$AllPools | Select-Object -ExpandProperty Name -Unique | ForEach-Object { Log "Pool $_ was responsive" }
Log "Found $($AllPools.Count) pool/algo variations"
# Filter by MinWorkers variable (only if there is any pool greater than minimum)
$Pools = ($AllPools | Where-Object {
$_.PoolWorkers -eq $null -or
$_.PoolWorkers -ge $(if ($Config.('MinWorkers_' + $_.PoolName) -ne $null) { $Config.('MinWorkers_' + $_.PoolName) } else { $Config.MinWorkers })
}
)
if ($Pools.Count -ge 1) {
Log "$($Pools.Count) pools left after MinWorkers filter"
} else {
$Pools = $AllPools
Log "No pools matching MinWorkers config, filter ignored"
}
# Select highest paying pool for each algo and check if pool is alive.
Log "Select top paying pool for each algo in config"
if ($Config.PingPools) { Log "Checking pool availability" }
if ($DeviceGroups | Where-Object { -not $_.Algorithms }) {
$AlgoList = $null
} else {
$AlgoList = $DeviceGroups.Algorithms | ForEach-Object { $_ -split '_' } | Select-Object -Unique
}
$PoolsFiltered = $Pools |
Group-Object -Property Algorithm |
Where-Object { $null -eq $AlgoList -or $AlgoList -contains $_.Name } |
ForEach-Object {
$NeedPool = $true
# Order by price (profitability)
$_.Group | Select-Object *, @{Name = "Estimate"; Expression = { if ($MiningMode -eq 'Automatic24h' -and $_.Price24h) { [decimal]$_.Price24h } else { [decimal]$_.Price } } } |
Sort-Object -Property `
@{Expression = "Estimate"; Descending = $true },
@{Expression = "LocationPriority"; Ascending = $true } | ForEach-Object {
if ($NeedPool) {
# test tcp connection to pool
if (-not $Config.PingPools -or (Test-TCPPort -Server $_.Host -Port $_.Port -Timeout 100)) {
$NeedPool = $false
$_ # return result
} else {
Log "$($_.PoolName): $($_.Host):$($_.Port) is not responding!" -Severity Warn
}
}
}
}
$Pools = $PoolsFiltered
Log "$($Pools.Count) pools left"
Remove-Variable PoolsFiltered
# Call API for local currenry convertion rates
try {
$CDKResponse = Invoke-APIRequest -Url "https://api.coindesk.com/v1/bpi/currentprice/$($Config.LocalCurrency).json" -MaxAge 60 |
Select-Object -ExpandProperty BPI
$LocalBTCvalue = $CDKResponse.$($Config.LocalCurrency).rate_float
Log "CoinDesk API was responsive"
} catch {
Log "Coindesk API not responding, no local coin conversion" -Severity Warn
}
# Load Miners
$Miners = @()
$Params = @{
Path = $MinersPath + "*"
Include = "*.json*", "*.ps1"
}
$MinersFolderContent = Get-ChildItem @Params
Log "Files in miner folder: $($MinersFolderContent.count)" -Severity Debug
Log "Number of device groups: $(($DeviceGroups | Where-Object Enabled).Count)/$($DeviceGroups.Count)" -Severity Debug
foreach ($MinerFile in $MinersFolderContent) {
$Miner = Get-MinerFile -MinerFile $MinerFile
if (-not $Miner) {
Continue
}
foreach ($DeviceGroup in ($DeviceGroups | Where-Object GroupType -eq $Miner.Type)) {
if (
$Config.("ExcludeMiners_" + $DeviceGroup.GroupName) -and
($Config.("ExcludeMiners_" + $DeviceGroup.GroupName).Split(',') | Where-Object { $MinerFile.BaseName -ilike $_.Trim() })
) {
Log "$($MinerFile.BaseName) is Excluded for $($DeviceGroup.GroupName). Skipping" -Severity Debug
Continue
}
Log "$($MinerFile.BaseName) is valid for $($DeviceGroup.GroupName)" -Severity Debug
foreach ($Algo in $Miner.Algorithms.PSObject.Properties) {
$AlgoTmp, $AlgoLabel = $Algo.Name -split "\|"
$AlgoName, $AlgoNameDual = $AlgoTmp -split "_" | ForEach-Object { Get-AlgoUnifiedName $_ }
$Algorithms = @($AlgoName, $AlgoNameDual) -ne $null -join '_'
if ($null -ne $SystemInfo.CUDAVersion -and $null -ne $Miner.CUDA) {
if ([version]("$($Miner.CUDA).0") -gt [version]$SystemInfo.CUDAVersion) {
Log "$($MinerFile.BaseName) skipped due to CUDA version constraints" -Severity Debug
Continue
}
}
if ($null -ne $DeviceGroup.MemoryGB -and $Miner.Mem -gt $DeviceGroup.MemoryGB) {
Log "$($MinerFile.BaseName) skipped due to memory constraints" -Severity Debug
Continue
}
if ($DeviceGroup.GroupType -eq 'CPU' -and $Config.CpuThreads -gt 0) {
$AlgoLabel += 't' + $Config.CpuThreads
$CpuThreads = $Config.CpuThreads
} else {
$CpuThreads = $null
}
if ($DeviceGroup.Algorithms -and $DeviceGroup.Algorithms -notcontains $Algorithms) { Continue } #check config has this algo as minable
foreach ($Pool in ($Pools | Where-Object Algorithm -eq $AlgoName)) {
# Search pools for that algo
if (-not $AlgoNameDual -or ($Pools | Where-Object Algorithm -eq $AlgoNameDual)) {
# Set flag if both Miner and Pool support SSL
$EnableSSL = [bool]($Miner.SSL -and $Pool.SSL)
# Replace placeholder patterns
$WorkerNameMain = $Config.WorkerName + '_' + $DeviceGroup.GroupName
if ($Pool.PoolName -eq 'Nicehash') {
$WorkerNameMain = $WorkerNameMain -replace '[^\w\.]', '_' # Nicehash requires alphanumeric WorkerNames
}
$PoolUser = $Pool.User -replace '#WorkerName#', $WorkerNameMain
$PoolPass = $Pool.Pass -replace '#WorkerName#', $WorkerNameMain
$MinerFee = $ExecutionContext.InvokeCommand.ExpandString($Miner.Fee)
$NoCpu = $ExecutionContext.InvokeCommand.ExpandString($Miner.NoCpu)
$CustomParams = $Miner.Custom
if ($Algo.Value -is [string]) {
$AlgoParams = $Algo.Value
} else {
$AlgoParams = $Algo.Value.Params
if ($Algo.Value.PSObject.Properties['Custom']) {
$CustomParams = $Algo.Value.Custom
}
if ($Algo.Value.PSObject.Properties['Fee']) {
$MinerFee = $ExecutionContext.InvokeCommand.ExpandString($Algo.Value.Fee)
}
if ($Algo.Value.PSObject.Properties['NoCpu']) {
$NoCpu = $ExecutionContext.InvokeCommand.ExpandString($Algo.Value.NoCpu)
}
# Limitations
if (
$Algo.Value.Enabled -eq $false -or
$Algo.Value.NH -eq $false -and $Pool.PoolName -eq 'NiceHash' -or
($Algo.Value.Mem -gt $DeviceGroup.MemoryGB * $(if ($SystemInfo.OSVersion.Major -eq 10) { 0.9 } else { 1 }) -and $DeviceGroup.MemoryGB -gt 0)
) {
Continue
}
}
if ($MinerParameters.($MinerFile.BaseName).($Algo.Name) -is [string] ) {
$CustomParams = $MinerParameters.($MinerFile.BaseName).($Algo.Name)
}
$Params = @{
'#AlgorithmParameters#' = $AlgoParams
'#CustomParameters#' = $CustomParams
'#Algorithm#' = $AlgoName
'#Protocol#' = $(if ($EnableSSL) { $Pool.ProtocolSSL } else { $Pool.Protocol })
'#Server#' = $(if ($EnableSSL -and $null -ne $Pool.HostSSL) { $Pool.HostSSL } else { $Pool.Host })
'#Port#' = $(if ($EnableSSL) { $Pool.PortSSL } else { $Pool.Port })
'#Login#' = $PoolUser
'#Password#' = $PoolPass
'#EMail#' = $Config.EMail
'#WorkerName#' = $WorkerNameMain
'#EthStMode#' = $Pool.EthStMode
'#GPUPlatform#' = $DeviceGroup.PlatformId
'#Devices#' = $DeviceGroup.Devices
'#DevicesClayMode#' = Format-DeviceList -List $DeviceGroup.Devices -Type Clay
'#DevicesETHMode#' = Format-DeviceList -List $DeviceGroup.Devices -Type Eth
'#DevicesNsgMode#' = Format-DeviceList -List $DeviceGroup.Devices -Type Nsg
'#GroupName#' = $DeviceGroup.GroupName
}
$Arguments = $Miner.Arguments -join " "
$Arguments = $Arguments -replace '#AlgorithmParameters#', $AlgoParams
foreach ($P in $Params.Keys) { $Arguments = $Arguments -replace $P, $Params.$P }
foreach ($P in $Params.Keys) { $Arguments = $Arguments -replace $P, $Params.$P }
$PatternConfigFile = $Miner.PatternConfigFile -replace '#Algorithm#', $AlgoName -replace '#GroupName#', $DeviceGroup.GroupName
if ($PatternConfigFile -and (Test-Path -Path "./Data/Patterns/$PatternConfigFile")) {
$ConfigFileArguments = Edit-ForEachDevice (Get-FileContent "./Data/Patterns/$PatternConfigFile") -Devices $DeviceGroup
foreach ($P in $Params.Keys) { $ConfigFileArguments = $ConfigFileArguments -replace $P, $Params.$P }
foreach ($P in $Params.Keys) { $ConfigFileArguments = $ConfigFileArguments -replace $P, $Params.$P }
} else { $ConfigFileArguments = $null }
# Search for DualMining pool
if ($AlgoNameDual) {
$PoolDual = $Pools |
Where-Object Algorithm -eq $AlgoNameDual |
Sort-Object Estimate -Descending |
Select-Object -First 1
# Set flag if both Miner and Pool support SSL
$EnableDualSSL = ($Miner.SSL -and $PoolDual.SSL)
# Replace placehoder patterns
$WorkerNameDual = $Config.WorkerName + '_' + $DeviceGroup.GroupName + 'D'
if ($PoolDual.PoolName -eq 'Nicehash') {
$WorkerNameDual = $WorkerNameDual -replace '[^\w\.]', '_' # Nicehash requires alphanumeric WorkerNames
}
$PoolUserDual = $PoolDual.User -replace '#WorkerName#', $WorkerNameDual
$PoolPassDual = $PoolDual.Pass -replace '#WorkerName#', $WorkerNameDual
$Params = @{
'#PortDual#' = $(if ($EnableDualSSL) { $PoolDual.PortSSL } else { $PoolDual.Port })
'#ServerDual#' = $(if ($EnableDualSSL -and $null -ne $PoolDual.HostSSL) { $PoolDual.HostSSL } else { $PoolDual.Host })
'#ProtocolDual#' = $(if ($EnableDualSSL) { $PoolDual.ProtocolSSL } else { $PoolDual.Protocol })
'#LoginDual#' = $PoolUserDual
'#PasswordDual#' = $PoolPassDual
'#AlgorithmDual#' = $AlgoNameDual
'#WorkerNameDual#' = $WorkerNameDual
}
foreach ($P in $Params.Keys) { $Arguments = $Arguments -replace $P, $Params.$P }
foreach ($P in $Params.Keys) { $Arguments = $Arguments -replace $P, $Params.$P }
if ($PatternConfigFile -and (Test-Path -Path "./Data/Patterns/$PatternConfigFile")) {
foreach ($P in $Params.Keys) { $ConfigFileArguments = $ConfigFileArguments -replace $P, $Params.$P }
foreach ($P in $Params.Keys) { $ConfigFileArguments = $ConfigFileArguments -replace $P, $Params.$P }
}
} else {
$PoolDual = $null
$PoolUserDual = $null
}
$Arguments = $ExecutionContext.InvokeCommand.ExpandString($Arguments)
# SubMiner are variations of miner that not need to relaunch
# Creates a "SubMiner" object for each PL
$SubMiners = @()
foreach ($PowerLimit in ($DeviceGroup.PowerLimits)) {
# Always create as least a power limit 0
# Check ActiveMiners if the miner exists already to conserve some properties and not read files
$FoundMiner = $ActiveMiners | Where-Object {
$_.Name -eq $MinerFile.BaseName -and
$_.Algorithm -eq $AlgoName -and
$_.AlgorithmDual -eq $AlgoNameDual -and
$_.AlgoLabel -eq $AlgoLabel -and
$_.Pool.PoolName -eq $Pool.PoolName -and
$_.PoolDual.PoolName -eq $PoolDual.PoolName -and
$_.Pool.Info -eq $Pool.Info -and
$_.PoolDual.Info -eq $PoolDual.Info -and
$_.DeviceGroup.GroupName -eq $DeviceGroup.GroupName
}
if ($FoundMiner) { $FoundMiner.DeviceGroup = $DeviceGroup }
$FoundSubMiner = $FoundMiner.SubMiners | Where-Object { $_.PowerLimit -eq $PowerLimit }
if (-not $FoundSubMiner) {
$Params = @{
Algorithm = $Algorithms
MinerName = $MinerFile.BaseName
GroupName = $DeviceGroup.GroupName
PowerLimit = $PowerLimit
AlgoLabel = $AlgoLabel
}
[array]$Hrs = Get-HashRates @Params
} else {
[array]$Hrs = $FoundSubMiner.SpeedReads
}
if ($Hrs.Count -gt 10) {
# Remove 10 percent of lowest and highest rate samples which may skew the average
$Hrs = $Hrs | Sort-Object Speed
$p5Index = [math]::Ceiling($Hrs.Count * 0.05)
$p95Index = [math]::Ceiling($Hrs.Count * 0.95)
$Hrs = $Hrs[$p5Index..$p95Index] | Sort-Object SpeedDual, Speed
$p5Index = [math]::Ceiling($Hrs.Count * 0.05)
$p95Index = [math]::Ceiling($Hrs.Count * 0.95)
$Hrs = $Hrs[$p5Index..$p95Index]
$PowerValue = [decimal]($Hrs | Measure-Object -property Power -average).average
$HashRateValue = [decimal]($Hrs | Measure-Object -property Speed -average).average
$HashRateValueDual = [decimal]($Hrs | Measure-Object -property SpeedDual -average).average
} else {
$PowerValue = 0
$HashRateValue = 0
$HashRateValueDual = 0
}
# Calculate revenue
$SubMinerRevenue = [decimal]($HashRateValue * $Pool.Estimate)
$SubMinerRevenueDual = [decimal]($HashRateValueDual * $PoolDual.Estimate)
# Apply fee to revenue
$SubMinerRevenue *= (1 - $MinerFee)
if (-not $FoundSubMiner) {
$Params = @{
Algorithm = $Algorithms
MinerName = $MinerFile.BaseName
GroupName = $DeviceGroup.GroupName
PowerLimit = $PowerLimit
AlgoLabel = $AlgoLabel
}
$StatsHistory = Get-Stats @Params
} else {
$StatsHistory = $FoundSubMiner.StatsHistory
}
$Stats = [PSCustomObject]@{
BestTimes = 0
BenchmarkedTimes = 0
LastTimeActive = [DateTime]0
ActivatedTimes = 0
ActiveTime = 0
FailedTimes = 0
StatsTime = [DateTime]0
}
if (-not $StatsHistory) { $StatsHistory = $Stats }
if ($SubMiners.Count -eq 0 -or $SubMiners[0].StatsHistory.BestTimes -gt 0) {
# Only add a SubMiner (distinct from first if first was best at some time)
$SubMiners += [PSCustomObject]@{
Id = $SubMiners.Count
Best = $false
BestBySwitch = ""
CpuLoad = 0
HashRate = $HashRateValue
HashRateDual = $HashRateValueDual
NeedBenchmark = [bool]($HashRateValue -eq 0 -or ($AlgorithmDual -and $HashRateValueDual -eq 0))
PowerAvg = $PowerValue
PowerLimit = $PowerLimit
PowerLive = 0
Profits = (($SubMinerRevenue + $SubMinerRevenueDual) * $localBTCvalue) - ($PowerCost * ($PowerValue * 24) / 1000) # Profit is revenue minus electricity cost
ProfitsLive = 0
Revenue = $SubMinerRevenue
RevenueDual = $SubMinerRevenueDual
RevenueLive = 0
RevenueLiveDual = 0
SharesLive = @($null, $null)
SpeedLive = 0
SpeedLiveDual = 0
SpeedReads = if ($null -ne $Hrs) { [array]$Hrs } else { @() }
Status = 'Idle'
Stats = $Stats
StatsHistory = $StatsHistory
TimeSinceStartInterval = [TimeSpan]0
}
}
} # End foreach PowerLimit
$Miners += [PSCustomObject] @{
AlgoLabel = $AlgoLabel
Algorithm = $AlgoName
AlgorithmDual = $AlgoNameDual
Algorithms = $Algorithms
Api = $Miner.Api
ApiPort = $( if (-not $Config.ForceDynamicPorts) { $DeviceGroup.ApiPort } )
Arguments = $ExecutionContext.InvokeCommand.ExpandString($Arguments)
BenchmarkArg = $ExecutionContext.InvokeCommand.ExpandString($Miner.BenchmarkArg)
ConfigFileArguments = $ExecutionContext.InvokeCommand.ExpandString($ConfigFileArguments)
DeviceGroup = $DeviceGroup
ExtractionPath = $BinPath + $MinerFile.BaseName + "/"
GenerateConfigFile = $(if ($PatternConfigFile) { $BinPath + $MinerFile.BaseName + "/" + $($Miner.GenerateConfigFile -replace '#GroupName#', $DeviceGroup.GroupName -replace '#Algorithm#', $AlgoName) })
MinerFee = [decimal]$MinerFee
Name = $MinerFile.BaseName
NoCpu = $NoCpu
Path = $BinPath + $MinerFile.BaseName + "/" + $ExecutionContext.InvokeCommand.ExpandString($Miner.Path)
Pool = $Pool
PoolDual = $PoolDual
PrelaunchCommand = $Miner.PrelaunchCommand
SubMiners = $SubMiners
URI = $Miner.URI
UserName = $PoolUser
UserNameDual = $PoolUserDual
WorkerName = $WorkerNameMain
WorkerNameDual = $WorkerNameDual
}
} # Dualmining
} # End foreach pool
} # End foreach algo
} # End foreach DeviceGroup
} # End foreach Miner
Log "Miners/Pools combinations detected: $($Miners.Count)"
# Launch download of miners
$Miners |
Where-Object {
-not [string]::IsNullOrEmpty($_.Uri) -and
-not [string]::IsNullOrEmpty($_.ExtractionPath) -and
-not [string]::IsNullOrEmpty($_.Path) } |
Select-Object Uri, ExtractionPath, Path -Unique |
ForEach-Object {
if (-not (Test-Path $_.Path)) {
Start-Downloader -Uri $_.Uri -ExtractionPath $_.ExtractionPath -Path $_.Path
}
}
Send-ErrorsToLog $LogFile
# Show no miners message
$Miners = $Miners | Where-Object { Test-Path $_.Path }
if ($Miners.Count -eq 0) {
Log "NO MINERS! Retry in 30 seconds" -Severity Warn
Start-Sleep -Seconds 30
Continue
}
# Update the active miners list which exists for all execution time
foreach ($ActiveMiner in ($ActiveMiners | Sort-Object [int]id)) {
# Search existing miners to update data
$Miner = $Miners | Where-Object {
$_.Name -eq $ActiveMiner.Name -and
$_.Algorithm -eq $ActiveMiner.Algorithm -and
$_.AlgorithmDual -eq $ActiveMiner.AlgorithmDual -and
$_.AlgoLabel -eq $ActiveMiner.AlgoLabel -and
$_.Pool.PoolName -eq $ActiveMiner.Pool.PoolName -and
$_.PoolDual.PoolName -eq $ActiveMiner.PoolDual.PoolName -and
$_.Pool.Info -eq $ActiveMiner.Pool.Info -and
$_.PoolDual.Info -eq $ActiveMiner.PoolDual.Info -and
$_.DeviceGroup.Id -eq $ActiveMiner.DeviceGroup.Id
}
if (($Miner | Measure-Object).count -gt 1) {
Log "DUPLICATE MINER $($Miner.Algorithms) in $($Miner.Name)" -Severity Warn
Exit
}
if ($Miner) {
# We found that miner
$ActiveMiner.Arguments = $Miner.Arguments
$ActiveMiner.Pool = $Miner.Pool
$ActiveMiner.PoolDual = $Miner.PoolDual
$ActiveMiner.IsValid = $true
foreach ($SubMiner in $Miner.SubMiners) {
if (($ActiveMiner.SubMiners | Where-Object { $_.Id -eq $SubMiner.Id }).Count -eq 0) {
$SubMiner | Add-Member IdF $ActiveMiner.Id
$ActiveMiner.SubMiners += $SubMiner
} else {
$ActiveMiner.SubMiners[$SubMiner.Id].HashRate = $SubMiner.HashRate
$ActiveMiner.SubMiners[$SubMiner.Id].HashRateDual = $SubMiner.HashRateDual
$ActiveMiner.SubMiners[$SubMiner.Id].NeedBenchmark = $SubMiner.NeedBenchmark
$ActiveMiner.SubMiners[$SubMiner.Id].PowerAvg = $SubMiner.PowerAvg
$ActiveMiner.SubMiners[$SubMiner.Id].Profits = $SubMiner.Profits
$ActiveMiner.SubMiners[$SubMiner.Id].Revenue = $SubMiner.Revenue
$ActiveMiner.SubMiners[$SubMiner.Id].RevenueDual = $SubMiner.RevenueDual
}
}
} else {
# An existing miner is not found now
$ActiveMiner.IsValid = $false
}
}
# Add new miners to list
foreach ($Miner in $Miners) {
$ActiveMiner = $ActiveMiners | Where-Object {
$_.Name -eq $Miner.Name -and
$_.Algorithm -eq $Miner.Algorithm -and
$_.AlgorithmDual -eq $Miner.AlgorithmDual -and
$_.AlgoLabel -eq $Miner.AlgoLabel -and
$_.Pool.PoolName -eq $Miner.Pool.PoolName -and
$_.PoolDual.PoolName -eq $Miner.PoolDual.PoolName -and
$_.Pool.Info -eq $Miner.Pool.Info -and
$_.PoolDual.Info -eq $Miner.PoolDual.Info -and
$_.DeviceGroup.Id -eq $Miner.DeviceGroup.Id
}
if (-not $ActiveMiner) {
$Miner.SubMiners | Add-Member IdF $ActiveMiners.Count
$ActiveMiners += [PSCustomObject]@{
AlgoLabel = $Miner.AlgoLabel
Algorithm = $Miner.Algorithm
AlgorithmDual = $Miner.AlgorithmDual
Algorithms = $Miner.Algorithms
Api = $Miner.Api
ApiPort = $Miner.ApiPort
Arguments = $Miner.Arguments
BenchmarkArg = $Miner.BenchmarkArg
ConfigFileArguments = $Miner.ConfigFileArguments
DeviceGroup = $Miner.DeviceGroup
GenerateConfigFile = $Miner.GenerateConfigFile
Id = $ActiveMiners.Count
IsValid = $true
MinerFee = $Miner.MinerFee
Name = $Miner.Name
NoCpu = $Miner.NoCpu
Path = Convert-Path $Miner.Path
Pool = $Miner.Pool
PoolDual = $Miner.PoolDual
PrelaunchCommand = $Miner.PrelaunchCommand
Process = $null
SubMiners = $Miner.SubMiners
UserName = $Miner.UserName
UserNameDual = $Miner.UserNameDual
WorkerName = $Miner.WorkerName
WorkerNameDual = $Miner.WorkerNameDual
}
}
}
# Reset failed miners after 2 hours
$ActiveMiners.SubMiners | Where-Object { $_.Status -eq 'Failed' -and $_.Stats.LastTimeActive -lt (Get-Date).AddHours(-2) } | ForEach-Object {
$_.Status = 'Idle'
$_.Stats.FailedTimes = 0
Log "Reset failed miner status: $($ActiveMiners[$_.IdF].Name)/$($ActiveMiners[$_.IdF].Algorithms)"
}
Log "Active Miners-Pools: $(($ActiveMiners | Where-Object IsValid | Select-Object -ExpandProperty SubMiners | Where-Object Status -ne 'Failed').Count)"
Send-ErrorsToLog $LogFile
Log "Pending benchmarks: $(($ActiveMiners | Where-Object IsValid | Select-Object -ExpandProperty SubMiners | Where-Object NeedBenchmark | Select-Object -ExpandProperty Id).Count)"
$Msg = ($ActiveMiners.SubMiners | ForEach-Object {
"$($_.IdF)-$($_.Id), " +
"$($ActiveMiners[$_.IdF].DeviceGroup.GroupName), " +
"$(if ($ActiveMiners[$_.IdF].IsValid) {'Valid'} else {'Invalid'}), " +
"PL $($_.PowerLimit), " +
"$($_.Status), " +
"$($ActiveMiners[$_.IdF].Name), " +
"$($ActiveMiners[$_.IdF].Algorithms), " +
"$($ActiveMiners[$_.IdF].Pool.Info), " +
"$($ActiveMiners[$_.IdF].Process.Id)"
}) | ConvertTo-Json
Log $Msg -Severity Debug
$BestLastMiners = $ActiveMiners.SubMiners | Where-Object { @("Running", "PendingStop", "PendingFail") -contains $_.Status }
# Check if must cancel miner/algo/coin combo
$BestLastMiners | Where-Object {
$_.Status -eq 'PendingFail' -and
($ActiveMiners[$_.IdF].SubMiners.Stats.FailedTimes | Measure-Object -Sum).Sum -ge 3
} | ForEach-Object {
$ActiveMiners[$_.IdF].SubMiners | ForEach-Object { $_.Status = 'Failed' }
Log "Detected 3 fails, disabling $($ActiveMiners[$_.IdF].DeviceGroup.GroupName)/$($ActiveMiners[$_.IdF].Name)/$($ActiveMiners[$_.IdF].Algorithms)" -Severity Warn
}
# Select miners that need Benchmark, or if running in Manual mode, or highest Profit above zero.
$BestNowCandidates = $ActiveMiners | Where-Object { $_.IsValid -and $_.UserName -and $_.DeviceGroup.Enabled } |
Group-Object { $_.DeviceGroup.GroupName } | ForEach-Object {
$_.Group.Subminers | Where-Object {
$_.Status -ne 'Failed' -and
(
$_.NeedBenchmark -or
$MiningMode -eq "Manual" -or
$Interval.Current -eq "Donate" -or
$_.Profits -gt $ActiveMiners[$_.IdF].DeviceGroup.MinProfit -or
-not $LocalBTCvalue -gt 0
)
} | Sort-Object NeedBenchmark,
{ $(if ($MiningMode -eq "Manual") { $_.HashRate } elseif ($LocalBTCvalue -gt 0) { $_.Profits } else { $_.Revenue + $_.RevenueDual }) },
{ [int]($_.PowerLimit -replace '[^\d]') } -Descending
}
if ($Interval.Current -eq "Donate") {
# Don't use unbenchmarked miners during donation unless there is no benchmarked miner
$DonateBest = $BestNowCandidates | Where-Object NeedBenchmark -ne $true
if ($null -ne $DonateBest) {
$BestNowCandidates = $DonateBest
}
Remove-Variable DonateBest
}
$BestNowMiners = $BestNowCandidates | Group-Object {
$ActiveMiners[$_.IdF].DeviceGroup.GroupName
} | ForEach-Object { $_.Group | Select-Object -First 1 }
# If GPU miner prevents CPU mining, check if it's more probitable to skip such miner or mine GPU only
if ($DeviceGroups.GroupType -contains 'CPU' -and ($BestNowMiners | Where-Object { $ActiveMiners[$_.IdF].NoCpu })) {
$AltBestNowMiners = $BestNowCandidates | Where-Object {
$ActiveMiners[$_.IdF].NoCpu -ne $true
} | Group-Object {
$ActiveMiners[$_.IdF].DeviceGroup.GroupName
} | ForEach-Object { $_.Group | Select-Object -First 1 }
$BestNowProfits = ($BestNowMiners | Where-Object { $ActiveMiners[$_.IdF].DeviceGroup.GroupType -ne 'CPU' }).Profits | Measure-Object -Sum | Select-Object -ExpandProperty Sum
$AltBestNowProfits = $AltBestNowMiners.Profits | Measure-Object -Sum | Select-Object -ExpandProperty Sum
if ($AltBestNowMiners.NeedBenchmark -contains $true -or ($AltBestNowProfits -gt $BestNowProfits -and $BestNowMiners.NeedBenchmark -notcontains $true)) {
$BestNowMiners = $AltBestNowMiners
Log "Skipping miners that prevent CPU mining" -Severity Warn
} else {
$BestNowMiners = $BestNowMiners | Where-Object { $ActiveMiners[$_.IdF].DeviceGroup.GroupType -ne 'CPU' }
Log "Miner prevents CPU mining. Will not mine on CPU" -Severity Warn
}
}
# For each type, select most profitable miner, not benchmarked has priority, new miner is only lauched if new profit is greater than old by PercentToSwitch
# This section changes SubMiner
foreach ($DeviceGroup in $DeviceGroups) {
# Look for best miner from last Interval
$BestLast = $BestLastMiners | Where-Object { $ActiveMiners[$_.IdF].DeviceGroup.GroupName -eq $DeviceGroup.GroupName }
if ($BestLast) {
$ProfitLast = $BestLast.Profits
$BestLastLogMsg = @(
"$($DeviceGroup.GroupName)"
"$($ActiveMiners[$BestLast.IdF].Name)"
"$($ActiveMiners[$BestLast.IdF].Algorithms)"
"$($ActiveMiners[$BestLast.IdF].AlgoLabel)"
"PL$($BestLast.PowerLimit)"
) -join '/'
# Cancel miner if current pool workers below MinWorkers
if (
$null -ne $ActiveMiners[$BestLast.IdF].PoolWorkers -and
$ActiveMiners[$BestLast.IdF].PoolWorkers -le $(if ($null -ne $Config.("MinWorkers_" + $ActiveMiners[$BestLast.IdF].Pool.PoolName)) { $Config.("MinWorkers_" + $ActiveMiners[$BestLast.IdF].Pool.PoolName) }else { $Config.MinWorkers })
) {
$BestLast.Status = 'PendingStop'
Log "Cancelling miner due to low worker count"
}
} else {
$ProfitLast = 0
}
if ($BestLast -and $Config.SessionStatistics) {
$BestLast | Select-Object -Property `
@{Name = "Date" ; Expression = { Get-Date -f "yyyy-MM-dd" } },
@{Name = "Time" ; Expression = { Get-Date -f "HH:mm:ss" } },
@{Name = "Group" ; Expression = { $DeviceGroup.GroupName } },
@{Name = "Name" ; Expression = { $ActiveMiners[$_.IdF].Name } },
@{Name = "Algorithm" ; Expression = { $ActiveMiners[$_.IdF].Algorithm } },
@{Name = "AlgorithmDual" ; Expression = { $ActiveMiners[$_.IdF].AlgorithmDual } },
@{Name = "AlgoLabel" ; Expression = { $ActiveMiners[$_.IdF].AlgoLabel } },
@{Name = "Coin" ; Expression = { $ActiveMiners[$_.IdF].Pool.Info } },
@{Name = "CoinDual" ; Expression = { $ActiveMiners[$_.IdF].PoolDual.Info } },
@{Name = "PoolName" ; Expression = { $ActiveMiners[$_.IdF].Pool.PoolName } },
@{Name = "PoolNameDual" ; Expression = { $ActiveMiners[$_.IdF].PoolDual.PoolName } },
@{Name = "PowerLimit" ; Expression = { $_.PowerLimit } },
@{Name = "HashRate" ; Expression = { [decimal]$_.HashRate } },
@{Name = "HashRateDual" ; Expression = { [decimal]$_.HashRateDual } },
@{Name = "Revenue" ; Expression = { [decimal]$_.Revenue } },
@{Name = "RevenueDual" ; Expression = { [decimal]$_.RevenueDual } },
@{Name = "Profits" ; Expression = { [decimal]$_.Profits } },
@{Name = "IntervalRevenue" ; Expression = { [decimal]$_.Revenue * $Interval.LastTime.TotalSeconds / (24 * 60 * 60) } },
@{Name = "IntervalRevenueDual" ; Expression = { [decimal]$_.RevenueDual * $Interval.LastTime.TotalSeconds / (24 * 60 * 60) } },
@{Name = "Interval" ; Expression = { [int]$Interval.LastTime.TotalSeconds } } |
Export-Csv -Path $("./Logs/Stats-" + (Get-Process -PID $PID).StartTime.tostring('yyyy-MM-dd_HH-mm-ss') + ".csv") -Append -NoTypeInformation
}
# Check for best for next interval
$BestNow = $BestNowMiners | Where-Object { $ActiveMiners[$_.IdF].DeviceGroup.GroupName -eq $DeviceGroup.GroupName }
if ($BestNow) {
$BestNowLogMsg = @(
"$($DeviceGroup.GroupName)"
"$($ActiveMiners[$BestNow.IdF].Name)"
"$($ActiveMiners[$BestNow.IdF].Algorithms)"
"$($ActiveMiners[$BestNow.IdF].AlgoLabel)"
"PL$($BestNow.PowerLimit)"
) -join '/'
$ProfitNow = $BestNow.Profits
if ($BestNow.NeedBenchmark -eq $false) {
$ActiveMiners[$BestNow.IdF].SubMiners[$BestNow.Id].BestBySwitch = ""
$ActiveMiners[$BestNow.IdF].SubMiners[$BestNow.Id].Stats.BestTimes++
$ActiveMiners[$BestNow.IdF].SubMiners[$BestNow.Id].StatsHistory.BestTimes++
}
Log ("Current best: $BestNowLogMsg")
} else {
Log "No valid candidate for device group $($DeviceGroup.GroupName)" -Severity Warn
}
if (
$BestLast.IdF -ne $BestNow.IdF -or
$BestLast.Id -ne $BestNow.Id -or
@('PendingStop', 'PendingFail', 'Failed') -contains $BestLast.Status -or
$Interval.Current -ne $Interval.Last -or
-not $BestNow
) {
# Something changes or some miner error
if (
$Interval.Current -ne $Interval.Last -or
-not $BestLast -or
-not $BestNow -or
-not $ActiveMiners[$BestLast.IdF].IsValid -or
$BestNow.NeedBenchmark -or
@('PendingStop', 'PendingFail', 'Failed') -contains $BestLast.Status -or
(@('Running') -contains $BestLast.Status -and $ProfitNow -gt ($ProfitLast * (1 + ($Config.PercentToSwitch / 100)))) -or
(($ActiveMiners[$BestLast.IdF].NoCpu -or $ActiveMiners[$BestNow.IdF].NoCpu) -and $BestLast -ne $BestNow)
) {
# Must launch other miner and/or stop actual
# Stop old miner
if ($BestLast) {
if (
$ActiveMiners[$BestLast.IdF].Process -and