Skip to content

Commit

Permalink
Remove account updated error
Browse files Browse the repository at this point in the history
  • Loading branch information
patrick-ogrady committed Oct 25, 2020
1 parent 578663a commit bfa6e76
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 40 deletions.
6 changes: 0 additions & 6 deletions reconciler/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,6 @@ var (
// we are close to the live head (waitToCheckDiff).
ErrHeadBlockBehindLive = errors.New("head block behind")

// ErrAccountUpdated is returned when the
// account was updated at a height later than
// the live height (when the account balance was fetched).
ErrAccountUpdated = errors.New("account updated")

// ErrBlockGone is returned when the processed block
// head is greater than the live head but the block
// does not exist in the store. This likely means
Expand All @@ -50,7 +45,6 @@ var (
func Err(err error) bool {
reconcilerErrors := []error{
ErrHeadBlockBehindLive,
ErrAccountUpdated,
ErrBlockGone,
ErrGetCurrentBlockFailed,
ErrBlockExistsFailed,
Expand Down
40 changes: 6 additions & 34 deletions reconciler/reconciler.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,8 @@ type Helper interface {
ctx context.Context,
account *types.AccountIdentifier,
currency *types.Currency,
headBlock *types.BlockIdentifier,
) (*types.Amount, *types.BlockIdentifier, error)
block *types.BlockIdentifier,
) (*types.Amount, error)

LiveBalance(
ctx context.Context,
Expand Down Expand Up @@ -446,12 +446,12 @@ func (r *Reconciler) CompareBalance(
)
}

// Check if live block < computed head
computedBalance, computedBlock, err := r.helper.ComputedBalance(
// Get computed balance at live block
computedBalance, err := r.helper.ComputedBalance(
ctx,
account,
currency,
head,
liveBlock,
)
if err != nil {
return zeroString, "", head.Index, fmt.Errorf(
Expand All @@ -463,15 +463,6 @@ func (r *Reconciler) CompareBalance(
)
}

if liveBlock.Index < computedBlock.Index {
return zeroString, "", head.Index, fmt.Errorf(
"%w %+v updated at %d",
ErrAccountUpdated,
account,
computedBlock.Index,
)
}

difference, err := types.SubtractValues(amount, computedBalance.Value)
if err != nil {
return "", "", -1, err
Expand Down Expand Up @@ -676,23 +667,6 @@ func (r *Reconciler) accountReconciliation(
)
}

if errors.Is(err, ErrAccountUpdated) {
// If account was updated, it must be
// enqueued again
r.debugLog(
"skipping reconciliation because account %s updated",
types.PrintStruct(accountCurrency.Account),
)

return r.handler.ReconciliationSkipped(
ctx,
reconciliationType,
account,
currency,
AccountUpdated,
)
}

return err
}

Expand Down Expand Up @@ -773,6 +747,7 @@ func (r *Reconciler) updateLastChecked(index int64) {
// were correct.
func (r *Reconciler) reconcileActiveAccounts(ctx context.Context) error { // nolint:gocognit
for {
// TODO: delete old states after reconciled (otherwise could use significantly more storage)..optionally
select {
case <-ctx.Done():
return ctx.Err()
Expand All @@ -795,9 +770,6 @@ func (r *Reconciler) reconcileActiveAccounts(ctx context.Context) error { // nol
continue
}

// TODO: Skip reconciliation if account has been updated so we don't lookup
// balance unnecessarily

amount, block, err := r.bestLiveBalance(
ctx,
balanceChange.Account,
Expand Down

0 comments on commit bfa6e76

Please sign in to comment.