Skip to content

Commit

Permalink
pevm: remove the ParallelLegacy (bnb-chain#201)
Browse files Browse the repository at this point in the history
  • Loading branch information
sunny2022da committed Nov 14, 2024
1 parent a7cdead commit df8aaa7
Show file tree
Hide file tree
Showing 12 changed files with 6 additions and 4,056 deletions.
1 change: 0 additions & 1 deletion cmd/geth/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,6 @@ var (
utils.RollupComputePendingBlock,
utils.RollupHaltOnIncompatibleProtocolVersionFlag,
utils.RollupSuperchainUpgradesFlag,
utils.ParallelTxLegacyFlag,
utils.ParallelTxFlag,
utils.ParallelTxUnorderedMergeFlag,
utils.ParallelTxNumFlag,
Expand Down
32 changes: 0 additions & 32 deletions cmd/utils/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import (
"net/http"
"os"
"path/filepath"
"runtime"
godebug "runtime/debug"
"strconv"
"strings"
Expand Down Expand Up @@ -1100,12 +1099,6 @@ Please note that --` + MetricsHTTPFlag.Name + ` must be set to start the server.
Category: flags.MetricsCategory,
}

ParallelTxLegacyFlag = &cli.BoolFlag{
Name: "parallel-legacy",
Usage: "Enable the experimental parallel transaction execution mode, only valid in full sync mode (default = false)",
Category: flags.VMCategory,
}

ParallelTxFlag = &cli.BoolFlag{
Name: "parallel",
Usage: "Enable the experimental parallel transaction execution mode, only valid in full sync mode (default = false)",
Expand Down Expand Up @@ -2034,37 +2027,12 @@ func SetEthConfig(ctx *cli.Context, stack *node.Node, cfg *ethconfig.Config) {
cfg.EnablePreimageRecording = ctx.Bool(VMEnableDebugFlag.Name)
}

if ctx.IsSet(ParallelTxLegacyFlag.Name) {
cfg.ParallelTxLegacyMode = ctx.Bool(ParallelTxLegacyFlag.Name)
// The best parallel num will be tuned later, we do a simple parallel num set here
numCpu := runtime.NumCPU()
var parallelNum int
if ctx.IsSet(ParallelTxNumFlag.Name) {
// first of all, we use "--parallel.num", but "--parallel.num 0" is not allowed
parallelNum = ctx.Int(ParallelTxNumFlag.Name)
if parallelNum < 1 {
parallelNum = 1
}
} else if numCpu == 1 {
parallelNum = 1 // single CPU core
} else {
// 1-2 core for merge (with parallel KV check)
// 1-2 core for others (bc optimizer, main)
// 1-2 core for possible other concurrent routine
parallelNum = max(1, numCpu-6)
}
cfg.ParallelTxNum = parallelNum
}

if ctx.IsSet(ParallelTxFlag.Name) {
cfg.ParallelTxMode = ctx.Bool(ParallelTxFlag.Name)
}

if ctx.IsSet(ParallelTxUnorderedMergeFlag.Name) {
cfg.ParallelTxUnorderedMerge = ctx.Bool(ParallelTxUnorderedMergeFlag.Name)
if ctx.IsSet(ParallelTxLegacyFlag.Name) && ctx.Bool(ParallelTxLegacyFlag.Name) {
log.Warn("ParallelTxUnorderedMergeFlag does not have any effect in ParallelTxLegacy mode")
}
}

if ctx.IsSet(ParallelTxDAGFlag.Name) {
Expand Down
55 changes: 3 additions & 52 deletions core/blockchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -564,11 +564,7 @@ func NewBlockChain(db ethdb.Database, cacheConfig *CacheConfig, genesis *Genesis
bc.snaps, _ = snapshot.New(snapconfig, bc.db, bc.triedb, head.Root)
}

if bc.vmConfig.EnableParallelExecLegacy {
bc.CreateParallelProcessor(bc.vmConfig.ParallelTxNum)
bc.CreateSerialProcessor(chainConfig, bc, engine)
log.Info("Parallel V1 enabled", "parallelNum", bc.vmConfig.ParallelTxNum)
} else if bc.vmConfig.EnableParallelExec {
if bc.vmConfig.EnableParallelExec {
bc.processor = newPEVMProcessor(chainConfig, bc, engine)
log.Info("Parallel V2 enabled", "parallelNum", ParallelNum())
} else {
Expand Down Expand Up @@ -1978,20 +1974,6 @@ func (bc *BlockChain) insertChain(chain types.Blocks, setHead bool) (int, error)
statedb.StartPrefetcher("chain")
activeState = statedb

if bc.vmConfig.EnableParallelExecLegacy {
bc.parseTxDAG(block)
txsCount := block.Transactions().Len()
threshold := min(bc.vmConfig.ParallelTxNum/2+2, 4)
if bc.vmConfig.ParallelTxNum < 2 || txsCount < threshold || bc.isEmptyTxDAG() {
bc.UseSerialProcessor()
log.Debug("Disable Parallel Tx execution", "block", block.NumberU64(), "transactions", txsCount, "parallelTxNum", bc.vmConfig.ParallelTxNum)
} else {
bc.UseParallelProcessor()
log.Debug("Enable Parallel Tx execution", "block", block.NumberU64(), "transactions", txsCount, "parallelTxNum", bc.vmConfig.ParallelTxNum)

}
}

if bc.vmConfig.EnableParallelExec {
bc.parseTxDAG(block)
}
Expand All @@ -2018,10 +2000,6 @@ func (bc *BlockChain) insertChain(chain types.Blocks, setHead bool) (int, error)
// Process block using the parent state as reference point
pstart = time.Now()
receipts, logs, usedGas, err = bc.processor.Process(block, statedb, bc.vmConfig)
if err == FallbackToSerialProcessorErr {
bc.UseSerialProcessor()
receipts, logs, usedGas, err = bc.processor.Process(block, statedb, bc.vmConfig)
}
if err != nil {
bc.reportBlock(block, receipts, err)
followupInterrupt.Store(true)
Expand All @@ -2040,7 +2018,7 @@ func (bc *BlockChain) insertChain(chain types.Blocks, setHead bool) (int, error)
vtime := time.Since(vstart)
proctime := time.Since(start) // processing + validation

if bc.enableTxDAG && !bc.vmConfig.EnableParallelExecLegacy && !bc.vmConfig.EnableParallelExec {
if bc.enableTxDAG && !bc.vmConfig.EnableParallelExec {
// compare input TxDAG when it enable in consensus
dag, err := statedb.ResolveTxDAG(len(block.Transactions()), []common.Address{block.Coinbase(), params.OptimismBaseFeeRecipient, params.OptimismL1FeeRecipient})
if err == nil {
Expand Down Expand Up @@ -2845,14 +2823,6 @@ func (bc *BlockChain) GetTrieFlushInterval() time.Duration {
return time.Duration(bc.flushInterval.Load())
}

func (bc *BlockChain) CreateParallelProcessor(parallelNum int) *BlockChain {
if bc.parallelProcessor == nil {
bc.parallelProcessor = newParallelStateProcessor(bc.Config(), bc, bc.engine, parallelNum)
bc.parallelExecution = true
}
return bc
}

func (bc *BlockChain) NoTries() bool {
return bc.stateCache.NoTries()
}
Expand Down Expand Up @@ -2885,7 +2855,7 @@ func (bc *BlockChain) HeaderChainForceSetHead(headNumber uint64) {
}

func (bc *BlockChain) TxDAGEnabledWhenMine() bool {
return bc.enableTxDAG && bc.txDAGWriteCh == nil && bc.txDAGReader == nil && !bc.vmConfig.EnableParallelExec && !bc.vmConfig.EnableParallelExecLegacy
return bc.enableTxDAG && bc.txDAGWriteCh == nil && bc.txDAGReader == nil && !bc.vmConfig.EnableParallelExec
}

func (bc *BlockChain) SetupTxDAGGeneration(output string, readFile bool) {
Expand Down Expand Up @@ -2933,25 +2903,6 @@ func (bc *BlockChain) SetupTxDAGGeneration(output string, readFile bool) {
}()
}

func (bc *BlockChain) UseParallelProcessor() {
if bc.parallelProcessor != nil {
bc.parallelExecution = true
bc.processor = bc.parallelProcessor
} else {
log.Error("bc.ParallelProcessor is nil! fallback to serial processor!")
bc.UseSerialProcessor()
}
}

func (bc *BlockChain) UseSerialProcessor() {
if bc.serialProcessor != nil {
bc.parallelExecution = false
bc.processor = bc.serialProcessor
} else {
bc.CreateSerialProcessor(bc.chainConfig, bc, bc.engine)
}
}

type TxDAGOutputItem struct {
blockNumber uint64
txDAG types.TxDAG
Expand Down
Loading

0 comments on commit df8aaa7

Please sign in to comment.