Skip to content

Commit

Permalink
exec3: reduce code depth (#11106)
Browse files Browse the repository at this point in the history
  • Loading branch information
AskAlexSharov authored Jul 10, 2024
1 parent 57ecc92 commit 60c25ef
Showing 1 changed file with 53 additions and 49 deletions.
102 changes: 53 additions & 49 deletions eth/stagedsync/exec3.go
Original file line number Diff line number Diff line change
Expand Up @@ -777,66 +777,70 @@ Loop:
} else {
rs.AddWork(ctx, txTask, in)
}
} else {
count++
stageProgress = blockNum
inputTxNum++
continue
}

count++
if txTask.Error != nil {
break Loop
}
applyWorker.RunTxTaskNoLock(txTask)
if err := func() error {
if errors.Is(txTask.Error, context.Canceled) {
return err
}
if txTask.Error != nil {
break Loop
return fmt.Errorf("%w, txnIdx=%d, %v", consensus.ErrInvalidBlock, txTask.TxIndex, txTask.Error) //same as in stage_exec.go
}
applyWorker.RunTxTaskNoLock(txTask)
if err := func() error {
if errors.Is(txTask.Error, context.Canceled) {
return err
}
if txTask.Error != nil {
return fmt.Errorf("%w, txnIdx=%d, %v", consensus.ErrInvalidBlock, txTask.TxIndex, txTask.Error) //same as in stage_exec.go
}
usedGas += txTask.UsedGas
if txTask.Tx != nil {
blobGasUsed += txTask.Tx.GetBlobGas()
}
if txTask.Final {
checkReceipts := !cfg.vmConfig.StatelessExec && chainConfig.IsByzantium(txTask.BlockNum) && !cfg.vmConfig.NoReceipts
if txTask.BlockNum > 0 && !skipPostEvaluation { //Disable check for genesis. Maybe need somehow improve it in future - to satisfy TestExecutionSpec
if err := core.BlockPostValidation(usedGas, blobGasUsed, checkReceipts, receipts, txTask.Header); err != nil {
return fmt.Errorf("%w, txnIdx=%d, %v", consensus.ErrInvalidBlock, txTask.TxIndex, err) //same as in stage_exec.go
}
usedGas += txTask.UsedGas
if txTask.Tx != nil {
blobGasUsed += txTask.Tx.GetBlobGas()
}
if txTask.Final {
checkReceipts := !cfg.vmConfig.StatelessExec && chainConfig.IsByzantium(txTask.BlockNum) && !cfg.vmConfig.NoReceipts
if txTask.BlockNum > 0 && !skipPostEvaluation { //Disable check for genesis. Maybe need somehow improve it in future - to satisfy TestExecutionSpec
if err := core.BlockPostValidation(usedGas, blobGasUsed, checkReceipts, receipts, txTask.Header); err != nil {
return fmt.Errorf("%w, txnIdx=%d, %v", consensus.ErrInvalidBlock, txTask.TxIndex, err) //same as in stage_exec.go
}
usedGas, blobGasUsed = 0, 0
receipts = receipts[:0]
} else if txTask.TxIndex >= 0 {
receipts = append(receipts, txTask.CreateReceipt(usedGas))
}
return nil
}(); err != nil {
if errors.Is(err, context.Canceled) {
usedGas, blobGasUsed = 0, 0
receipts = receipts[:0]
} else if txTask.TxIndex >= 0 {
receipts = append(receipts, txTask.CreateReceipt(usedGas))
}
return nil
}(); err != nil {
if errors.Is(err, context.Canceled) {
return err
}
logger.Warn(fmt.Sprintf("[%s] Execution failed", execStage.LogPrefix()), "block", blockNum, "txNum", txTask.TxNum, "hash", header.Hash().String(), "err", err)
if cfg.hd != nil && errors.Is(err, consensus.ErrInvalidBlock) {
cfg.hd.ReportBadHeaderPoS(header.Hash(), header.ParentHash)
}
if cfg.badBlockHalt {
return err
}
if errors.Is(err, consensus.ErrInvalidBlock) {
if err := u.UnwindTo(blockNum-1, BadBlock(header.Hash(), err), applyTx); err != nil {
return err
}
logger.Warn(fmt.Sprintf("[%s] Execution failed", execStage.LogPrefix()), "block", blockNum, "txNum", txTask.TxNum, "hash", header.Hash().String(), "err", err)
if cfg.hd != nil && errors.Is(err, consensus.ErrInvalidBlock) {
cfg.hd.ReportBadHeaderPoS(header.Hash(), header.ParentHash)
}
if cfg.badBlockHalt {
} else {
if err := u.UnwindTo(blockNum-1, ExecUnwind, applyTx); err != nil {
return err
}
if errors.Is(err, consensus.ErrInvalidBlock) {
if err := u.UnwindTo(blockNum-1, BadBlock(header.Hash(), err), applyTx); err != nil {
return err
}
} else {
if err := u.UnwindTo(blockNum-1, ExecUnwind, applyTx); err != nil {
return err
}
}
break Loop
}

// MA applystate
if err := rs.ApplyState4(ctx, txTask); err != nil {
return err
}
break Loop
}

outputTxNum.Add(1)
// MA applystate
if err := rs.ApplyState4(ctx, txTask); err != nil {
return err
}

outputTxNum.Add(1)

stageProgress = blockNum
inputTxNum++
}
Expand Down

0 comments on commit 60c25ef

Please sign in to comment.