예제 #1
0
 private void ClearStats()
 {
     // Reset stats to intial state
     SessionHashRateTxtBox.Clear();
     HashRateThreadTxtBox.Clear();
     SessionTimeTxtBox.Clear();
     ThreadTimeTxtBox.Clear();
     TotalSharesTxtBox.Clear();
     AcceptedSharesTxtBox.Clear();
     FailedHWTxtBox.Clear();
     RejectedSharesTxtBox.Clear();
     CurrentDiffTxtBox.Clear();
     DiffOneSharesTxtBox.Clear();
     LastShareDiffTxtBox.Clear();
     MaxDiffTxtBox.Clear();
     NetworkDiffTxtBox.Clear();
     AverageDiffTxtBox.Clear();
     BlockProgressBar.Value = 0;
     ProgressCntLbl.Text    = "xx% Complete";
     OutputTxtBox.Clear();
     DebugTxtBox.Clear();
     BatchTimeTxtBox.Clear();
     //_stats.ClearStats();
 }
예제 #2
0
        private void Start_Mining_Click(object sender, EventArgs e)
        {
            // Clear up any unused crap before starting a mining session
            GC.Collect();

            InitOpenCL();

            // Create instances of classes for next mining session
            _miner  = new Miner();
            _stats  = new Stats();
            _logger = new Logger();
            _worker.ResetClass();

            // Get user data and place info into user data class for easy access
            GetUserControlData();

            // Disable User data field since we already got the data and disable the start button and enable the stop button
            UserControlDataState(false);

            /*
             * // Check to see if we are going to log output.
             * if (isLogOutput)
             * {
             *  StoreDataDirectory = "";
             *
             *  // Prompt user to select a directory where the data files will be stored
             *  // Set up initial parameters
             *  folderBrowserDialog1.Description = "Select The Directory To Store log Files";
             *  folderBrowserDialog1.RootFolder = Environment.SpecialFolder.Desktop;
             *
             *  // Open up prompt for user to select directory and store the path
             *  if (folderBrowserDialog1.ShowDialog() == DialogResult.OK)
             *  {
             *      try
             *      {
             *          StoreDataDirectory = folderBrowserDialog1.SelectedPath;
             *      }
             *      catch (Exception ex)
             *      {
             *          MessageBox.Show("Error Prompting User To Select Folder Director. Error Code:: " + ex.Message);
             *      }
             *
             *  }
             *
             *  String FileNamePath = StoreDataDirectory + "\\" + "OutputLogFile_" + DateTime.Now.ToString() + ".csv";
             *  FileOutputStreamWriter = new StreamWriter(FileNamePath);
             * }
             */

            // Clear all stats and output window
            ClearStats();
            OutputTxtBox.Clear();

            // Build OpenCL program
            if (isAnalyzeData == true)
            {
                _worker.KernelSelection = Worker.OPENCL_CUSTOM_MIN;
            }
            else
            {
                _worker.KernelSelection = Worker.OPENCL_CUSTOM;
            }

            _worker.BuildOpenCL();

            _miner.ContinueMining = true;

            //Mine from a file using a csv file of block header data. Format = "BlochHeight","BlockHeaderData"
            if (_miner.MiningProtocolType == Miner.PROTCOL_FROM_FILE)
            {
                Int32         i, j = 0;
                List <String> intBlockHeaderList   = new List <String>();
                List <String> intBlockHeaderHeight = new List <String>();

                _miner.BlockHeaderList.Clear();
                _miner.BlockHeightList.Clear();

                openFileDialog1.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
                openFileDialog1.Multiselect      = true;

                if (openFileDialog1.ShowDialog() == DialogResult.OK)
                {
                    try
                    {
                        Int32  FileCnt = openFileDialog1.FileNames.Length;
                        String str = "";
                        Int32  start, end = 0;

                        for (i = 0; i < FileCnt; i++)
                        {
                            StreamReader sr_data = new StreamReader(openFileDialog1.FileNames[i]);

                            str = "";

                            // Reset index pointers. Read in data until end of file or max array size
                            j = 0;
                            while (((str = sr_data.ReadLine()) != null) & (j <= Int32.MaxValue))
                            {
                                // There might be some extra line feeds at the end of the dataset. If so then the end of file has been reached for usefull data
                                if (str == "")
                                {
                                    continue;
                                }

                                start = 0;
                                end   = str.IndexOf(",", start); // First "," = Block Height
                                _miner.BlockHeightList.Add(str.Substring(start, (end - start)));

                                start = end + 1;
                                end   = str.Length;
                                _miner.BlockHeaderList.Add(str.Substring(start, (end - start)));

                                // Increment line counter
                                j++;
                            }
                            sr_data.Close();
                        }
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show("Error: Could not read file from disk. Original error: " + ex.Message);
                        return;
                    }
                }
                else
                {
                    return;
                }
            }

            // Call prepare work method to initiate the first thread minining attempt
            if (PrepareWork())
            {
                // Set up stats/log timer based on user input
                LogTimer.Interval = _logger.LogInterval * 1000; // Convert to seconds
                LogTimer.Enabled  = true;
                LogTimer.Start();
            }
            else
            {
                UserControlDataState(true);
            }
        }
예제 #3
0
 private void Clear_Output_Click(object sender, EventArgs e)
 {
     OutputTxtBox.Clear();
     DebugTxtBox.Clear();
 }
예제 #4
0
        private void bgWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
        {
            // Once we arrive here we are either finished our thread or it was cancelled or there was an error.
            stopWatch.Stop();

            // Some clean-up of buffers that was used from the last batch.
            _worker.DiposeMemObjects();
            GC.Collect();

            if (e.Error != null)
            {
                OutputTxtBox.AppendText(DateTime.Now.ToString() + ": " + e.Error.Message + "\n");
                OutputTxtBox.AppendText("\n");
                UserControlDataState(true);
                _miner.ContinueMining = false;
                // Stop stats/log timer based on user input
                LogTimer.Stop();
                LogTimer.Enabled = false;

                return;
            }
            else if (e.Cancelled)
            {
                OutputTxtBox.AppendText(DateTime.Now.ToString() + ": " + "** Cancelled **" + "\n");
                OutputTxtBox.AppendText("\n");
                UserControlDataState(true);
                _miner.ContinueMining = false;
                // Stop stats/log timer based on user input
                LogTimer.Stop();
                LogTimer.Enabled = false;

                return;
            }
            else
            {
                String ResultMessage = "";

                //Update some stats
                _stats.ThreadTime          = ((Double)stopWatch.ElapsedMilliseconds / 1000.0);
                _stats.Sessiontime        += _stats.ThreadTime;
                _stats.TimeSinceLastShare += _stats.ThreadTime;
                _stats.NoncesProcessed     = (Int64)e.Result;
                _stats.UpdateHashRateThread();
                _stats.UpdateBatchTime((Int64)ThreadBatchNumBox.Value);
                _stats.NoncesProcessed = 0;

                _stats.TotalBlocks++;

                // Only keep one event in the output windows as it can get huge if you log eveything!
                OutputTxtBox.Clear();

                // Did we find a Nonce? or did we run out of nonces to try?
                if (_worker.CompletedWorkFlag == _worker.NONCE_FOUND)
                {
                    // Check work to see if it meets difficulty 1
                    if (_worker.VerifyWork(_worker.NonceToCheck))
                    {
                        // [DEBUG] Output to debug screen
                        _logger.UpdateLogger(_worker.BlockHeader, _worker.ValidNonce, _worker.MidState);
                        DebugTxtBox.AppendText(_logger.CreateOutputString().ToUpper() + "," + Utils.u8Array_To_HexString(_worker.FinalHash).ToUpper() + "," + "TRUE" + "\n");

                        // Update some stats
                        _stats.DiffOneBlocks++;
                        _stats.LastShareDiff = Utils.GetDiffculty(_worker.FinalHash);
                        _stats.TotalDiff    += _stats.LastShareDiff;
                        _stats.UpdateMaxDiffculty();
                        _stats.UpdateSessionHashRate();
                        _stats.UpdateSessionAvgHashRate();
                        _stats.TimeSinceLastShare = 0;

                        // Check to see if it meets target
                        if (_worker.CompareTarget())
                        {
                            // If this is a internal test then don't actually send a share!
                            if ((_miner.MiningProtocolType != Miner.PROTCOL_TEST) && (_miner.MiningProtocolType != Miner.PROTCOL_FROM_FILE))
                            {
                                // Send share and check it was successfull
                                if (_miner.SendShare(Utils.HexString_To_u8Array(_worker.ValidBlockHeader)))
                                {
                                    _stats.AcceptedBlocks++;
                                    ResultMessage = "Share Found >= Target and was ACCEPTED!";
                                }
                                else
                                {
                                    _stats.RejectedBlocks++;
                                    ResultMessage = "Share Found >= Target and was REJECTED!";
                                }
                            }
                            else
                            {
                                _stats.AcceptedBlocks++;
                                ResultMessage = "Share Found >= Target and was ACCEPTED!";
                            }
                        }
                        else
                        {
                            ResultMessage = "Share Found >= Diff 1 (but not above Target)";
                        }
                    }
                    else
                    {
                        ResultMessage = "Share Found but failed verification";
                        _stats.FailedHWBlocks++;
                    }


                    OutputTxtBox.AppendText("**  " + DateTime.Now.ToString() + " **\n");

                    if (isAnalyzeData == true)
                    {
                        OutputTxtBox.AppendText("!! Analysis block !! \n");
                    }
                    else
                    {
                        OutputTxtBox.AppendText("!! Mining block !! \n");
                    }

                    OutputTxtBox.AppendText(ResultMessage + "\n");
                    OutputTxtBox.AppendText("Message: " + _worker.BlockHeader.ToUpper() + "\n");
                    OutputTxtBox.AppendText("Valid Nonce Value: " + _worker.ValidNonce.ToString("X") + "\n");
                    OutputTxtBox.AppendText("Hash Result: " + Utils.u8Array_To_HexString(_worker.FinalHash).ToUpper() + "\n");
                    OutputTxtBox.AppendText("Target:      " + _worker.Target.ToUpper() + "\n");
                    OutputTxtBox.AppendText("Share Diffculty: " + _stats.LastShareDiff.ToString());
                    OutputTxtBox.AppendText("\n");
                }
                else if (_worker.CompletedWorkFlag == _worker.MAXNONCE_REACHED)
                {
                    OutputTxtBox.AppendText("**  " + DateTime.Now.ToString() + " **\n");
                    OutputTxtBox.AppendText("!! Mining block !! \n");
                    OutputTxtBox.AppendText("!! No Nonce Found. Reached Maximum Nonce Attempts \n");
                    OutputTxtBox.AppendText("\n");

                    // [DEBUG] Output to debug screen
                    _logger.UpdateLogger(_worker.BlockHeader, 0, _worker.MidState);
                    DebugTxtBox.AppendText(_logger.CreateOutputString().ToUpper() + "," + "--" + "," + "FALSE" + "\n");
                }
                else if (_worker.CompletedWorkFlag == _worker.NONCE_NOTFOUND)
                {
                    OutputTxtBox.AppendText("**  " + DateTime.Now.ToString() + " **\n");
                    OutputTxtBox.AppendText("!! Analysis block !! \n");
                    OutputTxtBox.AppendText("!! No >= 1 Diff Shares Found \n");
                    OutputTxtBox.AppendText("\n");

                    // [DEBUG] Output to debug screen
                    _logger.UpdateLogger(_worker.BlockHeader, _worker.NonceToCheck, _worker.MidState);
                    DebugTxtBox.AppendText(_logger.CreateOutputString().ToUpper() + "," + Utils.u8Array_To_HexString(_worker.GetHash(_worker.NonceToCheck)).ToUpper() + "," + "FALSE" + "\n");
                }
                else
                {
                    OutputTxtBox.AppendText(DateTime.Now.ToString() + ": " + "** Unknown Error?!?! **" + "\n");
                    OutputTxtBox.AppendText("\n");
                    UserControlDataState(true);
                    // Stop stats/log timer based on user input
                    LogTimer.Stop();
                    LogTimer.Enabled = false;

                    return;
                }

                // Call prepare work method with repeat mining thread attempt. If failed attempt end mining.
                if (!PrepareWork())
                {
                    _miner.ContinueMining = false;

                    // Stop stats/log timer based on user input
                    LogTimer.Stop();
                    LogTimer.Enabled = false;
                    UserControlDataState(true);
                }
            }
        }