diff --git a/src/Nethermind/Nethermind.Consensus/Processing/BlockchainProcessor.cs b/src/Nethermind/Nethermind.Consensus/Processing/BlockchainProcessor.cs index 6598b9798a8..38eb14b3671 100644 --- a/src/Nethermind/Nethermind.Consensus/Processing/BlockchainProcessor.cs +++ b/src/Nethermind/Nethermind.Consensus/Processing/BlockchainProcessor.cs @@ -397,6 +397,7 @@ private void FireProcessingQueueEmpty() _stopwatch.Restart(); Block[]? processedBlocks = ProcessBranch(processingBranch, options, tracer, out error); + _stopwatch.Stop(); if (processedBlocks is null) { return null; @@ -414,6 +415,16 @@ private void FireProcessingQueueEmpty() if (_logger.IsDebug) _logger.Debug($"Skipped processing of {suggestedBlock.ToString(Block.Format.FullHashAndNumber)}, last processed is null: {true}, processedBlocks.Length: {processedBlocks.Length}"); } + bool readonlyChain = options.ContainsFlag(ProcessingOptions.ReadOnlyChain); + if (!readonlyChain) + { + long blockProcessingTimeInMicrosecs = _stopwatch.ElapsedMicroseconds(); + Metrics.LastBlockProcessingTimeInMs = blockProcessingTimeInMicrosecs / 1000; + Metrics.RecoveryQueueSize = _recoveryQueue.Count; + Metrics.ProcessingQueueSize = _blockQueue.Count; + _stats.UpdateStats(lastProcessed, blockProcessingTimeInMicrosecs); + } + bool updateHead = !options.ContainsFlag(ProcessingOptions.DoNotUpdateHead); if (updateHead) { @@ -421,26 +432,15 @@ private void FireProcessingQueueEmpty() _blockTree.UpdateMainChain(processingBranch.Blocks, true); } - bool readonlyChain = options.ContainsFlag(ProcessingOptions.ReadOnlyChain); - long blockProcessingTimeInMs = _stopwatch.ElapsedMilliseconds; - if (!readonlyChain) - { - Metrics.LastBlockProcessingTimeInMs = blockProcessingTimeInMs; - } - if ((options & ProcessingOptions.MarkAsProcessed) == ProcessingOptions.MarkAsProcessed) { if (_logger.IsTrace) _logger.Trace($"Marked blocks as processed {lastProcessed}, blocks count: {processedBlocks.Length}"); _blockTree.MarkChainAsProcessed(processingBranch.Blocks); - - Metrics.LastBlockProcessingTimeInMs = blockProcessingTimeInMs; } if (!readonlyChain) { - Metrics.RecoveryQueueSize = _recoveryQueue.Count; - Metrics.ProcessingQueueSize = _blockQueue.Count; - _stats.UpdateStats(lastProcessed, _blockTree, _stopwatch.ElapsedMicroseconds()); + Metrics.BestKnownBlockNumber = _blockTree.BestKnownNumber; } return lastProcessed; diff --git a/src/Nethermind/Nethermind.Consensus/Processing/ProcessingStats.cs b/src/Nethermind/Nethermind.Consensus/Processing/ProcessingStats.cs index 48845fb904d..b49407e54e7 100644 --- a/src/Nethermind/Nethermind.Consensus/Processing/ProcessingStats.cs +++ b/src/Nethermind/Nethermind.Consensus/Processing/ProcessingStats.cs @@ -57,7 +57,7 @@ public ProcessingStats(ILogger logger) #endif } - public void UpdateStats(Block? block, IBlockTree blockTreeCtx, long blockProcessingTimeInMicros) + public void UpdateStats(Block? block, long blockProcessingTimeInMicros) { if (block is null) { @@ -82,7 +82,6 @@ public void UpdateStats(Block? block, IBlockTree blockTreeCtx, long blockProcess Metrics.GasLimit = block.GasLimit; Metrics.BlockchainHeight = block.Header.Number; - Metrics.BestKnownBlockNumber = blockTreeCtx.BestKnownNumber; _blockProcessingMicroseconds = _processingStopwatch.ElapsedMicroseconds(); _runningMicroseconds = _runStopwatch.ElapsedMicroseconds();