Skip to content

Commit cb9a019

Browse files
authored
stagedsync: polygon sync stage fix nil panic when downloading state sync events (#10469)
Problem: - we were using `ReadHeaderByNumber` to get the latest sprint start block header needed for fetching state sync events - `ReadHeaderByNumber` uses `ReadCanonicalHash` to get the hash and then calls `ReadHeader(hash, number)` - `ReadHeaderByNumber` returns nil when there is no canonical header for a given height - since we are syncing there will be no canonical hash hence we were getting nil panics - the fix is to switch to using `rawdb.ReadHeader(hash, number)` in a backward fashion until we reach the latest sprint block start header
1 parent 653c5e2 commit cb9a019

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

eth/stagedsync/stage_polygon_sync.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -322,9 +322,13 @@ func (s *polygonSyncStageService) downloadStateSyncEvents(ctx context.Context, t
322322
tipBlockNum := tip.Number.Uint64()
323323
sprintLen := borConfig.CalculateSprintLength(tipBlockNum)
324324
sprintRemainder := tipBlockNum % sprintLen
325-
if tipBlockNum > sprintLen && sprintRemainder > 0 {
326-
tipBlockNum -= sprintRemainder
327-
tip = rawdb.ReadHeaderByNumber(tx, tipBlockNum)
325+
for tipBlockNum > sprintLen && sprintRemainder > 0 {
326+
tipBlockNum--
327+
sprintRemainder--
328+
tip = rawdb.ReadHeader(tx, tip.ParentHash, tipBlockNum)
329+
if tip == nil {
330+
return errors.New("broken parent header chain")
331+
}
328332
}
329333

330334
s.logger.Info(

0 commit comments

Comments
 (0)