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 48272b8
Showing 1 changed file with 31 additions and 15 deletions.
46 changes: 31 additions & 15 deletions reconciler/reconciler.go
Original file line number Diff line number Diff line change
Expand Up @@ -593,6 +593,35 @@ func (r *Reconciler) reconcileActiveAccounts(
}
}

// shouldAttemptInactiveReconciliation returns a boolean indicating whether
// inactive reconciliation should be attempted based on syncing status.
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 +634,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 48272b8

Please sign in to comment.