Skip to content

Commit 7e2e192

Browse files
Use unit SC/TB/month for maxStoragePrice when pinning it (#1358)
2 parents b052e0c + 49bda1f commit 7e2e192

File tree

1 file changed

+9
-35
lines changed

1 file changed

+9
-35
lines changed

internal/bus/pinmanager.go

Lines changed: 9 additions & 35 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,15 +277,9 @@ 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

@@ -300,18 +288,10 @@ func (pm *pinManager) updateGougingSettings(ctx context.Context, pins api.Gougin
300288
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-
}
304-
update := maxStorageCurr.Div64(1e12).Div64(144 * 30) // convert from SC/TB/month to SC/byte/block
305-
if !gs.MaxStoragePrice.Equals(update) {
306-
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)
307293
gs.MaxStoragePrice = update
308-
if err := gs.Validate(); err != nil {
309-
pm.logger.Warnw("failed to update gouging setting, new storage price makes the setting invalid", zap.Error(err))
310-
gs.MaxStoragePrice = bkp
311-
} else {
312-
pm.logger.Infow("updating max storage price", "old", bkp, "new", gs.MaxStoragePrice, "rate", rate)
313-
updated = true
314-
}
294+
updated = true
315295
}
316296
}
317297

@@ -321,15 +301,9 @@ func (pm *pinManager) updateGougingSettings(ctx context.Context, pins api.Gougin
321301
if err != nil {
322302
pm.logger.Warnw("failed to convert max upload price to currency", zap.Error(err))
323303
} else if !gs.MaxUploadPrice.Equals(update) {
324-
bkp := gs.MaxUploadPrice
304+
pm.logger.Infow("updating max upload price", "old", gs.MaxUploadPrice, "new", update, "rate", rate)
325305
gs.MaxUploadPrice = update
326-
if err := gs.Validate(); err != nil {
327-
pm.logger.Warnw("failed to update gouging setting, new upload price makes the setting invalid", zap.Error(err))
328-
gs.MaxUploadPrice = bkp
329-
} else {
330-
pm.logger.Infow("updating max upload price", "old", bkp, "new", gs.MaxUploadPrice, "rate", rate)
331-
updated = true
332-
}
306+
updated = true
333307
}
334308
}
335309

0 commit comments

Comments
 (0)