Exemplo n.º 1
0
 private void FireProcessingQueueEmpty()
 {
     if (((IBlockProcessingQueue)this).IsEmpty)
     {
         ProcessingQueueEmpty?.Invoke(this, EventArgs.Empty);
     }
 }
Exemplo n.º 2
0
        private void RunProcessingLoop()
        {
            _stats.Start();
            if (_logger.IsDebug)
            {
                _logger.Debug($"Starting block processor - {_blockQueue.Count} blocks waiting in the queue.");
            }

            if (_blockQueue.Count == 0)
            {
                ProcessingQueueEmpty?.Invoke(this, EventArgs.Empty);
            }

            foreach (BlockRef blockRef in _blockQueue.GetConsumingEnumerable(_loopCancellationSource.Token))
            {
                if (blockRef.IsInDb || blockRef.Block == null)
                {
                    throw new InvalidOperationException("Processing loop expects only resolved blocks");
                }

                Block block = blockRef.Block;

                if (_logger.IsTrace)
                {
                    _logger.Trace($"Processing block {block.ToString(Block.Format.Short)}).");
                }

                IBlockTracer tracer = NullBlockTracer.Instance;
                if ((blockRef.ProcessingOptions & ProcessingOptions.StoreTraces) != 0)
                {
                    tracer = new ParityLikeBlockTracer(ParityTraceTypes.Trace | ParityTraceTypes.StateDiff);
                }

                Block processedBlock = Process(block, blockRef.ProcessingOptions, tracer);
                if (processedBlock == null)
                {
                    if (_logger.IsTrace)
                    {
                        _logger.Trace($"Failed / skipped processing {block.ToString(Block.Format.Full)}");
                    }
                }
                else
                {
                    if (_logger.IsTrace)
                    {
                        _logger.Trace($"Processed block {block.ToString(Block.Format.Full)}");
                    }
                    _stats.UpdateStats(block, _recoveryQueue.Count, _blockQueue.Count);
                }

                if (_logger.IsTrace)
                {
                    _logger.Trace($"Now {_blockQueue.Count} blocks waiting in the queue.");
                }
                if (_blockQueue.Count == 0)
                {
                    ProcessingQueueEmpty?.Invoke(this, EventArgs.Empty);
                }
            }

            if (_logger.IsTrace)
            {
                _logger.Trace($"Returns from processing loop");
            }
        }
        private void RunProcessingLoop()
        {
            _stats.Start();
            if (_logger.IsDebug)
            {
                _logger.Debug($"Starting block processor - {_blockQueue.Count} blocks waiting in the queue.");
            }

            if (IsEmpty)
            {
                ProcessingQueueEmpty?.Invoke(this, EventArgs.Empty);
            }

            foreach (BlockRef blockRef in _blockQueue.GetConsumingEnumerable(_loopCancellationSource.Token))
            {
                if (blockRef.IsInDb || blockRef.Block == null)
                {
                    throw new InvalidOperationException("Processing loop expects only resolved blocks");
                }

                Block block = blockRef.Block;

                if (_logger.IsTrace)
                {
                    _logger.Trace($"Processing block {block.ToString(Block.Format.Short)}).");
                }

                IBlockTracer tracer = GetDefaultTracer();
                try
                {
                    Block processedBlock = Process(block, blockRef.ProcessingOptions, tracer);
                    if (processedBlock == null)
                    {
                        if (_logger.IsTrace)
                        {
                            _logger.Trace($"Failed / skipped processing {block.ToString(Block.Format.Full)}");
                        }
                    }
                    else
                    {
                        if (_logger.IsTrace)
                        {
                            _logger.Trace($"Processed block {block.ToString(Block.Format.Full)}");
                        }
                        _stats.UpdateStats(block, _recoveryQueue.Count, _blockQueue.Count);
                    }

                    if (_logger.IsTrace)
                    {
                        _logger.Trace($"Now {_blockQueue.Count} blocks waiting in the queue.");
                    }
                    if (IsEmpty)
                    {
                        ProcessingQueueEmpty?.Invoke(this, EventArgs.Empty);
                    }
                }
                finally
                {
                    LogDiagnosticTrace(tracer);
                }
            }

            if (_logger.IsInfo)
            {
                _logger.Info("Block processor queue stopped.");
            }
        }