/// <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(); }
/// <summary> /// Starts reading plots for the specifed information and terminates and current plot mining. /// </summary> /// <param name="miningInfo"> /// The information to use to commence mining. /// </param> public void NotifyNewRound(MiningInfo miningInfo) { // Store this value _lastRoundStart = DateTime.UtcNow; _miningInfo = miningInfo; // First let's kill any existing plot reading foreach (PlotReader reader in _plotReaders) { reader.Terminate(); } // If no mining information stop now if (miningInfo == null) { return; } // Throw error if we have no readers if (_plotReaders == null) { Logger.Warn("Unable to process new block " + miningInfo.BlockHeight + ", no plot readers available"); return; } // Now we perform our basics to determine scoop number byte[] gensigHashable = new byte[40]; Array.Copy(miningInfo.PreviousGenerationSignatureBytes, gensigHashable, 32); Array.Copy(miningInfo.BlockHeightBytes, 0, gensigHashable, 32, 8); byte[] gensig = _shabel.ComputeBytes(gensigHashable).GetBytes(); uint scoop = (uint)((gensig[gensig.Length - 2] & 0x0F) << 8) | (gensig[gensig.Length - 1]); Logger.Debug("Calculated scoop for block as " + scoop); // Update our capacity values decimal utilisedStorage = 0; foreach (PlotReader reader in _plotReaders) { utilisedStorage += reader.UtilisedStorage; } if (UtilisedStorage != utilisedStorage) { UtilisedStorage = utilisedStorage; UtilisedStorageUpdated?.Invoke(this, new UtilisedStorageEventHandler(utilisedStorage)); } // With the config that we have we can now execute all of our readers foreach (PlotReader reader in _plotReaders) { reader.StartMining(miningInfo, scoop); } }