Skip to content

Commit

Permalink
Add early return in ComputeTxEnv for state sync transactions (#12447)
Browse files Browse the repository at this point in the history
Cherry pick #12315 into `release/2.61`

Co-authored-by: Shoham Chakraborty <shhmchk@gmail.com>
  • Loading branch information
yperbasis and shohamc1 authored Oct 24, 2024
1 parent f3dfa6d commit 8b3a532
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions turbo/transactions/tracing.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,6 @@ func ComputeTxEnv(ctx context.Context, engine consensus.EngineReader, block *typ
// Create the parent state database
statedb := state.New(reader)

if txIndex == 0 && len(block.Transactions()) == 0 {
return nil, evmtypes.BlockContext{}, evmtypes.TxContext{}, statedb, reader, nil
}
getHeader := func(hash libcommon.Hash, n uint64) *types.Header {
h, _ := headerReader.HeaderByNumber(ctx, dbtx, n)
return h
Expand All @@ -60,6 +57,11 @@ func ComputeTxEnv(ctx context.Context, engine consensus.EngineReader, block *typ
// Recompute transactions up to the target index.
signer := types.MakeSigner(cfg, block.NumberU64(), block.Time())
if historyV3 {
if txIndex == len(block.Transactions()) {
// tx is a state sync transaction
return nil, blockContext, evmtypes.TxContext{}, statedb, reader, nil
}

rules := cfg.Rules(blockContext.BlockNumber, blockContext.Time)
txn := block.Transactions()[txIndex]
statedb.SetTxContext(txn.Hash(), block.Hash(), txIndex)
Expand Down Expand Up @@ -120,6 +122,12 @@ func ComputeTxEnv(ctx context.Context, engine consensus.EngineReader, block *typ
return nil, blockContext, evmtypes.TxContext{}, statedb, reader, nil
}
}

if txIndex == len(block.Transactions()) {
// tx is a state sync transaction
return nil, blockContext, evmtypes.TxContext{}, statedb, reader, nil
}

return nil, evmtypes.BlockContext{}, evmtypes.TxContext{}, nil, nil, fmt.Errorf("transaction index %d out of range for block %x", txIndex, block.Hash())
}

Expand Down

0 comments on commit 8b3a532

Please sign in to comment.