Skip to content

eth, execution: Use block level gasPool in serial execution #14761

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
6 changes: 4 additions & 2 deletions eth/stagedsync/exec3.go
Original file line number Diff line number Diff line change
Expand Up @@ -527,6 +527,8 @@ Loop:
})
totalGasUsed += b.GasUsed()
blockContext := core.NewEVMBlockContext(header, getHashFn, cfg.engine, cfg.author /* author */, chainConfig)
gp := new(core.GasPool).AddGas(header.GasLimit).AddBlobGas(chainConfig.GetMaxBlobGasPerBlock(b.Time()))

// print type of engine
if parallel {
if err := executor.status(ctx, commitThreshold); err != nil {
Expand Down Expand Up @@ -651,7 +653,7 @@ Loop:
}

if parallel {
_, err := executor.execute(ctx, txTasks)
_, err := executor.execute(ctx, txTasks, nil /*gasPool*/) // For now don't use block's gas pool for parallel
if b.NumberU64() > 0 && hooks != nil && hooks.OnBlockEnd != nil {
hooks.OnBlockEnd(err)
}
Expand All @@ -665,7 +667,7 @@ Loop:

se.skipPostEvaluation = skipPostEvaluation

continueLoop, err := se.execute(ctx, txTasks)
continueLoop, err := se.execute(ctx, txTasks, gp)
if b.NumberU64() > 0 && hooks != nil && hooks.OnBlockEnd != nil {
hooks.OnBlockEnd(err)
}
Expand Down
4 changes: 2 additions & 2 deletions eth/stagedsync/exec3_parallel.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ When rwLoop has nothing to do - it does Prune, or flush of WAL to RwTx (agg.rota
*/

type executor interface {
execute(ctx context.Context, tasks []*state.TxTask) (bool, error)
execute(ctx context.Context, tasks []*state.TxTask, gp *core.GasPool) (bool, error)
status(ctx context.Context, commitThreshold uint64) error
wait() error
getHeader(ctx context.Context, hash common.Hash, number uint64) (h *types.Header)
Expand Down Expand Up @@ -538,7 +538,7 @@ func (pe *parallelExecutor) wait() error {
return nil
}

func (pe *parallelExecutor) execute(ctx context.Context, tasks []*state.TxTask) (bool, error) {
func (pe *parallelExecutor) execute(ctx context.Context, tasks []*state.TxTask, gp *core.GasPool) (bool, error) {
for _, txTask := range tasks {
if txTask.Sender() != nil {
if ok := pe.rs.RegisterSender(txTask); ok {
Expand Down
6 changes: 4 additions & 2 deletions eth/stagedsync/exec3_serial.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,14 @@ func (se *serialExecutor) status(ctx context.Context, commitThreshold uint64) er
return nil
}

func (se *serialExecutor) execute(ctx context.Context, tasks []*state.TxTask) (cont bool, err error) {
func (se *serialExecutor) execute(ctx context.Context, tasks []*state.TxTask, gp *core.GasPool) (cont bool, err error) {
for _, txTask := range tasks {
if txTask.Error != nil {
return false, nil
}

if gp != nil {
se.applyWorker.SetGaspool(gp)
}
se.applyWorker.RunTxTaskNoLock(txTask, se.isMining, se.skipPostEvaluation)
if err := func() error {
if errors.Is(txTask.Error, context.Canceled) {
Expand Down
7 changes: 6 additions & 1 deletion execution/exec3/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,10 @@ func (rw *Worker) ResetState(rs *state.ParallelExecutionState, accumulator *shar
rw.stateWriter = state.NewStateWriterV3(rs, accumulator)
}

func (rw *Worker) SetGaspool(gp *core.GasPool) {
rw.taskGasPool = gp
}

func (rw *Worker) Tx() kv.TemporalTx { return rw.chainTx }
func (rw *Worker) DiscardReadList() { rw.stateReader.DiscardReadList() }
func (rw *Worker) ResetTx(chainTx kv.Tx) {
Expand Down Expand Up @@ -272,7 +276,8 @@ func (rw *Worker) RunTxTaskNoLock(txTask *state.TxTask, isMining, skipPostEvalua
}
}
default:
rw.taskGasPool.Reset(txTask.Tx.GetGasLimit(), rw.chainConfig.GetMaxBlobGasPerBlock(header.Time))
// This doesn't make sense, but I am not sure if this wrong behaviour is needed somewhere else:
// rw.taskGasPool.Reset(txTask.Tx.GetGasLimit(), rw.chainConfig.GetMaxBlobGasPerBlock(header.Time))
rw.callTracer.Reset()
rw.vmCfg.SkipAnalysis = txTask.SkipAnalysis
ibs.SetTxContext(txTask.TxIndex)
Expand Down
Loading