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

Add early return in ComputeTxEnv for state sync transactions #12315

Merged
merged 2 commits into from
Oct 15, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions turbo/transactions/tracing.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,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 @@ -59,6 +56,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 @@ -119,6 +121,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
Loading