Skip to content

Commit

Permalink
Fixed babylon_checkpoint package logic
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeongseup committed Jan 13, 2025
1 parent a3a7da0 commit 03250b2
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ func (idx *CheckpointIndexer) batchSync(lastIndexPointerEpoch int64) (
/* new index pointer */ int64,
/* error */ error,
) {
newIndexerPointerEpoch := lastIndexPointerEpoch + 1
requester := idx.APIClient.R().SetContext(context.Background())
resp, err := requester.Get(CurrentEpochQueryPath)
if err != nil {
Expand All @@ -46,27 +47,31 @@ func (idx *CheckpointIndexer) batchSync(lastIndexPointerEpoch int64) (
idx.Debugf("current epoch: %d and last finalized epoch: %d", currentEpoch, lastFinalizedEpoch)

// NOTE: if (current epoch -1) > lastEpoch -> the indexer needs to sync more epoch
if lastIndexPointerEpoch > lastFinalizedEpoch {
if newIndexerPointerEpoch > lastFinalizedEpoch {
idx.Infof(
"last finalized epoch is %d and last db epoch is %d. nothing to sync epochs, so it'll skip the logic",
lastFinalizedEpoch, lastIndexPointerEpoch,
)
sleepDuration := (time.Second * 60)
sleepDuration := (time.Minute * 10)
idx.Infof("sleep %s sec...", sleepDuration.String())
time.Sleep(sleepDuration)
return lastIndexPointerEpoch, nil
}

for epoch := range lastFinalizedEpoch {
idx.Infof("last finalized epoch(current_epoch -1) is %d and last index pointer epoch is %d", lastFinalizedEpoch, lastIndexPointerEpoch)
idx.Infof("new sync epoch: %d", newIndexerPointerEpoch)

for epoch := range lastFinalizedEpoch + 1 {
if epoch <= 1 {
continue
}

if lastIndexPointerEpoch > epoch {
if newIndexerPointerEpoch > epoch {
idx.Debugf("skip %d epoch. the epoch was already stored in the DB", epoch)
continue
}

idx.Debugf("sync epoch: %d", epoch)
resp, err := requester.Get(EpochQueryPath(epoch))
if err != nil {
return lastIndexPointerEpoch, errors.Wrap(err, "failed to get epoch data")
Expand Down Expand Up @@ -209,7 +214,7 @@ func (idx *CheckpointIndexer) batchSync(lastIndexPointerEpoch int64) (
// update epoch & metrics
idx.updatePrometheusMetrics(epoch, blockSummary.BlockTimeStamp)
idx.Infof("updated babylon checkpoint BLS singings in %d epoch ", epoch)
return epoch + 1, nil
return newIndexerPointerEpoch, nil
}

// NOTE: sync will be working by each epoch. so, the normal situation it's not gonna run in the code.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ func (idx *CheckpointIndexer) Loop(indexPoint int64) {
common.Health.With(idx.RootLabels).Set(0)
common.Ops.With(idx.RootLabels).Inc()
isUnhealth = true
idx.Errorf("failed to sync validators vote status in %d height: %s\nit will be retried after sleep %s...",
idx.Errorf("failed to sync validators vote status in %d epoch: %s\nit will be retried after sleep %s...",
indexPoint, err, indexertypes.AfterFailedRetryTimeout.String(),
)
time.Sleep(indexertypes.AfterFailedRetryTimeout)
Expand Down

0 comments on commit 03250b2

Please sign in to comment.