Skip to content

Commit

Permalink
skip epochs during sync if synchronization failed more than 10 times
Browse files Browse the repository at this point in the history
  • Loading branch information
pk910 committed Aug 24, 2023
1 parent 33ed800 commit 5bea0b7
Showing 1 changed file with 22 additions and 7 deletions.
29 changes: 22 additions & 7 deletions indexer/synchronizer.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,15 +79,27 @@ func (sync *synchronizerState) runSync() {
sync.cachedBlocks = make(map[uint64]*CacheBlock)
sync.cachedSlot = 0
isComplete := false
retryCount := 0
synclogger.Infof("synchronization started. Head epoch: %v", sync.currentEpoch)

for {
// synchronize next epoch
syncEpoch := sync.currentEpoch

synclogger.Infof("synchronizing epoch %v", syncEpoch)
done, err := sync.syncEpoch(syncEpoch)
if done {
lastRetry := retryCount >= 10
if lastRetry {
synclogger.Infof("synchronizing epoch %v (retry: %v, last retry!)", syncEpoch, retryCount)
} else if retryCount > 0 {
synclogger.Infof("synchronizing epoch %v (retry: %v)", syncEpoch, retryCount)
} else {
synclogger.Infof("synchronizing epoch %v", syncEpoch)
}
done, err := sync.syncEpoch(syncEpoch, lastRetry)
if done || lastRetry {
if err != nil {
synclogger.Warnf("synchronization of epoch %v failed: %v - skipping epoch", syncEpoch, err)
}
retryCount = 0
finalizedEpoch, _ := sync.indexer.indexerCache.getFinalizedHead()
sync.stateMutex.Lock()
syncEpoch++
Expand All @@ -99,6 +111,7 @@ func (sync *synchronizerState) runSync() {
}
} else if err != nil {
synclogger.Warnf("synchronization of epoch %v failed: %v - Retrying in 10 sec...", syncEpoch, err)
retryCount++
time.Sleep(10 * time.Second)
}

Expand Down Expand Up @@ -134,7 +147,7 @@ func (sync *synchronizerState) checkKillChan(timeout time.Duration) bool {
}
}

func (sync *synchronizerState) syncEpoch(syncEpoch uint64) (bool, error) {
func (sync *synchronizerState) syncEpoch(syncEpoch uint64, lastTry bool) (bool, error) {
if db.IsEpochSynchronized(syncEpoch) {
return true, nil
}
Expand All @@ -144,8 +157,10 @@ func (sync *synchronizerState) syncEpoch(syncEpoch uint64) (bool, error) {
// load epoch assignments
epochAssignments, err := client.rpcClient.GetEpochAssignments(syncEpoch)
if err != nil || epochAssignments == nil {
synclogger.Errorf("error fetching epoch %v duties: %v", syncEpoch, err)
return false, err
return false, fmt.Errorf("error fetching epoch %v duties: %v", syncEpoch, err)
}
if epochAssignments.AttestorAssignments == nil && !lastTry {
return false, fmt.Errorf("error fetching epoch %v duties: attestor assignments empty", syncEpoch)
}

if sync.checkKillChan(0) {
Expand Down Expand Up @@ -196,7 +211,7 @@ func (sync *synchronizerState) syncEpoch(syncEpoch uint64) (bool, error) {
}
epochStats.loadValidatorStats(client, epochAssignments.DependendStateRef)

if epochStats.validatorStats == nil {
if epochStats.validatorStats == nil && !lastTry {
return false, fmt.Errorf("error fetching validator stats for epoch %v: %v", syncEpoch, err)
}
if sync.checkKillChan(0) {
Expand Down

0 comments on commit 5bea0b7

Please sign in to comment.