Skip to content

Commit f357d2e

Browse files
Use unit SC/TB/month for maxStoragePrice when pinning it (#1358)
1 parent 4b3ab23 commit f357d2e

File tree

1 file changed

+10
-34
lines changed

1 file changed

+10
-34
lines changed

internal/bus/pinmanager.go

Lines changed: 10 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -265,15 +265,9 @@ func (pm *pinManager) updateGougingSettings(ctx context.Context, pins api.Gougin
265265
if err != nil {
266266
pm.logger.Warn("failed to convert max download price to currency")
267267
} else if !gs.MaxDownloadPrice.Equals(update) {
268-
bkp := gs.MaxDownloadPrice
269268
gs.MaxDownloadPrice = update
270-
if err := gs.Validate(); err != nil {
271-
pm.logger.Warn("failed to update gouging setting, new download price makes the setting invalid", zap.Error(err))
272-
gs.MaxDownloadPrice = bkp
273-
} else {
274-
pm.logger.Infow("updating max download price", "old", bkp, "new", gs.MaxDownloadPrice, "rate", rate)
275-
updated = true
276-
}
269+
pm.logger.Infow("updating max download price", "old", gs.MaxDownloadPrice, "new", update, "rate", rate)
270+
updated = true
277271
}
278272
}
279273

@@ -283,33 +277,21 @@ func (pm *pinManager) updateGougingSettings(ctx context.Context, pins api.Gougin
283277
if err != nil {
284278
pm.logger.Warnw("failed to convert max RPC price to currency", zap.Error(err))
285279
} else if !gs.MaxRPCPrice.Equals(update) {
286-
bkp := gs.MaxRPCPrice
280+
pm.logger.Infow("updating max RPC price", "old", gs.MaxRPCPrice, "new", update, "rate", rate)
287281
gs.MaxRPCPrice = update
288-
if err := gs.Validate(); err != nil {
289-
pm.logger.Warnw("failed to update gouging setting, new RPC price makes the setting invalid", zap.Error(err))
290-
gs.MaxRPCPrice = bkp
291-
} else {
292-
pm.logger.Infow("updating max RPC price", "old", bkp, "new", gs.MaxRPCPrice, "rate", rate)
293-
updated = true
294-
}
282+
updated = true
295283
}
296284
}
297285

298286
// update max storage price
299287
if pins.MaxStorage.IsPinned() {
300-
update, err := convertCurrencyToSC(decimal.NewFromFloat(pins.MaxStorage.Value), rate)
288+
maxStorageCurr, err := convertCurrencyToSC(decimal.NewFromFloat(pins.MaxStorage.Value), rate)
301289
if err != nil {
302290
pm.logger.Warnw("failed to convert max storage price to currency", zap.Error(err))
303-
} else if !gs.MaxStoragePrice.Equals(update) {
304-
bkp := gs.MaxStoragePrice
291+
} else if update := maxStorageCurr.Div64(1e12).Div64(144 * 30); !gs.MaxStoragePrice.Equals(update) { // convert from SC/TB/month to SC/byte/block
292+
pm.logger.Infow("updating max storage price", "old", gs.MaxStoragePrice, "new", update, "rate", rate)
305293
gs.MaxStoragePrice = update
306-
if err := gs.Validate(); err != nil {
307-
pm.logger.Warnw("failed to update gouging setting, new storage price makes the setting invalid", zap.Error(err))
308-
gs.MaxStoragePrice = bkp
309-
} else {
310-
pm.logger.Infow("updating max storage price", "old", bkp, "new", gs.MaxStoragePrice, "rate", rate)
311-
updated = true
312-
}
294+
updated = true
313295
}
314296
}
315297

@@ -319,15 +301,9 @@ func (pm *pinManager) updateGougingSettings(ctx context.Context, pins api.Gougin
319301
if err != nil {
320302
pm.logger.Warnw("failed to convert max upload price to currency", zap.Error(err))
321303
} else if !gs.MaxUploadPrice.Equals(update) {
322-
bkp := gs.MaxUploadPrice
304+
pm.logger.Infow("updating max upload price", "old", gs.MaxUploadPrice, "new", update, "rate", rate)
323305
gs.MaxUploadPrice = update
324-
if err := gs.Validate(); err != nil {
325-
pm.logger.Warnw("failed to update gouging setting, new upload price makes the setting invalid", zap.Error(err))
326-
gs.MaxUploadPrice = bkp
327-
} else {
328-
pm.logger.Infow("updating max upload price", "old", bkp, "new", gs.MaxUploadPrice, "rate", rate)
329-
updated = true
330-
}
306+
updated = true
331307
}
332308
}
333309

0 commit comments

Comments
 (0)