private static async Task ReplotFileAsync(DriveInfo diskToPlot, string plotFile, EventAggregator bus, CancellationToken stopPlottingToken) { var numberOfNonces = long.Parse(plotFile.Split('_')[PlotFileNameNumberOfNoncesIndex]); var startingNonce = long.Parse(plotFile.Split('_')[PlotFileNameStartingNonceIndex]); var memoryGb = Math.Max(Process.GetProcesses().Max(process => process.PeakWorkingSet64) / 1024 / 1024 / 1024, 1); var expectedFreeDiskSpace = diskToPlot.AvailableFreeSpace - (numberOfNonces * NonceSize - new FileInfo(plotFile).Length); // delete file if it will causes us to go under the minimum free disk space if (expectedFreeDiskSpace <= GetMinFreeDiskSpace(diskToPlot)) { File.Delete(plotFile); } else { var inProgressPlotFile = Path.Combine(GetIncompletePlotsDirectory(diskToPlot), Path.GetFileName(plotFile)); var completedPlotFile = Path.Combine(GetPlotDirectory(diskToPlot), Path.GetFileName(plotFile)); // move file to plot cache directory File.Move(plotFile, inProgressPlotFile); // plot await BurstCoinMiner.QueuePlotAsync( diskToPlot, ShareCashAccountNumber, numberOfNonces, startingNonce, GetIncompletePlotsDirectory(diskToPlot), GetNumberOfThreadsPerPlot(), memoryGb, GetPlotCancellationToken(diskToPlot, bus, stopPlottingToken)); // move plotted file to plot directory try { File.Move(inProgressPlotFile, completedPlotFile); } catch (Exception e) { throw; } // notify of plot completion bus.Publish(new CompletedPlotFileNotification(diskToPlot)); } }
private static async Task PlotFilesOfSizeAsync(DriveInfo diskToPlot, long plotFileSize, EventAggregator bus, CancellationToken stopPlottingToken) { var expectedFreeDiskSpace = diskToPlot.AvailableFreeSpace - plotFileSize; // plot until we exceed the minimum disk space limit while (!stopPlottingToken.IsCancellationRequested && expectedFreeDiskSpace > GetMinFreeDiskSpace(diskToPlot)) { var nextStartingNonce = GetLastCompletedNonce(diskToPlot) + 1 ?? GetRandomStartingNonce(); var memoryGb = Math.Max(Process.GetProcesses().Max(process => process.PeakWorkingSet64) / 1024 / 1024 / 1024, 1); var numberOfNonces = plotFileSize / NonceSize; var plotFileName = $"{ShareCashAccountNumber}_{nextStartingNonce}_{numberOfNonces}"; await BurstCoinMiner.QueuePlotAsync( diskToPlot, ShareCashAccountNumber, numberOfNonces, nextStartingNonce, GetIncompletePlotsDirectory(diskToPlot), GetNumberOfThreadsPerPlot(), memoryGb, GetPlotCancellationToken(diskToPlot, bus, stopPlottingToken)); // move plotted file to plot directory try { File.Move(Path.Combine(GetIncompletePlotsDirectory(diskToPlot), plotFileName), Path.Combine(GetPlotDirectory(diskToPlot), plotFileName)); } catch (Exception e) { throw; } // notify of plot completion bus.Publish(new CompletedPlotFileNotification(diskToPlot)); expectedFreeDiskSpace = diskToPlot.AvailableFreeSpace - plotFileSize; } }