Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Always trace invalid block even if succeeds on trace #8131

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 27 additions & 5 deletions src/Nethermind/Nethermind.Blockchain/LogTraceDumper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;

using Nethermind.Core;
using Nethermind.Core.Crypto;
Expand Down Expand Up @@ -47,10 +48,31 @@ public static void LogDiagnosticRlp(

public static void LogDiagnosticTrace(
IBlockTracer blockTracer,
Hash256 blockHash,
object blocksOrHash,
ILogger logger)
{
string fileName = string.Empty;
string condition;
string blockHash;
if (blocksOrHash is Hash256 failedBlockHash)
{
condition = "invalid";
blockHash = failedBlockHash.ToString();
}
else
{
List<Block> blocks = blocksOrHash as List<Block>;
condition = "valid on rerun";

if (blocks.Count == 1)
{
blockHash = blocks[0].Hash.ToString();
}
else
{
blockHash = string.Join("|", blocks.Select(b => b.Hash.ToString()));
}
}
Comment on lines +55 to +75
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe put that in separate method


try
{
Expand All @@ -61,7 +83,7 @@ public static void LogDiagnosticTrace(
IReadOnlyList<TxReceipt> receipts = receiptsTracer.TxReceipts;
EthereumJsonSerializer.SerializeToStream(diagnosticFile, receipts, true);
if (logger.IsInfo)
logger.Info($"Created a Receipts trace of invalid block {blockHash} in file {diagnosticFile.Name}");
logger.Info($"Created a Receipts trace of {condition} block {blockHash} in file {diagnosticFile.Name}");
}

if (blockTracer is GethLikeBlockMemoryTracer gethTracer)
Expand All @@ -71,7 +93,7 @@ public static void LogDiagnosticTrace(
IReadOnlyCollection<GethLikeTxTrace> trace = gethTracer.BuildResult();
EthereumJsonSerializer.SerializeToStream(diagnosticFile, trace, true);
if (logger.IsInfo)
logger.Info($"Created a Geth-style trace of invalid block {blockHash} in file {diagnosticFile.Name}");
logger.Info($"Created a Geth-style trace of {condition} block {blockHash} in file {diagnosticFile.Name}");
}

if (blockTracer is ParityLikeBlockTracer parityTracer)
Expand All @@ -81,13 +103,13 @@ public static void LogDiagnosticTrace(
IReadOnlyCollection<ParityLikeTxTrace> trace = parityTracer.BuildResult();
EthereumJsonSerializer.SerializeToStream(diagnosticFile, trace, true);
if (logger.IsInfo)
logger.Info($"Created a Parity-style trace of invalid block {blockHash} in file {diagnosticFile.Name}");
logger.Info($"Created a Parity-style trace of {condition} block {blockHash} in file {diagnosticFile.Name}");
}
}
catch (IOException e)
{
if (logger.IsError)
logger.Error($"Cannot save trace of block {blockHash} in file {fileName}", e);
logger.Error($"Cannot save trace of {condition} block {blockHash} in file {fileName}", e);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -432,15 +432,11 @@ private void TraceFailingBranch(in ProcessingBranch processingBranch, Processing
processingBranch.BlocksToProcess,
options,
blockTracer);
BlockTraceDumper.LogDiagnosticTrace(blockTracer, processingBranch.BlocksToProcess, _logger);
}
catch (InvalidBlockException ex)
{
BlockTraceDumper.LogDiagnosticTrace(blockTracer, ex.InvalidBlock.Hash!, _logger);
Metrics.BadBlocks++;
if (ex.InvalidBlock.IsByNethermindNode())
{
Metrics.BadBlocksByNethermindNodes++;
}
}
catch (Exception ex)
{
Expand Down Expand Up @@ -484,6 +480,11 @@ void DeleteInvalidBlocks(in ProcessingBranch processingBranch, Hash256 invalidBl
Block? invalidBlock = processingBranch.BlocksToProcess.FirstOrDefault(b => b.Hash == invalidBlockHash);
if (invalidBlock is not null)
{
Metrics.BadBlocks++;
if (ex.InvalidBlock.IsByNethermindNode())
{
Metrics.BadBlocksByNethermindNodes++;
}
InvalidBlock?.Invoke(this, new IBlockchainProcessor.InvalidBlockEventArgs { InvalidBlock = invalidBlock, });

BlockTraceDumper.LogDiagnosticRlp(invalidBlock, _logger,
Expand Down
Loading