Skip to content

Commit

Permalink
Merge pull request #509 from SiaFoundation/02-24-fix_renterd_storage_…
Browse files Browse the repository at this point in the history
…and_upload_config_without_redundancy

fix: renterd storage and upload config without redundancy
  • Loading branch information
ChrisSchinnerl authored Feb 27, 2024
2 parents 2402cd6 + 2d6a9c7 commit fbf41ae
Show file tree
Hide file tree
Showing 20 changed files with 225 additions and 531 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.
61 changes: 32 additions & 29 deletions apps/renterd/components/Config/ConfigStats.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,35 +64,38 @@ export function ConfigStats() {
per TB/month with {redundancyMultiplier.toFixed(1)}x redundancy
</Text>
</div>
<div className="flex gap-1">
<ValueSc
size="12"
value={toHastings(estimatedSpendingPerMonth)}
dynamicUnits={false}
fixed={0}
variant="value"
/>
{perMonth.fiat && (
<div className="flex">
<ValueNum
size="12"
weight="medium"
value={perMonth.fiat}
color="subtle"
variant="value"
format={(v) =>
`(${perMonth.currency.prefix}${v.toFixed(
perMonth.currency.fixed
)})`
}
/>
</div>
)}
<Text size="12" font="mono" weight="medium" ellipsis>
to store {humanBytes(TBToBytes(storageTB).toNumber())}/month with{' '}
{redundancyMultiplier.toFixed(1)}x redundancy
</Text>
</div>
{/* additionally show estimated spending for total storage if it's different from per TB */}
{!estimatedSpendingPerTB.eq(estimatedSpendingPerMonth) && (
<div className="flex gap-1">
<ValueSc
size="12"
value={toHastings(estimatedSpendingPerMonth)}
dynamicUnits={false}
fixed={0}
variant="value"
/>
{perMonth.fiat && (
<div className="flex">
<ValueNum
size="12"
weight="medium"
value={perMonth.fiat}
color="subtle"
variant="value"
format={(v) =>
`(${perMonth.currency.prefix}${v.toFixed(
perMonth.currency.fixed
)})`
}
/>
</div>
)}
<Text size="12" font="mono" weight="medium" ellipsis>
to store {humanBytes(TBToBytes(storageTB).toNumber())}/month with{' '}
{redundancyMultiplier.toFixed(1)}x redundancy
</Text>
</div>
)}
</div>
</ScrollArea>
)
Expand Down
199 changes: 93 additions & 106 deletions apps/renterd/contexts/config/fields.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import {
Code,
ConfigFields,
FieldSwitch,
Separator,
Text,
Tooltip,
hoursInDays,
Expand All @@ -12,6 +12,8 @@ import {
import BigNumber from 'bignumber.js'
import React from 'react'
import { defaultValues, SettingsData } from './types'
import { humanSiacoin, toHastings } from '@siafoundation/units'
import { Information16 } from '@carbon/icons-react'

export const scDecimalPlaces = 6

Expand All @@ -28,9 +30,11 @@ type GetFields = {
isAutopilotEnabled: boolean
advancedDefaults?: SettingsData
showAdvanced: boolean
maxStoragePriceTBMonth: BigNumber
maxUploadPriceTB: BigNumber
minShards: BigNumber
totalShards: BigNumber
redundancyMultiplier: BigNumber
includeRedundancyMaxStoragePrice: boolean
includeRedundancyMaxUploadPrice: boolean
storageAverage?: BigNumber
uploadAverage?: BigNumber
downloadAverage?: BigNumber
Expand All @@ -41,9 +45,11 @@ export function getFields({
isAutopilotEnabled,
advancedDefaults,
showAdvanced,
maxStoragePriceTBMonth,
maxUploadPriceTB,
minShards,
totalShards,
redundancyMultiplier,
includeRedundancyMaxStoragePrice,
includeRedundancyMaxUploadPrice,
storageAverage,
uploadAverage,
downloadAverage,
Expand Down Expand Up @@ -336,37 +342,51 @@ 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 a host is allowed to charge to store 1 TB worth
of data per month.
</>
),
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 || !minShards || !totalShards) {
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
<>
<Separator />
<Tooltip
align="start"
side="bottom"
content={
<>
Price per TB/month when factoring in the configured{' '}
{minShards} of {totalShards} redundancy.
</>
}
>
<div className="flex gap-1 items-center relative overflow-hidden">
<Text className="flex relative">
<Information16 />
</Text>
<Text size="12" ellipsis>
{humanSiacoin(
toHastings(maxStoragePriceTBMonth).times(
redundancyMultiplier
),
{
fixed: 0,
dynamicUnits: false,
}
)}
/TB/month with redundancy
</Text>
</FieldSwitch>
</div>
</Tooltip>
</div>
</Tooltip>
</>
)
},
decimalsLimitSc: scDecimalPlaces,
Expand All @@ -378,37 +398,49 @@ 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 a host is allowed to charge for uploading 1 TB
worth of data.
</>
),
after: function After({ form, fields }) {
units: 'SC/TB',
average: uploadAverage,
averageTip: 'Averages provided by Sia Central.',
after: function After() {
if (!maxUploadPriceTB || !minShards || !totalShards) {
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
<>
<Separator />
<Tooltip
align="start"
side="bottom"
content={
<>
Price per TB when factoring in the configured {minShards} of{' '}
{totalShards} redundancy.
</>
}
>
<div className="flex gap-1 items-center relative overflow-hidden">
<Text className="flex relative">
<Information16 />
</Text>
</FieldSwitch>
</div>
</Tooltip>
<Text size="12" ellipsis>
{humanSiacoin(
toHastings(maxUploadPriceTB).times(redundancyMultiplier),
{
fixed: 0,
dynamicUnits: false,
}
)}
/TB with redundancy
</Text>
</div>
</Tooltip>
</>
)
},
decimalsLimitSc: scDecimalPlaces,
Expand All @@ -421,7 +453,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 +671,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.`
}
Loading

0 comments on commit fbf41ae

Please sign in to comment.