From 21ae6d093da13447da33045542304bc79db6dc89 Mon Sep 17 00:00:00 2001 From: Derrick Hammer Date: Sun, 10 Mar 2024 13:25:33 -0400 Subject: [PATCH] refactor: fetch redundancy settings and divide on it so price is always the total --- renter/price_tracker.go | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/renter/price_tracker.go b/renter/price_tracker.go index 804d61f..aaee177 100644 --- a/renter/price_tracker.go +++ b/renter/price_tracker.go @@ -95,18 +95,32 @@ SELECT AVG(rate) as average_rate FROM ( return errors.New("average rate is 0") } - gouge, err := p.renter.GougingSettings(context.Background()) + ctx := context.Background() + + gouge, err := p.renter.GougingSettings(ctx) if err != nil { p.logger.Error("failed to fetch gouging settings", zap.Error(err)) return err } - gouge.MaxDownloadPrice, err = siacoinsFromFloat(p.config.Config().Core.Storage.Sia.MaxDownloadPrice / averageRate) + redundancy, err := p.renter.RedundancySettings(ctx) + + if err != nil { + p.logger.Error("failed to fetch redundancy settings", zap.Error(err)) + return err + } + + maxDownloadPrice := p.config.Config().Core.Storage.Sia.MaxDownloadPrice / averageRate + maxDownloadPrice = maxDownloadPrice / redundancy.Redundancy() + + maxDownloadPriceSc, err := siacoinsFromFloat(maxDownloadPrice) if err != nil { return err } + gouge.MaxDownloadPrice = maxDownloadPriceSc + gouge.MaxUploadPrice, err = siacoinsFromFloat(p.config.Config().Core.Storage.Sia.MaxUploadPrice / averageRate) if err != nil { return err