core: fix integer divide by zero in function ValidateHeaderChain

This commit is contained in:
Daniel Liu 2025-02-25 15:10:13 +08:00
parent 7c9df61bd9
commit cc5359e063

View file

@ -233,6 +233,8 @@ func (hc *HeaderChain) ValidateHeaderChain(chain []*types.Header, checkFreq int)
// Generate the list of seal verification requests, and start the parallel verifier // Generate the list of seal verification requests, and start the parallel verifier
seals := make([]bool, len(chain)) seals := make([]bool, len(chain))
if checkFreq != 0 {
// In case of checkFreq == 0 all seals are left false.
for i := 0; i < len(seals)/checkFreq; i++ { for i := 0; i < len(seals)/checkFreq; i++ {
index := i*checkFreq + hc.rand.Intn(checkFreq) index := i*checkFreq + hc.rand.Intn(checkFreq)
if index >= len(seals) { if index >= len(seals) {
@ -240,7 +242,9 @@ func (hc *HeaderChain) ValidateHeaderChain(chain []*types.Header, checkFreq int)
} }
seals[index] = true seals[index] = true
} }
seals[len(seals)-1] = true // Last should always be verified to avoid junk // Last should always be verified to avoid junk
seals[len(seals)-1] = true
}
abort, results := hc.engine.VerifyHeaders(hc, chain, seals) abort, results := hc.engine.VerifyHeaders(hc, chain, seals)
defer close(abort) defer close(abort)