Skip to content

Commit c5f1c9e

Browse files
authored
Merge pull request bnb-chain#203 from welkin22/feature/TxDAG-PEVM-patch
pevm: If TxDAG is nil, then use the serial processor to handle it.
2 parents 743ca54 + 0fb3f73 commit c5f1c9e

File tree

4 files changed

+10
-21
lines changed

4 files changed

+10
-21
lines changed

core/blockchain.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,6 @@ type BlockChain struct {
317317
txDAGWriteCh chan TxDAGOutputItem
318318
txDAGReader *TxDAGFileReader
319319
serialProcessor Processor
320-
parallelProcessor Processor
321320
}
322321

323322
// NewBlockChain returns a fully initialised block chain using information
@@ -537,6 +536,7 @@ func NewBlockChain(db ethdb.Database, cacheConfig *CacheConfig, genesis *Genesis
537536

538537
if bc.vmConfig.EnableParallelExec {
539538
bc.processor = newPEVMProcessor(chainConfig, bc, engine)
539+
bc.serialProcessor = NewStateProcessor(chainConfig, bc, engine)
540540
log.Info("Parallel V2 enabled", "parallelNum", ParallelNum())
541541
} else {
542542
bc.processor = NewStateProcessor(chainConfig, bc, engine)
@@ -1936,7 +1936,11 @@ func (bc *BlockChain) insertChain(chain types.Blocks, setHead bool) (int, error)
19361936

19371937
// Process block using the parent state as reference point
19381938
pstart = time.Now()
1939-
receipts, logs, usedGas, err = bc.processor.Process(block, statedb, bc.vmConfig)
1939+
if bc.vmConfig.TxDAG == nil && bc.vmConfig.EnableParallelUnorderedMerge {
1940+
receipts, logs, usedGas, err = bc.serialProcessor.Process(block, statedb, bc.vmConfig)
1941+
} else {
1942+
receipts, logs, usedGas, err = bc.processor.Process(block, statedb, bc.vmConfig)
1943+
}
19401944
if err != nil {
19411945
bc.reportBlock(block, receipts, err)
19421946
followupInterrupt.Store(true)

core/pevm_processor.go

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ func (p *PEVMProcessor) executeInSlot(maindb *state.StateDB, txReq *PEVMTxReques
122122
// if it is in Stage 2 it is a likely result, not 100% sure
123123
func (p *PEVMProcessor) toConfirmTxIndexResult(txResult *PEVMTxResult) error {
124124
txReq := txResult.txReq
125-
if !p.unorderedMerge || !txReq.useDAG {
125+
if !p.unorderedMerge {
126126
// If we do not use a DAG, then we need to check for conflicts to ensure correct execution.
127127
// When we perform an unordered merge, we cannot conduct conflict checks
128128
// and can only choose to trust that the DAG is correct and that conflicts do not exist.
@@ -166,7 +166,6 @@ func (p *PEVMProcessor) confirmTxResult(statedb *state.StateDB, gp *GasPool, res
166166

167167
isByzantium := p.config.IsByzantium(header.Number)
168168
isEIP158 := p.config.IsEIP158(header.Number)
169-
//result.slotDB.FinaliseForParallel(isByzantium || isEIP158, statedb)
170169
if err := result.slotDB.Merge(isByzantium || isEIP158); err != nil {
171170
// something very wrong, should not happen
172171
log.Error("merge slotDB failed", "err", err)
@@ -285,17 +284,14 @@ func (p *PEVMProcessor) Process(block *types.Block, statedb *state.StateDB, cfg
285284
}(time.Now())
286285
log.Debug("pevm confirm", "txIndex", pr.txReq.txIndex)
287286
return p.confirmTxResult(statedb, gp, pr)
288-
}, p.unorderedMerge && txDAG != nil)
287+
}, p.unorderedMerge)
289288
parallelRunDuration := time.Since(start) - buildLevelsDuration
290289
if err != nil {
291290
tx := allTxs[txIndex]
292291
log.Error("ProcessParallel tx failed", "txIndex", txIndex, "txHash", tx.Hash().Hex(), "err", err)
293292
return nil, nil, 0, fmt.Errorf("could not apply tx %d [%v]: %w", txIndex, tx.Hash().Hex(), err)
294293
}
295294

296-
//fmt.Printf("ProcessParallel tx all done, parallelNum:%d, txNum: %d, conflictNum: %d, executeDuration:%s, confirmDurations:%s, buildLevelsDuration:%s, runDuration:%s\n",
297-
// ParallelNum(), txNum, p.debugConflictRedoNum, time.Duration(executeDurations), time.Duration(confirmDurations), buildLevelsDuration, parallelRunDuration)
298-
299295
// len(commonTxs) could be 0, such as: https://bscscan.com/block/14580486
300296
var redoRate int = 0
301297
if len(p.commonTxs) == 0 {
@@ -334,8 +330,8 @@ func (p *PEVMProcessor) Process(block *types.Block, statedb *state.StateDB, cfg
334330
var cumulativeGasUsed uint64
335331
for _, receipt := range p.receipts {
336332
// reset the log index
337-
for _, log := range receipt.Logs {
338-
log.Index = uint(lindex)
333+
for _, oneLog := range receipt.Logs {
334+
oneLog.Index = uint(lindex)
339335
lindex++
340336
}
341337
// re-calculate the cumulativeGasUsed

core/state/pevm_statedb.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -486,9 +486,6 @@ func (pst *UncommittedDB) Merge(deleteEmptyObjects bool) error {
486486
// so we don't need to merge anything.
487487
return nil
488488
}
489-
//if err := pst.conflictsToMaindb(); err != nil {
490-
// return err
491-
//}
492489

493490
// 0. set the TxContext
494491
pst.maindb.SetTxContext(pst.txHash, pst.txIndex)

core/state_processor.go

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -54,14 +54,6 @@ func NewStateProcessor(config *params.ChainConfig, bc *BlockChain, engine consen
5454
}
5555
}
5656

57-
// CreateSerialProcessor create a new StateProcessor
58-
func (bc *BlockChain) CreateSerialProcessor(config *params.ChainConfig, bc2 *BlockChain, engine consensus.Engine) {
59-
if bc.serialProcessor == nil {
60-
bc.serialProcessor = NewStateProcessor(config, bc2, engine)
61-
bc.parallelExecution = false
62-
}
63-
}
64-
6557
// Process processes the state changes according to the Ethereum rules by running
6658
// the transaction messages using the statedb and applying any rewards to both
6759
// the processor (coinbase) and any included uncles.

0 commit comments

Comments
 (0)