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

eth/tracers: add multiplexing tracer #26086

Merged
merged 3 commits into from
Nov 8, 2022
Merged

Conversation

s1na
Copy link
Contributor

@s1na s1na commented Nov 1, 2022

Sometimes users might need the result of multiple tracers for a given tx. This PR introduces the muxTracer which allows you to do this. It takes in a list of tracers and their configs and returns each one's corresponding result with one run through the tx:

> debug.traceTransaction('0xf8fd7bea3dc42ee81922584884d3f741e8e475ecccb75b0e4f2dad042061c723', { tracer: 'muxTracer', tracerConfig: { prestateTracer: { diffMode: true}, callTracer: null }})
{
  callTracer: {
    from: "0x2806a6d83218acc8b223063bd058957d38966a09",
    gas: "0x0",
    gasUsed: "0x5208",
    input: "0x",
    to: "0x2806a6d83218acc8b223063bd058957d38966a09",
    type: "CALL",
    value: "0x1"
  },
  prestateTracer: {
    post: {
      0x2806a6d83218acc8b223063bd058957d38966a09: {
        balance: "0xffffffffffffffffffffffffffffffffffffffffffffffffffffef49bca6f9f7",
        nonce: 1
      }
    },
    pre: {
      0x2806a6d83218acc8b223063bd058957d38966a09: {
        balance: "0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff7"
      }
    }
  }
}

There's a trick that allows you to use the same tracer with different configs by using a nested muxTracer (e.g. to get both prestate and statediff):

> debug.traceTransaction('0xf8fd7bea3dc42ee81922584884d3f741e8e475ecccb75b0e4f2dad042061c723', { tracer: 'muxTracer', tracerConfig: { prestateTracer: { diffMode: true}, muxTracer: { prestateTracer: null } }})
{
  muxTracer: {
    prestateTracer: {
      0x2806a6d83218acc8b223063bd058957d38966a09: {
        balance: "0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff7"
      }
    }
  },
  prestateTracer: {
    post: {
      0x2806a6d83218acc8b223063bd058957d38966a09: {
        balance: "0xffffffffffffffffffffffffffffffffffffffffffffffffffffef49bca6f9f7",
        nonce: 1
      }
    },
    pre: {
      0x2806a6d83218acc8b223063bd058957d38966a09: {
        balance: "0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff7"
      }
    }
  }
}

It's possible to directly add support for this to the API, e.g. debug.traceTransaction('<txhash>', { tracerList: {...} }) but I feel like being able to add this feature without having to modify the API is a big plus.

Unrelated commit in the PR: I also moved EVM cancellation to be the API's responsibility instead of the tracer. I feel like it's more fitting.

@rjl493456442
Copy link
Member

Good idea!

Copy link
Contributor

@holiman holiman left a comment

Choose a reason for hiding this comment

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

This is a nice idea. I'm curious to see if it is "only" a nice idea, or if it actually is meaningful too, in the sense that people will use it.

Up until now, I've been kind of starting to see a tendency to make tracers more complex, adding tracer-specific configurations (e.g. the call-tracer taking a config whether log log LOGs etc). This PR might make it a bit more "the Unix way", so the tracers are an assortment of small simple tools, and the ability to mux makes it possible to avoid complex tracers with everything and the kitchen-sink.

@holiman holiman added this to the 1.11.0 milestone Nov 8, 2022
@holiman holiman merged commit 53b624b into ethereum:master Nov 8, 2022
shekhirin pushed a commit to shekhirin/go-ethereum that referenced this pull request Jun 6, 2023
* eth/tracers: add native multiplexing tracer

* minor improv callTracer

* mv evm cancellation to api
maoueh pushed a commit to streamingfast/go-ethereum that referenced this pull request Jul 21, 2023
* eth/tracers: add native multiplexing tracer

* minor improv callTracer

* mv evm cancellation to api
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