From c6342dbeba76c2e2a4e67d5e4631dc894bf3d5f7 Mon Sep 17 00:00:00 2001 From: Ben Adams Date: Tue, 7 May 2024 09:20:34 +0100 Subject: [PATCH 1/3] Don't use tracing for non-traced rpc calls --- .../Nethermind.Evm/Tracing/CancellationTxTracer.cs | 2 ++ src/Nethermind/Nethermind.Evm/Tracing/ITxTracer.cs | 1 + .../Nethermind.Evm/Tracing/TracerExtensions.cs | 8 ++++---- src/Nethermind/Nethermind.Evm/VirtualMachine.cs | 9 +++++++++ 4 files changed, 16 insertions(+), 4 deletions(-) diff --git a/src/Nethermind/Nethermind.Evm/Tracing/CancellationTxTracer.cs b/src/Nethermind/Nethermind.Evm/Tracing/CancellationTxTracer.cs index 6cd4af28425..7ab97bb54c8 100644 --- a/src/Nethermind/Nethermind.Evm/Tracing/CancellationTxTracer.cs +++ b/src/Nethermind/Nethermind.Evm/Tracing/CancellationTxTracer.cs @@ -37,6 +37,8 @@ public CancellationTxTracer(ITxTracer innerTracer, CancellationToken token = def _token = token; } + public bool IsCancelled => _token.IsCancellationRequested; + public bool IsTracingReceipt { get => _isTracingReceipt || _innerTracer.IsTracingReceipt; diff --git a/src/Nethermind/Nethermind.Evm/Tracing/ITxTracer.cs b/src/Nethermind/Nethermind.Evm/Tracing/ITxTracer.cs index 5f1b2646abb..6a8f0b2d6f6 100644 --- a/src/Nethermind/Nethermind.Evm/Tracing/ITxTracer.cs +++ b/src/Nethermind/Nethermind.Evm/Tracing/ITxTracer.cs @@ -12,6 +12,7 @@ namespace Nethermind.Evm.Tracing; public interface ITxTracer : IWorldStateTracer, IDisposable { + bool IsCancelled => false; /// /// Defines whether MarkAsSuccess or MarkAsFailed will be called /// diff --git a/src/Nethermind/Nethermind.Evm/Tracing/TracerExtensions.cs b/src/Nethermind/Nethermind.Evm/Tracing/TracerExtensions.cs index 0463b5d4f52..752f482e6ea 100644 --- a/src/Nethermind/Nethermind.Evm/Tracing/TracerExtensions.cs +++ b/src/Nethermind/Nethermind.Evm/Tracing/TracerExtensions.cs @@ -13,10 +13,10 @@ public static CancellationTxTracer WithCancellation(this ITxTracer txTracer, Can ? new(txTracer, cancellationToken) : new(txTracer, cancellationToken) { - IsTracingActions = true, - IsTracingOpLevelStorage = true, - IsTracingInstructions = true, // a little bit costly but almost all are simple calls - IsTracingRefunds = true + IsTracingActions = txTracer.IsTracingActions, + IsTracingOpLevelStorage = txTracer.IsTracingOpLevelStorage, + IsTracingInstructions = txTracer.IsTracingInstructions, // a little bit costly but almost all are simple calls + IsTracingRefunds = txTracer.IsTracingRefunds }; } diff --git a/src/Nethermind/Nethermind.Evm/VirtualMachine.cs b/src/Nethermind/Nethermind.Evm/VirtualMachine.cs index ad870107b8f..8efcc55c99f 100644 --- a/src/Nethermind/Nethermind.Evm/VirtualMachine.cs +++ b/src/Nethermind/Nethermind.Evm/VirtualMachine.cs @@ -818,6 +818,11 @@ private CallResult ExecuteCode(gasAvailable, exceptionType); + + [DoesNotReturn] + static void ThrowOperationCanceledException() => + throw new OperationCanceledException("Cancellation Requested"); } [SkipLocalsInit] From 8330d460d28c40d08404053eb8c6f2e57e097ef9 Mon Sep 17 00:00:00 2001 From: Ben Adams Date: Tue, 7 May 2024 09:26:27 +0100 Subject: [PATCH 2/3] Simpler --- .../Nethermind.Evm/Tracing/TracerExtensions.cs | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/src/Nethermind/Nethermind.Evm/Tracing/TracerExtensions.cs b/src/Nethermind/Nethermind.Evm/Tracing/TracerExtensions.cs index 752f482e6ea..50bddec114c 100644 --- a/src/Nethermind/Nethermind.Evm/Tracing/TracerExtensions.cs +++ b/src/Nethermind/Nethermind.Evm/Tracing/TracerExtensions.cs @@ -7,17 +7,9 @@ namespace Nethermind.Evm.Tracing; public static class TracerExtensions { - public static CancellationTxTracer WithCancellation(this ITxTracer txTracer, CancellationToken cancellationToken, bool setDefaultCancellations = true) + public static CancellationTxTracer WithCancellation(this ITxTracer txTracer, CancellationToken cancellationToken) { - return !setDefaultCancellations - ? new(txTracer, cancellationToken) - : new(txTracer, cancellationToken) - { - IsTracingActions = txTracer.IsTracingActions, - IsTracingOpLevelStorage = txTracer.IsTracingOpLevelStorage, - IsTracingInstructions = txTracer.IsTracingInstructions, // a little bit costly but almost all are simple calls - IsTracingRefunds = txTracer.IsTracingRefunds - }; + return new(txTracer, cancellationToken); } public static CancellationBlockTracer WithCancellation(this IBlockTracer blockTracer, CancellationToken cancellationToken) => From 6a8e07bfb6d96f611a4296b94e35fe2b0a852fd3 Mon Sep 17 00:00:00 2001 From: Ben Adams Date: Tue, 7 May 2024 09:45:59 +0100 Subject: [PATCH 3/3] Avoid interface call if cannot be cancelled --- src/Nethermind/Nethermind.Evm/Tracing/CancellationTxTracer.cs | 1 + src/Nethermind/Nethermind.Evm/Tracing/ITxTracer.cs | 1 + src/Nethermind/Nethermind.Evm/VirtualMachine.cs | 3 ++- 3 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/Nethermind/Nethermind.Evm/Tracing/CancellationTxTracer.cs b/src/Nethermind/Nethermind.Evm/Tracing/CancellationTxTracer.cs index 7ab97bb54c8..bc6badef0df 100644 --- a/src/Nethermind/Nethermind.Evm/Tracing/CancellationTxTracer.cs +++ b/src/Nethermind/Nethermind.Evm/Tracing/CancellationTxTracer.cs @@ -37,6 +37,7 @@ public CancellationTxTracer(ITxTracer innerTracer, CancellationToken token = def _token = token; } + public bool IsCancelable => true; public bool IsCancelled => _token.IsCancellationRequested; public bool IsTracingReceipt diff --git a/src/Nethermind/Nethermind.Evm/Tracing/ITxTracer.cs b/src/Nethermind/Nethermind.Evm/Tracing/ITxTracer.cs index 6a8f0b2d6f6..4552b43b2d1 100644 --- a/src/Nethermind/Nethermind.Evm/Tracing/ITxTracer.cs +++ b/src/Nethermind/Nethermind.Evm/Tracing/ITxTracer.cs @@ -12,6 +12,7 @@ namespace Nethermind.Evm.Tracing; public interface ITxTracer : IWorldStateTracer, IDisposable { + bool IsCancelable => false; bool IsCancelled => false; /// /// Defines whether MarkAsSuccess or MarkAsFailed will be called diff --git a/src/Nethermind/Nethermind.Evm/VirtualMachine.cs b/src/Nethermind/Nethermind.Evm/VirtualMachine.cs index 8efcc55c99f..ee5e1eef67e 100644 --- a/src/Nethermind/Nethermind.Evm/VirtualMachine.cs +++ b/src/Nethermind/Nethermind.Evm/VirtualMachine.cs @@ -810,6 +810,7 @@ private CallResult ExecuteCode