refactor: fetch redundancy settings and divide on it so price is always the total

This commit is contained in:
Derrick Hammer 2024-03-10 13:25:33 -04:00
parent c9683453c0
commit 21ae6d093d
Signed by: pcfreak30
GPG Key ID: C997C339BE476FF2
1 changed files with 16 additions and 2 deletions

View File

@ -95,18 +95,32 @@ SELECT AVG(rate) as average_rate FROM (
return errors.New("average rate is 0") 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 { if err != nil {
p.logger.Error("failed to fetch gouging settings", zap.Error(err)) p.logger.Error("failed to fetch gouging settings", zap.Error(err))
return 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 { if err != nil {
return err return err
} }
gouge.MaxDownloadPrice = maxDownloadPriceSc
gouge.MaxUploadPrice, err = siacoinsFromFloat(p.config.Config().Core.Storage.Sia.MaxUploadPrice / averageRate) gouge.MaxUploadPrice, err = siacoinsFromFloat(p.config.Config().Core.Storage.Sia.MaxUploadPrice / averageRate)
if err != nil { if err != nil {
return err return err