From 1b6b6400f565da2bd587809d256bc4d68ecf48f7 Mon Sep 17 00:00:00 2001 From: Alex Freska Date: Wed, 11 Sep 2024 10:40:08 -0400 Subject: [PATCH] refactor(renterd): gouging base units --- .changeset/tender-dragons-relax.md | 5 +++++ apps/renterd/contexts/config/resources.ts | 10 ++++------ apps/renterd/contexts/config/transform.spec.ts | 8 ++++---- apps/renterd/contexts/config/transformDown.ts | 8 ++++++-- apps/renterd/contexts/config/transformUp.ts | 9 +++++++-- 5 files changed, 26 insertions(+), 14 deletions(-) create mode 100644 .changeset/tender-dragons-relax.md diff --git a/.changeset/tender-dragons-relax.md b/.changeset/tender-dragons-relax.md new file mode 100644 index 000000000..acc40b0d5 --- /dev/null +++ b/.changeset/tender-dragons-relax.md @@ -0,0 +1,5 @@ +--- +'renterd': minor +--- + +The configuration now internally uses the updated gouging base units. diff --git a/apps/renterd/contexts/config/resources.ts b/apps/renterd/contexts/config/resources.ts index b39a315c4..74ff75eae 100644 --- a/apps/renterd/contexts/config/resources.ts +++ b/apps/renterd/contexts/config/resources.ts @@ -118,11 +118,9 @@ export function firstTimeGougingData({ return { ...gouging, maxStoragePrice: averages.settings.storage_price, - maxDownloadPrice: new BigNumber(averages.settings.download_price) - .times(TBToBytes(1)) - .toString(), - maxUploadPrice: new BigNumber(averages.settings.upload_price) - .times(TBToBytes(1)) - .toString(), + maxDownloadPrice: new BigNumber( + averages.settings.download_price + ).toString(), + maxUploadPrice: new BigNumber(averages.settings.upload_price).toString(), } } diff --git a/apps/renterd/contexts/config/transform.spec.ts b/apps/renterd/contexts/config/transform.spec.ts index e830aef31..8c150d0a6 100644 --- a/apps/renterd/contexts/config/transform.spec.ts +++ b/apps/renterd/contexts/config/transform.spec.ts @@ -353,10 +353,10 @@ describe('tansforms', () => { foobar: 'value', hostBlockHeightLeeway: 4, maxContractPrice: '20000000000000000000000000', - maxDownloadPrice: '1004310000000000000000000000', + maxDownloadPrice: '1004310000000000', maxRPCPrice: '99970619000000000000000000', maxStoragePrice: '210531181019', - maxUploadPrice: '1000232323000000000000000000', + maxUploadPrice: '1000232323000000', minAccountExpiry: 86400000000000, minMaxEphemeralAccountBalance: '1000000000000000000000000', minPriceTableValidity: 300000000000, @@ -573,10 +573,10 @@ function buildAllResponses() { gouging: { hostBlockHeightLeeway: 4, maxContractPrice: '20000000000000000000000000', - maxDownloadPrice: '1004310000000000000000000000', + maxDownloadPrice: '1004310000000000', maxRPCPrice: '99970619000000000000000000', maxStoragePrice: '210531181019', - maxUploadPrice: '1000232323000000000000000000', + maxUploadPrice: '1000232323000000', minAccountExpiry: 86400000000000, minMaxEphemeralAccountBalance: '1000000000000000000000000', minPriceTableValidity: 300000000000, diff --git a/apps/renterd/contexts/config/transformDown.ts b/apps/renterd/contexts/config/transformDown.ts index dea85145e..9c0f7b1de 100644 --- a/apps/renterd/contexts/config/transformDown.ts +++ b/apps/renterd/contexts/config/transformDown.ts @@ -20,6 +20,7 @@ import { weeksToBlocks, nanosecondsInDays, nanosecondsInMinutes, + valuePerByteToPerTB, } from '@siafoundation/units' import BigNumber from 'bignumber.js' import { @@ -148,10 +149,13 @@ export function transformDownGouging({ scDecimalPlaces ), // TB/month maxUploadPriceTB: toSiacoins( - new BigNumber(gouging.maxUploadPrice), + valuePerByteToPerTB(new BigNumber(gouging.maxUploadPrice)), + scDecimalPlaces + ), + maxDownloadPriceTB: toSiacoins( + valuePerByteToPerTB(new BigNumber(gouging.maxDownloadPrice)), scDecimalPlaces ), - maxDownloadPriceTB: toSiacoins(gouging.maxDownloadPrice, scDecimalPlaces), maxContractPrice: toSiacoins(gouging.maxContractPrice, scDecimalPlaces), maxRPCPriceMillion: toSiacoins( valuePerOneToPerMillion(new BigNumber(gouging.maxRPCPrice)), diff --git a/apps/renterd/contexts/config/transformUp.ts b/apps/renterd/contexts/config/transformUp.ts index e37ec0cf4..8cc555f8b 100644 --- a/apps/renterd/contexts/config/transformUp.ts +++ b/apps/renterd/contexts/config/transformUp.ts @@ -15,6 +15,7 @@ import { valuePerMillionToPerOne, daysInNanoseconds, minutesInNanoseconds, + valuePerTBToPerByte, } from '@siafoundation/units' import { AutopilotData, @@ -118,8 +119,12 @@ export function transformUpGouging( maxStoragePrice: toHastings( valuePerTBPerMonthToPerBytePerBlock(values.maxStoragePriceTBMonth) ).toString(), - maxUploadPrice: toHastings(values.maxUploadPriceTB).toString(), - maxDownloadPrice: toHastings(values.maxDownloadPriceTB).toString(), + maxUploadPrice: toHastings( + valuePerTBToPerByte(values.maxUploadPriceTB) + ).toString(), + maxDownloadPrice: toHastings( + valuePerTBToPerByte(values.maxDownloadPriceTB) + ).toString(), maxContractPrice: toHastings(values.maxContractPrice).toString(), hostBlockHeightLeeway: Math.round( values.hostBlockHeightLeeway?.toNumber() || 0