Skip to content

Commit

Permalink
stagedsync: polygon sync stage fix nil panic when downloading state s…
Browse files Browse the repository at this point in the history
…ync 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
  • Loading branch information
taratorio authored May 27, 2024
1 parent 653c5e2 commit cb9a019
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions eth/stagedsync/stage_polygon_sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -322,9 +322,13 @@ func (s *polygonSyncStageService) downloadStateSyncEvents(ctx context.Context, t
tipBlockNum := tip.Number.Uint64()
sprintLen := borConfig.CalculateSprintLength(tipBlockNum)
sprintRemainder := tipBlockNum % sprintLen
if tipBlockNum > sprintLen && sprintRemainder > 0 {
tipBlockNum -= sprintRemainder
tip = rawdb.ReadHeaderByNumber(tx, tipBlockNum)
for tipBlockNum > sprintLen && sprintRemainder > 0 {
tipBlockNum--
sprintRemainder--
tip = rawdb.ReadHeader(tx, tip.ParentHash, tipBlockNum)
if tip == nil {
return errors.New("broken parent header chain")
}
}

s.logger.Info(
Expand Down

0 comments on commit cb9a019

Please sign in to comment.