Skip to content

Commit

Permalink
Merge pull request #259 from coinbase/patrick/final-nits
Browse files Browse the repository at this point in the history
[chore] Miscellaneous Nits Before Release
  • Loading branch information
patrick-ogrady committed Dec 1, 2020
2 parents fa7c8e4 + bc0337e commit 3507943
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 18 deletions.
2 changes: 0 additions & 2 deletions reconciler/reconciler.go
Original file line number Diff line number Diff line change
Expand Up @@ -563,8 +563,6 @@ func (r *Reconciler) inactiveAccountQueue(
})
}

r.inactiveQueueMutex.Unlock()

return nil
}

Expand Down
34 changes: 19 additions & 15 deletions storage/modules/balance_storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -344,19 +344,7 @@ func (b *BalanceStorage) SetBalance(
amount *types.Amount,
block *types.BlockIdentifier,
) error {
// Remove all historical records
if err := b.removeHistoricalBalances(
ctx,
dbTransaction,
account,
amount.Currency,
-1,
true, // We want everything >= -1
); err != nil {
return err
}

// Remove all account keys
// Remove all account-related items
if err := b.deleteAccountRecords(
ctx,
dbTransaction,
Expand Down Expand Up @@ -647,6 +635,19 @@ func (b *BalanceStorage) deleteAccountRecords(
account *types.AccountIdentifier,
currency *types.Currency,
) error {
// Remove historical balance records
if err := b.removeHistoricalBalances(
ctx,
dbTx,
account,
currency,
-1,
true, // We want everything >= -1
); err != nil {
return err
}

// Remove single key records
for _, namespace := range []string{
accountNamespace,
reconciliationNamepace,
Expand Down Expand Up @@ -940,8 +941,9 @@ func (b *BalanceStorage) GetBalanceTransactional(

if exists && lastPruned.Int64() >= index {
return nil, fmt.Errorf(
"%w: last pruned %d",
"%w: desired %d last pruned %d",
storageErrs.ErrBalancePruned,
index,
lastPruned.Int64(),
)
}
Expand Down Expand Up @@ -1315,7 +1317,9 @@ func (b *BalanceStorage) removeHistoricalBalances(
}
}

if orphan {
// We don't update the pruned value when index is less
// than 0 because big.Int conversion doesn't support signed values.
if orphan || index < 0 {
return nil
}

Expand Down
2 changes: 1 addition & 1 deletion storage/modules/balance_storage_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -723,7 +723,7 @@ func TestBalance(t *testing.T) {
ctx,
account,
largeDeduction.Currency,
-1,
-1238900,
)
assert.NoError(t, err)

Expand Down
10 changes: 10 additions & 0 deletions storage/modules/counter_storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,16 @@ func (c *CounterStorage) Get(ctx context.Context, counter string) (*big.Int, err
return value, err
}

// GetTransactional returns the current value of a counter in a database.Transaction.
func (c *CounterStorage) GetTransactional(
ctx context.Context,
dbTx database.Transaction,
counter string,
) (*big.Int, error) {
_, value, err := BigIntGet(ctx, getCounterKey(counter), dbTx)
return value, err
}

// AddingBlock is called by BlockStorage when adding a block.
func (c *CounterStorage) AddingBlock(
ctx context.Context,
Expand Down

0 comments on commit 3507943

Please sign in to comment.