Skip to content

Commit

Permalink
nits
Browse files Browse the repository at this point in the history
  • Loading branch information
patrick-ogrady committed Jul 14, 2020
1 parent 9cff6f8 commit ff0c8ad
Showing 1 changed file with 25 additions and 15 deletions.
40 changes: 25 additions & 15 deletions reconciler/reconciler.go
Original file line number Diff line number Diff line change
Expand Up @@ -593,6 +593,29 @@ func (r *Reconciler) reconcileActiveAccounts(
}
}

func (r *Reconciler) shouldAttemptInactiveReconciliation(ctx context.Context) (bool, *types.BlockIdentifier) {
head, err := r.helper.CurrentBlock(ctx)
// When first start syncing, this loop may run before the genesis block is synced.
// If this is the case, we should sleep and try again later instead of exiting.
if err != nil {
if r.debugLogging {
log.Println("waiting to start intactive reconciliation until a block is synced...")
}

return false, nil
}

if head.Index < r.highWaterMark {
if r.debugLogging {
log.Println("waiting to continue intactive reconciliation until reaching high water mark...")
}

return false, nil
}

return true, head
}

// reconcileInactiveAccounts selects a random account
// from all previously seen accounts and reconciles
// the balance. This is useful for detecting balance
Expand All @@ -605,21 +628,8 @@ func (r *Reconciler) reconcileInactiveAccounts(
return ctx.Err()
}

head, err := r.helper.CurrentBlock(ctx)
// When first start syncing, this loop may run before the genesis block is synced.
// If this is the case, we should sleep and try again later instead of exiting.
if err != nil {
if r.debugLogging {
log.Println("waiting to start intactive reconciliation until a block is synced...")
}
time.Sleep(inactiveReconciliationSleep)
continue
}

if head.Index < r.highWaterMark {
if r.debugLogging {
log.Println("waiting to continue intactive reconciliation until reaching high water mark...")
}
shouldAttempt, head := r.shouldAttemptInactiveReconciliation(ctx)
if !shouldAttempt {
time.Sleep(inactiveReconciliationSleep)
continue
}
Expand Down

0 comments on commit ff0c8ad

Please sign in to comment.