public Task <Block> SealBlock(Block block, CancellationToken cancellationToken) { if (_poSSwitcher.IsPostMerge(block.Header)) { return(Task.FromResult(block)); } return(_preMergeSealValidator.SealBlock(block, cancellationToken)); }
private void OnBlockProcessorQueueEmpty(object sender, EventArgs e) { CancellationToken token; lock (_syncToken) { _cancellationTokenSource = new CancellationTokenSource(); token = _cancellationTokenSource.Token; } if (!_sealEngine.CanSeal) { return; } Block block = PrepareBlock(); if (block == null) { if (_logger.IsError) { _logger.Error("Failed to prepare block for mining."); } return; } Block processedBlock = _processor.Process(block, ProcessingOptions.NoValidation | ProcessingOptions.ReadOnlyChain | ProcessingOptions.WithRollback, NullBlockTracer.Instance); _sealEngine.SealBlock(processedBlock, token).ContinueWith(t => { if (t.IsCompletedSuccessfully) { _blockTree.SuggestBlock(t.Result); } else if (t.IsFaulted) { _logger.Error("Mining failer", t.Exception); } else if (t.IsCanceled) { if (_logger.IsDebug) { _logger.Debug($"Mining block {processedBlock.ToString(Block.Format.HashAndNumber)} cancelled"); } } }, token); }