/// <summary> /// Create a new instance of this class. /// </summary> /// <param name="deadline"> /// The duration of the deadline. /// </param> /// <param name="scoop"> /// The scoop the dealdine came from. /// The</param> /// <param name="miningInfo"> /// The information about the network that this deadline was found matching. /// </param> public Deadline(TimeSpan deadline, Scoop scoop, MiningInfo miningInfo) { Status = DeadlineStatus.Found; DeadlineDuration = deadline; Scoop = scoop; MiningInfo = miningInfo; NextSubmissionDate = DateTime.UtcNow; }
/// <summary> /// Create a new instance of this class. /// </summary> /// <param name="deadline"> /// The deadline that has been found. /// </param> /// <param name="scoop"> /// The scoop that this deadline was generated from. /// </param> /// <param name="miningInfo"> /// The mining information that was used to generate this deadline. /// </param> public DeadlineFoundEventArgs(ulong deadline, Scoop scoop, MiningInfo miningInfo) { Scoop = scoop; MiningInfo = miningInfo; Deadline = deadline; }
/// <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)); } } } }