engine_v2: fix negative underflow in getBlockInfoByEpochNum (#1481)

This commit is contained in:
wgr523 2025-09-17 22:52:28 +08:00 committed by GitHub
parent b8e5baa978
commit 5a6d25ec08
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -271,7 +271,13 @@ func (x *XDPoS_v2) binarySearchBlockByEpochNumber(chain consensus.ChainReader, t
} else {
end = header.Number.Uint64()
// trick to shorten the search
estStart := end - uint64(round)%x.config.Epoch
estStart := uint64(0)
// if statement to avoid negative underflow
roundModEpoch := uint64(round) % x.config.Epoch
if end >= roundModEpoch {
estStart = end - roundModEpoch
}
if start < estStart {
start = estStart
}