From e5f18d3f368eead9e8adcb0d5f65c9f96d71d93a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9CGheisMohammadi=E2=80=9D?= <36589218+GheisMohammadi@users.noreply.github.com> Date: Wed, 4 Jan 2023 14:34:09 +0800 Subject: [PATCH] fix short range hash chain --- api/service/stagedstreamsync/short_range_helper.go | 10 +++------- api/service/stagedstreamsync/stage_short_range.go | 8 +------- 2 files changed, 4 insertions(+), 14 deletions(-) diff --git a/api/service/stagedstreamsync/short_range_helper.go b/api/service/stagedstreamsync/short_range_helper.go index 210d1aa0c..90415c87c 100644 --- a/api/service/stagedstreamsync/short_range_helper.go +++ b/api/service/stagedstreamsync/short_range_helper.go @@ -139,15 +139,11 @@ func (sh *srHelper) checkPrerequisites() error { return nil } -func (sh *srHelper) prepareBlockHashNumbers(curNumber uint64, count int) []uint64 { +func (sh *srHelper) prepareBlockHashNumbers(curNumber uint64) []uint64 { - n := count - if count > BlockHashesPerRequest { - n = BlockHashesPerRequest - } - res := make([]uint64, 0, n) + res := make([]uint64, 0, BlockHashesPerRequest) - for bn := curNumber + 1; bn <= curNumber+uint64(n); bn++ { + for bn := curNumber + 1; bn <= curNumber+uint64(BlockHashesPerRequest); bn++ { res = append(res, bn) } return res diff --git a/api/service/stagedstreamsync/stage_short_range.go b/api/service/stagedstreamsync/stage_short_range.go index de83beafa..cfe29f39e 100644 --- a/api/service/stagedstreamsync/stage_short_range.go +++ b/api/service/stagedstreamsync/stage_short_range.go @@ -54,11 +54,6 @@ func (sr *StageShortRange) Exec(firstCycle bool, invalidBlockRevert bool, s *Sta return nil } - curBN := sr.configs.bc.CurrentBlock().NumberU64() - if curBN >= s.state.status.targetBN { - return nil - } - // do short range sync n, err := sr.doShortRangeSync(s) s.state.inserted = n @@ -109,8 +104,7 @@ func (sr *StageShortRange) doShortRangeSync(s *StageState) (int, error) { return 0, errors.Wrap(err, "prerequisite") } curBN := sr.configs.bc.CurrentBlock().NumberU64() - blkCount := int(s.state.status.targetBN) - int(curBN) - blkNums := sh.prepareBlockHashNumbers(curBN, blkCount) + blkNums := sh.prepareBlockHashNumbers(curBN) hashChain, whitelist, err := sh.getHashChain(blkNums) if err != nil { return 0, errors.Wrap(err, "getHashChain")