From 796ee818e3dcc94532d810d28bd5c8384ee181a5 Mon Sep 17 00:00:00 2001 From: wanwiset25 Date: Wed, 11 Jun 2025 18:37:02 +0400 Subject: [PATCH] add condition to fix endIndex out of bounds --- consensus/XDPoS/api.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/consensus/XDPoS/api.go b/consensus/XDPoS/api.go index 1ca24401ee..0dbcb897f3 100644 --- a/consensus/XDPoS/api.go +++ b/consensus/XDPoS/api.go @@ -467,6 +467,9 @@ func (api *API) getRewardFileNamesInRange(begin, end *rpc.BlockNumber) ([]reward startIndex := sort.SearchInts(epochNumbers, int(beginHeader.Number.Int64())) endIndex := sort.SearchInts(epochNumbers, int(endHeader.Number.Int64())) + if endIndex == len(epochNumbers) { + endIndex = endIndex - 1 //this is to prevent endIndex out of bounds when endInput is higher than last reward(epoch) block but lower than latest block + } var rewardfileNamesInRange []rewardFileName for i := startIndex; i <= endIndex; i++ {