Skip to content

Commit edeb6d9

Browse files
committed
handle err in tracing
1 parent c28fe4b commit edeb6d9

File tree

3 files changed

+14
-9
lines changed

3 files changed

+14
-9
lines changed

miner/worker.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -847,7 +847,7 @@ func (w *worker) makeCurrent(parent *types.Block, header *types.Header) error {
847847
// don't commit the state during tracing for circuit capacity checker, otherwise we cannot revert.
848848
// and even if we don't commit the state, the `refund` value will still be correct, as explained in `CommitTransaction`
849849
commitStateAfterApply := false
850-
traceEnv, err := tracing.CreateTraceEnv(w.chainConfig, w.chain, w.engine, w.eth.ChainDb(), state, w.chain.GetVMConfig().L1Client, parent,
850+
traceEnv, err := tracing.CreateTraceEnv(w.chainConfig, w.chain, w.engine, w.eth.ChainDb(), state, w.chain.GetVMConfig().L1Client, vm.CallerTypeWorker, parent,
851851
// new block with a placeholder tx, for traceEnv's ExecutionResults length & TxStorageTraces length
852852
types.NewBlockWithHeader(header).WithBody([]*types.Transaction{types.NewTx(&types.LegacyTx{})}, nil),
853853
commitStateAfterApply)

miner/worker_test.go

+5-3
Original file line numberDiff line numberDiff line change
@@ -1231,8 +1231,10 @@ func TestL1SloadFailedTxReexecuted(t *testing.T) {
12311231
chainConfig.DescartesBlock = big.NewInt(0)
12321232

12331233
w, b := newTestWorker(t, chainConfig, engine, db, 0)
1234-
// GetStoragesAt shouldn't fail 2 times on block tracing and should fail then on tx executing
1235-
w.chain.GetVMConfig().L1Client = &mockL1Client{failList: []bool{false, false, true, true, true}}
1234+
// GetStoragesAt should fail at tracing request 2 times (3 retries for each), commitTransaction will fail during tracing and will be retried in next work
1235+
// after that GetStoragesAt shouls pass tracing 2 times and then fail on execution tx (3 retries)
1236+
// after that tx will be retried again and executed without fails
1237+
w.chain.GetVMConfig().L1Client = &mockL1Client{failList: []bool{true, true, true, true, true, true, false, false, true, true, true}}
12361238
defer w.close()
12371239

12381240
// This test chain imports the mined blocks.
@@ -1271,7 +1273,7 @@ func TestL1SloadFailedTxReexecuted(t *testing.T) {
12711273
if _, err := chain.InsertChain([]*types.Block{block}); err != nil {
12721274
t.Fatalf("failed to insert new mined block %d: %v", block.NumberU64(), err)
12731275
}
1274-
case <-time.After(3 * time.Second): // Worker needs 1s to include new changes.
1276+
case <-time.After(5 * time.Second): // Worker needs 1s to include new changes.
12751277
t.Fatalf("timeout")
12761278
}
12771279
}

rollup/tracing/tracing.go

+8-5
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ func NewTracerWrapper() *TracerWrapper {
4747

4848
// CreateTraceEnvAndGetBlockTrace wraps the whole block tracing logic for a block
4949
func (tw *TracerWrapper) CreateTraceEnvAndGetBlockTrace(chainConfig *params.ChainConfig, chainContext core.ChainContext, engine consensus.Engine, chaindb ethdb.Database, statedb *state.StateDB, l1Client vm.L1Client, parent *types.Block, block *types.Block, commitAfterApply bool) (*types.BlockTrace, error) {
50-
traceEnv, err := CreateTraceEnv(chainConfig, chainContext, engine, chaindb, statedb, l1Client, parent, block, commitAfterApply)
50+
traceEnv, err := CreateTraceEnv(chainConfig, chainContext, engine, chaindb, statedb, l1Client, vm.CallerTypeNonWorker, parent, block, commitAfterApply)
5151
if err != nil {
5252
return nil, err
5353
}
@@ -60,6 +60,7 @@ type TraceEnv struct {
6060
commitAfterApply bool
6161
chainConfig *params.ChainConfig
6262
l1Client vm.L1Client
63+
callerType vm.CallerType
6364

6465
coinbase common.Address
6566

@@ -99,13 +100,14 @@ type txTraceTask struct {
99100
index int
100101
}
101102

102-
func CreateTraceEnvHelper(chainConfig *params.ChainConfig, logConfig *vm.LogConfig, l1Client vm.L1Client, blockCtx vm.BlockContext, startL1QueueIndex uint64, coinbase common.Address, statedb *state.StateDB, rootBefore common.Hash, block *types.Block, commitAfterApply bool) *TraceEnv {
103+
func CreateTraceEnvHelper(chainConfig *params.ChainConfig, logConfig *vm.LogConfig, l1Client vm.L1Client, callerType vm.CallerType, blockCtx vm.BlockContext, startL1QueueIndex uint64, coinbase common.Address, statedb *state.StateDB, rootBefore common.Hash, block *types.Block, commitAfterApply bool) *TraceEnv {
103104
return &TraceEnv{
104105
logConfig: logConfig,
105106
commitAfterApply: commitAfterApply,
106107
chainConfig: chainConfig,
107108
coinbase: coinbase,
108109
l1Client: l1Client,
110+
callerType: callerType,
109111
signer: types.MakeSigner(chainConfig, block.Number()),
110112
state: statedb,
111113
blockCtx: blockCtx,
@@ -122,7 +124,7 @@ func CreateTraceEnvHelper(chainConfig *params.ChainConfig, logConfig *vm.LogConf
122124
}
123125
}
124126

125-
func CreateTraceEnv(chainConfig *params.ChainConfig, chainContext core.ChainContext, engine consensus.Engine, chaindb ethdb.Database, statedb *state.StateDB, l1Client vm.L1Client, parent *types.Block, block *types.Block, commitAfterApply bool) (*TraceEnv, error) {
127+
func CreateTraceEnv(chainConfig *params.ChainConfig, chainContext core.ChainContext, engine consensus.Engine, chaindb ethdb.Database, statedb *state.StateDB, l1Client vm.L1Client, callerType vm.CallerType, parent *types.Block, block *types.Block, commitAfterApply bool) (*TraceEnv, error) {
126128
var coinbase common.Address
127129

128130
var err error
@@ -160,6 +162,7 @@ func CreateTraceEnv(chainConfig *params.ChainConfig, chainContext core.ChainCont
160162
EnableReturnData: true,
161163
},
162164
l1Client,
165+
callerType,
163166
core.NewEVMBlockContext(block.Header(), chainContext, chainConfig, nil),
164167
*startL1QueueIndex,
165168
coinbase,
@@ -231,7 +234,7 @@ func (env *TraceEnv) GetBlockTrace(block *types.Block) (*types.BlockTrace, error
231234
// Generate the next state snapshot fast without tracing
232235
msg, _ := tx.AsMessage(env.signer, block.BaseFee())
233236
env.state.SetTxContext(tx.Hash(), i)
234-
vmenv := vm.NewEVM(env.blockCtx, core.NewEVMTxContext(msg), env.state, env.chainConfig, vm.Config{L1Client: env.l1Client})
237+
vmenv := vm.NewEVM(env.blockCtx, core.NewEVMTxContext(msg), env.state, env.chainConfig, vm.Config{L1Client: env.l1Client, CallerType: env.callerType})
235238
l1DataFee, err := fees.CalculateL1DataFee(tx, env.state)
236239
if err != nil {
237240
failed = err
@@ -332,7 +335,7 @@ func (env *TraceEnv) getTxResult(state *state.StateDB, index int, block *types.B
332335
structLogger := vm.NewStructLogger(env.logConfig)
333336
tracer := NewMuxTracer(structLogger, callTracer, prestateTracer)
334337
// Run the transaction with tracing enabled.
335-
vmenv := vm.NewEVM(env.blockCtx, txContext, state, env.chainConfig, vm.Config{L1Client: env.l1Client, Debug: true, Tracer: tracer, NoBaseFee: true})
338+
vmenv := vm.NewEVM(env.blockCtx, txContext, state, env.chainConfig, vm.Config{L1Client: env.l1Client, Debug: true, Tracer: tracer, NoBaseFee: true, CallerType: env.callerType})
336339

337340
// Call Prepare to clear out the statedb access list
338341
state.SetTxContext(txctx.TxHash, txctx.TxIndex)

0 commit comments

Comments
 (0)