From a3282d41193d7856962396ca2633301aa21cc6a6 Mon Sep 17 00:00:00 2001 From: wgr523 Date: Wed, 10 Dec 2025 09:36:58 +0800 Subject: [PATCH] XFN-155: consensus V2 initial timer kick-off check (#1849) * fix: consensus V2 initial timer kick-off check * style: use Cmp for big.Int --- consensus/XDPoS/engines/engine_v2/engine.go | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/consensus/XDPoS/engines/engine_v2/engine.go b/consensus/XDPoS/engines/engine_v2/engine.go index 4617ced2a7..88c7787dc9 100644 --- a/consensus/XDPoS/engines/engine_v2/engine.go +++ b/consensus/XDPoS/engines/engine_v2/engine.go @@ -200,7 +200,7 @@ func (x *XDPoS_v2) initial(chain consensus.ChainReader, header *types.Header) er var quorumCert *types.QuorumCert var err error - if header.Number.Int64() == x.config.V2.SwitchBlock.Int64() { + if header.Number.Cmp(x.config.V2.SwitchBlock) == 0 { log.Info("[initial] highest QC for consensus v2 first block") blockInfo := &types.BlockInfo{ Hash: header.Hash(), @@ -273,7 +273,11 @@ func (x *XDPoS_v2) initial(chain consensus.ChainReader, header *types.Header) er }() // Kick-off the countdown timer - x.timeoutWorker.Reset(chain, 0, 0) + // Only kick-off if it is V2 switch block + // Otherwise it is a lagging node, already kick-off in `processQC` + if header.Number.Cmp(x.config.V2.SwitchBlock) == 0 { + x.timeoutWorker.Reset(chain, 0, 0) + } x.isInitilised = true log.Warn("[initial] finish initialisation") @@ -989,7 +993,7 @@ func (x *XDPoS_v2) calcMasternodes(chain consensus.ChainReader, blockNum *big.In } candidates := snap.NextEpochCandidates - if blockNum.Uint64() == x.config.V2.SwitchBlock.Uint64()+1 { + if blockNum.Cmp(new(big.Int).Add(x.config.V2.SwitchBlock, big.NewInt(1))) == 0 { log.Info("[calcMasternodes] examing first v2 block") if len(candidates) > maxMasternodes { candidates = candidates[:maxMasternodes]