Esempio n. 1
0
 public void AddAlgorithmsToDevices()
 {
     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 configs = dev.GetDeviceConfig();
             var algos   = _cachedNiceHashMinerAlgorithms[dev.Uuid];
             foreach (var algo in algos)
             {
                 if (algo is Algorithms.PluginAlgorithm == false)
                 {
                     continue;
                 }
                 var pluginConf = configs.PluginAlgorithmSettings.Where(c => c.GetAlgorithmStringID() == algo.AlgorithmStringID).FirstOrDefault();
                 if (pluginConf == null)
                 {
                     pluginConf = dev.PluginAlgorithmSettings.Where(c => c.GetAlgorithmStringID() == algo.AlgorithmStringID).FirstOrDefault();
                 }
                 if (pluginConf == null)
                 {
                     continue;
                 }
                 // set plugin algo
                 var pluginAlgo     = algo as Algorithms.PluginAlgorithm;
                 pluginAlgo.Speeds  = pluginConf.Speeds;
                 pluginAlgo.Enabled = pluginConf.Enabled;
                 pluginAlgo.ExtraLaunchParameters = pluginConf.ExtraLaunchParameters;
                 pluginAlgo.PowerUsage            = pluginConf.PowerUsage;
                 pluginAlgo.ConfigVersion         = pluginConf.GetVersion();
                 // check if re-bench is needed
                 var isReBenchmark = ShouldReBenchmarkAlgorithmOnDevice(dev.BaseDevice, pluginAlgo.ConfigVersion, pluginAlgo.IDs);
                 if (isReBenchmark)
                 {
                     Logger.Info(LogTag, $"Algorithms {pluginAlgo.AlgorithmStringID} SET TO RE-BENCHMARK");
                 }
                 pluginAlgo.IsReBenchmark = isReBenchmark;
             }
             // finally update algorithms
             // remove old
             dev.RemovePluginAlgorithms(PluginUUID);
             dev.AddPluginAlgorithms(algos);
         }
     });
 }
 private void CopyBenchmarks()
 {
     Helpers.ConsolePrint("CopyBenchmarks", "Checking for benchmarks to copy");
     foreach (var cDev in AvailableDevices.Devices)
     {
         // check if copy
         if (!cDev.Enabled && cDev.BenchmarkCopyUuid != null)
         {
             var copyCdevSettings = AvailableDevices.GetDeviceWithUuid(cDev.BenchmarkCopyUuid);
             if (copyCdevSettings != null)
             {
                 Helpers.ConsolePrint("CopyBenchmarks", $"Copy from {cDev.Uuid} to {cDev.BenchmarkCopyUuid}");
                 cDev.CopyBenchmarkSettingsFrom(copyCdevSettings);
             }
         }
     }
 }
Esempio n. 3
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;
                        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);
                }
            });
        }
Esempio n. 4
0
        public bool InitPluginContainer()
        {
            if (IsInitialized)
            {
                return(true);
            }
            IsInitialized = true;
            try
            {
                // set identity
                PluginUUID = _plugin.PluginUUID;
                Version    = _plugin.Version;
                Name       = _plugin.Name;
                Author     = _plugin.Author;

                // get devices
                var baseDevices = AvailableDevices.Devices.Select(dev => dev.BaseDevice);
                // get devs
                // register and add
                var allDevUUIDs = baseDevices.Select(d => d.UUID);
                var hasDeviceWithSupportedAlgos = false;
                var supported = _plugin.GetSupportedAlgorithms(baseDevices);
                // who knows who wrote this don't blindly trust the content
                if (supported != null)
                {
                    foreach (var kvp in supported)
                    {
                        var baseDev   = kvp.Key;
                        var baseAlgos = kvp.Value;
                        if (baseDev == null || baseAlgos == null)
                        {
                            // TODO this is something we should consider harmfull ???
                            continue;
                        }
                        if (allDevUUIDs.Contains(baseDev.UUID) == false)
                        {
                            Logger.Error(LogTag, $"InitPluginContainer plugin GetSupportedAlgorithms returned an unknown device {baseDev.UUID}. Setting plugin as broken");
                            SetAsBroken(this);
                            return(false);
                        }
                        if (baseAlgos.Count == 0)
                        {
                            continue;
                        }
                        hasDeviceWithSupportedAlgos = true;
                        _cachedAlgorithms[baseDev]  = baseAlgos;
                    }
                }
                // dependencies and services are considered compatible or if we have algorithms on any device
                IsCompatible = (_plugin is IBackgroundService) || (_plugin is IPluginDependency) || hasDeviceWithSupportedAlgos;
                if (!IsCompatible)
                {
                    return(false);
                }

                // transform
                foreach (var deviceAlgosPair in _cachedAlgorithms)
                {
                    var deviceUUID = deviceAlgosPair.Key.UUID;
                    var algos      = deviceAlgosPair.Value
                                     .Select(a => new AlgorithmContainer(a, this, AvailableDevices.GetDeviceWithUuid(deviceUUID)))
                                     .ToList();
                    _cachedNiceHashMinerAlgorithms[deviceUUID] = algos;
                }

                // Ethlargement extra check
                if (_plugin == EthlargementIntegratedPlugin.Instance)
                {
                    IsCompatible = EthlargementIntegratedPlugin.Instance.SystemContainsSupportedDevices;
                }
            }
            catch (Exception e)
            {
                SetAsBroken(this);
                Logger.Error(LogTag, $"InitPluginContainer error: {e.Message}");
                return(false);
            }


            return(true);
        }