Skip to content

Commit

Permalink
fix: renterd storage and upload config without redundancy
Browse files Browse the repository at this point in the history
  • Loading branch information
alexfreska committed Feb 24, 2024
1 parent df37738 commit 7108516
Show file tree
Hide file tree
Showing 15 changed files with 138 additions and 496 deletions.
5 changes: 5 additions & 0 deletions .changeset/strong-bags-beam.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'renterd': minor
---

Storage and upload price settings no longer default to or have the option to include redundancy. The price with the configured redundancy is now always shown below.
159 changes: 50 additions & 109 deletions apps/renterd/contexts/config/fields.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@
import {
Code,
ConfigFields,
FieldSwitch,
Separator,
Text,
Tooltip,
hoursInDays,
secondsInMinutes,
toFixedMax,
} from '@siafoundation/design-system'
import BigNumber from 'bignumber.js'
import React from 'react'
import { defaultValues, SettingsData } from './types'
import { humanSiacoin, toHastings } from '@siafoundation/units'

export const scDecimalPlaces = 6

Expand All @@ -28,9 +28,9 @@ type GetFields = {
isAutopilotEnabled: boolean
advancedDefaults?: SettingsData
showAdvanced: boolean
maxStoragePriceTBMonth: BigNumber
maxUploadPriceTB: BigNumber
redundancyMultiplier: BigNumber
includeRedundancyMaxStoragePrice: boolean
includeRedundancyMaxUploadPrice: boolean
storageAverage?: BigNumber
uploadAverage?: BigNumber
downloadAverage?: BigNumber
Expand All @@ -41,9 +41,9 @@ export function getFields({
isAutopilotEnabled,
advancedDefaults,
showAdvanced,
maxStoragePriceTBMonth,
maxUploadPriceTB,
redundancyMultiplier,
includeRedundancyMaxStoragePrice,
includeRedundancyMaxUploadPrice,
storageAverage,
uploadAverage,
downloadAverage,
Expand Down Expand Up @@ -336,37 +336,30 @@ export function getFields({
category: 'gouging',
type: 'siacoin',
title: 'Max storage price',
description: <>The max allowed price to store 1 TB per month.</>,
description: (
<>The max allowed price to store 1 TB per month without redundancy.</>
),
units: 'SC/TB/month',
average: storageAverage,
averageTip: getAverageTip(
includeRedundancyMaxStoragePrice,
redundancyMultiplier
),
after: function After({ form, fields }) {
averageTip: 'Averages provided by Sia Central.',
after: function After() {
if (!maxStoragePriceTBMonth) {
return null
}
return (
<Tooltip
align="start"
side="bottom"
content={getRedundancyTip(
includeRedundancyMaxStoragePrice,
redundancyMultiplier
)}
>
<div>
<FieldSwitch
size="small"
form={form}
fields={fields}
name="includeRedundancyMaxStoragePrice"
group={false}
>
<Text size="12" weight="medium">
Including {redundancyMultiplier.toFixed(1)}x redundancy
</Text>
</FieldSwitch>
</div>
</Tooltip>
<>
<Separator />
<Text size="12" weight="medium">
{humanSiacoin(
toHastings(maxStoragePriceTBMonth).times(redundancyMultiplier),
{
fixed: 0,
dynamicUnits: false,
}
)}
/TB/month with redundancy
</Text>
</>
)
},
decimalsLimitSc: scDecimalPlaces,
Expand All @@ -378,37 +371,30 @@ export function getFields({
category: 'gouging',
type: 'siacoin',
title: 'Max upload price',
description: <>The max allowed price to upload 1 TB.</>,
units: 'SC/TB/month',
average: uploadAverage,
averageTip: getAverageTip(
includeRedundancyMaxUploadPrice,
redundancyMultiplier
description: (
<>The max allowed price to upload 1 TB without redundancy.</>
),
after: function After({ form, fields }) {
units: 'SC/TB',
average: uploadAverage,
averageTip: 'Averages provided by Sia Central.',
after: function After() {
if (!maxUploadPriceTB) {
return null
}
return (
<Tooltip
align="start"
side="bottom"
content={getRedundancyTip(
includeRedundancyMaxUploadPrice,
redundancyMultiplier
)}
>
<div>
<FieldSwitch
size="small"
form={form}
fields={fields}
name="includeRedundancyMaxUploadPrice"
group={false}
>
<Text size="12" weight="medium">
Including {redundancyMultiplier.toFixed(1)}x redundancy
</Text>
</FieldSwitch>
</div>
</Tooltip>
<>
<Separator />
<Text size="12" weight="medium">
{humanSiacoin(
toHastings(maxUploadPriceTB).times(redundancyMultiplier),
{
fixed: 0,
dynamicUnits: false,
}
)}
/TB with redundancy
</Text>
</>
)
},
decimalsLimitSc: scDecimalPlaces,
Expand All @@ -421,7 +407,7 @@ export function getFields({
type: 'siacoin',
title: 'Max download price',
description: <>The max allowed price to download 1 TB.</>,
units: 'SC/TB/month',
units: 'SC/TB',
average: downloadAverage,
averageTip: `Averages provided by Sia Central.`,
decimalsLimitSc: scDecimalPlaces,
Expand Down Expand Up @@ -639,50 +625,5 @@ export function getFields({
}
: {},
},

// hidden fields used by other config options
includeRedundancyMaxStoragePrice: {
type: 'boolean',
title: 'Include redundancy',
validation: {},
},
includeRedundancyMaxUploadPrice: {
type: 'boolean',
title: 'Include redundancy',
validation: {},
},
}
}

function getAverageTip(
includeRedundancy: boolean,
redundancyMultiplier: BigNumber
) {
if (includeRedundancy) {
return `The average price is adjusted for ${redundancyMultiplier.toFixed(
1
)}x redundancy. Averages provided by Sia Central.`
}
return `The average price is not adjusted for redundancy. Averages provided by Sia Central.`
}

function getRedundancyTip(
includeRedundancy: boolean,
redundancyMultiplier: BigNumber
) {
if (includeRedundancy) {
return (
<div className="flex flex-col gap-1">
<Text color="subtle">
Specified max price includes the cost of{' '}
{redundancyMultiplier.toFixed(1)}x redundancy.
</Text>
<Text color="subtle">
Redundancy is calculated from the ratio of data shards:{' '}
<Code>total shards / min shards</Code>.
</Text>
</div>
)
}
return `Specified max price does not include redundancy.`
}
26 changes: 11 additions & 15 deletions apps/renterd/contexts/config/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ import {

export function useConfigMain() {
const {
autopilotState,
autopilot,
contractSet,
display,
gouging,
redundancy,
uploadPacking,
Expand All @@ -42,8 +42,6 @@ export function useConfigMain() {
storageTB,
downloadTBMonth,
uploadTBMonth,
includeRedundancyMaxStoragePrice,
includeRedundancyMaxUploadPrice,
redundancyMultiplier,
fields,
showAdvanced,
Expand All @@ -53,6 +51,10 @@ export function useConfigMain() {
// resources required to intialize form
const resources = useMemo(
() => ({
autopilotState: {
data: autopilotState.data,
error: autopilotState.error,
},
autopilot: {
data: autopilot.data,
error: autopilot.error,
Expand All @@ -73,10 +75,6 @@ export function useConfigMain() {
data: redundancy.data,
error: redundancy.error,
},
display: {
data: display.data,
error: display.error,
},
averages: {
data: averages.data,
error: averages.error,
Expand All @@ -88,6 +86,8 @@ export function useConfigMain() {
},
}),
[
autopilotState.data,
autopilotState.error,
autopilot.data,
autopilot.error,
contractSet.data,
Expand All @@ -98,8 +98,6 @@ export function useConfigMain() {
gouging.error,
redundancy.data,
redundancy.error,
display.data,
display.error,
averages.data,
averages.error,
appSettings.settings.siaCentral,
Expand All @@ -111,13 +109,13 @@ export function useConfigMain() {
return null
}
return transformDown({
hasBeenConfigured: resources.autopilotState.data?.configured,
autopilot: resources.autopilot.data,
contractSet: resources.contractSet.data,
uploadPacking: resources.uploadPacking.data,
gouging: resources.gouging.data,
averages: resources.averages.data,
redundancy: resources.redundancy.data,
display: resources.display.data,
})
}, [resources])

Expand All @@ -128,36 +126,36 @@ export function useConfigMain() {

const revalidateAndResetForm = useCallback(async () => {
// these do not seem to throw on errors, just return undefined
const _autopilotState = await autopilotState.mutate()
const _autopilot = isAutopilotEnabled ? await autopilot.mutate() : undefined
const _contractSet = await contractSet.mutate()
const _gouging = await gouging.mutate()
const _redundancy = await redundancy.mutate()
const _uploadPacking = await uploadPacking.mutate()
const _display = await display.mutate()
if (!gouging || !redundancy) {
triggerErrorToast('Error fetching settings.')
return null
}
form.reset(
transformDown({
hasBeenConfigured: _autopilotState.configured,
autopilot: _autopilot,
contractSet: _contractSet,
uploadPacking: _uploadPacking,
gouging: _gouging,
averages: averages.data,
redundancy: _redundancy,
display: _display,
})
)
}, [
form,
autopilotState,
isAutopilotEnabled,
autopilot,
contractSet,
gouging,
uploadPacking,
redundancy,
display,
averages.data,
])

Expand All @@ -174,8 +172,6 @@ export function useConfigMain() {
const { canEstimate, estimatedSpendingPerMonth, estimatedSpendingPerTB } =
useEstimates({
isAutopilotEnabled,
includeRedundancyMaxStoragePrice,
includeRedundancyMaxUploadPrice,
redundancyMultiplier,
maxStoragePriceTBMonth,
storageTB,
Expand Down
Loading

0 comments on commit 7108516

Please sign in to comment.