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

Refactor Blockchain Bridge Simulate to Support Multiple Generic Tracers #8148

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

Deeptanshu-sankhwar
Copy link

Overview

This refactor makes Simulate in the Blockchain Bridge generic, allowing it to support SimulateBlockTracer, GethLikeBlockMemoryTracer, and ParityLikeBlockTracer dynamically.

Key Changes

  • Generic Simulate Implementation

    • Introduced SimulateBlockResult<T> to support multiple tracers.
    • Converted Simulate to a generic function to improve flexibility.
  • Factory Method for Tracer Selection

    • Added a factory method to instantiate the appropriate tracer dynamically.
    • Removed hardcoded dependencies for cleaner, maintainable code.
  • Changes to Data Structures

    • Updated SimulatePayload and SimulateBlockResult to work generically.
    • Adjusted serialization to handle different tracer results seamlessly.

@Deeptanshu-sankhwar Deeptanshu-sankhwar changed the base branch from master to eth_simulate_v1 February 3, 2025 07:54
@Deeptanshu-sankhwar Deeptanshu-sankhwar requested review from rubo and a team as code owners February 3, 2025 07:54
@Deeptanshu-sankhwar Deeptanshu-sankhwar force-pushed the refactor/simulate-generic-tracers branch from 16a582f to 5f088c6 Compare February 3, 2025 08:18
@Deeptanshu-sankhwar Deeptanshu-sankhwar changed the base branch from eth_simulate_v1 to master February 3, 2025 08:34
@Deeptanshu-sankhwar Deeptanshu-sankhwar force-pushed the refactor/simulate-generic-tracers branch from 5f088c6 to 2b7ad66 Compare February 3, 2025 08:37
Deeptanshu Sankhwar added 4 commits February 3, 2025 01:40
…t for SimulateBlockTracer, GethLikeBlockMemoryTracer, and ParityLikeBlockTracer while ensuring flexibility in SimulateBlockResult<T> and updating test cases accordingly.
@Deeptanshu-sankhwar Deeptanshu-sankhwar force-pushed the refactor/simulate-generic-tracers branch from 2b7ad66 to bd3accd Compare February 3, 2025 08:41
Copy link
Member

@LukaszRozmej LukaszRozmej left a comment

Choose a reason for hiding this comment

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

Close but I think we need 2 generic parameters to make it smooth

Comment on lines +210 to +213
if (tracer is SimulateBlockTracer simulateTracer)
{
result.Items = simulateTracer.Results as IReadOnlyList<SimulateBlockResult<T>>;
}
Copy link
Member

Choose a reason for hiding this comment

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

Instead of this make generic constraint where T : ISimulateTracer and IBlockTracer<TTrace> interface should have Results of this type.

Comment on lines +214 to +218
else
{
throw new InvalidOperationException($"Tracer type {typeof(T).Name} does not support 'Results'");
}

Copy link
Member

Choose a reason for hiding this comment

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

You also don't need this then as the generic constraint would guard it

Comment on lines +171 to +176
public SimulateOutput<T> Simulate<T>(
BlockHeader header,
SimulatePayload<TransactionWithSourceDetails> payload,
CancellationToken cancellationToken,
ITracerFactory<T> tracerFactory)
where T : class
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
public SimulateOutput<T> Simulate<T>(
BlockHeader header,
SimulatePayload<TransactionWithSourceDetails> payload,
CancellationToken cancellationToken,
ITracerFactory<T> tracerFactory)
where T : class
public SimulateOutput<TTrace> Simulate<TTracer, TTrace>(
BlockHeader header,
SimulatePayload<TransactionWithSourceDetails> payload,
CancellationToken cancellationToken,
ITracerFactory<TTracer> tracerFactory)
where TTracer : IBlockTracer<TTrace>

@LukaszRozmej LukaszRozmej marked this pull request as draft February 3, 2025 14:51
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.

2 participants