From 4513f63bb61c09280e20201dd83ac9b881543967 Mon Sep 17 00:00:00 2001 From: NathanBSC Date: Thu, 1 Aug 2024 19:35:44 +0800 Subject: [PATCH] define logic LastBlockMiningTime --- miner/worker.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/miner/worker.go b/miner/worker.go index ce75f37a8b..5fc7d20b61 100644 --- a/miner/worker.go +++ b/miner/worker.go @@ -1332,6 +1332,20 @@ LOOP: workList = append(workList, work) delay := w.engine.Delay(w.chain, work.header, &w.config.DelayLeftOver) + if w.config.MB.LastBlockMiningTime > w.chainConfig.Parlia.Period*1000/2 { + if p, ok := w.engine.(*parlia.Parlia); ok { + service := p.APIs(w.chain)[0].Service + latestBlockNumber := rpc.LatestBlockNumber + currentTurnLength, err := service.(*parlia.API).GetTurnLength(&latestBlockNumber) + if err == nil && (work.header.Number.Uint64()+1)%uint64(currentTurnLength) == 0 { + *delay += time.Duration((w.config.MB.LastBlockMiningTime - w.chainConfig.Parlia.Period*1000/2) * uint64(time.Millisecond)) + timeLeft := time.Until(time.Unix(int64(work.header.Time), 0)) + if *delay > timeLeft { + *delay = timeLeft + } + } + } + } if delay == nil { log.Warn("commitWork delay is nil, something is wrong") stopTimer = nil