diff --git a/src/Nethermind/Nethermind.Consensus/Processing/ProcessingStats.cs b/src/Nethermind/Nethermind.Consensus/Processing/ProcessingStats.cs index 3dbba850b58..980a4197764 100644 --- a/src/Nethermind/Nethermind.Consensus/Processing/ProcessingStats.cs +++ b/src/Nethermind/Nethermind.Consensus/Processing/ProcessingStats.cs @@ -105,6 +105,19 @@ public void UpdateStats(Block? block, Hash256 branchRoot, long blockProcessingTi private void GenerateReport() => ThreadPool.UnsafeQueueUserWorkItem(this, preferLocal: false); void IThreadPoolWorkItem.Execute() + { + try + { + Execute(); + } + catch (Exception ex) + { + // Don't allow exception to escape to ThreadPool + if (_logger.IsError) _logger.Error("Error when generating processing statistics", ex); + } + } + + void Execute() { const long weiToEth = 1_000_000_000_000_000_000; const string resetColor = "\u001b[37m"; @@ -125,7 +138,7 @@ void IThreadPoolWorkItem.Execute() Address beneficiary = block.Header.GasBeneficiary ?? Address.Zero; Transaction lastTx = txs.Length > 0 ? txs[^1] : null; bool isMev = false; - if (lastTx is not null && (lastTx.SenderAddress == beneficiary || _alternateMevPayees.Contains(lastTx.SenderAddress))) + if (lastTx?.To is not null && (lastTx.SenderAddress == beneficiary || _alternateMevPayees.Contains(lastTx.SenderAddress))) { // Mev reward with in last tx beneficiary = lastTx.To; @@ -134,9 +147,18 @@ void IThreadPoolWorkItem.Execute() if (_lastBranchRoot is null || !_stateReader.HasStateForRoot(_lastBranchRoot) || block.StateRoot is null || !_stateReader.HasStateForRoot(block.StateRoot)) return; - UInt256 beforeBalance = _stateReader.GetBalance(_lastBranchRoot, beneficiary); - UInt256 afterBalance = _stateReader.GetBalance(block.StateRoot, beneficiary); - UInt256 rewards = beforeBalance < afterBalance ? afterBalance - beforeBalance : default; + + UInt256 rewards = default; + try + { + UInt256 beforeBalance = _stateReader.GetBalance(_lastBranchRoot, beneficiary); + UInt256 afterBalance = _stateReader.GetBalance(block.StateRoot, beneficiary); + rewards = beforeBalance < afterBalance ? afterBalance - beforeBalance : default; + } + catch (Exception ex) + { + if (_logger.IsError) _logger.Error("Error when calculating block rewards", ex); + } long currentSelfDestructs = Evm.Metrics.SelfDestructs;