Ejemplo n.º 1
0
        public static void UpdateGroup(ApiData apiData, string minerUUID, string minerName)
        {
            if (apiData == null)
            {
                return;
            }
            if (apiData.AlgorithmSpeedsPerDevice == null || apiData.AlgorithmSpeedsPerDevice.Count == 0)
            {
                return;
            }
            if (apiData.PowerUsagePerDevice == null || apiData.PowerUsagePerDevice.Count == 0)
            {
                return;
            }
            if (apiData.AlgorithmSpeedsTotal == null || apiData.AlgorithmSpeedsTotal.Count == 0)
            {
                return;
            }

            var sortedDeviceUUIDs = apiData.AlgorithmSpeedsPerDevice.Select(speedInfo => speedInfo.Key).OrderBy(uuid => uuid).ToList();
            var uuidsKeys         = string.Join(",", sortedDeviceUUIDs);


            var groupKey = $"{minerUUID}-{uuidsKeys}";

            // update groups
            lock (_lock)
            {
                // check what keys to remove
                var removeKeys = _apiDataGroups.Keys.Where(checkKey => {
                    var minerUUIDDiffers = checkKey.StartsWith(minerUUID) == false;
                    var deviceInKey      = sortedDeviceUUIDs.Any(uuid => checkKey.Contains(uuid));
                    return(minerUUIDDiffers && deviceInKey);
                }).ToArray();
                foreach (var removeKey in removeKeys)
                {
                    _apiDataGroups.Remove(removeKey);
                    _minersMiningStats.Remove(removeKey);
                }
                // add / update data
                _apiDataGroups[groupKey] = apiData;

                var payingRates = NHSmaData.CurrentPayingRatesSnapshot();
                // update stats
                UpdateMinerMiningStats(apiData, minerUUID, minerName, groupKey, payingRates);
                // update device stats
                foreach (var deviceUuid in sortedDeviceUUIDs)
                {
                    UpdateDeviceMiningStats(apiData, minerUUID, minerName, groupKey, deviceUuid, payingRates);
                }

                // TODO notify change
            }
        }
Ejemplo n.º 2
0
        public void AddAlgorithmsToDevices()
        {
            var payingRates = NHSmaData.CurrentPayingRatesSnapshot();

            CheckExec(nameof(AddAlgorithmsToDevices), () => {
                if (!_initInternalsCalled && _plugin is IInitInternals impl)
                {
                    _initInternalsCalled = true;
                    impl.InitInternals();
                }
                // update settings for algos per device
                var devices = _cachedNiceHashMinerAlgorithms.Keys.Select(uuid => AvailableDevices.GetDeviceWithUuid(uuid)).Where(d => d != null);
                foreach (var dev in devices)
                {
                    var algos = _cachedNiceHashMinerAlgorithms[dev.Uuid];
                    foreach (var algo in algos)
                    {
                        algo.UpdateEstimatedProfit(payingRates);
                        // try get data from configs
                        var pluginConf = dev.GetPluginAlgorithmConfig(algo.AlgorithmStringID);
                        if (pluginConf == null)
                        {
                            continue;
                        }
                        // set plugin algo
                        algo.Speeds  = pluginConf.Speeds;
                        algo.Enabled = pluginConf.Enabled;
                        if (ConfigManager.IsVersionChanged && PluginUUID == "0e0a7320-94ec-11ea-a64d-17be303ea466" && algo.AlgorithmName.Contains(AlgorithmType.RandomXmonero.ToString()) && (pluginConf.ExtraLaunchParameters == "" || pluginConf.ExtraLaunchParameters == "--cpu-priority=0"))
                        {
                            algo.ExtraLaunchParameters = "--cpu-priority 0";
                        }
                        else
                        {
                            algo.ExtraLaunchParameters = pluginConf.ExtraLaunchParameters;
                        }
                        algo.PowerUsage    = pluginConf.PowerUsage;
                        algo.ConfigVersion = pluginConf.GetVersion();
                        // check if re-bench is needed
                        var isReBenchmark = ShouldReBenchmarkAlgorithmOnDevice(dev.BaseDevice, algo.ConfigVersion, algo.IDs);
                        if (isReBenchmark)
                        {
                            Logger.Info(LogTag, $"Algorithms {algo.AlgorithmStringID} SET TO RE-BENCHMARK");
                        }
                        algo.IsReBenchmark = isReBenchmark;
                    }
                    // finally update algorithms
                    // remove old
                    dev.RemovePluginAlgorithms(PluginUUID);
                    dev.AddPluginAlgorithms(algos);
                }
            });
        }