From f357d2ef23f47f00a1acfd5f0d68d422f0ac4873 Mon Sep 17 00:00:00 2001 From: Christopher Schinnerl Date: Wed, 3 Jul 2024 09:23:26 +0200 Subject: [PATCH] Use unit SC/TB/month for maxStoragePrice when pinning it (#1358) --- internal/bus/pinmanager.go | 44 +++++++++----------------------------- 1 file changed, 10 insertions(+), 34 deletions(-) diff --git a/internal/bus/pinmanager.go b/internal/bus/pinmanager.go index 02e4df79b..21591b21c 100644 --- a/internal/bus/pinmanager.go +++ b/internal/bus/pinmanager.go @@ -265,15 +265,9 @@ func (pm *pinManager) updateGougingSettings(ctx context.Context, pins api.Gougin if err != nil { pm.logger.Warn("failed to convert max download price to currency") } else if !gs.MaxDownloadPrice.Equals(update) { - bkp := gs.MaxDownloadPrice gs.MaxDownloadPrice = update - if err := gs.Validate(); err != nil { - pm.logger.Warn("failed to update gouging setting, new download price makes the setting invalid", zap.Error(err)) - gs.MaxDownloadPrice = bkp - } else { - pm.logger.Infow("updating max download price", "old", bkp, "new", gs.MaxDownloadPrice, "rate", rate) - updated = true - } + pm.logger.Infow("updating max download price", "old", gs.MaxDownloadPrice, "new", update, "rate", rate) + updated = true } } @@ -283,33 +277,21 @@ func (pm *pinManager) updateGougingSettings(ctx context.Context, pins api.Gougin if err != nil { pm.logger.Warnw("failed to convert max RPC price to currency", zap.Error(err)) } else if !gs.MaxRPCPrice.Equals(update) { - bkp := gs.MaxRPCPrice + pm.logger.Infow("updating max RPC price", "old", gs.MaxRPCPrice, "new", update, "rate", rate) gs.MaxRPCPrice = update - if err := gs.Validate(); err != nil { - pm.logger.Warnw("failed to update gouging setting, new RPC price makes the setting invalid", zap.Error(err)) - gs.MaxRPCPrice = bkp - } else { - pm.logger.Infow("updating max RPC price", "old", bkp, "new", gs.MaxRPCPrice, "rate", rate) - updated = true - } + updated = true } } // update max storage price if pins.MaxStorage.IsPinned() { - update, err := convertCurrencyToSC(decimal.NewFromFloat(pins.MaxStorage.Value), rate) + maxStorageCurr, err := convertCurrencyToSC(decimal.NewFromFloat(pins.MaxStorage.Value), rate) if err != nil { pm.logger.Warnw("failed to convert max storage price to currency", zap.Error(err)) - } else if !gs.MaxStoragePrice.Equals(update) { - bkp := gs.MaxStoragePrice + } else if update := maxStorageCurr.Div64(1e12).Div64(144 * 30); !gs.MaxStoragePrice.Equals(update) { // convert from SC/TB/month to SC/byte/block + pm.logger.Infow("updating max storage price", "old", gs.MaxStoragePrice, "new", update, "rate", rate) gs.MaxStoragePrice = update - if err := gs.Validate(); err != nil { - pm.logger.Warnw("failed to update gouging setting, new storage price makes the setting invalid", zap.Error(err)) - gs.MaxStoragePrice = bkp - } else { - pm.logger.Infow("updating max storage price", "old", bkp, "new", gs.MaxStoragePrice, "rate", rate) - updated = true - } + updated = true } } @@ -319,15 +301,9 @@ func (pm *pinManager) updateGougingSettings(ctx context.Context, pins api.Gougin if err != nil { pm.logger.Warnw("failed to convert max upload price to currency", zap.Error(err)) } else if !gs.MaxUploadPrice.Equals(update) { - bkp := gs.MaxUploadPrice + pm.logger.Infow("updating max upload price", "old", gs.MaxUploadPrice, "new", update, "rate", rate) gs.MaxUploadPrice = update - if err := gs.Validate(); err != nil { - pm.logger.Warnw("failed to update gouging setting, new upload price makes the setting invalid", zap.Error(err)) - gs.MaxUploadPrice = bkp - } else { - pm.logger.Infow("updating max upload price", "old", bkp, "new", gs.MaxUploadPrice, "rate", rate) - updated = true - } + updated = true } }