From 2b40d1337fddc800fcb0e01b0bce4ce2dc2cba91 Mon Sep 17 00:00:00 2001 From: Liam Date: Wed, 18 May 2022 11:17:49 -0400 Subject: [PATCH] initial snapshot when there is no snapshot (#86) --- consensus/XDPoS/engines/engine_v2/engine.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/consensus/XDPoS/engines/engine_v2/engine.go b/consensus/XDPoS/engines/engine_v2/engine.go index f1cb161eb3b1..d4827fc22d0a 100644 --- a/consensus/XDPoS/engines/engine_v2/engine.go +++ b/consensus/XDPoS/engines/engine_v2/engine.go @@ -171,13 +171,13 @@ func (x *XDPoS_v2) Initial(chain consensus.ChainReader, header *types.Header) er } // Initial first v2 snapshot - if header.Number.Uint64() < x.config.V2.SwitchBlock.Uint64()+x.config.Gap { + lastGapNum := x.config.V2.SwitchBlock.Uint64() - x.config.Gap + lastGapHeader := chain.GetHeaderByNumber(lastGapNum) - checkpointBlockNumber := header.Number.Uint64() - header.Number.Uint64()%x.config.Epoch - checkpointHeader := chain.GetHeaderByNumber(checkpointBlockNumber) + snap, _ := loadSnapshot(x.db, lastGapHeader.Hash()) - lastGapNum := checkpointBlockNumber - x.config.Gap - lastGapHeader := chain.GetHeaderByNumber(lastGapNum) + if snap == nil { + checkpointHeader := chain.GetHeaderByNumber(x.config.V2.SwitchBlock.Uint64()) log.Info("[Initial] init first snapshot") _, _, masternodes, err := x.getExtraFields(checkpointHeader)