Trace
The tracers a Debug.trace* call can run, as data: the options that select each one, the
schema of what it returns, and the shape of a traced block.
import { Effect } from "effect";import { Debug } from "@ethect/core/rpc";import type { Hash } from "@ethect/core";
const busiest = (hash: Hash.Hash) => Debug.traceTransaction(hash, { tracer: "4byteTracer" }).pipe( // counts: Trace.FourByte Effect.map((counts) => Object.entries(counts).sort(([, a], [, b]) => b - a)[0]), // ["0x00000000-28", 1] );The page that explains the tracers and how the options select one is
Tracers. This module is what the Debug.trace* methods are built
from.
Schemas
Section titled “Schemas”| Schema | Type | Describes | Used by |
|---|---|---|---|
Trace.fourByteSchema |
Trace.FourByte |
the result of the 4byteTracer: a count per selector |
a Debug.trace* call with tracer: "4byteTracer" |
Trace.blockSchema(result) |
an array of entries | what tracing a block returns, for a tracer whose result has the schema result |
the methods that trace a block |
Trace.tracers |
a tuple of Trace.Tracer |
every tracer the library defines, in the order a call is matched against them | the five Debug.trace* methods |
Trace.Tracer is an interface, not a schema: the description of one tracer.
FourByte
Section titled “FourByte”Trace.FourByte is Record<string, number>: how many calls each function selector got.
| Part | Type | Notes |
|---|---|---|
| key | string |
the selector, a dash, then the size in bytes of the calldata after it: "0x00000000-28" |
| value | number |
how many calls had that selector and that size |
blockSchema
Section titled “blockSchema”Trace.blockSchema(result) builds the schema of a traced block from the schema of one trace: an
array with one entry per transaction.
| Entry | Type | When |
|---|---|---|
{ txHash, result } |
txHash is a Hash, result is the value the given schema decodes |
the transaction was traced |
{ txHash, error } |
txHash is a Hash, error is a string |
the node could not trace it |
Use it to give a type to a tracer of your own when it runs on a block.
import { Schema } from "effect";import { BlockId, Method, Trace } from "@ethect/core/rpc";
// a JavaScript tracer that collects the name of every opcode executedconst tracer = [ "{ ops: [],", "step(log) { this.ops.push(log.op.toString()) },", "fault() {},", "result() { return this.ops } }",].join(" ");
// per transaction: { txHash, result: ReadonlyArray<string> } or { txHash, error }const opcodesOfBlock = Method.make<[block: unknown, options: unknown]>()( "debug_traceBlockByNumber", [BlockId.numberOrTagSchema, Schema.Struct({ tracer: Schema.Literal(tracer) })], Trace.blockSchema(Schema.Array(Schema.String)),);
const latest = opcodesOfBlock("latest", { tracer });See Custom methods.
Tracer
Section titled “Tracer”Trace.Tracer describes one tracer with three schemas.
| Field | Type | Holds |
|---|---|---|
options |
a record of field schemas | the fields of the options that select and configure the tracer |
execution |
a schema | what the tracer returns for one execution |
block |
a schema | what it returns for a block: Trace.blockSchema of the one above |
tracers
Section titled “tracers”Trace.tracers is the list of every tracer, in the order a call is matched against them.
| Position | Tracer | execution decodes to |
|---|---|---|
0 |
the struct logger: options without a tracer key |
StructLog.Trace |
1 |
callTracer |
CallFrame.CallFrame |
2 |
prestateTracer in diff mode |
Prestate.Diff |
3 |
prestateTracer |
Prestate.Prestate |
4 |
4byteTracer |
Trace.FourByte |
5 |
noopTracer |
an empty object |
6 |
any other tracer string |
unknown |
import { Debug, Trace } from "@ethect/core/rpc";
Trace.tracers.length; // 7Trace.tracers[1].execution; // the schema of a CallFrameDebug.traceTransaction.variants.length; // 7: one definition per tracerBehavior
Section titled “Behavior”- The order is the matching order. A call goes to the first tracer whose options accept the
ones given. Diff mode is before plain
prestateTracerbecause its config is the one that has to ask for it, and the custom tracer is last because it accepts any name. - Every tracer takes
timeoutandreexec. The two fields are part of theoptionsof each entry. - The struct logger refuses a
tracerkey. Its options declaretraceras a field that can hold no value, so options that name a tracer never match it. - The list is fixed. Adding a tracer of your own is done with a
custom method, as above, not by changing
Trace.tracers.