Ejemplo n.º 1
0
 public static extern void HashMidState(IntPtr instance, ref Structs.DeviceCPU device, ref Structs.Processor processor);
Ejemplo n.º 2
0
        private void StartThreadFinding(Device.CPU device, Structs.Processor processor, bool isKingMaking)
        {
            try
            {
                var errorMessage     = new StringBuilder(1024);
                var currentChallenge = (byte[])Array.CreateInstance(typeof(byte), UINT256_LENGTH);

                DateTime loopStartTime;
                int      loopTimeElapsed;
                double   timeAccuracy;
                var      loopTimeTarget = (int)(m_hashPrintTimer.Interval * 0.1);

                var processorIndex = -1;
                for (var i = 0; i < device.Processor_Structs.Length; i++)
                {
                    if (device.Processor_Structs[i].Affinity == processor.Affinity)
                    {
                        processorIndex = i;
                    }
                }

                Helper.CPU.Solver.SetThreadAffinity(UnmanagedInstance, processor.Affinity, errorMessage);
                if (errorMessage.Length > 0)
                {
                    PrintMessage(device.Type, device.Platform, processorIndex, "Error", errorMessage.ToString());
                    return;
                }

                device.HashStartTime = DateTime.Now;
                device.HashCount     = 0;
                device.IsMining      = true;
                do
                {
                    while (device.IsPause)
                    {
                        Task.Delay(500).Wait();
                        device.HashStartTime = DateTime.Now;
                        device.HashCount     = 0;
                    }

                    CheckInputs(device, isKingMaking, ref currentChallenge);

                    Work.IncrementPosition(ref processor.WorkPosition, processor.WorkSize);

                    lock (device)
                        device.HashCount += processor.WorkSize;

                    loopStartTime = DateTime.Now;

                    if (isKingMaking)
                    {
                        Helper.CPU.Solver.HashMessage(UnmanagedInstance, ref device.DeviceCPU_Struct, ref processor);
                    }
                    else
                    {
                        Helper.CPU.Solver.HashMidState(UnmanagedInstance, ref device.DeviceCPU_Struct, ref processor);
                    }

                    loopTimeElapsed = (int)(DateTime.Now - loopStartTime).TotalMilliseconds;

                    timeAccuracy = (float)loopTimeTarget / loopTimeElapsed;

                    if (timeAccuracy > 1.2f || timeAccuracy < 0.8f)
                    {
                        processor.WorkSize = (ulong)(timeAccuracy * processor.WorkSize);
                    }

                    if (processor.SolutionCount > 0)
                    {
                        SubmitSolutions(device.Solutions[processorIndex].ToArray(),
                                        currentChallenge,
                                        device.Type,
                                        device.Platform,
                                        device.DeviceID,
                                        processor.SolutionCount,
                                        isKingMaking);

                        processor.SolutionCount = 0;
                    }
                } while (device.IsMining);

                if (processor.Affinity == device.Processor_Structs.First().Affinity)
                {
                    PrintMessage(device.Type, device.Platform, device.DeviceID, "Info", "Stop mining...");
                }

                device.HashCount     = 0;
                device.IsStopped     = true;
                device.IsInitialized = false;
            }
            catch (Exception ex)
            {
                PrintMessage(device.Type, device.Platform, -1, "Error", ex.Message);
            }
            if (processor.Affinity == device.Processor_Structs.First().Affinity)
            {
                PrintMessage(device.Type, device.Platform, device.DeviceID, "Info", "Mining stopped.");
            }
        }