Skip to content

Commit

Permalink
fix parallel Num (bnb-chain#36)
Browse files Browse the repository at this point in the history
* refine log to use debug for conflict detail

* fix: adjust parallelNum to use CpuNum-1 by default

---------

Co-authored-by: Sunny <sunny2022.za@gmail.com>
  • Loading branch information
DavidZangNR and sunny2022da authored Aug 15, 2024
1 parent 808d048 commit bc622a4
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 14 deletions.
4 changes: 1 addition & 3 deletions cmd/utils/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -2018,10 +2018,8 @@ func SetEthConfig(ctx *cli.Context, stack *node.Node, cfg *ethconfig.Config) {
}
} else if numCpu == 1 {
parallelNum = 1 // single CPU core
} else if numCpu < 10 {
parallelNum = numCpu - 1
} else {
parallelNum = 8
parallelNum = numCpu - 1
}
cfg.ParallelTxNum = parallelNum
}
Expand Down
2 changes: 1 addition & 1 deletion core/parallel_state_processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,7 @@ func (p *ParallelStateProcessor) toConfirmTxIndex(targetTxIndex int, isStage2 bo
func (p *ParallelStateProcessor) toConfirmTxIndexResult(txResult *ParallelTxResult, isStage2 bool) bool {
txReq := txResult.txReq
if p.hasConflict(txResult, isStage2) {
log.Warn(fmt.Sprintf("HasConflict!! block: %d, txIndex: %d\n", txResult.txReq.block.NumberU64(), txResult.txReq.txIndex))
log.Info(fmt.Sprintf("HasConflict!! block: %d, txIndex: %d\n", txResult.txReq.block.NumberU64(), txResult.txReq.txIndex))
return false
}
if isStage2 { // not its turn
Expand Down
20 changes: 10 additions & 10 deletions core/state/parallel_statedb.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func hasKvConflict(slotDB *ParallelStateDB, addr common.Address, key common.Hash
}
if valUnconfirm, ok := slotDB.getKVFromUnconfirmedDB(addr, key); ok {
if !bytes.Equal(val.Bytes(), valUnconfirm.Bytes()) {
log.Warn("IsSlotDBReadsValid KV read is invalid in unconfirmed", "addr", addr,
log.Debug("IsSlotDBReadsValid KV read is invalid in unconfirmed", "addr", addr,
"valSlot", val, "valUnconfirm", valUnconfirm,
"SlotIndex", slotDB.parallel.SlotIndex,
"txIndex", slotDB.txIndex, "baseTxIndex", slotDB.parallel.baseTxIndex)
Expand All @@ -57,7 +57,7 @@ func hasKvConflict(slotDB *ParallelStateDB, addr common.Address, key common.Hash
valMain := mainDB.GetStateNoUpdate(addr, key)

if !bytes.Equal(val.Bytes(), valMain.Bytes()) {
log.Warn("hasKvConflict is invalid", "addr", addr,
log.Debug("hasKvConflict is invalid", "addr", addr,
"key", key, "valSlot", val,
"valMain", valMain, "SlotIndex", slotDB.parallel.SlotIndex,
"txIndex", slotDB.txIndex, "baseTxIndex", slotDB.parallel.baseTxIndex,
Expand Down Expand Up @@ -1288,7 +1288,7 @@ func (slotDB *ParallelStateDB) IsParallelReadsValid(isStage2 bool) bool {
}
if nonceUnconfirm, ok := slotDB.getNonceFromUnconfirmedDB(addr); ok {
if nonceSlot != nonceUnconfirm {
log.Warn("IsSlotDBReadsValid nonce read is invalid in unconfirmed", "addr", addr,
log.Debug("IsSlotDBReadsValid nonce read is invalid in unconfirmed", "addr", addr,
"nonceSlot", nonceSlot, "nonceUnconfirm", nonceUnconfirm, "SlotIndex", slotDB.parallel.SlotIndex,
"txIndex", slotDB.txIndex, "baseTxIndex", slotDB.parallel.baseTxIndex)
return false
Expand All @@ -1301,7 +1301,7 @@ func (slotDB *ParallelStateDB) IsParallelReadsValid(isStage2 bool) bool {
nonceMain = mainObj.Nonce()
}
if nonceSlot != nonceMain {
log.Warn("IsSlotDBReadsValid nonce read is invalid", "addr", addr,
log.Debug("IsSlotDBReadsValid nonce read is invalid", "addr", addr,
"nonceSlot", nonceSlot, "nonceMain", nonceMain, "SlotIndex", slotDB.parallel.SlotIndex,
"txIndex", slotDB.txIndex, "baseTxIndex", slotDB.parallel.baseTxIndex,
"mainIndex", mainDB.txIndex)
Expand Down Expand Up @@ -1331,7 +1331,7 @@ func (slotDB *ParallelStateDB) IsParallelReadsValid(isStage2 bool) bool {
}

if balanceSlot.Cmp(balanceMain) != 0 {
log.Warn("IsSlotDBReadsValid balance read is invalid", "addr", addr,
log.Debug("IsSlotDBReadsValid balance read is invalid", "addr", addr,
"balanceSlot", balanceSlot, "balanceMain", balanceMain, "SlotIndex", slotDB.parallel.SlotIndex,
"txIndex", slotDB.txIndex, "baseTxIndex", slotDB.parallel.baseTxIndex,
"mainIndex", mainDB.txIndex)
Expand Down Expand Up @@ -1422,7 +1422,7 @@ func (slotDB *ParallelStateDB) IsParallelReadsValid(isStage2 bool) bool {
codeMain = object.Code()
}
if !bytes.Equal(codeSlot, codeMain) {
log.Warn("IsSlotDBReadsValid code read is invalid", "addr", addr,
log.Debug("IsSlotDBReadsValid code read is invalid", "addr", addr,
"len codeSlot", len(codeSlot), "len codeMain", len(codeMain), "SlotIndex", slotDB.parallel.SlotIndex,
"txIndex", slotDB.txIndex, "baseTxIndex", slotDB.parallel.baseTxIndex,
"mainIndex", mainDB.txIndex)
Expand All @@ -1437,7 +1437,7 @@ func (slotDB *ParallelStateDB) IsParallelReadsValid(isStage2 bool) bool {
codeHashMain = common.BytesToHash(object.CodeHash())
}
if !bytes.Equal(codeHashSlot.Bytes(), codeHashMain.Bytes()) {
log.Warn("IsSlotDBReadsValid codehash read is invalid", "addr", addr,
log.Debug("IsSlotDBReadsValid codehash read is invalid", "addr", addr,
"codeHashSlot", codeHashSlot, "codeHashMain", codeHashMain, "SlotIndex", slotDB.parallel.SlotIndex,
"txIndex", slotDB.txIndex, "baseTxIndex", slotDB.parallel.baseTxIndex, "mainIndex", mainDB.txIndex)
return false
Expand All @@ -1450,7 +1450,7 @@ func (slotDB *ParallelStateDB) IsParallelReadsValid(isStage2 bool) bool {
stateMain = true // addr exist in main DB
}
if stateSlot != stateMain {
log.Warn("IsSlotDBReadsValid addrState read invalid(true: exist, false: not exist)",
log.Debug("IsSlotDBReadsValid addrState read invalid(true: exist, false: not exist)",
"addr", addr, "stateSlot", stateSlot, "stateMain", stateMain,
"SlotIndex", slotDB.parallel.SlotIndex,
"txIndex", slotDB.txIndex, "baseTxIndex", slotDB.parallel.baseTxIndex, "mainIndex", mainDB.txIndex)
Expand All @@ -1461,7 +1461,7 @@ func (slotDB *ParallelStateDB) IsParallelReadsValid(isStage2 bool) bool {
for addr, destructRead := range slotDB.parallel.addrSnapDestructsReadsInSlot {
mainObj := mainDB.getDeletedStateObjectNoUpdate(addr)
if mainObj == nil {
log.Warn("IsSlotDBReadsValid snapshot destructs read invalid, address should exist",
log.Debug("IsSlotDBReadsValid snapshot destructs read invalid, address should exist",
"addr", addr, "destruct", destructRead,
"SlotIndex", slotDB.parallel.SlotIndex,
"txIndex", slotDB.txIndex, "baseTxIndex", slotDB.parallel.baseTxIndex)
Expand All @@ -1471,7 +1471,7 @@ func (slotDB *ParallelStateDB) IsParallelReadsValid(isStage2 bool) bool {
_, destructMain := mainDB.snapDestructs[addr] // addr not exist
slotDB.snapParallelLock.RUnlock()
if destructRead != destructMain && addr.Hex() != "0x0000000000000000000000000000000000000001" {
log.Warn("IsSlotDBReadsValid snapshot destructs read invalid",
log.Debug("IsSlotDBReadsValid snapshot destructs read invalid",
"addr", addr, "destructRead", destructRead, "destructMain", destructMain,
"SlotIndex", slotDB.parallel.SlotIndex,
"txIndex", slotDB.txIndex, "baseTxIndex", slotDB.parallel.baseTxIndex,
Expand Down

0 comments on commit bc622a4

Please sign in to comment.