Skip to content

Commit

Permalink
feat: renterd zen config values
Browse files Browse the repository at this point in the history
  • Loading branch information
alexfreska committed Nov 20, 2023
1 parent 32f9a8b commit 5958be2
Show file tree
Hide file tree
Showing 7 changed files with 163 additions and 49 deletions.
5 changes: 5 additions & 0 deletions .changeset/calm-coins-shave.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'renterd': minor
---

The configuration now has zen-specific suggested/default values for number of contract hosts and shard values.
53 changes: 27 additions & 26 deletions apps/renterd/contexts/config/fields.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,7 @@ import {
} from '@siafoundation/design-system'
import BigNumber from 'bignumber.js'
import React from 'react'
import {
defaultValues,
advancedDefaultAutopilot,
advancedDefaultContractSet,
advancedDefaultGouging,
} from './types'
import { defaultValues, SettingsData } from './types'

export const scDecimalPlaces = 6

Expand All @@ -31,6 +26,7 @@ type Categories =

type GetFields = {
isAutopilotEnabled: boolean
advancedDefaults?: SettingsData
showAdvanced: boolean
redundancyMultiplier: BigNumber
includeRedundancyMaxStoragePrice: boolean
Expand All @@ -43,6 +39,7 @@ type GetFields = {

export function getFields({
isAutopilotEnabled,
advancedDefaults,
showAdvanced,
redundancyMultiplier,
includeRedundancyMaxStoragePrice,
Expand Down Expand Up @@ -120,8 +117,8 @@ export function getFields({
title: 'Period',
description: <>The length of the storage contracts.</>,
units: 'weeks',
suggestion: advancedDefaultAutopilot.periodWeeks,
suggestionTip: `Typically ${advancedDefaultAutopilot.periodWeeks} weeks.`,
suggestion: advancedDefaults?.periodWeeks,
suggestionTip: `Typically ${advancedDefaults?.periodWeeks} weeks.`,
hidden: !isAutopilotEnabled || !showAdvanced,
validation:
isAutopilotEnabled && showAdvanced
Expand All @@ -142,8 +139,8 @@ export function getFields({
),
units: 'weeks',
decimalsLimit: 6,
suggestion: advancedDefaultAutopilot.renewWindowWeeks,
suggestionTip: `Typically ${advancedDefaultAutopilot.renewWindowWeeks} weeks.`,
suggestion: advancedDefaults?.renewWindowWeeks,
suggestionTip: `Typically ${advancedDefaults?.renewWindowWeeks} weeks.`,
hidden: !isAutopilotEnabled || !showAdvanced,
validation:
isAutopilotEnabled && showAdvanced
Expand All @@ -159,8 +156,8 @@ export function getFields({
description: <>The number of hosts to create contracts with.</>,
units: 'hosts',
decimalsLimit: 0,
suggestion: advancedDefaultAutopilot.amountHosts,
suggestionTip: `Typically ${advancedDefaultAutopilot.amountHosts} hosts.`,
suggestion: advancedDefaults?.amountHosts,
suggestionTip: `Typically ${advancedDefaults?.amountHosts} hosts.`,
hidden: !isAutopilotEnabled || !showAdvanced,
validation:
isAutopilotEnabled && showAdvanced
Expand All @@ -179,12 +176,12 @@ export function getFields({
the same as the default contract set.
</>
),
placeholder: advancedDefaultAutopilot.autopilotContractSet,
suggestion: advancedDefaultAutopilot.autopilotContractSet,
placeholder: advancedDefaults?.autopilotContractSet,
suggestion: advancedDefaults?.autopilotContractSet,
suggestionTip: (
<>
The default contract set is{' '}
<Code>{advancedDefaultAutopilot.autopilotContractSet}</Code>.
<Code>{advancedDefaults?.autopilotContractSet}</Code>.
</>
),
hidden: !isAutopilotEnabled || !showAdvanced,
Expand All @@ -207,9 +204,9 @@ export function getFields({
same IP subnet. The subnets used are /16 for IPv4, and /64 for IPv6.
</>
),
suggestion: advancedDefaultAutopilot.allowRedundantIPs,
suggestion: advancedDefaults?.allowRedundantIPs,
suggestionTip: `Defaults to ${
advancedDefaultAutopilot.allowRedundantIPs ? 'on' : 'off'
advancedDefaults?.allowRedundantIPs ? 'on' : 'off'
}.`,
hidden: !isAutopilotEnabled || !showAdvanced,
validation: {},
Expand All @@ -225,12 +222,12 @@ export function getFields({
</>
),
units: 'hours',
suggestion: advancedDefaultAutopilot.maxDowntimeHours,
suggestionTip: `Defaults to ${advancedDefaultAutopilot.maxDowntimeHours
suggestion: advancedDefaults?.maxDowntimeHours,
suggestionTip: `Defaults to ${advancedDefaults?.maxDowntimeHours
.toNumber()
.toLocaleString()} which is ${toFixedMax(
new BigNumber(
hoursInDays(advancedDefaultAutopilot.maxDowntimeHours.toNumber())
hoursInDays(advancedDefaults?.maxDowntimeHours.toNumber())
),
1
)} days.`,
Expand All @@ -254,8 +251,8 @@ export function getFields({
),
units: 'scans',
decimalsLimit: 0,
suggestion: advancedDefaultAutopilot.minRecentScanFailures,
suggestionTip: `Defaults to ${advancedDefaultAutopilot.minRecentScanFailures.toNumber()}.`,
suggestion: advancedDefaults?.minRecentScanFailures,
suggestionTip: `Defaults to ${advancedDefaults?.minRecentScanFailures.toNumber()}.`,
hidden: !isAutopilotEnabled || !showAdvanced,
validation:
isAutopilotEnabled && showAdvanced
Expand All @@ -274,7 +271,7 @@ export function getFields({
<>The threshold after which autopilot will defrag wallet outputs.</>
),
units: 'outputs',
suggestion: advancedDefaultAutopilot.defragThreshold,
suggestion: advancedDefaults?.defragThreshold,
suggestionTip: 'Defaults to 1,000.',
hidden: !isAutopilotEnabled || !showAdvanced,
validation:
Expand All @@ -290,8 +287,8 @@ export function getFields({
category: 'contractset',
type: 'text',
title: 'Default contract set',
placeholder: advancedDefaultContractSet.defaultContractSet,
suggestion: advancedDefaultContractSet.defaultContractSet,
placeholder: advancedDefaults?.defaultContractSet,
suggestion: advancedDefaults?.defaultContractSet,
suggestionTip: (
<>
Autopilot users will typically want to keep this the same as the
Expand Down Expand Up @@ -487,7 +484,7 @@ export function getFields({
),
units: 'blocks',
decimalsLimit: 0,
suggestion: advancedDefaultGouging.hostBlockHeightLeeway,
suggestion: advancedDefaults?.hostBlockHeightLeeway,
suggestionTip: 'The recommended value is 6 blocks.',
hidden: !showAdvanced,
validation: showAdvanced
Expand Down Expand Up @@ -600,6 +597,8 @@ export function getFields({
category: 'redundancy',
title: 'Min shards',
description: <>The min amount of shards needed to reconstruct a slab.</>,
suggestion: advancedDefaults?.minShards,
suggestionTip: `Typically ${advancedDefaults?.minShards} shards.`,
units: 'shards',
hidden: !showAdvanced,
validation: showAdvanced
Expand All @@ -619,6 +618,8 @@ export function getFields({
category: 'redundancy',
title: 'Total shards',
description: <>The total amount of shards for each slab.</>,
suggestion: advancedDefaults?.totalShards,
suggestionTip: `Typically ${advancedDefaults?.totalShards} shards.`,
units: 'shards',
hidden: !showAdvanced,
validation: showAdvanced
Expand Down
19 changes: 16 additions & 3 deletions apps/renterd/contexts/config/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,11 @@ import {
UploadPackingSettings,
useSettingUpdate,
useAutopilotTrigger,
useBusState,
} from '@siafoundation/react-renterd'
import { toSiacoins } from '@siafoundation/sia-js'
import { getFields } from './fields'
import { SettingsData, defaultValues } from './types'
import { SettingsData, defaultValues, getAdvancedDefaults } from './types'
import {
getRedundancyMultiplier,
getRedundancyMultiplierIfIncluded,
Expand Down Expand Up @@ -282,9 +283,14 @@ export function useConfigMain() {
[minShards, totalShards]
)

const renterdState = useBusState()
const fields = useMemo(() => {
const advancedDefaults = renterdState.data
? getAdvancedDefaults(renterdState.data.network)
: undefined
if (averages.data) {
return getFields({
advancedDefaults,
isAutopilotEnabled,
showAdvanced,
redundancyMultiplier,
Expand Down Expand Up @@ -315,13 +321,15 @@ export function useConfigMain() {
})
}
return getFields({
advancedDefaults,
isAutopilotEnabled,
showAdvanced,
redundancyMultiplier,
includeRedundancyMaxStoragePrice,
includeRedundancyMaxUploadPrice,
})
}, [
renterdState.data,
isAutopilotEnabled,
showAdvanced,
averages.data,
Expand Down Expand Up @@ -394,7 +402,7 @@ export function useConfigMain() {
const mutate = useMutate()
const onValid = useCallback(
async (values: typeof defaultValues) => {
if (!gouging.data || !redundancy.data) {
if (!gouging.data || !redundancy.data || !renterdState.data) {
return
}
try {
Expand All @@ -411,7 +419,11 @@ export function useConfigMain() {
const firstTimeSettingConfig = isAutopilotEnabled && !autopilot.data
const autopilotResponse = isAutopilotEnabled
? await autopilotUpdate.put({
payload: transformUpAutopilot(finalValues, autopilot.data),
payload: transformUpAutopilot(
renterdState.data.network,
finalValues,
autopilot.data
),
})
: undefined

Expand Down Expand Up @@ -511,6 +523,7 @@ export function useConfigMain() {
}
},
[
renterdState.data,
estimatedSpendingPerMonth,
showAdvanced,
isAutopilotEnabled,
Expand Down
56 changes: 53 additions & 3 deletions apps/renterd/contexts/config/transform.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ describe('tansforms', () => {
it('up autopilot', () => {
expect(
transformUpAutopilot(
'Mainnet',
{
autopilotContractSet: 'autopilot',
allowanceMonth: new BigNumber('6006'),
Expand Down Expand Up @@ -223,10 +224,10 @@ describe('tansforms', () => {
},
})
})

it('up autopilot accepts unknown values', () => {
expect(
transformUpAutopilot(
'Mainnet',
{
autopilotContractSet: 'autopilot',
allowanceMonth: new BigNumber('6006'),
Expand Down Expand Up @@ -282,6 +283,55 @@ describe('tansforms', () => {
},
})
})
it('uses testnet defaults', () => {
expect(
transformUpAutopilot(
'Zen Testnet',
{
autopilotContractSet: 'autopilot',
allowanceMonth: new BigNumber('6006'),
amountHosts: undefined,
periodWeeks: new BigNumber('6'),
renewWindowWeeks: new BigNumber('2.2301587301587302'),
downloadTBMonth: new BigNumber('0.785365448411428571428571428571'),
uploadTBMonth: new BigNumber('0.785714285714285714285714285714'),
storageTB: new BigNumber('1'),
allowRedundantIPs: false,
maxDowntimeHours: new BigNumber('1440'),
minRecentScanFailures: new BigNumber('10'),
defragThreshold: new BigNumber('1000'),
},
{
wallet: {},
contracts: {
period: 7777,
},
hosts: {},
// eslint-disable-next-line @typescript-eslint/no-explicit-any
} as any
)
).toEqual({
wallet: {
defragThreshold: 1000,
},
hosts: {
allowRedundantIPs: false,
maxDowntimeHours: 1440,
minRecentScanFailures: 10,
scoreOverrides: null,
},
contracts: {
set: 'autopilot',
amount: 12,
allowance: '8408400000000000000000000000',
period: 6048,
renewWindow: 2248,
download: 1099511627776,
upload: 1100000000000,
storage: 1000000000000,
},
})
})

it('up contractset', () => {
expect(
Expand Down Expand Up @@ -462,7 +512,7 @@ describe('tansforms', () => {
expect(settings.downloadTBMonth).toEqual(new BigNumber('92.72'))
// a little different due to rounding
expect(
transformUpAutopilot(settings, autopilot).contracts.download
transformUpAutopilot('Mainnet', settings, autopilot).contracts.download
).toEqual(91088814814815)

settings = transformDown(
Expand All @@ -483,7 +533,7 @@ describe('tansforms', () => {
expect(settings.downloadTBMonth).toEqual(new BigNumber('92.72'))
// using the rounded value results in same value
expect(
transformUpAutopilot(settings, autopilot).contracts.download
transformUpAutopilot('Mainnet', settings, autopilot).contracts.download
).toEqual(91088814814815)
})
})
Expand Down
5 changes: 3 additions & 2 deletions apps/renterd/contexts/config/transform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import {
AutopilotData,
scDecimalPlaces,
SettingsData,
advancedDefaultAutopilot,
getAdvancedDefaultAutopilot,
ConfigAppData,
ContractSetData,
defaultConfigApp,
Expand All @@ -46,14 +46,15 @@ const filterUndefinedKeys = (obj: Record<string, unknown>) => {

// up
export function transformUpAutopilot(
network: 'Mainnet' | 'Zen Testnet',
values: AutopilotData,
// eslint-disable-next-line @typescript-eslint/no-explicit-any
existingValues: AutopilotConfig | undefined
): AutopilotConfig {
// merge suggestions with values, if advanced values are required they will
// be added before this function is called and will override suggestions
const v: AutopilotData = {
...advancedDefaultAutopilot,
...getAdvancedDefaultAutopilot(network),
...filterUndefinedKeys(values),
}

Expand Down
Loading

0 comments on commit 5958be2

Please sign in to comment.