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 20097d8 commit 58a2d4a
Show file tree
Hide file tree
Showing 6 changed files with 110 additions and 46 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
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
72 changes: 58 additions & 14 deletions apps/renterd/contexts/config/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,18 +77,39 @@ export type RedundancyData = typeof defaultRedundancy
export type SettingsData = typeof defaultValues

// advanced defaults
export const advancedDefaultAutopilot: AutopilotData = {
...defaultAutopilot,
downloadTBMonth: new BigNumber(1),
uploadTBMonth: new BigNumber(1),
periodWeeks: new BigNumber(6),
renewWindowWeeks: new BigNumber(2),
amountHosts: new BigNumber(50),
autopilotContractSet: 'autopilot',
allowRedundantIPs: false,
maxDowntimeHours: new BigNumber(336),
minRecentScanFailures: new BigNumber(10),
defragThreshold: new BigNumber(1000),
export function getAdvancedDefaultAutopilot(
network: 'Mainnet' | 'Zen Testnet'
): AutopilotData {
return {
// must be set
storageTB: undefined,
downloadTBMonth: undefined,
uploadTBMonth: undefined,
// calcuated and set
allowanceMonth: undefined,
// defaults
...(network === 'Mainnet'
? {
periodWeeks: new BigNumber(6),
renewWindowWeeks: new BigNumber(2),
amountHosts: new BigNumber(50),
autopilotContractSet: 'autopilot',
allowRedundantIPs: false,
maxDowntimeHours: new BigNumber(336),
minRecentScanFailures: new BigNumber(10),
defragThreshold: new BigNumber(1000),
}
: {
periodWeeks: new BigNumber(6),
renewWindowWeeks: new BigNumber(2),
amountHosts: new BigNumber(12),
autopilotContractSet: 'autopilot',
allowRedundantIPs: false,
maxDowntimeHours: new BigNumber(336),
minRecentScanFailures: new BigNumber(10),
defragThreshold: new BigNumber(1000),
}),
}
}

export const advancedDefaultContractSet: ContractSetData = {
Expand All @@ -108,6 +129,29 @@ export const advancedDefaultGouging: GougingData = {
...defaultGouging,
}

export const advancedDefaultRedundancy: RedundancyData = {
...defaultRedundancy,
export function getAdvancedDefaultRedundancy(
network: 'Mainnet' | 'Zen Testnet'
): RedundancyData {
return network === 'Mainnet'
? {
minShards: new BigNumber(10),
totalShards: new BigNumber(30),
}
: {
minShards: new BigNumber(2),
totalShards: new BigNumber(6),
}
}

export function getAdvancedDefaults(
network: 'Mainnet' | 'Zen Testnet'
): SettingsData {
return {
...getAdvancedDefaultAutopilot(network),
...advancedDefaultContractSet,
...advancedDefaultConfigApp,
...advancedDefaultUploadPacking,
...advancedDefaultGouging,
...getAdvancedDefaultRedundancy(network),
}
}
2 changes: 1 addition & 1 deletion libs/react-renterd/src/siaTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ export interface Host {
interactions: {
Downtime: number
FailedInteractions: number
LastScan: string
LastScan?: string
LastScanSuccess: boolean
SecondToLastScanSuccess: boolean
SuccessfulInteractions: number
Expand Down

0 comments on commit 58a2d4a

Please sign in to comment.