From 226fa7d69636050486a2c0de6dd233e493749bf7 Mon Sep 17 00:00:00 2001 From: Stefan Date: Wed, 1 Mar 2023 11:42:08 +0100 Subject: [PATCH] chore(wallet) increase the all-time fetching sample count Also: - extend maximum expected DB entries to fetch - fix test TestBalanceHistoryGetWithoutOverlappingFetch passing because of all-time stride side effect Closes status-desktop #9624 --- services/wallet/history/balance.go | 10 +++++----- services/wallet/history/balance_test.go | 16 +++++++++------- 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/services/wallet/history/balance.go b/services/wallet/history/balance.go index 7b120f7a5..7a90cf816 100644 --- a/services/wallet/history/balance.go +++ b/services/wallet/history/balance.go @@ -31,9 +31,9 @@ var averageBlockDurationForChain = map[uint64]time.Duration{ // Must have a common divisor to share common blocks and increase the cache hit const ( - twiceADayStride time.Duration = time.Duration(12) * time.Hour - weekStride = 14 * twiceADayStride - fourMonthsStride = 4 /*months*/ * 4 * weekStride + twiceADayStride time.Duration = time.Duration(12) * time.Hour + weekStride = 14 * twiceADayStride + monthsStride = 1 /*months*/ * 4 * weekStride ) // bitsetFilters used to fetch relevant data points in one batch and to increase cache hit @@ -74,7 +74,7 @@ var timeIntervalToStrideDuration = map[TimeInterval]time.Duration{ BalanceHistory1Month: twiceADayStride, BalanceHistory6Months: weekStride, BalanceHistory1Year: weekStride, - BalanceHistoryAllTime: fourMonthsStride, + BalanceHistoryAllTime: monthsStride, } func strideBlockCount(timeInterval TimeInterval, chainID uint64) int { @@ -244,7 +244,7 @@ func (b *Balance) get(ctx context.Context, chainID uint64, currency string, addr startTimestamp = endTimestamp - int64(timeIntervalDuration[timeInterval].Seconds()) fetchTimestamp = startTimestamp - int64(timeIntervalToStrideDuration[timeInterval].Seconds()) } - cached, _, err := b.db.filter(&assetIdentity{chainID, address, currency}, nil, &balanceFilter{fetchTimestamp, endTimestamp, expandFlag(timeIntervalToBitsetFilter[timeInterval])}, 200, asc) + cached, _, err := b.db.filter(&assetIdentity{chainID, address, currency}, nil, &balanceFilter{fetchTimestamp, endTimestamp, expandFlag(timeIntervalToBitsetFilter[timeInterval])}, 800, asc) if err != nil { return nil, err } diff --git a/services/wallet/history/balance_test.go b/services/wallet/history/balance_test.go index 22426808b..a2b61f2bf 100644 --- a/services/wallet/history/balance_test.go +++ b/services/wallet/history/balance_test.go @@ -273,16 +273,18 @@ func TestBalanceHistoryGetWithoutOverlappingFetch(t *testing.T) { currentTimestamp := dataSource.TimeNow() getUntilTimestamp := currentTimestamp - int64((400 /*days*/ * 24 * time.Hour).Seconds()) - fetchInterval := testInput.interval + 3 - if fetchInterval > BalanceHistoryAllTime { - fetchInterval = BalanceHistory7Days + BalanceHistoryAllTime - testInput.interval + getInterval := testInput.interval + 3 + if getInterval > BalanceHistoryAllTime { + getInterval = BalanceHistory7Days + BalanceHistoryAllTime - testInput.interval } - err := bh.update(context.Background(), dataSource, common.Address{7}, fetchInterval) + err := bh.update(context.Background(), dataSource, common.Address{7}, testInput.interval) require.NoError(t, err) - balanceData, err := bh.get(context.Background(), dataSource.ChainID(), dataSource.Currency(), common.Address{7}, getUntilTimestamp, testInput.interval) + balanceData, err := bh.get(context.Background(), dataSource.ChainID(), dataSource.Currency(), common.Address{7}, getUntilTimestamp, getInterval) require.NoError(t, err) - require.Equal(t, 0, len(balanceData)) + if testInput.interval != BalanceHistoryAllTime { + require.Equal(t, 0, len(balanceData)) + } }) } } @@ -688,7 +690,7 @@ func TestBlockStrideHaveCommonDivisor(t *testing.T) { func TestBlockStrideMatchesBitsetFilter(t *testing.T) { filterToStrideEquivalence := map[bitsetFilter]time.Duration{ - filterAllTime: fourMonthsStride, + filterAllTime: monthsStride, filterWeekly: weekStride, filterTwiceADay: twiceADayStride, }