Skip to content

Commit a989b53

Browse files
Don't protect against orphans
1 parent 084899f commit a989b53

File tree

1 file changed

+7
-15
lines changed

1 file changed

+7
-15
lines changed

storage/balance_storage.go

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -511,7 +511,7 @@ func (b *BalanceStorage) UpdateBalance(
511511
var storedValue string
512512
if exists {
513513
// Get most recent historical balance
514-
balance, lastUpdate, err := b.getHistoricalBalance(
514+
balance, err := b.getHistoricalBalance(
515515
ctx,
516516
dbTransaction,
517517
change.Account,
@@ -526,12 +526,6 @@ func (b *BalanceStorage) UpdateBalance(
526526
default:
527527
storedValue = balance.Value
528528
}
529-
530-
// Ensure the caller isn't trying to orphan balances by calling
531-
// UpdateBalance.
532-
if lastUpdate != nil && lastUpdate.Index >= change.Block.Index {
533-
return errors.New("cannot update already updated balance")
534-
}
535529
}
536530

537531
// Find account existing value whether the account is new, has an
@@ -651,7 +645,7 @@ func (b *BalanceStorage) GetBalanceTransactional(
651645
block *types.BlockIdentifier,
652646
) (*types.Amount, error) {
653647
if block == nil {
654-
return nil, errors.New("block cannot be empty")
648+
return nil, ErrBlockNil
655649
}
656650

657651
key := GetAccountKey(account, currency)
@@ -701,7 +695,7 @@ func (b *BalanceStorage) GetBalanceTransactional(
701695
)
702696
}
703697

704-
amount, _, err := b.getHistoricalBalance(
698+
amount, err := b.getHistoricalBalance(
705699
ctx,
706700
dbTx,
707701
account,
@@ -906,9 +900,8 @@ func (b *BalanceStorage) getHistoricalBalance(
906900
account *types.AccountIdentifier,
907901
currency *types.Currency,
908902
block *types.BlockIdentifier,
909-
) (*types.Amount, *types.BlockIdentifier, error) {
903+
) (*types.Amount, error) {
910904
var foundAmount *types.Amount
911-
var foundBlock *types.BlockIdentifier
912905
_, err := dbTx.Scan(
913906
ctx,
914907
GetHistoricalBalancePrefix(account, currency),
@@ -935,20 +928,19 @@ func (b *BalanceStorage) getHistoricalBalance(
935928
}
936929

937930
foundAmount = deserialBal.Amount
938-
foundBlock = deserialBal.Block
939931
return errAccountFound
940932
},
941933
false,
942934
true,
943935
)
944936
if errors.Is(err, errAccountFound) {
945-
return foundAmount, foundBlock, nil
937+
return foundAmount, nil
946938
}
947939
if err != nil {
948-
return nil, nil, fmt.Errorf("%w: database scan failed", err)
940+
return nil, fmt.Errorf("%w: database scan failed", err)
949941
}
950942

951-
return nil, nil, errAccountMissing
943+
return nil, errAccountMissing
952944
}
953945

954946
func (b *BalanceStorage) updateAccountEntry(

0 commit comments

Comments
 (0)