Skip to content

Commit

Permalink
refactor(renterd): min account expiry and min price table validity units
Browse files Browse the repository at this point in the history
  • Loading branch information
alexfreska committed Dec 12, 2024
1 parent b3e42fb commit 0f8b3ab
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 15 deletions.
5 changes: 5 additions & 0 deletions .changeset/rich-rats-try.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'renterd': minor
---

The min account expiry and min price table validity configuration settings are now stored in milliseconds.
5 changes: 5 additions & 0 deletions .changeset/spicy-dots-wait.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@siafoundation/units': minor
---

Add and remove time methods.
8 changes: 4 additions & 4 deletions apps/renterd/contexts/config/transform.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -270,9 +270,9 @@ describe('tansforms', () => {
maxRPCPrice: '99970619000000000000000000',
maxStoragePrice: '210531181019',
maxUploadPrice: '1000232323000000',
minAccountExpiry: 86400000000000,
minAccountExpiry: 86400000,
minMaxEphemeralAccountBalance: '1000000000000000000000000',
minPriceTableValidity: 300000000000,
minPriceTableValidity: 300000,
})
})
})
Expand Down Expand Up @@ -503,9 +503,9 @@ function buildAllResponses() {
maxRPCPrice: '99970619000000000000000000',
maxStoragePrice: '210531181019',
maxUploadPrice: '1000232323000000',
minAccountExpiry: 86400000000000,
minAccountExpiry: 86400000,
minMaxEphemeralAccountBalance: '1000000000000000000000000',
minPriceTableValidity: 300000000000,
minPriceTableValidity: 300000,
} as SettingsGouging,
pinned: {
currency: 'usd' as CurrencyId,
Expand Down
8 changes: 4 additions & 4 deletions apps/renterd/contexts/config/transformDown.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import {
import {
blocksToWeeks,
bytesToTB,
nanosecondsInDays,
nanosecondsInMinutes,
millisecondsInDays,
millisecondsInMinutes,
toSiacoins,
valuePerBytePerBlockToPerTBPerMonth,
valuePerByteToPerTB,
Expand Down Expand Up @@ -106,10 +106,10 @@ export function transformDownGouging({
),
hostBlockHeightLeeway: new BigNumber(gouging.hostBlockHeightLeeway),
minPriceTableValidityMinutes: new BigNumber(
nanosecondsInMinutes(gouging.minPriceTableValidity)
millisecondsInMinutes(gouging.minPriceTableValidity)
),
minAccountExpiryDays: new BigNumber(
nanosecondsInDays(gouging.minAccountExpiry)
millisecondsInDays(gouging.minAccountExpiry)
),
minMaxEphemeralAccountBalance: toSiacoins(
gouging.minMaxEphemeralAccountBalance,
Expand Down
6 changes: 4 additions & 2 deletions apps/renterd/contexts/config/transformUp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import {
daysInNanoseconds,
minutesInNanoseconds,
valuePerTBToPerByte,
minutesInMilliseconds,
daysInMilliseconds,
} from '@siafoundation/units'
import {
getAdvancedDefaultsAutopilot,
Expand Down Expand Up @@ -102,10 +104,10 @@ export function transformUpGouging(
maxContractPrice: toHastings(v.maxContractPrice).toString(),
hostBlockHeightLeeway: Math.round(v.hostBlockHeightLeeway.toNumber() || 0),
minPriceTableValidity: Math.round(
minutesInNanoseconds(v.minPriceTableValidityMinutes.toNumber() || 0)
minutesInMilliseconds(v.minPriceTableValidityMinutes.toNumber() || 0)
),
minAccountExpiry: Math.round(
daysInNanoseconds(v.minAccountExpiryDays.toNumber())
daysInMilliseconds(v.minAccountExpiryDays.toNumber())
),
minMaxEphemeralAccountBalance: toHastings(
v.minMaxEphemeralAccountBalance
Expand Down
10 changes: 5 additions & 5 deletions libs/units/src/time.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,16 @@ export function nowInMilliseconds() {
return new Date().getTime()
}

export function nanosecondsInMinutes(ns: number) {
return ns / 1000 / 1000 / 1000 / 60
export function millisecondsInMinutes(ms: number) {
return ms / 1000 / 60
}

export function millisecondsInHours(ms: number) {
return ms / 1000 / 1000 / 60 / 60
return ms / 1000 / 60 / 60
}

export function millisecondsInMinutes(ms: number) {
return ms / 1000 / 60
export function millisecondsInDays(ms: number) {
return ms / 1000 / 60 / 60 / 24
}

export function microsecondsInMinutes(us: number) {
Expand Down

0 comments on commit 0f8b3ab

Please sign in to comment.