From 5a6d25ec08477c21c6135f4be75abc2973edace9 Mon Sep 17 00:00:00 2001 From: wgr523 Date: Wed, 17 Sep 2025 22:52:28 +0800 Subject: [PATCH] engine_v2: fix negative underflow in getBlockInfoByEpochNum (#1481) --- consensus/XDPoS/engines/engine_v2/utils.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/consensus/XDPoS/engines/engine_v2/utils.go b/consensus/XDPoS/engines/engine_v2/utils.go index 6fa21a304f..d8003aa920 100644 --- a/consensus/XDPoS/engines/engine_v2/utils.go +++ b/consensus/XDPoS/engines/engine_v2/utils.go @@ -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 }