initial snapshot when there is no snapshot (#86)

This commit is contained in:
Liam 2022-05-18 11:17:49 -04:00 committed by GitHub
parent 5fffa0cd43
commit 2b40d1337f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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)