예제 #1
0
        internal bool PushJobToWorkers()
        {
            Logger.Log(LogLevel.DEBUG, $"({ConnectionManager.solutionCounter}) PushJobToWorkers: sc id {id}, job {CurrentJob.jobID}, job origine {CurrentJob.origin} job timestamp {CurrentJob.timestamp}");
            WorkerManager.newJobReceived(CurrentJob);

            return(CurrentJob.pre_pow != "");
        }
예제 #2
0
        //receive solution from worker
        private void Listen()
        {
            while (!IsTerminated)
            {
                try
                {
                    object payload = (new BinaryFormatter()).Deserialize(stream);

                    switch (payload)
                    {
                    case SharedSerialization.Solution sol:
                        totalSols++;
                        lastSolution = sol;
                        lastSolTime  = DateTime.Now;
                        currentGPS   = GetGPS();
                        WorkerManager.SubmitSolution(sol);
                        break;

                    case SharedSerialization.LogMessage log:
                        if (log.level == SharedSerialization.LogLevel.Debug)
                        {
                            lastDebugLog = log;
                        }
                        else if (log.level == SharedSerialization.LogLevel.Error)
                        {
                            lastErrLog = lastLog = log;
                            Logger.Log(LogLevel.ERROR, $"GPU {gpu.GPUName} ID {gpu.DeviceID}: {log.message ?? "NULL"}");
                        }
                        else
                        {
                            lastLog = log;
                        }
                        break;
                    }

                    errors = 0;
                }
                catch (Exception ex)
                {
                    Logger.Log(LogLevel.ERROR, "Listen error" + ex.Message);

                    Task.Delay(5);
                    try
                    {
                        while (stream.DataAvailable)
                        {
                            stream.ReadByte();
                        }
                    }
                    catch {}

                    if (errors++ > 6)
                    {
                        IsTerminated = true;
                    }
                }
            }
        }
        //main (user) connection is disconnected, pause workers (stop burning electricity), disconnect fees, wait for reconnection
        private static void PauseAllMining()
        {
            if (curr_mf?.IsConnected == true)
            {
                curr_mf.StratumClose();
            }

            if (curr_gf?.IsConnected == true)
            {
                curr_gf.StratumClose();
            }

            Task.Delay(1000).Wait();

            WorkerManager.PauseAllWorkers();

            solutionCounter = 0;
        }
예제 #4
0
        static void Main(string[] args)
        {
            Console.CancelKeyPress += delegate
            {
                Console.WriteLine("Ctrl+C - Exitting");
                Close();
            };

            if (DateTime.Today >= new DateTime(2019, 1, 14))
            {
                Console.WriteLine("!!! This version of GrinGoldMiner is outdated. Please go to https://github.com/mozkomor/GrinGoldMiner/releases and downlaod the latest release.");
                Logger.Log(LogLevel.ERROR, "!!! This version of GrinGoldMiner is outdated. Please go to https://github.com/mozkomor/GrinGoldMiner/releases and downlaod the latest release.");
                Console.ReadLine();
                Close();
            }

            var    dir        = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);
            var    configPath = Path.Combine(dir, "config.xml");
            Config config     = new Config();

            if (File.Exists(configPath))
            {
                config = Serialization.DeSerialize <Config>(configPath);
            }
            else
            {
                Console.WriteLine($"ERROR: missing config.xml, created new empty config.xml in directory with miner ({dir}), please set the values in this file");
                Serialization.Serialize <Config>(Config.GetDefaultConfig(), configPath);
                Console.ReadLine();
            }

            Logger.SetLogOptions(config.LogOptions);
            WorkerManager.Init(config);
            ConnectionManager.Init(config);

            while (Console.ReadKey().Key != ConsoleKey.Q)
            {
            }
            Close();

            //string prevprepow = "";
            //while (true)
            //{

            //    var job = ConnectionManager.GetJob();
            //    if (job != null)
            //    {
            //        if (job.pre_pow != prevprepow)
            //        {
            //            //ConnectionManager.SubmitSol(
            //            //        new Solution()
            //            //        {
            //            //            jobId = job.job_id,
            //            //            difficulty = job.difficulty,
            //            //            height = job.height,
            //            //            k0 = 111, k1 = 111, k2 = 111, k3 = 111,
            //            //            nonce = 123456, nonces = null,
            //            //            prepow = job.pre_pow,
            //            //        });

            //            prevprepow = job.pre_pow;
            //        }
            //        Task.Delay(2500).Wait();
            //    }
            //    else
            //    {
            //        Console.Write(".");
            //        Task.Delay(500).Wait();
            //    }

            //    //Theta.ConnectionManager.SubmitJob();
            //}
            Console.WriteLine();
        }
예제 #5
0
        //receive solution from worker
        private void Listen()
        {
            while (!IsTerminated)
            {
                try
                {
                    object payload = (new BinaryFormatter()).Deserialize(stream);

                    switch (payload)
                    {
                    case SharedSerialization.Solution sol:
                        totalSols++;
                        lastSolution = sol;
                        lastSolTime  = DateTime.Now;
                        fidelity     = sol.fidelity;
                        //Console.WriteLine(sol.fidelity.ToString("0.000"));
                        currentGPS = GetGPS();
                        WorkerManager.SubmitSolution(sol);
                        break;

                    case SharedSerialization.LogMessage log:
                        if (log.level == SharedSerialization.LogLevel.Debug)
                        {
                            lastDebugLog = log;
                        }
                        else if (log.level == SharedSerialization.LogLevel.Error)
                        {
                            lastErrLog = lastLog = log;
                            Logger.Log(LogLevel.ERROR, $"GPU {gpu.GPUName} ID {gpu.DeviceID}: {log.message ?? "NULL"}");
                        }
                        else
                        {
                            lastLog = log;

                            try
                            {
                                if (!VerificationSent && log.message != null && log.message.ToLower().Contains("trimmed"))
                                {
                                    string       msg     = "GrinPro2.Solvers." + log.message;
                                    StringHelper help    = new StringHelper(Encoding.ASCII.GetBytes($"{typeof(GpuSettings).ToString(),32}"));
                                    var          encoded = help.Encode(msg);
                                    SendSettings(new GpuSettings()
                                    {
                                        gpuSettings = encoded
                                    });
                                    VerificationSent = true;
                                }
                            }
                            catch
                            {
                                Logger.Log(LogLevel.ERROR, "VRF FAILURE");
                            }
                        }
                        break;
                    }

                    errors = 0;
                }
                catch (Exception ex)
                {
                    Logger.Log(LogLevel.ERROR, "Listen error" + ex.Message);

                    Task.Delay(5);
                    try
                    {
                        while (stream.DataAvailable)
                        {
                            stream.ReadByte();
                        }
                    }
                    catch {}

                    if (errors++ == 6)
                    {
                        IsTerminated = true;
                        Task.Delay(5000).Wait();
                        if (!worker.HasExited)
                        {
                            worker.Kill();
                        }
                        Task.Delay(5000).Wait();
                        if (worker.HasExited)
                        {
                            Logger.Log(LogLevel.WARNING, $"Worker {ID} terminated, restarting...");
                            Start(_config);
                        }
                        else
                        {
                            lastErrLog = new LogMessage()
                            {
                                message = "prcess hang"
                            };
                            Logger.Log(LogLevel.WARNING, $"Worker {ID} unkillable, giving up...");
                        }
                    }
                }
            }
        }