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
This commit is contained in:
Stefan 2023-03-01 11:42:08 +01:00 committed by Stefan Dunca
parent 30f167e63d
commit 226fa7d696
2 changed files with 14 additions and 12 deletions

View File

@ -33,7 +33,7 @@ var averageBlockDurationForChain = map[uint64]time.Duration{
const (
twiceADayStride time.Duration = time.Duration(12) * time.Hour
weekStride = 14 * twiceADayStride
fourMonthsStride = 4 /*months*/ * 4 * weekStride
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
}

View File

@ -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)
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,
}