Skip to content

Commit

Permalink
Don't fail when stats can't retrieve beneficiary (#7839)
Browse files Browse the repository at this point in the history
Co-authored-by: Lukasz Rozmej <lukasz.rozmej@gmail.com>
  • Loading branch information
2 people authored and kamilchodola committed Nov 29, 2024
1 parent 232f177 commit 949617c
Showing 1 changed file with 26 additions and 4 deletions.
30 changes: 26 additions & 4 deletions src/Nethermind/Nethermind.Consensus/Processing/ProcessingStats.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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;
Expand All @@ -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;

Expand Down

0 comments on commit 949617c

Please sign in to comment.