From bc622a406880bddfa05028b6eb18628a7112ba00 Mon Sep 17 00:00:00 2001 From: DavidZang <110075234+DavidZangNR@users.noreply.github.com> Date: Thu, 15 Aug 2024 15:53:22 +0800 Subject: [PATCH] fix parallel Num (#36) * refine log to use debug for conflict detail * fix: adjust parallelNum to use CpuNum-1 by default --------- Co-authored-by: Sunny --- cmd/utils/flags.go | 4 +--- core/parallel_state_processor.go | 2 +- core/state/parallel_statedb.go | 20 ++++++++++---------- 3 files changed, 12 insertions(+), 14 deletions(-) diff --git a/cmd/utils/flags.go b/cmd/utils/flags.go index 17027a6599..4b9fda8ea8 100644 --- a/cmd/utils/flags.go +++ b/cmd/utils/flags.go @@ -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 } diff --git a/core/parallel_state_processor.go b/core/parallel_state_processor.go index 19e50947ca..1c0b4c135f 100644 --- a/core/parallel_state_processor.go +++ b/core/parallel_state_processor.go @@ -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 diff --git a/core/state/parallel_statedb.go b/core/state/parallel_statedb.go index 520526227d..476ed99165 100644 --- a/core/state/parallel_statedb.go +++ b/core/state/parallel_statedb.go @@ -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) @@ -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, @@ -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 @@ -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) @@ -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) @@ -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) @@ -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 @@ -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) @@ -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) @@ -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,