From 7b161e63da72054be98668c7be9d66e0cab05f24 Mon Sep 17 00:00:00 2001 From: Lukasz Rozmej Date: Tue, 7 May 2024 20:58:32 +0200 Subject: [PATCH] Fix too eager dispose in js block tracing (#6987) --- .../Nethermind.Consensus/Tracing/GethStyleTracer.cs | 9 ++++++--- .../Custom/JavaScript/GethLikeBlockJavaScriptTracer.cs | 7 +++---- .../Custom/JavaScript/GethLikeJavaScriptTxTracer.cs | 2 +- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/src/Nethermind/Nethermind.Consensus/Tracing/GethStyleTracer.cs b/src/Nethermind/Nethermind.Consensus/Tracing/GethStyleTracer.cs index 84898e0e2ca..1e89583e906 100644 --- a/src/Nethermind/Nethermind.Consensus/Tracing/GethStyleTracer.cs +++ b/src/Nethermind/Nethermind.Consensus/Tracing/GethStyleTracer.cs @@ -126,9 +126,10 @@ public GethLikeTxTrace Trace(Hash256 blockHash, int txIndex, GethTraceOptions op _processor.Process(block, ProcessingOptions.Trace, blockTracer.WithCancellation(cancellationToken)); return blockTracer.BuildResult().SingleOrDefault(); } - finally + catch { blockTracer.TryDispose(); + throw; } } @@ -177,9 +178,10 @@ public IEnumerable TraceBlockToFile(Hash256 blockHash, GethTraceOptions _processor.Process(block, ProcessingOptions.Trace, tracer.WithCancellation(cancellationToken)); return tracer.BuildResult().SingleOrDefault(); } - finally + catch { tracer.TryDispose(); + throw; } } @@ -212,9 +214,10 @@ private IReadOnlyCollection TraceBlock(Block? block, GethTraceO _processor.Process(block, ProcessingOptions.Trace, tracer.WithCancellation(cancellationToken)); return tracer.BuildResult(); } - finally + catch { tracer.TryDispose(); + throw; } } diff --git a/src/Nethermind/Nethermind.Evm/Tracing/GethStyle/Custom/JavaScript/GethLikeBlockJavaScriptTracer.cs b/src/Nethermind/Nethermind.Evm/Tracing/GethStyle/Custom/JavaScript/GethLikeBlockJavaScriptTracer.cs index 4f7fe879610..3c8d9f6e5f9 100644 --- a/src/Nethermind/Nethermind.Evm/Tracing/GethStyle/Custom/JavaScript/GethLikeBlockJavaScriptTracer.cs +++ b/src/Nethermind/Nethermind.Evm/Tracing/GethStyle/Custom/JavaScript/GethLikeBlockJavaScriptTracer.cs @@ -20,7 +20,7 @@ public class GethLikeBlockJavaScriptTracer : BlockTracerBase? _engines; + private List? _engines; private UInt256 _baseFee; public GethLikeBlockJavaScriptTracer(IWorldState worldState, IReleaseSpec spec, GethTraceOptions options) : base(options.TxHash) @@ -33,7 +33,7 @@ public GethLikeBlockJavaScriptTracer(IWorldState worldState, IReleaseSpec spec, public override void StartNewBlockTrace(Block block) { - _engines = new ArrayPoolList(block.Transactions.Length + 1); + _engines = new List(block.Transactions.Length + 1); _ctx.block = block.Number; _ctx.BlockHash = block.Hash; _baseFee = block.BaseFeePerGas; @@ -75,11 +75,10 @@ public override void EndBlockTrace() protected override GethLikeTxTrace OnEnd(GethLikeJavaScriptTxTracer txTracer) => txTracer.BuildResult(); public void Dispose() { - ArrayPoolList? list = Interlocked.Exchange(ref _engines, null); + List? list = Interlocked.Exchange(ref _engines, null); if (list is not null) { list.ForEach(e => e.Dispose()); - list.Dispose(); } } } diff --git a/src/Nethermind/Nethermind.Evm/Tracing/GethStyle/Custom/JavaScript/GethLikeJavaScriptTxTracer.cs b/src/Nethermind/Nethermind.Evm/Tracing/GethStyle/Custom/JavaScript/GethLikeJavaScriptTxTracer.cs index f9a1b022ed8..dde143ac7e3 100644 --- a/src/Nethermind/Nethermind.Evm/Tracing/GethStyle/Custom/JavaScript/GethLikeJavaScriptTxTracer.cs +++ b/src/Nethermind/Nethermind.Evm/Tracing/GethStyle/Custom/JavaScript/GethLikeJavaScriptTxTracer.cs @@ -59,7 +59,7 @@ public GethLikeJavaScriptTxTracer( public override GethLikeTxTrace BuildResult() { GethLikeTxTrace result = base.BuildResult(); - result.CustomTracerResult = new GethLikeCustomTrace() { Value = _tracer.result(_ctx, _db) }; + result.CustomTracerResult = new GethLikeCustomTrace { Value = _tracer.result(_ctx, _db) }; _resultConstructed = true; return result; }