コード例 #1
0
        /// <summary>
        /// Create a new instance of this class.
        /// </summary>
        public PlotReaderManager()
        {
            // Create our shabel for local hashing when determining the scoop number for each block
            _shabel = new Shabal256();

            // Now create and hook up to these events
            Logger.Info("Initialising plot readers");
            if (Configuration.PlotDirectories != null && Configuration.PlotDirectories.Length > 0)
            {
                _plotReaders = new PlotReader[Configuration.PlotDirectories.Length];
                decimal utilisedStorage = 0;
                Parallel.For(0, Configuration.PlotDirectories.Length, (int i) =>
                {
                    _plotReaders[i] = new PlotReader(Configuration.PlotDirectories[i]);
                    _plotReaders[i].ScoopsDiscovered += PlotReaderOnScoopsDiscovered;
                    _plotReaders[i].UpdateUtilisedStorage();
                    utilisedStorage += _plotReaders[i].UtilisedStorage;
                });
                UtilisedStorage = utilisedStorage;
                UtilisedStorageUpdated?.Invoke(this, new UtilisedStorageEventHandler(UtilisedStorage));
            }
            Logger.Debug("Finished initialising plot readers");

            // Start the progress monitor
            _isAlive = true;
            _progressMonitoringThread = new Thread(ProgressMonitoringThread)
            {
                IsBackground = true, Name = "Plot Reader Progress Monitor"
            };
            _progressMonitoringThread.Start();
        }
コード例 #2
0
        /// <summary>
        /// The main entry point for the threads that individually check for deadlines.
        /// </summary>
        private void ThreadEntry()
        {
            Shabal256 shabal = new Shabal256();

            byte[] hashBuffer = new byte[32 + Plot.SCOOP_SIZE];
            ulong  lastBlockHeightPrevGenCopied = 0;

            while (_isAlive)
            {
                // Get a few items from the queue to process
                Scoop[] scoops;
                lock (_scoopQueueLocker)
                {
                    scoops = new Scoop[_scoopQueue.Count > 100 ? 100 : _scoopQueue.Count];
                    if (scoops.Length > 0)
                    {
                        for (int i = 0; i < scoops.Length; i++)
                        {
                            scoops[i] = _scoopQueue[_scoopQueue.Count - i - 1];
                        }
                        _scoopQueue.RemoveRange(_scoopQueue.Count - scoops.Length, scoops.Length);
                    }
                }

                // If we didn't get an item or if for some reason the mining info has been wiped wait and try again
                if (scoops == null || scoops.Length < 1)
                {
                    Thread.Sleep(200);
                    continue;
                }

                foreach (Scoop scoop in scoops)
                {
                    // Breakout if we're no longer running
                    MiningInfo miningInfo = _miningInfo;
                    if (!_isAlive || miningInfo == null)
                    {
                        break;
                    }

                    // Ensure we're on right block
                    if (scoop.BlockHeight != miningInfo.BlockHeight)
                    {
                        continue;
                    }

                    // Calculate the deadline for this scoop
                    if (lastBlockHeightPrevGenCopied != miningInfo.BlockHeight)
                    {
                        Array.Copy(_miningInfo.PreviousGenerationSignatureBytes, hashBuffer, 32);
                        lastBlockHeightPrevGenCopied = miningInfo.BlockHeight;
                    }
                    Array.Copy(scoop.Data, 0, hashBuffer, 32, Plot.SCOOP_SIZE);
                    byte[] target       = shabal.ComputeBytes(hashBuffer).GetBytes();
                    ulong  targetResult = BitConverter.ToUInt64(target, 0);

                    // And with our target compute a deadline
                    ulong deadline = targetResult / miningInfo.BaseTarget;
                    if (deadline < miningInfo.Deadline)
                    {
                        DeadlineFound?.Invoke(this, new DeadlineFoundEventArgs(deadline, scoop, miningInfo));
                    }
                }
            }
        }