Skip to content

Conversation

@AnkushinDaniil
Copy link
Contributor

Changes

  • Centralize _gasCostAlreadySetForCurrentOp guard in GethLikeTxTracer base class
  • Make ReportOperationRemainingGas sealed, add protected virtual OnOperationRemainingGas callback
  • Update GethLikeTxTracer<TEntry>, GethLikeJavaScriptTxTracer, and NativeCallTracer to use OnOperationRemainingGas
  • Add RegisterExternalTracer method to GethLikeNativeTracerFactory for plugin tracer registration

Types of changes

What types of changes does your code introduce?

  • Bugfix (a non-breaking change that fixes an issue)
  • New feature (a non-breaking change that adds functionality)
  • Breaking change (a change that causes existing functionality not to work as expected)
  • Optimization
  • Refactoring
  • Documentation update
  • Build-related changes
  • Other: Description

Testing

Requires testing

  • Yes
  • No

If yes, did you write tests?

  • Yes
  • No

Documentation

Requires documentation update

  • Yes
  • No

Requires explanation in Release Notes

  • Yes
  • No

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR refactors the tracing infrastructure to centralize the gas cost guard mechanism in the GethLikeTxTracer base class, eliminating code duplication and improving maintainability. The refactoring introduces a template method pattern where ReportOperationRemainingGas is sealed and derived classes override OnOperationRemainingGas instead.

Key changes:

  • Moved _gasCostAlreadySetForCurrentOp guard from derived classes to the base GethLikeTxTracer class
  • Introduced sealed ReportOperationRemainingGas with protected virtual OnOperationRemainingGas callback pattern
  • Added RegisterExternalTracer method to support plugin-based tracer registration

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated no comments.

Show a summary per file
File Description
Nethermind.Evm.Test/Tracing/GethLikeTxTracerTests.cs New test file validating gas cost guard behavior with multiple calls per operation
Nethermind.Evm.Test/Tracing/GethLikeNativeTracerFactoryTests.cs Added tests for external tracer registration including idempotency and overwrite protection
Nethermind.Blockchain/Tracing/GethStyle/GethLikeTxTracer.cs Centralized gas guard in base class with sealed ReportOperationRemainingGas and virtual OnOperationRemainingGas callback
Nethermind.Blockchain/Tracing/GethStyle/Custom/Native/GethLikeNativeTracerFactory.cs Added RegisterExternalTracer method using TryAdd for thread-safe registration
Nethermind.Blockchain/Tracing/GethStyle/Custom/Native/FourByte/Native4ByteTracer.cs Added base call to StartOperation to support centralized guard reset
Nethermind.Blockchain/Tracing/GethStyle/Custom/Native/Call/NativeCallTracer.cs Updated to override OnOperationRemainingGas instead of ReportOperationRemainingGas
Nethermind.Blockchain/Tracing/GethStyle/Custom/JavaScript/GethLikeJavaScriptTxTracer.cs Updated to override OnOperationRemainingGas and added base call to StartOperation

This is an excellent refactoring that follows best practices for code reuse and the template method pattern. The changes are well-tested, maintain backward compatibility, and improve code maintainability. I found no issues with the implementation.

@flcl42
Copy link
Contributor

flcl42 commented Jan 6, 2026

In what case is this path triggered? Can we avoid it at all?

 if (_gasCostAlreadySetForCurrentOp)
     return;

Comment on lines +39 to +42
public static void RegisterExternalTracer(string tracerName, GethLikeNativeTracerFactoryDelegate tracerDelegate)
{
_tracers.TryAdd(tracerName, tracerDelegate);
}
Copy link
Member

Choose a reason for hiding this comment

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

Either should be Add and it throws, or at least return if it fails

Suggested change
public static void RegisterExternalTracer(string tracerName, GethLikeNativeTracerFactoryDelegate tracerDelegate)
{
_tracers.TryAdd(tracerName, tracerDelegate);
}
public static bool RegisterExternalTracer(string tracerName, GethLikeNativeTracerFactoryDelegate tracerDelegate) =>
_tracers.TryAdd(tracerName, tracerDelegate);

@AnkushinDaniil AnkushinDaniil marked this pull request as draft January 8, 2026 08:33
@AnkushinDaniil
Copy link
Contributor Author

Replaced by #10228

@AnkushinDaniil AnkushinDaniil deleted the daniil/feature/tracer-template-method-guard branch January 14, 2026 12:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants