Example #1
0
        private void logProcessClose(MinerProcess minerProcess)
        {
            DateTime startDate = minerProcess.StartDate;
            DateTime endDate   = DateTime.Now;
            string   coinName  = minerProcess.MinerConfiguration.CoinName;

            double priceAtStart = 0;
            string coinSymbol   = String.Empty;

            //coin may not be in CoinChoose.com
            if (minerProcess.CoinInformation != null)
            {
                coinSymbol   = minerProcess.CoinInformation.Symbol;
                priceAtStart = minerProcess.CoinInformation.Price;
            }

            double priceAtEnd = priceAtStart;

            //can't use Single here - coin info may be gone now and we crash
            CoinInformation coinInfo = coinInformation.SingleOrDefault(c => c.Symbol.Equals(coinSymbol, StringComparison.OrdinalIgnoreCase));

            if (coinInfo != null)
            {
                priceAtEnd = coinInfo.Price;
            }

            List <int> deviceIndexes = minerProcess.MinerConfiguration.DeviceIndexes;

            logProcessClose(startDate, endDate, coinName, coinSymbol, priceAtStart, priceAtEnd, deviceIndexes);
        }
Example #2
0
        private void StartMining()
        {
            IEnumerable <string> coinSymbols = engineConfiguration.DeviceConfigurations
                                               .Where(c => c.Enabled && !string.IsNullOrEmpty(c.CoinSymbol))
                                               .Select(c => c.CoinSymbol)
                                               .Distinct();

            int port = 4028;

            foreach (string coinSymbol in coinSymbols)
            {
                MinerConfiguration minerConfiguration = CreateMinerConfiguration(port, coinSymbol);

                Process process = LaunchMinerProcess(minerConfiguration, "Starting mining");

                if (!process.HasExited)
                {
                    MinerProcess minerProcess = new MinerProcess();

                    minerProcess.Process            = process;
                    minerProcess.ApiPort            = port;
                    minerProcess.MinerConfiguration = minerConfiguration;

                    setupProcessStartInfo(minerProcess);

                    minerProcesses.Add(minerProcess);
                }

                port++;
            }

            mining = true;
        }
Example #3
0
        private void DoLogProcessClose(MinerProcess minerProcess)
        {
            if (LogProcessClose == null)
            {
                return;
            }

            DateTime startDate = minerProcess.StartDate;
            DateTime endDate   = DateTime.Now;
            string   coinName  = minerProcess.MinerConfiguration.CoinName;

            double priceAtStart = 0;
            string coinSymbol   = String.Empty;

            //coin may not be in Coin API
            if (minerProcess.CoinInformation != null)
            {
                coinSymbol   = minerProcess.CoinInformation.Symbol;
                priceAtStart = minerProcess.CoinInformation.Price;
            }

            double priceAtEnd = priceAtStart;

            //can't use Single here - coin info may be gone now and we crash
            CoinInformation coinInfo = null;

            if (coinInformation != null) //null if no internet connection
            {
                coinInfo = coinInformation.SingleOrDefault(c => c.Symbol.Equals(coinSymbol, StringComparison.OrdinalIgnoreCase));
            }
            if (coinInfo != null)
            {
                priceAtEnd = coinInfo.Price;
            }

            //get a copy using ToList() so we can change the list in the event handler without
            //affecting relaunching processes
            List <DeviceDescriptor> deviceDescriptors = minerProcess.MinerConfiguration.DeviceDescriptors.ToList();

            LogProcessCloseArgs args = new LogProcessCloseArgs
            {
                StartDate          = startDate,
                EndDate            = endDate,
                CoinName           = coinName,
                CoinSymbol         = coinSymbol,
                StartPrice         = priceAtStart,
                EndPrice           = priceAtEnd,
                DeviceDescriptors  = deviceDescriptors,
                MinerConfiguration = minerProcess.MinerConfiguration,
                AcceptedShares     = minerProcess.AcceptedShares
            };

            LogProcessClose(this, args);
        }
Example #4
0
        private void StoreMinerProcess(Process process, MinerConfiguration minerConfiguration, int port)
        {
            MinerProcess minerProcess = new MinerProcess();

            minerProcess.Process            = process;
            minerProcess.ApiPort            = port;
            minerProcess.MinerConfiguration = minerConfiguration;

            setupProcessStartInfo(minerProcess);

            minerProcesses.Add(minerProcess);
        }
Example #5
0
        private void setupProcessStartInfo(MinerProcess minerProcess)
        {
            string          coinName        = minerProcess.MinerConfiguration.CoinName;
            string          coinSymbol      = engineConfiguration.CoinConfigurations.Single(c => c.Coin.Name.Equals(coinName, StringComparison.OrdinalIgnoreCase)).Coin.Symbol;
            CoinInformation processCoinInfo = coinInformation.SingleOrDefault(c => c.Symbol.Equals(coinSymbol, StringComparison.OrdinalIgnoreCase));

            //coin may not be in CoinChoose.com
            if (coinInformation != null)
            {
                minerProcess.CoinInformation = processCoinInfo;
            }

            minerProcess.StartDate = DateTime.Now;
        }
Example #6
0
        private MinerProcess StoreMinerProcess(Process process, string coinSymbol, Xgminer.Data.Configuration.Miner minerConfiguration, int port)
        {
            MinerProcess minerProcess = new MinerProcess();

            minerProcess.Process            = process;
            minerProcess.ApiPort            = port;
            minerProcess.MinerConfiguration = minerConfiguration;
            minerProcess.CoinSymbol         = coinSymbol;

            setupProcessStartInfo(minerProcess);

            minerProcesses.Add(minerProcess);

            return(minerProcess);
        }
Example #7
0
        private MinerProcess StoreMinerProcess(Process process, MinerDescriptor miner, string coinSymbol, Xgminer.Data.Configuration.Miner minerConfiguration, int apiPort)
        {
            MinerProcess minerProcess = new MinerProcess()
            {
                Process            = process,
                Miner              = miner,
                ApiPort            = apiPort,
                MinerConfiguration = minerConfiguration,
                CoinSymbol         = coinSymbol
            };

            setupProcessStartInfo(minerProcess);

            minerProcesses.Add(minerProcess);

            return(minerProcess);
        }
Example #8
0
        private void LaunchMiners(ref int apiPort, string coinSymbol, DeviceKind deviceKind, bool terminateProcess)
        {
            Xgminer.Data.Configuration.Miner minerConfiguration = CreateMinerConfiguration(apiPort, coinSymbol, deviceKind);


            //null if no pools configured
            if (minerConfiguration != null)
            {
                Process process = LaunchMinerProcess(minerConfiguration, "Starting mining");
                if (!process.HasExited)
                {
                    MinerDescriptor miner        = MinerFactory.Instance.GetMiner(deviceKind, minerConfiguration.Algorithm, engineConfiguration.XgminerConfiguration.AlgorithmMiners);
                    MinerProcess    minerProcess = StoreMinerProcess(process, miner, coinSymbol, minerConfiguration, apiPort);
                    minerProcess.TerminateProcess = terminateProcess;
                }

                apiPort++;
            }
        }
Example #9
0
        private void setupProcessStartInfo(MinerProcess minerProcess)
        {
            string coinName   = minerProcess.MinerConfiguration.CoinName;
            string coinSymbol = engineConfiguration.CoinConfigurations.Single(c => c.CryptoCoin.Name.Equals(coinName, StringComparison.OrdinalIgnoreCase)).CryptoCoin.Symbol;

            CoinInformation processCoinInfo = null;

            if (coinInformation != null) //null if no network connection
            {
                processCoinInfo = coinInformation.SingleOrDefault(c => c.Symbol.Equals(coinSymbol, StringComparison.OrdinalIgnoreCase));
            }

            //coin may not be in Coin API
            if (processCoinInfo != null)
            {
                minerProcess.CoinInformation = processCoinInfo;
            }

            minerProcess.StartDate = DateTime.Now;
        }
Example #10
0
        private void StartMining()
        {
            IEnumerable <string> coinSymbols = engineConfiguration.DeviceConfigurations
                                               .Where(c => c.Enabled && !string.IsNullOrEmpty(c.CoinSymbol))
                                               .Select(c => c.CoinSymbol)
                                               .Distinct();

            int port = engineConfiguration.XgminerConfiguration.StartingApiPort;

            foreach (string coinSymbol in coinSymbols)
            {
                //launch separate processes for CPU & GPU vs USB & PXY (for stability)
                Xgminer.Data.Configuration.Miner minerConfiguration = CreateMinerConfiguration(port, coinSymbol, DeviceKind.CPU | DeviceKind.GPU);
                if (minerConfiguration != null)
                {
                    Process process = LaunchMinerProcess(minerConfiguration, "Starting mining");
                    if (!process.HasExited)
                    {
                        MinerProcess minerProcess = StoreMinerProcess(process, coinSymbol, minerConfiguration, port);
                        minerProcess.TerminateProcess = engineConfiguration.XgminerConfiguration.TerminateGpuMiners;
                    }

                    port++;
                }

                minerConfiguration = CreateMinerConfiguration(port, coinSymbol, DeviceKind.PXY | DeviceKind.USB);
                if (minerConfiguration != null)
                {
                    Process process = LaunchMinerProcess(minerConfiguration, "Starting mining");
                    if (!process.HasExited)
                    {
                        StoreMinerProcess(process, coinSymbol, minerConfiguration, port);
                    }

                    port++;
                }
            }

            mining = true;
        }
Example #11
0
        private void FlagSuspiciousMiner(MinerProcess minerProcess, DeviceInformation deviceInformation)
        {
            if (deviceInformation.Status.ToLower().Contains("sick"))
                minerProcess.HasSickDevice = true;
            if (deviceInformation.Status.ToLower().Contains("dead"))
                minerProcess.HasDeadDevice = true;
            if (deviceInformation.CurrentHashrate == 0)
                minerProcess.HasZeroHashrateDevice = true;

            //only check GPUs for subpar hashrate
            //ASICs spike too much for this to be reliable there
            //don't check average hashrate if using dynamic intensity
            if (deviceInformation.Kind.Equals("GPU", StringComparison.OrdinalIgnoreCase) &&
                !engineConfiguration.XgminerConfiguration.DesktopMode)
            {
                //avoid div by 0
                if (deviceInformation.AverageHashrate > 0)
                {
                    double performanceRatio = deviceInformation.CurrentHashrate / deviceInformation.AverageHashrate;
                    if (performanceRatio <= 0.50)
                        minerProcess.HasPoorPerformingDevice = true;
                }
            }

            if (miningCoinConfigurations == null)
                //started mining but haven't yet assigned mining members
                //cannot check the following yet
                return;

            //Work Utility not returned by legacy API miners
            if (!minerProcess.Miner.LegacyApi)
            {
                double effectiveHashrate = WorkUtilityToHashrate(deviceInformation.WorkUtility);
                //avoid div by 0
                if (deviceInformation.AverageHashrate > 0)
                {
                    double performanceRatio = effectiveHashrate / deviceInformation.AverageHashrate;
                    if (performanceRatio <= 0.25)
                        minerProcess.StoppedAcceptingShares = true;
                }
            }
        }
Example #12
0
        private void CheckAndNotifyFoundBlocks(MinerProcess minerProcess, long foundBlocks)
        {
            //started mining but haven't yet assigned mining members
            if (miningCoinConfigurations == null)
                return;

            string coinName = minerProcess.MinerConfiguration.CoinName;
            //reference miningCoinConfigurations so that we get access to the mining coins
            Engine.Data.Configuration.Coin configuration = miningCoinConfigurations.SingleOrDefault(c => c.CryptoCoin.Name.Equals(coinName, StringComparison.OrdinalIgnoreCase));
            if (configuration == null)
                return;

            if (configuration.NotifyOnBlockFound2 && (foundBlocks > minerProcess.FoundBlocks))
            {
                minerProcess.FoundBlocks = foundBlocks;

                string notificationReason = String.Format("Block(s) found for {0} (block {1})",
                    coinName, minerProcess.FoundBlocks);

                PostNotification(notificationReason, notificationReason, () =>
                {
                }, ToolTipIcon.Info, "");
            }
        }
Example #13
0
        private void FlagSuspiciousMiner(MinerProcess minerProcess, DeviceInformation deviceInformation)
        {
            if (deviceInformation.Status.ToLower().Contains("sick"))
                minerProcess.HasSickDevice = true;
            if (deviceInformation.Status.ToLower().Contains("dead"))
                minerProcess.HasDeadDevice = true;
            if (deviceInformation.CurrentHashrate == 0)
                minerProcess.HasZeroHashrateDevice = true;

            //only check GPUs for subpar hashrate
            //ASICs spike too much for this to be reliable there
            //don't check average hashrate if using dynamic intensity
            if (deviceInformation.Kind.Equals("GPU", StringComparison.OrdinalIgnoreCase) &&
                !engineConfiguration.XgminerConfiguration.DesktopMode)
            {
                //avoid div by 0
                if (deviceInformation.AverageHashrate > 0)
                {
                    double performanceRatio = deviceInformation.CurrentHashrate / deviceInformation.AverageHashrate;
                    if (performanceRatio <= 0.50)
                        minerProcess.HasPoorPerformingDevice = true;
                }
            }

            double effectiveHashrate = WorkUtilityToHashrate(deviceInformation.WorkUtility);
            //avoid div by 0
            if (deviceInformation.AverageHashrate > 0)
            {
                double performanceRatio = effectiveHashrate / deviceInformation.AverageHashrate;
                if (performanceRatio <= 0.25)
                    minerProcess.StoppedAcceptingShares = true;
            }
        }
Example #14
0
        private void CheckAndNotifyAcceptedShares(MinerProcess minerProcess, long acceptedShares)
        {
            string coinName = minerProcess.MinerConfiguration.CoinName;
            //reference miningCoinConfigurations so that we get access to the mining coins
            CoinConfiguration configuration = miningCoinConfigurations.Single(c => c.Coin.Name.Equals(coinName, StringComparison.OrdinalIgnoreCase));
            if (configuration == null)
                return;

            if (configuration.NotifyOnShareAccepted && (acceptedShares > minerProcess.AcceptedShares))
            {
                minerProcess.AcceptedShares = acceptedShares;

                string notificationReason = String.Format("Share(s) accepted for {0} (share {1})",
                    coinName, minerProcess.AcceptedShares);

                notificationsControl.AddNotification(notificationReason, notificationReason, () =>
                {
                }, "");
            }
        }
Example #15
0
        private List<DeviceDetailsResponse> GetProcessDevices(MinerProcess minerProcess, List<DeviceInformationResponse> deviceInformationList)
        {
            List<DeviceDetailsResponse> processDevices = null;
            if (processDeviceDetails.ContainsKey(minerProcess))
            {
                processDevices = processDeviceDetails[minerProcess];

                foreach (DeviceInformationResponse deviceInformation in deviceInformationList)
                {
                    DeviceDetailsResponse deviceDetails = processDevices.SingleOrDefault(d => d.Name.Equals(deviceInformation.Name, StringComparison.OrdinalIgnoreCase)
                        && (d.ID == deviceInformation.ID));
                    if (deviceDetails == null)
                    {
                        //devs API returned a device not in the previous DEVDETAILS response
                        //need to clear our previous response and get a new one
                        processDevices = null;
                        break;
                    }
                }
            }

            if (processDevices == null)
            {
                processDevices = GetDeviceDetailsFromProcess(minerProcess);
                processDeviceDetails[minerProcess] = processDevices;
            }
            return processDevices;
        }
Example #16
0
        private List<DeviceInformationResponse> GetDeviceInfoFromProcess(MinerProcess minerProcess)
        {
            Xgminer.Api.ApiContext apiContext = minerProcess.ApiContext;

            //setup logging
            apiContext.LogEvent -= LogApiEvent;
            apiContext.LogEvent += LogApiEvent;

            List<DeviceInformationResponse> deviceInformationList = null;
            try
            {
                try
                {
                    deviceInformationList = apiContext.GetDeviceInformation().Where(d => d.Enabled).ToList();
                }
                catch (IOException ex)
                {
                    //don't fail and crash out due to any issues communicating via the API
                    deviceInformationList = null;
                }
            }
            catch (SocketException ex)
            {
                //won't be able to connect for the first 5s or so
                deviceInformationList = null;
            }

            return deviceInformationList;
        }
Example #17
0
        private static void FlagSuspiciousProxy(MinerProcess minerProcess, List<DeviceInformation> deviceInformationList)
        {
            double currentProxyHashrate = deviceInformationList
                                .Where(device => device.Name.Equals("PXY", StringComparison.OrdinalIgnoreCase))
                                .Sum(device => device.CurrentHashrate);

            double averageProxyHashrate = deviceInformationList
                .Where(device => device.Name.Equals("PXY", StringComparison.OrdinalIgnoreCase))
                .Sum(device => device.AverageHashrate);

            //proxy is 0 hashrate and used to have a positive hashrate
            if ((averageProxyHashrate > 0) && (currentProxyHashrate == 0))
            {
                minerProcess.HasZeroHashrateDevice = true;
            }
        }
Example #18
0
        private void StoreMinerProcess(Process process, MinerConfiguration minerConfiguration, int port)
        {
            MinerProcess minerProcess = new MinerProcess();

            minerProcess.Process = process;
            minerProcess.ApiPort = port;
            minerProcess.MinerConfiguration = minerConfiguration;

            setupProcessStartInfo(minerProcess);

            minerProcesses.Add(minerProcess);
        }
Example #19
0
        private MinerProcess StoreMinerProcess(Process process, string coinSymbol, Xgminer.Data.Configuration.Miner minerConfiguration, int port)
        {
            MinerProcess minerProcess = new MinerProcess();

            minerProcess.Process = process;
            minerProcess.ApiPort = port;
            minerProcess.MinerConfiguration = minerConfiguration;
            minerProcess.CoinSymbol = coinSymbol;

            setupProcessStartInfo(minerProcess);

            minerProcesses.Add(minerProcess);

            return minerProcess;
        }
Example #20
0
        private void logProcessClose(MinerProcess minerProcess)
        {
            if (this.LogProcessClose == null)
                return;

            DateTime startDate = minerProcess.StartDate;
            DateTime endDate = DateTime.Now;
            string coinName = minerProcess.MinerConfiguration.CoinName;

            double priceAtStart = 0;
            string coinSymbol = String.Empty;
            //coin may not be in Coin API
            if (minerProcess.CoinInformation != null)
            {
                coinSymbol = minerProcess.CoinInformation.Symbol;
                priceAtStart = minerProcess.CoinInformation.Price;
            }

            double priceAtEnd = priceAtStart;

            //can't use Single here - coin info may be gone now and we crash
            CoinInformation coinInfo = null;
            if (coinInformation != null) //null if no internet connection
                coinInfo = coinInformation.SingleOrDefault(c => c.Symbol.Equals(coinSymbol, StringComparison.OrdinalIgnoreCase));
            if (coinInfo != null)
                priceAtEnd = coinInfo.Price;

            //get a copy using ToList() so we can change the list in the event handler without
            //affecting relaunching processes
            List<DeviceDescriptor> deviceDescriptors = minerProcess.MinerConfiguration.DeviceDescriptors.ToList();
                        
            LogProcessCloseArgs args = new LogProcessCloseArgs();
            args.StartDate = startDate;
            args.EndDate = endDate;
            args.CoinName = coinName;
            args.CoinSymbol = coinSymbol;
            args.StartPrice = priceAtStart;
            args.EndPrice = priceAtEnd;
            args.DeviceDescriptors = deviceDescriptors;
            args.MinerConfiguration = minerProcess.MinerConfiguration;
            args.AcceptedShares = minerProcess.AcceptedShares;
            this.LogProcessClose(this, args);
        }
Example #21
0
        private void setupProcessStartInfo(MinerProcess minerProcess)
        {
            string coinName = minerProcess.MinerConfiguration.CoinName;
            string coinSymbol = engineConfiguration.CoinConfigurations.Single(c => c.CryptoCoin.Name.Equals(coinName, StringComparison.OrdinalIgnoreCase)).CryptoCoin.Symbol;

            CoinInformation processCoinInfo = null;
            if (coinInformation != null) //null if no network connection
                processCoinInfo = coinInformation.SingleOrDefault(c => c.Symbol.Equals(coinSymbol, StringComparison.OrdinalIgnoreCase));
            
            //coin may not be in Coin API
            if (processCoinInfo != null)
                minerProcess.CoinInformation = processCoinInfo;
            
            minerProcess.StartDate = DateTime.Now;
        }
Example #22
0
        private void StartMining()
        {
            IEnumerable<string> coinSymbols = engineConfiguration.DeviceConfigurations
                .Where(c => c.Enabled && !string.IsNullOrEmpty(c.CoinSymbol))
                .Select(c => c.CoinSymbol)
                .Distinct();

            int port = engineConfiguration.XgminerConfiguration.StartingApiPort;

            foreach (string coinSymbol in coinSymbols)
            {
                MinerConfiguration minerConfiguration = CreateMinerConfiguration(port, coinSymbol);

                Process process = LaunchMinerProcess(minerConfiguration, "Starting mining");

                if (!process.HasExited)
                {
                    MinerProcess minerProcess = new MinerProcess();

                    minerProcess.Process = process;
                    minerProcess.ApiPort = port;
                    minerProcess.MinerConfiguration = minerConfiguration;

                    setupProcessStartInfo(minerProcess);

                    minerProcesses.Add(minerProcess);
                }

                port++;
            }

            mining = true;
        }
Example #23
0
        private void RebaseGpuDeviceIndexes(MinerProcess minerProcess, List<int> deviceIndexes)
        {
            //we need to rebase GPUs here so that they match the rebasing done in CreateMinerConfiguration()
            if (minerProcess.MinerConfiguration.Algorithm == CoinAlgorithm.Scrypt)
            {
                int firstGpuIndex = GetIndexOfFirstGpu();

                for (int i = 0; i < deviceIndexes.Count; i++)
                    deviceIndexes[i] += firstGpuIndex;
            }
        }
Example #24
0
        private void logProcessClose(MinerProcess minerProcess)
        {
            DateTime startDate = minerProcess.StartDate;
            DateTime endDate = DateTime.Now;
            string coinName = minerProcess.MinerConfiguration.CoinName;

            double priceAtStart = 0;
            string coinSymbol = String.Empty;
            //coin may not be in CoinChoose.com
            if (minerProcess.CoinInformation != null)
            {
                coinSymbol = minerProcess.CoinInformation.Symbol;
                priceAtStart = minerProcess.CoinInformation.Price;
            }

            double priceAtEnd = priceAtStart;

            //can't use Single here - coin info may be gone now and we crash
            CoinInformation coinInfo = null;
            if (coinInformation != null) //null if no internet connection
                coinInfo = coinInformation.SingleOrDefault(c => c.Symbol.Equals(coinSymbol, StringComparison.OrdinalIgnoreCase));
            if (coinInfo != null)
                priceAtEnd = coinInfo.Price;

            //get a copy using ToList() so we can change the list in the event handler without
            //affecting relaunching processes
            List<int> deviceIndexes = minerProcess.MinerConfiguration.DeviceIndexes.ToList();

            logProcessClose(startDate, endDate, coinName, coinSymbol, priceAtStart, priceAtEnd, deviceIndexes, minerProcess.MinerConfiguration);
        }
Example #25
0
        private int GetDeviceIndexForDeviceDetails(DeviceDetails deviceDetails, MinerProcess minerProcess)
        {
            int result = devices
                .FindIndex((device) => {
                    return device.Driver.Equals(deviceDetails.Driver, StringComparison.OrdinalIgnoreCase)
                    &&
                    (
                        //serial == serial && path == path (serial may not be unique)
                        (!String.IsNullOrEmpty(device.Serial) && device.Serial.Equals(deviceDetails.Serial, StringComparison.OrdinalIgnoreCase)
                            && !String.IsNullOrEmpty(device.Path) && device.Path.Equals(deviceDetails.DevicePath, StringComparison.OrdinalIgnoreCase))

                        //serial == serial && path == String.Empty - WinUSB/LibUSB has no path, but has a serial #
                        || (!String.IsNullOrEmpty(device.Serial) && device.Serial.Equals(deviceDetails.Serial, StringComparison.OrdinalIgnoreCase)
                            && String.IsNullOrEmpty(device.Path) && String.IsNullOrEmpty(deviceDetails.DevicePath))

                        //path == path
                        || (!String.IsNullOrEmpty(device.Path) && device.Path.Equals(deviceDetails.DevicePath, StringComparison.OrdinalIgnoreCase))

                        //proxy == proxy && ID = RelativeIndex
                        || (device.Driver.Equals("proxy", StringComparison.OrdinalIgnoreCase) && (minerProcess.MinerConfiguration.DeviceDescriptors.Contains(device)))

                        //opencl = opencl && ID = RelativeIndex
                        || (device.Driver.Equals("opencl", StringComparison.OrdinalIgnoreCase) && (device.RelativeIndex == deviceDetails.ID))

                        //cpu = cpu && ID = RelativeIndex
                        || (device.Driver.Equals("cpu", StringComparison.OrdinalIgnoreCase) && (device.RelativeIndex == deviceDetails.ID))
                    );

                });

            return result;
        }
Example #26
0
        private List<PoolInformation> GetPoolInfoFromProcess(MinerProcess minerProcess)
        {
            Xgminer.Api.ApiContext apiContext = minerProcess.ApiContext;

            //setup logging
            apiContext.LogEvent -= LogApiEvent;
            apiContext.LogEvent += LogApiEvent;

            List<PoolInformation> poolInformation = null;
            try
            {
                try
                {
                    poolInformation = apiContext.GetPoolInformation();
                }
                catch (IOException)
                {
                    //don't fail and crash out due to any issues communicating via the API
                    poolInformation = null;
                }
            }
            catch (SocketException)
            {
                //won't be able to connect for the first 5s or so
                poolInformation = null;
            }

            return poolInformation;
        }
Example #27
0
        private MinerProcess StoreMinerProcess(Process process, MinerDescriptor miner, string coinSymbol, Xgminer.Data.Configuration.Miner minerConfiguration, int apiPort)
        {
            MinerProcess minerProcess = new MinerProcess()
            {
                Process = process,
                Miner = miner,
                ApiPort = apiPort,
                MinerConfiguration = minerConfiguration,
                CoinSymbol = coinSymbol
            };

            setupProcessStartInfo(minerProcess);

            minerProcesses.Add(minerProcess);

            return minerProcess;
        }
Example #28
0
        private void FlagSuspiciousMiner(MinerProcess minerProcess, DeviceInformationResponse deviceInformation)
        {
            if (deviceInformation.Status.ToLower().Contains("sick"))
                minerProcess.HasSickDevice = true;
            if (deviceInformation.Status.ToLower().Contains("dead"))
                minerProcess.HasDeadDevice = true;
            if (deviceInformation.CurrentHashrate == 0)
                minerProcess.HasZeroHashrateDevice = true;

            //don't check average hashrate if using dynamic intensity and its a GPU
            if (!engineConfiguration.XgminerConfiguration.DesktopMode ||
                (!deviceInformation.Kind.Equals("GPU", StringComparison.OrdinalIgnoreCase)))
            {
                //avoid div by 0
                if (deviceInformation.AverageHashrate > 0)
                {
                    double performanceRatio = deviceInformation.CurrentHashrate / deviceInformation.AverageHashrate;
                    if (performanceRatio <= 0.50)
                        minerProcess.HasPoorPerformingDevice = true;
                }
            }
        }
Example #29
0
        private void logProcessClose(MinerProcess minerProcess)
        {
            DateTime startDate = minerProcess.StartDate;
            DateTime endDate = DateTime.Now;
            string coinName = minerProcess.MinerConfiguration.CoinName;

            double priceAtStart = 0;
            string coinSymbol = String.Empty;
            //coin may not be in CoinChoose.com
            if (minerProcess.CoinInformation != null)
            {
                coinSymbol = minerProcess.CoinInformation.Symbol;
                priceAtStart = minerProcess.CoinInformation.Price;
            }

            double priceAtEnd = priceAtStart;

            //can't use Single here - coin info may be gone now and we crash
            CoinInformation coinInfo = coinInformation.SingleOrDefault(c => c.Symbol.Equals(coinSymbol, StringComparison.OrdinalIgnoreCase));
            if (coinInfo != null)
                priceAtEnd = coinInfo.Price;

            List<int> deviceIndexes = minerProcess.MinerConfiguration.DeviceIndexes;

            logProcessClose(startDate, endDate, coinName, coinSymbol, priceAtStart, priceAtEnd, deviceIndexes);
        }
Example #30
0
 private static void ClearSuspectProcessFlags(MinerProcess minerProcess)
 {
     minerProcess.HasDeadDevice = false;
     minerProcess.HasSickDevice = false;
     minerProcess.HasZeroHashrateDevice = false;
     minerProcess.MinerIsFrozen = false;
     minerProcess.HasPoorPerformingDevice = false;
 }
        private void CheckAndNotifyAcceptedShares(MinerProcess minerProcess, long acceptedShares)
        {
            //started mining but haven't yet assigned mining members
            if (miningCoinConfigurations == null)
                return;

            string coinName = minerProcess.MinerConfiguration.CoinName;
            //reference miningCoinConfigurations so that we get access to the mining coins
            Coin configuration = miningCoinConfigurations.SingleOrDefault(c => c.PoolGroup.Name.Equals(coinName, StringComparison.OrdinalIgnoreCase));
            if (configuration == null)
                return;

            if (configuration.NotifyOnShareAccepted2 && (acceptedShares > minerProcess.AcceptedShares))
            {
                minerProcess.AcceptedShares = acceptedShares;

                PostNotification(String.Format("Share(s) accepted for {0} (share {1})",
                    coinName, minerProcess.AcceptedShares), NotificationKind.Information);
            }
        }
Example #32
0
        private SummaryInformationResponse GetSummaryInfoFromProcess(MinerProcess minerProcess)
        {
            Xgminer.Api.ApiContext apiContext = minerProcess.ApiContext;

            //setup logging
            apiContext.LogEvent -= LogApiEvent;
            apiContext.LogEvent += LogApiEvent;

            SummaryInformationResponse summaryInformation = null;
            try
            {
                try
                {
                    summaryInformation = apiContext.GetSummaryInformation();
                }
                catch (IOException ex)
                {
                    //don't fail and crash out due to any issues communicating via the API
                    summaryInformation = null;
                }
            }
            catch (SocketException ex)
            {
                //won't be able to connect for the first 5s or so
                summaryInformation = null;
            }

            return summaryInformation;
        }
        private List<DeviceDetails> GetDeviceDetailsFromProcess(MinerProcess minerProcess)
        {
            ApiContext apiContext = minerProcess.ApiContext;

            //setup logging
            apiContext.LogEvent -= LogApiEvent;
            apiContext.LogEvent += LogApiEvent;

            List<DeviceDetails> deviceDetailsList;
            try
            {
                try
                {
                    deviceDetailsList = apiContext.GetDeviceDetails().ToList();
                }
                catch (IOException)
                {
                    //don't fail and crash out due to any issues communicating via the API
                    deviceDetailsList = null;
                }
            }
            catch (SocketException)
            {
                //won't be able to connect for the first 5s or so
                deviceDetailsList = null;
            }

            return deviceDetailsList;
        }
Example #34
0
        private void CheckAndNotifyFoundBlocks(MinerProcess minerProcess, long foundBlocks)
        {
            string coinName = minerProcess.MinerConfiguration.CoinName;
            //reference miningCoinConfigurations so that we get access to the mining coins
            CoinConfiguration configuration = miningCoinConfigurations.Single(c => c.Coin.Name.Equals(coinName, StringComparison.OrdinalIgnoreCase));
            if (configuration == null)
                return;

            if (configuration.NotifyOnBlockFound && (foundBlocks > minerProcess.FoundBlocks))
            {
                minerProcess.FoundBlocks = foundBlocks;

                string notificationReason = String.Format("Block(s) found for {0} (block {1})",
                    coinName, minerProcess.FoundBlocks);

                notificationsControl.AddNotification(notificationReason, notificationReason, () =>
                {
                }, "");
            }
        }
        private void RefreshProcessDeviceStats(MinerProcess minerProcess)
        {
            ClearSuspectProcessFlags(minerProcess);

            List<DeviceInformation> deviceInformationList = GetDeviceInfoFromProcess(minerProcess);
            if (deviceInformationList == null) //handled failure getting API info
            {
                minerProcess.MinerIsFrozen = true;
                return;
            }
            
            //starting with bfgminer 3.7 we need the DEVDETAILS response to tie things from DEVS up with -d? details
            List<DeviceDetails> processDevices = GetProcessDeviceDetails(minerProcess, deviceInformationList);
            if (processDevices == null) //handled failure getting API info
            {
                minerProcess.MinerIsFrozen = true;
                return;
            }

            //clear accepted shares as we'll be summing that as well
            minerProcess.AcceptedShares = 0;

            foreach (DeviceInformation deviceInformation in deviceInformationList)
            {
                //don't consider a standalone miner suspect - restarting the proxy doesn't help and often hurts
                if (!deviceInformation.Name.Equals("PXY", StringComparison.OrdinalIgnoreCase))
                    FlagSuspiciousMiner(minerProcess, deviceInformation);

                DeviceDetails deviceDetails = processDevices.SingleOrDefault(d => d.Name.Equals(deviceInformation.Name, StringComparison.OrdinalIgnoreCase)
                    && (d.ID == deviceInformation.ID));
                int deviceIndex = GetDeviceIndexForDeviceDetails(deviceDetails, minerProcess);

                if (deviceIndex >= 0)
                {
                    minerProcess.AcceptedShares += deviceInformation.AcceptedShares;

                    Device device = Devices[deviceIndex];
                    Coin coinConfiguration = CoinConfigurationForDevice(device);

                    if (minerProcess.Miner.LegacyApi && (coinConfiguration != null))
                        deviceInformation.WorkUtility = AdjustWorkUtilityForPoolMultipliers(deviceInformation.WorkUtility, coinConfiguration.PoolGroup.Algorithm);

                    DeviceViewModel deviceViewModel = LocalViewModel.ApplyDeviceInformationResponseModel(device, deviceInformation);
                    DeviceDetailsMapping[deviceViewModel] = deviceDetails;

                    if (coinConfiguration != null)
                    {
                        string poolName = GetPoolNameByIndex(coinConfiguration, deviceViewModel.PoolIndex);
                        //may be blank if donating
                        if (!String.IsNullOrEmpty(poolName))
                        {
                            deviceViewModel.Pool = poolName;
                            lastDevicePoolMapping[deviceViewModel] = poolName;
                        }
                        else
                        {
                            if (lastDevicePoolMapping.ContainsKey(deviceViewModel))
                                deviceViewModel.Pool = lastDevicePoolMapping[deviceViewModel];
                        }

                        if (!String.IsNullOrEmpty(deviceViewModel.Pool))
                            CheckAndSetNetworkDifficulty(minerProcess.ApiContext.IpAddress, minerProcess.ApiContext.Port, deviceViewModel.Pool);
                    }
                }
            }

            FlagSuspiciousProxy(minerProcess, deviceInformationList);

            LocalViewModel.ApplyDeviceDetailsResponseModels(minerProcess.MinerConfiguration.DeviceDescriptors, processDevices);
        }