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

exec3: reduce code depth #11106

Merged
merged 1 commit into from
Jul 10, 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
save
  • Loading branch information
AskAlexSharov committed Jul 10, 2024
commit 4227b1d18cb39386cbf88a7f7858181bb1165bcc
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
Loading