diff --git a/reconciler/reconciler.go b/reconciler/reconciler.go index 21c93354..cee3b50a 100644 --- a/reconciler/reconciler.go +++ b/reconciler/reconciler.go @@ -563,8 +563,6 @@ func (r *Reconciler) inactiveAccountQueue( }) } - r.inactiveQueueMutex.Unlock() - return nil } diff --git a/storage/modules/balance_storage.go b/storage/modules/balance_storage.go index 523106bc..49b9a349 100644 --- a/storage/modules/balance_storage.go +++ b/storage/modules/balance_storage.go @@ -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, @@ -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, @@ -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(), ) } @@ -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 } diff --git a/storage/modules/balance_storage_test.go b/storage/modules/balance_storage_test.go index c5111e19..1d35fb4d 100644 --- a/storage/modules/balance_storage_test.go +++ b/storage/modules/balance_storage_test.go @@ -723,7 +723,7 @@ func TestBalance(t *testing.T) { ctx, account, largeDeduction.Currency, - -1, + -1238900, ) assert.NoError(t, err) diff --git a/storage/modules/counter_storage.go b/storage/modules/counter_storage.go index 461ec4df..45901869 100644 --- a/storage/modules/counter_storage.go +++ b/storage/modules/counter_storage.go @@ -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,