Skip to content

Commit 612b4a4

Browse files
manav2401claude
andauthored
feat(evmonly): add debug_trace* RPC methods to EVM-only RPC (#4597)
This PR adds the following methods to EVM-only (Autobahn) RPC. - `debug_traceTransaction` - `debug_traceCall` - `debug_traceBlockByNumber` / `debug_traceBlockByHash` How it works - debugAPI hands requests to go-ethereum's tracers.API through traceBackend, our implementation of tracers.Backend. Request and response shapes and the native tracers therefore match go-ethereum and v2. - The state before a transaction comes from Executor.ReplayState. It re-applies the block's earlier transactions with executeTx, the same function block execution uses. - The app exposes this as EvmStateAt, EvmStateBeforeTx and EvmBlockContext on proxy.EVMApplication. FinalizeBlock and tracing build the block context through one shared helper, blockContext. - debug_traceCall runs against the state after the named block. latest means the latest committed block. Only go-ethereum's native tracers run. JavaScript tracers are refused, including inside muxTracer. State and block overrides are refused for now, will be addressed via a separate PR. New [giga.rpc] keys, with v2's defaults: - `max_concurrent_trace_calls` (10) - `trace_timeout` (30s) - `max_trace_struct_log_bytes` (32 MiB) There is no consensus or state impact. The only executor changes are exporting EVMBlockContext and adding SetTxContext/GetLogs to nativeStateDB; only the tracer calls those two. Past transactions and blocks can only be traced on a full node, because validators keep no state history. The oldest retained block can't be traced because its parent has been pruned. Block traces skip transactions the block rejected. As a result, flatCallTracer's transactionPosition counts only executed transactions and can differ from the receipt's index. This is listed as a known issue in the README and will be revisited with the block-filtering work. Checklist - [x] RPC tests: refusals (unknown hash, JavaScript tracers, muxTracer nesting, overrides, concurrency limit, timeout, struct-log cap) and edge cases (rejected transactions skipped, block 1, txIndex on an empty block, latest for calls, blocks not yet indexed) - [x] Fixture test: every transaction, block and recorded call of the synthetic-basic parity fixture, traced with every native tracer and the struct logger, compared against recorded output - [x] Executor and app tests: replay matches the committed state; unheld heights, block 0 and validator history are refused - [x] EVMProxy / EVMEnvironment pass-through tests; config keys and defaults - [x] Autobahn integration test: the deploy and its block traced on the RPC node, a call traced on every node, a validator refusing a past transaction - [x] go test -race on the affected packages; golangci-lint and fmt --diff clean --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
1 parent e138b61 commit 612b4a4

29 files changed

Lines changed: 8522 additions & 40 deletions

‎giga/config/config.go‎

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,13 @@ type RPCConfig struct {
9999
BatchResponseMaxSize int `mapstructure:"batch_response_max_size"`
100100
// MaxWSConnections caps simultaneously open WebSocket connections.
101101
MaxWSConnections int `mapstructure:"max_ws_connections"`
102+
// MaxConcurrentTraceCalls caps debug_trace* calls running at once; a call past it is refused.
103+
MaxConcurrentTraceCalls int `mapstructure:"max_concurrent_trace_calls"`
104+
// TraceTimeout bounds how long one debug_trace* call may run.
105+
TraceTimeout time.Duration `mapstructure:"trace_timeout"`
106+
// MaxTraceStructLogBytes caps the default struct logger's output, in bytes, for each traced
107+
// transaction.
108+
MaxTraceStructLogBytes int `mapstructure:"max_trace_struct_log_bytes"`
102109
}
103110

104111
// StateSyncConfig is the [giga.state_sync] sub-table: whether this node uses giga state sync.
@@ -130,6 +137,9 @@ var DefaultConfig = Config{
130137
BatchRequestLimit: 100,
131138
BatchResponseMaxSize: 25 * 1000 * 1000,
132139
MaxWSConnections: 2000,
140+
MaxConcurrentTraceCalls: 10,
141+
TraceTimeout: 30 * time.Second,
142+
MaxTraceStructLogBytes: 32 * 1024 * 1024,
133143
},
134144
StateSync: StateSyncConfig{
135145
Enabled: false,
@@ -176,6 +186,9 @@ const (
176186
FlagRPCBatchRequestLimit = "giga.rpc.batch_request_limit"
177187
FlagRPCBatchResponseMaxSize = "giga.rpc.batch_response_max_size"
178188
FlagRPCMaxWSConnections = "giga.rpc.max_ws_connections"
189+
FlagRPCMaxConcurrentTraceCalls = "giga.rpc.max_concurrent_trace_calls"
190+
FlagRPCTraceTimeout = "giga.rpc.trace_timeout"
191+
FlagRPCMaxTraceStructLogBytes = "giga.rpc.max_trace_struct_log_bytes"
179192
FlagStateSyncEnabled = "giga.state_sync.enabled"
180193
)
181194

@@ -298,6 +311,21 @@ func ReadConfig(opts AppOptions) (Config, error) {
298311
return cfg, fmt.Errorf("%s: %w", FlagRPCMaxWSConnections, err)
299312
}
300313
}
314+
if v := opts.Get(FlagRPCMaxConcurrentTraceCalls); v != nil {
315+
if cfg.RPC.MaxConcurrentTraceCalls, err = cast.ToIntE(v); err != nil {
316+
return cfg, fmt.Errorf("%s: %w", FlagRPCMaxConcurrentTraceCalls, err)
317+
}
318+
}
319+
if v := opts.Get(FlagRPCTraceTimeout); v != nil {
320+
if cfg.RPC.TraceTimeout, err = cast.ToDurationE(v); err != nil {
321+
return cfg, fmt.Errorf("%s: %w", FlagRPCTraceTimeout, err)
322+
}
323+
}
324+
if v := opts.Get(FlagRPCMaxTraceStructLogBytes); v != nil {
325+
if cfg.RPC.MaxTraceStructLogBytes, err = cast.ToIntE(v); err != nil {
326+
return cfg, fmt.Errorf("%s: %w", FlagRPCMaxTraceStructLogBytes, err)
327+
}
328+
}
301329
if v := opts.Get(FlagStateSyncEnabled); v != nil {
302330
if cfg.StateSync.Enabled, err = cast.ToBoolE(v); err != nil {
303331
return cfg, fmt.Errorf("%s: %w", FlagStateSyncEnabled, err)
@@ -376,6 +404,15 @@ func (c Config) Validate() error {
376404
if c.RPC.MaxWSConnections < 0 {
377405
return fmt.Errorf("%s: must be >= 0, got %d", FlagRPCMaxWSConnections, c.RPC.MaxWSConnections)
378406
}
407+
if c.RPC.MaxConcurrentTraceCalls < 0 {
408+
return fmt.Errorf("%s: must be >= 0, got %d", FlagRPCMaxConcurrentTraceCalls, c.RPC.MaxConcurrentTraceCalls)
409+
}
410+
if c.RPC.TraceTimeout < 0 {
411+
return fmt.Errorf("%s: must be >= 0, got %s", FlagRPCTraceTimeout, c.RPC.TraceTimeout)
412+
}
413+
if c.RPC.MaxTraceStructLogBytes < 0 {
414+
return fmt.Errorf("%s: must be >= 0, got %d", FlagRPCMaxTraceStructLogBytes, c.RPC.MaxTraceStructLogBytes)
415+
}
379416
return nil
380417
}
381418

@@ -474,6 +511,16 @@ batch_response_max_size = {{ .Giga.RPC.BatchResponseMaxSize }}
474511
# max_ws_connections caps simultaneously open WebSocket connections.
475512
max_ws_connections = {{ .Giga.RPC.MaxWSConnections }}
476513
514+
# max_concurrent_trace_calls caps debug_trace* calls running at once; a call past it is refused.
515+
max_concurrent_trace_calls = {{ .Giga.RPC.MaxConcurrentTraceCalls }}
516+
517+
# trace_timeout bounds how long one debug_trace* call may run.
518+
trace_timeout = "{{ .Giga.RPC.TraceTimeout }}"
519+
520+
# max_trace_struct_log_bytes caps the default struct logger's output, in bytes, for each traced
521+
# transaction.
522+
max_trace_struct_log_bytes = {{ .Giga.RPC.MaxTraceStructLogBytes }}
523+
477524
[giga.state_sync]
478525
# enabled allows the state-sync-snapshot create and restore commands on this node, and the
479526
# seed of a restored home on start.

‎giga/config/config_test.go‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@ func TestRPCDefaultsMatchTheV2EVMRPC(t *testing.T) {
5050
require.Equal(t, v2.BatchRequestLimit, r.BatchRequestLimit)
5151
require.Equal(t, v2.BatchResponseMaxSize, r.BatchResponseMaxSize)
5252
require.Equal(t, v2.MaxOpenConnections, r.MaxWSConnections)
53+
require.Equal(t, v2.MaxConcurrentTraceCalls, uint64(r.MaxConcurrentTraceCalls))
54+
require.Equal(t, v2.TraceTimeout, r.TraceTimeout)
55+
require.Equal(t, v2.MaxTraceStructLogBytes, uint64(r.MaxTraceStructLogBytes))
5356
require.Equal(t, uint64(100), r.MaxSubscriptionsPerConnection)
5457
}
5558

@@ -91,6 +94,9 @@ func TestReadConfigReadsEveryKey(t *testing.T) {
9194
"giga.rpc.batch_request_limit": "10",
9295
"giga.rpc.batch_response_max_size": "1000",
9396
"giga.rpc.max_ws_connections": "7",
97+
"giga.rpc.max_concurrent_trace_calls": "3",
98+
"giga.rpc.trace_timeout": "4s",
99+
"giga.rpc.max_trace_struct_log_bytes": "512",
94100
"giga.state_sync.enabled": "true",
95101
})
96102
require.NoError(t, err)
@@ -122,6 +128,9 @@ func TestReadConfigReadsEveryKey(t *testing.T) {
122128
BatchRequestLimit: 10,
123129
BatchResponseMaxSize: 1000,
124130
MaxWSConnections: 7,
131+
MaxConcurrentTraceCalls: 3,
132+
TraceTimeout: 4 * time.Second,
133+
MaxTraceStructLogBytes: 512,
125134
},
126135
StateSync: gigaconfig.StateSyncConfig{
127136
Enabled: true,
@@ -156,6 +165,12 @@ func TestReadConfigRejectsUnusableValues(t *testing.T) {
156165
"negative batch limit": {"giga.rpc.batch_request_limit": "-1"},
157166
"negative batch response size": {"giga.rpc.batch_response_max_size": "-1"},
158167
"negative ws connections": {"giga.rpc.max_ws_connections": "-1"},
168+
"negative trace calls": {"giga.rpc.max_concurrent_trace_calls": "-1"},
169+
"negative trace timeout": {"giga.rpc.trace_timeout": "-1s"},
170+
"negative struct log bytes": {"giga.rpc.max_trace_struct_log_bytes": "-1"},
171+
"non-numeric trace calls": {"giga.rpc.max_concurrent_trace_calls": "many"},
172+
"non-duration trace timeout": {"giga.rpc.trace_timeout": "later"},
173+
"non-numeric struct log bytes": {"giga.rpc.max_trace_struct_log_bytes": "big"},
159174
"non-numeric request bytes": {"giga.rpc.max_concurrent_request_bytes": "lots"},
160175
"non-duration admission timeout": {"giga.rpc.ws_admission_timeout": "soon"},
161176
"non-numeric batch limit": {"giga.rpc.batch_request_limit": "many"},

‎giga/evmonly/call.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ func (e *Executor) Call(ctx context.Context, blockCtx BlockContext, msg *core.Me
4040
defer e.releaseStateDB(stateDB)
4141

4242
// NoBaseFee matches go-ethereum's eth_call: zero fee fields skip the fee-cap check.
43-
evm := vm.NewEVM(buildBlockContext(blockCtx), stateDB, chainConfig, vm.Config{NoBaseFee: true}, e.customContracts)
43+
evm := vm.NewEVM(EVMBlockContext(blockCtx), stateDB, chainConfig, vm.Config{NoBaseFee: true}, e.customContracts)
4444
stateDB.SetEVM(evm)
4545
evm.SetTxContext(core.NewEVMTxContext(msg))
4646

‎giga/evmonly/custom_precompile_execution_test.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ func TestRegisteredCustomPrecompileReportsGas(t *testing.T) {
123123
var remaining uint64
124124
contract := registeredCustomPrecompile{address: registeredPrecompileAddress, contract: gasRecorder{&remaining}}
125125
stateDB := newNativeStateDB(NewMemoryState())
126-
evm := vm.NewEVM(buildBlockContext(blockContext(big.NewInt(testChainID))), stateDB, params.AllDevChainProtocolChanges, vm.Config{}, nil)
126+
evm := vm.NewEVM(EVMBlockContext(blockContext(big.NewInt(testChainID))), stateDB, params.AllDevChainProtocolChanges, vm.Config{}, nil)
127127
stateDB.SetEVM(evm)
128128
type change struct{ from, to uint64 }
129129
var changes []change

‎giga/evmonly/executor.go‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@ func (e *Executor) executeBlockSequential(ctx context.Context, req PreparedBlock
300300

301301
stateDB := e.acquireStateDB(source)
302302
defer e.releaseStateDB(stateDB)
303-
blockCtx := buildBlockContext(req.Context)
303+
blockCtx := EVMBlockContext(req.Context)
304304
evm := vm.NewEVM(blockCtx, stateDB, chainConfig, vm.Config{}, e.customContracts)
305305
stateDB.SetEVM(evm)
306306

@@ -500,7 +500,9 @@ func transactionToPreparedMessage(p PreparedTx, baseFee *big.Int) *core.Message
500500
return msg
501501
}
502502

503-
func buildBlockContext(ctx BlockContext) vm.BlockContext {
503+
// EVMBlockContext returns the go-ethereum block context the executor runs a block with context ctx
504+
// at. BLOCKHASH answers only for the parent block.
505+
func EVMBlockContext(ctx BlockContext) vm.BlockContext {
504506
prevRandao := ctx.PrevRandao
505507
baseFee := cloneOptionalBig(ctx.BaseFee)
506508
blobBaseFee := cloneOptionalBig(ctx.BlobBaseFee)

‎giga/evmonly/executor_parity_test.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -916,7 +916,7 @@ func executeGethReferenceBlock(t *testing.T, initial *MemoryState, cfg Config, c
916916
return nil, err
917917
}
918918
stateDB := newGethStateFromMemory(t, initial)
919-
evm := vm.NewEVM(buildBlockContext(ctx), stateDB, chainConfig, vm.Config{}, nil)
919+
evm := vm.NewEVM(EVMBlockContext(ctx), stateDB, chainConfig, vm.Config{}, nil)
920920
gasPool := new(core.GasPool).AddGas(ctx.GasLimit)
921921
baseFee := cloneOptionalBig(ctx.BaseFee)
922922
signer := ethtypes.MakeSigner(chainConfig, new(big.Int).SetUint64(ctx.Number), ctx.Time)

‎giga/evmonly/occ.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ func newOCCSpeculativeRunner(e *Executor, req PreparedBlock) occSpeculativeRunne
6363
executor: e,
6464
req: req,
6565
chainConfig: e.chainConfig(req.Context),
66-
blockCtx: buildBlockContext(req.Context),
66+
blockCtx: EVMBlockContext(req.Context),
6767
baseFee: cloneOptionalBig(req.Context.BaseFee),
6868
blockGasLimit: req.Context.GasLimit,
6969
}

0 commit comments

Comments
 (0)