public static async Task PauseAllMiners() { EthlargementIntegratedPlugin.Instance.Stop(); await _semaphore.WaitAsync(); try { foreach (var groupMiner in _runningMiners.Values) { groupMiner.End(); } _runningMiners.Clear(); } finally { _semaphore.Release(); } ApplicationStateManager.ClearRatesAll(); }
public static async Task StopAllMiners() { EthlargementIntegratedPlugin.Instance.Stop(); await _semaphore.WaitAsync(); try { foreach (var groupMiner in _runningMiners.Values) { groupMiner.End(); } _runningMiners.Clear(); //// TODO enable StabilityAnalyzer //// Speed stability analyzer was here or deviant algo checker //foreach (var miningDev in _miningDevices) //{ // var deviceUuid = miningDev.Device.Uuid; // foreach (var algorithm in miningDev.Algorithms) // { // var speedID = $"{deviceUuid}-{algorithm.AlgorithmStringID}"; // var isDeviant = BenchmarkingAnalyzer.IsDeviant(speedID); // if (isDeviant) // { // var stableSpeeds = BenchmarkingAnalyzer.GetStableSpeeds(speedID); // if (stableSpeeds != null) // { // algorithm.Speeds = stableSpeeds; // } // } // } //} } finally { _semaphore.Release(); } _switchingManager?.Stop(); ApplicationStateManager.ClearRatesAll(); //_internetCheckTimer?.Stop(); }
private static async Task SwichMostProfitableGroupUpMethodTask(object sender, SmaUpdateEventArgs e) { CalculateAndUpdateMiningDevicesProfits(e.NormalizedProfits); var(currentProfit, prevStateProfit) = GetCurrentAndPreviousProfits(); // log profits scope { var stringBuilderFull = new StringBuilder(); stringBuilderFull.AppendLine("Current device profits:"); foreach (var device in _miningDevices) { var stringBuilderDevice = new StringBuilder(); stringBuilderDevice.AppendLine($"\tProfits for {device.Device.Uuid} ({device.Device.GetFullName()}):"); foreach (var algo in device.Algorithms) { stringBuilderDevice.AppendLine( $"\t\tPROFIT = {algo.CurrentProfit.ToString(DoubleFormat)}" + $"\t(SPEED = {algo.AvaragedSpeed:e5}" + $"\t\t| NHSMA = {algo.CurNhmSmaDataVal:e5})" + $"\t[{algo.AlgorithmStringID}]" ); if (algo is PluginAlgorithm dualAlg && dualAlg.IsDual) { stringBuilderDevice.AppendLine( $"\t\t\t\t\t Secondary:\t\t {dualAlg.SecondaryAveragedSpeed:e5}" + $"\t\t\t\t {dualAlg.SecondaryCurNhmSmaDataVal:e5}" ); } } // most profitable stringBuilderDevice.AppendLine( $"\t\tMOST PROFITABLE ALGO: {device.GetMostProfitableString()}, PROFIT: {device.GetCurrentMostProfitValue.ToString(DoubleFormat)}"); stringBuilderFull.AppendLine(stringBuilderDevice.ToString()); } Logger.Info(Tag, stringBuilderFull.ToString()); } // check if should mine // Only check if profitable inside this method when getting SMA data, cheching during mining is not reliable if (CheckIfShouldMine(currentProfit) == false) { foreach (var device in _miningDevices) { device.SetNotMining(); } await PauseAllMiners(); return; } // check profit threshold Logger.Info(Tag, $"PrevStateProfit {prevStateProfit}, CurrentProfit {currentProfit}"); if (prevStateProfit > 0 && currentProfit > 0) { var a = Math.Max(prevStateProfit, currentProfit); var b = Math.Min(prevStateProfit, currentProfit); //double percDiff = Math.Abs((PrevStateProfit / CurrentProfit) - 1); var percDiff = ((a - b)) / b; if (percDiff < ConfigManager.GeneralConfig.SwitchProfitabilityThreshold) { // don't switch Logger.Info(Tag, $"Will NOT switch profit diff is {percDiff}, current threshold {ConfigManager.GeneralConfig.SwitchProfitabilityThreshold}"); // RESTORE OLD PROFITS STATE foreach (var device in _miningDevices) { device.RestoreOldProfitsState(); } return; } Logger.Info(Tag, $"Will SWITCH profit diff is {percDiff}, current threshold {ConfigManager.GeneralConfig.SwitchProfitabilityThreshold}"); } await _semaphore.WaitAsync(); var hasChanged = false; try { // group new miners var newGroupedMiningPairs = GroupingUtils.GetGroupedMiningPairs(GetProfitableMiningPairs()); // check newGroupedMiningPairs and running Groups to figure out what to start/stop and keep running var currentRunningGroups = _runningMiners.Keys.ToArray(); // check which groupMiners should be stopped and which ones should be started and which to keep running var noChangeGroupMinersKeys = newGroupedMiningPairs.Where(pair => currentRunningGroups.Contains(pair.Key)).Select(pair => pair.Key).OrderBy(uuid => uuid).ToArray(); var toStartMinerGroupKeys = newGroupedMiningPairs.Where(pair => !currentRunningGroups.Contains(pair.Key)).Select(pair => pair.Key).OrderBy(uuid => uuid).ToArray(); var toStopMinerGroupKeys = currentRunningGroups.Where(runningKey => !newGroupedMiningPairs.Keys.Contains(runningKey)).OrderBy(uuid => uuid).ToArray(); // first stop currently running foreach (var stopKey in toStopMinerGroupKeys) { var stopGroup = _runningMiners[stopKey]; _runningMiners.Remove(stopKey); await stopGroup.StopTask(); stopGroup.End(); } // start new var miningLocation = StratumService.SelectedServiceLocation; foreach (var startKey in toStartMinerGroupKeys) { var miningPairs = newGroupedMiningPairs[startKey]; var toStart = MinerFactory.CreateMinerForMining(miningPairs, startKey); if (toStart == null) { Logger.Error(Tag, $"CreateMinerForMining for key='{startKey}' returned <null>"); continue; } _runningMiners[startKey] = toStart; await toStart.StartTask(miningLocation, _username); } // log scope { var stopLog = toStopMinerGroupKeys.Length > 0 ? string.Join(",", toStopMinerGroupKeys) : "EMTPY"; Logger.Info(Tag, $"Stop Old Mining: ({stopLog})"); var startLog = toStartMinerGroupKeys.Length > 0 ? string.Join(",", toStartMinerGroupKeys) : "EMTPY"; Logger.Info(Tag, $"Start New Mining : ({startLog})"); var sameLog = noChangeGroupMinersKeys.Length > 0 ? string.Join(",", noChangeGroupMinersKeys) : "EMTPY"; Logger.Info(Tag, $"No change : ({sameLog})"); } hasChanged = toStartMinerGroupKeys.Length > 0 || toStopMinerGroupKeys.Length > 0; } finally { _semaphore.Release(); } // There is a change in groups, change GUI if (hasChanged) { ApplicationStateManager.ClearRatesAll(); await MinerStatsCheck(); } }