public void StartTest() { PowInformation.Height = 1; PowInformation.TargetPowValue = DifficultyUtility.GetTargetPowValue(1000); PowInformation.BlockHeaderTemplate = JsonConvert.SerializeObject(LastBlock, Formatting.None); NewJob?.Invoke(this, PowInformation); BlockRenewTask = Task.Run(async() => { var powInformation = PowInformation; while (true) { if (FoundBlocks.Count != 0) { if (DateTimeOffset.Now > FoundBlocks[FoundBlocks.Count - 1].DateTime.AddMinutes(1 + RenewIndex)) { RenewIndex++; powInformation.TargetPowValue = FoundBlocks.Count - 1 - RenewIndex < 0 ? DifficultyUtility.GetTargetPowValue(1000) : FoundBlocks.Select(a => a.TargetPowValue).OrderBy(a => a).SkipWhile(a => a <= powInformation.TargetPowValue).FirstOrDefault(); NewJob?.Invoke(this, powInformation); } } await Task.Delay(1).ConfigureAwait(false); } }); }
public TuckfirtlePowBenchmarkTest() { LastBlock = new TuckfirtlePowBenchmarkTestBlock { Version = 1, Height = 0, DateTime = DateTimeOffset.Now, Nonce = 0, TargetPowValue = DifficultyUtility.GetTargetPowValue(1000) }; }
private void ExecuteTestMode() { var consoleLogger = ConsoleLogger; var config = Config; var threadCount = config.Threads.Length; var benchmarkTest = new TuckfirtlePowBenchmarkTest(); var miners = new TuckfirtlePowMiner[threadCount]; consoleLogger.LogMessage("use benchmark"); benchmarkTest.NewJob += (test, information) => { consoleLogger.LogMessage(new ConsoleMessageBuilder() .Write("new job ", ConsoleColor.Magenta) .WriteLine($"diff {DifficultyUtility.GetDifficulty(information.TargetPowValue)} algo {nameof(TuckfirtlePow)} height {information.Height}", false) .Build()); }; benchmarkTest.ShareResult += (test, accepted, reason) => { if (accepted) { consoleLogger.LogMessage(new ConsoleMessageBuilder() .Write("accecpted ", ConsoleColor.Green) .WriteLine($"({test.TotalAcceptedShare}/{test.TotalRejectedShare})", false) .Build()); } else { consoleLogger.LogMessage(new ConsoleMessageBuilder() .Write("rejected ", ConsoleColor.Red) .Write($"({test.TotalAcceptedShare}/{test.TotalRejectedShare}) ", false) .WriteLine(reason, false) .Build()); } }; benchmarkTest.StartTest(); for (var i = 0; i < threadCount; i++) { miners[i] = new TuckfirtlePowMiner(new TuckfirtlePowMinerInformation { ThreadAffinity = config.Threads[i].AffinityToCpu < 0 ? 0 : 1 << config.Threads[i].AffinityToCpu, StartingNonce = ulong.MaxValue / (ulong)threadCount * (ulong)i }, benchmarkTest.PowInformation, benchmarkTest.SubmitTestResult); miners[i].StartMining(); } }