Exemplo n.º 1
0
        private static void BenchmarkIfNeeded()
        {
            if (!Config.DisableBenchmarking)
            {
                WriteInfo(" Checking if benchmarking is needed..");
                List <MiningConfig> configsToTest = new List <MiningConfig>();
                foreach (Algorithm algorithm in Config.Algorithms)
                {
                    if (algorithm.Enabled)
                    {
                        foreach (DeviceConfig deviceConfig in algorithm.DeviceConfigs)
                        {
                            if (deviceConfig.Enabled && deviceConfig.ExpectedHashrate <= 0)
                            {
                                configsToTest.Add(new MiningConfig(deviceConfig, algorithm.Pools.First(p => p.Enabled)));
                            }
                        }
                    }
                }

                if (configsToTest.Count == 0)
                {
                    WriteInfo(" Benchmarking not needed: All algorithm-device-combinations have a valid expected hashrate.");
                }
                else
                {
                    WriteInfo(" Benchmarking needed: Not all algorithm-device-combinations have a valid expected hashrate.");
                    Console.WriteLine();
                    WriteLineColor(" BENCHMARKING:", ConsoleColor.Cyan);
                    foreach (MiningConfig miningConfig in configsToTest)
                    {
                        Console.WriteLine();
                        Console.Write(" Benchmarking ");
                        WriteColor(miningConfig.DeviceConfig.FullDeviceId, ConsoleColor.Yellow);
                        Console.Write(" on ");
                        WriteColor(miningConfig.Pool.UniqueName, ConsoleColor.Yellow);
                        Console.WriteLine("..");
                        IMiner miner = MinerFactory.GetMiner(new HashSet <DeviceConfig>()
                        {
                            miningConfig.DeviceConfig
                        }, miningConfig.Pool);
                        miner.StartMiner(Config.StartMinerMinimized);
                        int userInputHashrate = 0;
                        while (userInputHashrate <= 0)
                        {
                            Console.Write(" Please enter the hashrate: ");
                            Console.CursorVisible   = true;
                            Console.ForegroundColor = ConsoleColor.Yellow;
                            string input = Console.ReadLine();
                            Console.ResetColor();
                            int.TryParse(input, out userInputHashrate);
                        }
                        Console.CursorVisible = false;
                        miningConfig.DeviceConfig.ExpectedHashrate = userInputHashrate;
                        SaveConfig();
                        miner.StopMiner();
                    }
                }
            }
        }
Exemplo n.º 2
0
        private static void StartMiner(Mineable mineable, Settings settings, string appRoot, DirectoryInfo appRootFolder)
        {
            var differenceToLastProfitSwitch = DateTimeOffset.Now.Subtract(_lastProfitSwitch).TotalSeconds;

            if (differenceToLastProfitSwitch > settings.ProfitSwitchCooldown)
            {
                StopMiner();

                _currentMineable = mineable;

                ExecuteScript(mineable.PrepareScript, appRoot);

                _currentMiner     = MinerFactory.GetMiner(mineable.Miner);
                _lastProfitSwitch = DateTimeOffset.Now;

                try
                {
                    Log.Information($"Starting {_currentMiner.Name} with {mineable.DisplayName}.");
                    _currentMiner.StartMiner(mineable, settings, appRoot, appRootFolder);
                }
                catch (Exception ex)
                {
                    Log.Warning("Couldn't start miner: " + ex);
                    ResetApp(settings, appRoot, false);
                }

                if (_manualWatchdogEnabled.HasValue)
                {
                    if (_manualWatchdogEnabled.Value)
                    {
                        _watchdogCts?.Cancel();
                        _watchdogCts = new CancellationTokenSource();
                        var watchdogTask = WatchdogTaskAsync(settings, appRoot, appRootFolder, _watchdogCts.Token);
                    }
                }
                else
                {
                    if (settings.EnableWatchdog)
                    {
                        _watchdogCts?.Cancel();
                        _watchdogCts = new CancellationTokenSource();
                        var watchdogTask = WatchdogTaskAsync(settings, appRoot, appRootFolder, _watchdogCts.Token);
                    }
                }
            }
            else
            {
                Console.WriteLine($"Didn't switched to {mineable.DisplayName}! Waiting {settings.ProfitSwitchCooldown} seconds to cooldown.");
            }
        }
Exemplo n.º 3
0
        private static void CheckSwitching()
        {
            try
            {
                WriteInfo(" Check switching..");
                IProfitSwitchingStrategy profitSwitchingStrategy = ProfitSwitchingStrategyFactory.GetProfitSwitchingStrategy(_profitSwitchingStrategy ?? ProfitSwitchingStrategy.MaximizeFiat);
                // Find optimal configs
                Dictionary <string, MiningConfig> optimalMiningConfigs = new Dictionary <string, MiningConfig>();
                if (_manualMode)
                {
                    foreach (var manualMininigConfig in _manualMininigConfigs)
                    {
                        MiningConfig miningConfig = new MiningConfig(manualMininigConfig.Value.DeviceConfig, manualMininigConfig.Value.Pool);
                        optimalMiningConfigs.Add(manualMininigConfig.Key, miningConfig);
                    }
                }
                else
                {
                    foreach (Algorithm algorithm in Config.Algorithms)
                    {
                        if (algorithm.Enabled)
                        {
                            foreach (DeviceConfig algorithmDeviceConfig in algorithm.DeviceConfigs)
                            {
                                if (algorithmDeviceConfig.Enabled)
                                {
                                    foreach (Pool algorithmPool in algorithm.Pools.Where(p => p.Enabled))
                                    {
                                        Profit?profit = GetAdjustedProfit(algorithmPool, algorithmDeviceConfig.ExpectedHashrate, true);
                                        if (profit.HasValue)
                                        {
                                            if (!optimalMiningConfigs.ContainsKey(algorithmDeviceConfig.FullDeviceId))
                                            {
                                                SetOptimalMiningConfigWithThreshold(profit.Value, profitSwitchingStrategy, algorithmDeviceConfig, algorithmPool, optimalMiningConfigs);
                                            }
                                            else
                                            {
                                                MiningConfig bestMiningConfig = optimalMiningConfigs[algorithmDeviceConfig.FullDeviceId];
                                                Profit?      bestProfit       = GetAdjustedProfit(bestMiningConfig.Pool, bestMiningConfig.DeviceConfig.ExpectedHashrate, true);
                                                if (!bestProfit.HasValue || profitSwitchingStrategy.IsProfitABetterThanB(profit.Value, algorithmPool.ProfitTimeframe, bestProfit.Value, bestMiningConfig.Pool.ProfitTimeframe, 0))
                                                {
                                                    SetOptimalMiningConfigWithThreshold(profit.Value, profitSwitchingStrategy, algorithmDeviceConfig, algorithmPool, optimalMiningConfigs);
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }

                // Merge miners and get list of optimal miners
                List <IMiner> optimalMiners = new List <IMiner>();
                foreach (var optimalMiningConfigKeyValue in optimalMiningConfigs)
                {
                    MiningConfig miningConfig = optimalMiningConfigKeyValue.Value;
                    IMiner       miner        = MinerFactory.GetMiner(new HashSet <DeviceConfig>()
                    {
                        miningConfig.DeviceConfig
                    }, miningConfig.Pool);
                    IMiner existingMiner = optimalMiners.FirstOrDefault(m => m.Name == miner.Name && m.Pool.Equals(miner.Pool));
                    if (existingMiner != null)
                    {
                        existingMiner.DeviceConfigs.Add(miningConfig.DeviceConfig);
                        miningConfig.Miner = existingMiner;
                    }
                    else
                    {
                        miningConfig.Miner = miner;
                        optimalMiners.Add(miner);
                    }
                }

                bool displayNeedsUpdate = false;
                // Get list of current miners
                List <IMiner> currentMiners = GetCurrentMiners();

                //Check if existing miner will be kept
                foreach (IMiner currentMiner in currentMiners)
                {
                    if (optimalMiners.Any(om => om.Pool.Equals(currentMiner.Pool) && om.DeviceConfigs.SetEquals(currentMiner.DeviceConfigs)))
                    {
                        foreach (DeviceConfig currentMinerDeviceConfig in currentMiner.DeviceConfigs)
                        {
                            optimalMiningConfigs[currentMinerDeviceConfig.FullDeviceId].Miner = currentMiner;
                        }
                    }
                }

                //Check if existing miner has to be closed
                foreach (IMiner currentMiner in currentMiners.ToArray())
                {
                    if (!optimalMiners.Any(om => om.Pool.Equals(currentMiner.Pool) && om.DeviceConfigs.SetEquals(currentMiner.DeviceConfigs)))
                    {
                        displayNeedsUpdate = true;
                        currentMiner.StopMiner();
                        currentMiners.Remove(currentMiner);
                    }
                }

                //Check if new miner has to start
                foreach (IMiner optimalMiner in optimalMiners)
                {
                    if (!currentMiners.Any(cm => cm.Pool.Equals(optimalMiner.Pool) && cm.DeviceConfigs.SetEquals(optimalMiner.DeviceConfigs)))
                    {
                        displayNeedsUpdate = true;
                        foreach (DeviceConfig deviceConfig in optimalMiner.DeviceConfigs)
                        {
                            if (!string.IsNullOrEmpty(deviceConfig.PrepareScript))
                            {
                                Helpers.ExecuteScript(deviceConfig.MinerPath, AppFolderPath);
                            }
                        }
                        Task.Delay(TimeSpan.FromSeconds(Config.MinerStartDelay)).Wait();
                        optimalMiner.StartMiner(Config.StartMinerMinimized);
                    }
                }

                _currentMininigConfigs = optimalMiningConfigs;

                if (displayNeedsUpdate)
                {
                    _displayUpdaterCts?.Cancel();
                }
            }
            catch (Exception e)
            {
                Log.Debug("Check switching failed: " + e);
            }
        }