Esempio n. 1
0
 void OnWorkAccepted(IPool arg1, IPoolWork arg2, IMiningDevice arg3)
 {
     if (this.WorkAccepted != null)
     {
         this.WorkAccepted(arg1, arg2, arg3);
     }
 }
Esempio n. 2
0
        public void UpdatedHashRate(IMiningDevice d, bool resetTimer = true)
        {
            double acceptedHash  = d.AcceptedHashRate;
            double rejectedHash  = d.RejectedHashRate;
            double discardedHash = d.DiscardedHashRate;

            double total = acceptedHash + rejectedHash + discardedHash;

            if (total > 0)
            {
                AcceptedHashrate.Value  = string.Format("{0} ({1}%)", HashHelper.MegaHashDisplayString(acceptedHash), (int)(acceptedHash / total * 100));
                RejectedHashrate.Value  = string.Format("{0} ({1}%)", HashHelper.MegaHashDisplayString(rejectedHash), (int)(rejectedHash / total * 100));
                DiscardedHashrate.Value = string.Format("{0} ({1}%)", HashHelper.MegaHashDisplayString(discardedHash), (int)(discardedHash / total * 100));
            }
            else
            {
                AcceptedHashrate.Value  = string.Format("{0} (0%)", "0.00Mh");
                RejectedHashrate.Value  = string.Format("{0} (0%)", "0.00Mh");
                DiscardedHashrate.Value = string.Format("{0} (0%)", "0.00Mh");
            }

            if (resetTimer)
            {
                _timer.Stop();
                _timer.Start();
            }
        }
Esempio n. 3
0
 void OnDeviceConnected(IMiningDeviceManager arg1, IMiningDevice arg2)
 {
     if (this.DeviceConnected != null)
     {
         this.DeviceConnected(arg1, arg2);
     }
 }
Esempio n. 4
0
 void OnWorkRejected(IPool arg1, IPoolWork arg2, IMiningDevice arg3, IShareResponse arg4)
 {
     if (this.WorkRejected != null)
     {
         this.WorkRejected(arg1, arg2, arg3, arg4);
     }
 }
Esempio n. 5
0
 public void AddNewDevice(IMiningDevice d)
 {
     Task.Factory.StartNew(() =>
     {
         LoadDevice(d);
     });
 }
Esempio n. 6
0
 protected virtual void OnDeviceDisconnected(IMiningDevice device)
 {
     if (this.DeviceDisconnected != null)
     {
         this.DeviceDisconnected(this, device);
     }
 }
Esempio n. 7
0
        private void StartWorkOnDevice(IMiningDevice device, object[] param, string extranonce1, int extraNonce2Size, int diff)
        {
            string extranonce2 = string.Empty;

            lock (extraNonce2Lock)
            {
                extranonce2 = string.Format("{0:X8}", currentExtraNonce2);

                if (currentExtraNonce2 != int.MaxValue)
                {
                    currentExtraNonce2++;
                }
                else
                {
                    currentExtraNonce2 = 0;
                }
            }

            StratumWork deviceWork = new StratumWork(param, extranonce1, extraNonce2Size, extranonce2, diff);

            #if DEBUG
            string previous = deviceWork.Timestamp;
            #endif

            deviceWork.SetTimestamp(lastReceivedNTime + (uint)DateTime.Now.Subtract(lastWorkRecievedTime).TotalSeconds);

            #if DEBUG
            LogHelper.DebugConsoleLog(string.Format("Update timestamp from {0} to {1}.", previous, deviceWork.Timestamp), ConsoleColor.DarkYellow, LogVerbosity.Quiet);
            #endif

            device.StartWork(deviceWork);
        }
Esempio n. 8
0
        private void processWorkAcceptCommand(StratumWork work, IMiningDevice device, StratumResponse response, bool error = false)
        {
            if (error)
            {
                LogHelper.DebugConsoleLogError("Error. Unknown work result. Mismatch in work queue ID and recieved response ID.");
                return;
            }

            bool accepted = response.Data != null && response.Data.Equals(true);

            if (accepted)
            {
                Accepted++;
                AcceptedWorkUnits += work.Diff;
            }
            else
            {
                Rejected++;
                RejectedWorkUnits += work.Diff;
            }

            Task.Factory.StartNew(() =>
            {
                if (accepted)
                {
                    this.OnWorkAccepted(work, device, false);
                }
                else
                {
                    this.OnWorkRejected(work, device, response, false);
                }

                DisplaySubmissionResponse(accepted, response);
            });
        }
Esempio n. 9
0
        private void ProcessSubmitQueue()
        {
            foreach (var item in this.submissionQueue.GetConsumingEnumerable())
            {
                StratumWork   work   = item.Item1;
                IMiningDevice device = item.Item2;
                string        nonce  = item.Item3;

                if (this.connection == null || !this.connection.Connected)
                {
                    LogHelper.ConsoleLogError("Attempting to submit share to disconnected pool.");
                    return;
                }

                if (!this._allowOldWork && (this.latestWork == null || work.JobId != this.latestWork.JobId))
                {
                    if (LogHelper.ShouldDisplay(LogVerbosity.Verbose))
                    {
                        LogHelper.ConsoleLog(string.Format("Discarding share for old job {0}.", work.JobId), ConsoleColor.Magenta, LogVerbosity.Verbose);
                    }
                    return;
                }

                if (WorkSubmitQueue != null)
                {
                    try
                    {
                        long requestId = this.RequestId;
                        this.RequestId++;

                        string[]           param   = { this.Username, work.JobId, work.Extranonce2, work.Timestamp, nonce };
                        StratumSendCommand command = new StratumSendCommand(requestId, StratumSendCommand.SubmitCommandString, param);

                        WorkSubmitQueue.Enqueue(new Tuple <StratumSendCommand, StratumWork, IMiningDevice>(command, work, device));

                        if (this.connection != null && this.connection.Connected)
                        {
                            MemoryStream memStream = new MemoryStream();
                            command.Serialize(memStream);
                            this.SendData(memStream);
                        }
                    }
                    catch (Exception e)
                    {
                        LogHelper.LogErrorSecondary(e);

                        if ((this.connection == null || !this.connection.Connected) && this.Running)
                        {
                            Task.Factory.StartNew(() =>
                            {
                                this.Stop();

                                this.OnDisconnect();
                            });
                        }
                    }
                }
            }
        }
Esempio n. 10
0
 public virtual void InvalidNonce(IMiningDevice device, IPoolWork work)
 {
     if (this.ActivePool != null)
     {
         this.ActivePool.HardwareErrors++;
         this.ActivePool.DiscardedWorkUnits += work.Diff;
     }
 }
Esempio n. 11
0
        public void SubmitWork(IPoolWork work, IMiningDevice device, string nonce)
        {
            StratumWork stratumWork = work as StratumWork;

            if (stratumWork != null && device != null && nonce != null && this.submissionQueue != null)
            {
                this.submissionQueue.Add(new Tuple <StratumWork, IMiningDevice, string>(stratumWork, device, nonce));
            }
        }
Esempio n. 12
0
 protected override void SetUpDevice(IMiningDevice d)
 {
     if (d.HashRate > 0)
     {
         double fullHashTimeSec = 0xFFFFFFFF / (double)d.HashRate; // Hashes devided by Hashes per second yeilds seconds
         double safeWaitTime    = fullHashTimeSec * 0.85 * 0.95;   // Assume we have 15% more hash rate then only wait until we've covered 95% of the nonce space
         d.WorkRequestTimer.Interval = safeWaitTime * 1000;        // Convert to milliseconds
     }
 }
Esempio n. 13
0
        protected override void NoWork(IPoolWork oldWork, IMiningDevice device, bool requested)
        {
            StratumWork stratumWork = oldWork as StratumWork;

            if (stratumWork != null)
            {
                LogHelper.DebugConsoleLog("No new work, making new work.");
                StartWorkOnDevice(stratumWork, device, false, requested);
            }
        }
Esempio n. 14
0
        public MiningDeviceData(IMiningDevice d)
        {
            _timer          = new Timer(1000);
            _timer.Elapsed += Timer_Elapsed;
            _timer.Start();

            Device     = d;
            Name.Value = string.Format("{0} ({1})", d.Name, d.GetType().Name);
            UpdatedHashRate(d, false);
        }
Esempio n. 15
0
        void Miner_WorkRejected(IPool arg1, IPoolWork arg2, IMiningDevice arg3, IShareResponse arg4)
        {
            this.UpdateHashrate(arg1);

            MiningDeviceData data;

            if (DeviceMap.TryGetValue(arg3, out data))
            {
                data.UpdatedHashRate(arg3);
            }
        }
Esempio n. 16
0
        void Miner_WorkAccepted(IPool arg1, IPoolWork arg2, IMiningDevice arg3)
        {
            this.UpdateHashrate(arg1);

            MiningDeviceData data;

            if (DeviceMap.TryGetValue(arg3, out data))
            {
                data.UpdatedHashRate(arg3);
            }
        }
Esempio n. 17
0
 private void StartWorkOnDevice(StratumWork work, IMiningDevice device, bool restartWork, bool requested)
 {
     if (!restartWork && device != null && requested)
     {
         StartWorkOnDevice(device, work.CommandArray, work.Extranonce1, work.ExtraNonce2Size, work.Diff);
     }
     else if (restartWork)
     {
         StartWorking(work.CommandArray, work.Extranonce1, work.ExtraNonce2Size, work.Diff);
     }
 }
Esempio n. 18
0
        protected virtual void OnWorkAccepted(IPool pool, IPoolWork work, IMiningDevice device)
        {
            device.Accepted++;
            device.AcceptedWorkUnits += work.Diff;

            DisplayDeviceStats(device);

            if (this.WorkAccepted != null)
            {
                this.WorkAccepted(pool, work, device);
            }
        }
Esempio n. 19
0
        private void LoadDevice(IMiningDeviceObject d)
        {
            IDeviceLoader loader = d as IDeviceLoader;

            if (loader != null)
            {
                foreach (IMiningDevice device in loader.LoadDevices())
                {
                    LoadDevice(device);
                }
            }
            else
            {
                IHotplugLoader hotplugLoader = d as IHotplugLoader;

                if (hotplugLoader != null)
                {
                    hotplugLoader.DeviceFound += this.AddNewDevice;
                    hotplugLoader.StartListening();

                    lock (hotplugListLock)
                    {
                        hotplugLoaders.Add(hotplugLoader);
                    }
                }
                else
                {
                    IMiningDevice device = d as IMiningDevice;

                    if (device != null)
                    {
                        lock (deviceListLock)
                        {
                            device.Id = deviceId;
                            deviceId++;

                            loadedDevices.Add(device);
                        }

                        device.ValidNonce    += this.SubmitWork;
                        device.WorkRequested += this.RequestWork;
                        device.InvalidNonce  += this.InvalidNonce;

                        device.Connected    += OnDeviceConnected;
                        device.Disconnected += OnDeviceDisconnected;

                        device.Load();

                        this.SetUpDevice(device);
                    }
                }
            }
        }
Esempio n. 20
0
        protected override void StartWork(IPoolWork work, IMiningDevice device, bool restartAll, bool requested)
        {
            StratumWork stratumWork = work as StratumWork;

            if (stratumWork != null)
            {
                LogHelper.DebugConsoleLog("Starting new work on devices.");
                currentExtraNonce2 = Random.Next();
                StartWorkOnDevice(stratumWork, device, (restartAll || (AlwaysForceRestart && (mostRecentWork == null || mostRecentWork.JobId != work.JobId))), requested);

                mostRecentWork = stratumWork;
            }
        }
Esempio n. 21
0
        protected override void OnWorkRejected(IPool pool, IPoolWork work, IMiningDevice device, IShareResponse response)
        {
            base.OnWorkRejected(pool, work, device, response);

            if (response.JobNotFound || response.RejectReason.Contains("job not found") || response.RejectReason.Contains("stale"))
            {
                if (LogHelper.ShouldDisplay(LogVerbosity.Verbose))
                {
                    LogHelper.ConsoleLog(string.Format("Device {0} submitted stale share. Restarting with new work.", device.Name), LogVerbosity.Verbose);
                }

                this.RequestWork(device);
            }
        }
Esempio n. 22
0
        public virtual void SubmitWork(IMiningDevice device, IPoolWork work, string nonce)
        {
            if (started && this.ActivePool != null && currentWork != null && this.ActivePool.IsConnected)
            {
                this.ActivePool.SubmitWork(work, device, nonce);

                StartWorkOnDevice(work, device, false);
            }
            else if (this.ActivePool != null && !this.ActivePool.IsConnected && !this.ActivePool.IsConnecting)
            {
                //Attempt to connect to another pool
                this.AttemptPoolReconnect();
            }
        }
Esempio n. 23
0
 private void OnWorkRejected(StratumWork work, IMiningDevice device, IShareResponse response, bool async = true)
 {
     if (this.WorkRejected != null)
     {
         if (async)
         {
             Task.Factory.StartNew(() =>
             {
                 this.WorkRejected(this, work, device, response);
             });
         }
         else
         {
             this.WorkRejected(this, work, device, response);
         }
     }
 }
Esempio n. 24
0
 private void OnWorkAccepted(StratumWork work, IMiningDevice device, bool async = true)
 {
     if (this.WorkAccepted != null)
     {
         if (async)
         {
             Task.Factory.StartNew(() =>
             {
                 this.WorkAccepted(this, work, device);
             });
         }
         else
         {
             this.WorkAccepted(this, work, device);
         }
     }
 }
Esempio n. 25
0
        protected virtual void OnWorkRejected(IPool pool, IPoolWork work, IMiningDevice device, IShareResponse response)
        {
            if (!response.IsLowDifficlutyShare && !response.RejectReason.Contains("low difficulty") && !response.RejectReason.Contains("above target"))
            {
                device.Rejected++;
                device.RejectedWorkUnits += work.Diff;

                if (this.WorkRejected != null)
                {
                    this.WorkRejected(pool, work, device, response);
                }
            }
            else
            {
                // Fix for bug where some pools will change the difficluty in the middle of a job and expect shares at the new difficluty
                if (pool.Diff > work.Diff)
                {
                    LogHelper.DebugLogError(string.Format("Submitted share with low difficluty while pool diff was different than work diff. P: {0} W: {0}", pool.Diff, work.Diff));

                    LogHelper.DebugConsoleLog("Restarting work on all to attempt to synchronize difficluty.", ConsoleColor.Red, LogVerbosity.Quiet);

                    IPoolWork newWork = work.Clone() as IPoolWork;
                    newWork.Diff = pool.Diff;
                    StartNewWork(newWork);
                }

                device.HardwareErrors++;
                device.DiscardedWorkUnits += work.Diff;

                if (this.ActivePool != null)
                {
                    this.ActivePool.Rejected--;
                    this.ActivePool.RejectedWorkUnits -= work.Diff;

                    this.ActivePool.HardwareErrors++;
                    this.ActivePool.DiscardedWorkUnits += work.Diff;
                }
            }

            DisplayDeviceStats(device);

            if (this.WorkDiscarded != null)
            {
                this.WorkDiscarded(pool, work, device);
            }
        }
Esempio n. 26
0
        public void StartWorkOnDevice(IPoolWork work, IMiningDevice device, bool requested)
        {
            if (nextWork != null && currentWork != null)
            {
                if (nextWork.JobId != currentWork.JobId || nextWork.Diff != currentWork.Diff)
                {
                    // Start working on the last thing the server sent us
                    currentWork = nextWork;

                    StartWork(nextWork, device, false, requested);
                }
                else
                {
                    working = false;
                    NoWork(work, device, requested);
                }
            }
        }
Esempio n. 27
0
 private void DisplayDeviceStats(IMiningDevice d)
 {
     LogHelper.ConsoleLog(new Object[] {
         new Object[] { string.Format("Device {0} ", d.Name), false },
         new Object[] { " ( ", false },
         new Object[] { d.Accepted, ConsoleColor.Green, false },
         new Object[] { " : ", false },
         new Object[] { d.Rejected, ConsoleColor.Red, false },
         new Object[] { " : ", false },
         new Object[] { d.HardwareErrors, ConsoleColor.Magenta, false },
         new Object[] { " ) ", false },
         new Object[] { " ( ", false },
         new Object[] { HashHelper.MegaHashDisplayString(d.AcceptedHashRate), ConsoleColor.Green, false },
         new Object[] { " : ", false },
         new Object[] { HashHelper.MegaHashDisplayString(d.RejectedHashRate), ConsoleColor.Red, false },
         new Object[] { " : ", false },
         new Object[] { HashHelper.MegaHashDisplayString(d.DiscardedHashRate), ConsoleColor.Magenta, false },
         new Object[] { " )", true }
     },
                          LogVerbosity.Verbose);
 }
Esempio n. 28
0
 protected override void SetUpDevice(IMiningDevice d)
 {
     // do nothing
 }
Esempio n. 29
0
 protected override void NoWork(IPoolWork oldWork, IMiningDevice device, bool requested)
 {
     // do nothing
 }
Esempio n. 30
0
 protected override void StartWork(IPoolWork work, IMiningDevice device, bool restartAll, bool requested)
 {
     // do nothing
 }