Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 13 additions & 8 deletions module/state_synchronization/indexer/indexer.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,17 +158,22 @@ func (i *Indexer) onBlockIndexed() error {
highestIndexedHeight := i.jobConsumer.LastProcessedIndex()

if lastProcessedHeight < highestIndexedHeight {
if lastProcessedHeight+1000 < highestIndexedHeight {
i.log.Warn().Msgf("notifying processed heights from %d to %d", lastProcessedHeight+1, highestIndexedHeight)
}
// we need loop here because it's possible for a height to be missed here,
// we should guarantee all heights are processed
for height := lastProcessedHeight + 1; height <= highestIndexedHeight; height++ {
header, err := i.indexer.headers.ByHeight(height)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This call might cause 30% CPU spikes on startup for hours, if there are lots of height to iterate.

We are not using the header, I don't think it's necessary to query it.

if err != nil {
// if the execution data is available, the block must be locally finalized
i.log.Error().Err(err).Msgf("could not get header for height %d:", height)
return fmt.Errorf("could not get header for height %d: %w", height, err)
Copy link
Member Author

@zhangchiqing zhangchiqing Dec 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This error would not happen, because AN is only syncing execution data for sealed blocks, so an indexed height must be finalized already.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AN is only syncing execution data for sealed blocks

this is currently true. this system will be replaced soon by one that does sync unsealed data, but this logic is not used.

}

i.OnBlockProcessed(header.Height)
// Use BlockIDByHeight instead of ByHeight since we only need to verify the block exists
// and don't need the full header data. This avoids expensive header deserialization.
// _, err := i.indexer.headers.BlockIDByHeight(height)
// if err != nil {
// // if the execution data is available, the block must be locally finalized
// i.log.Error().Err(err).Msgf("could not get header for height %d:", height)
// return fmt.Errorf("could not get header for height %d: %w", height, err)
// }

i.OnBlockProcessed(height)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm actually not sure why this is needed. Do we remember the original issue that requires us to add this patch?

Copy link
Contributor

@peterargue peterargue Dec 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe it was related to the execution data tracker/pruner, but I don't remember why we needed to explicitly check that the header existed locally.

}
i.lastProcessedHeight.Store(highestIndexedHeight)
}
Expand Down
Loading