From 5958be26dd6712b5420fd2889553b5636de1d3ee Mon Sep 17 00:00:00 2001 From: Alex Freska Date: Mon, 20 Nov 2023 11:30:07 -0500 Subject: [PATCH] feat: renterd zen config values --- .changeset/calm-coins-shave.md | 5 ++ apps/renterd/contexts/config/fields.tsx | 53 +++++++------- apps/renterd/contexts/config/index.tsx | 19 ++++- .../renterd/contexts/config/transform.spec.ts | 56 ++++++++++++++- apps/renterd/contexts/config/transform.ts | 5 +- apps/renterd/contexts/config/types.ts | 72 +++++++++++++++---- libs/react-renterd/src/siaTypes.ts | 2 +- 7 files changed, 163 insertions(+), 49 deletions(-) create mode 100644 .changeset/calm-coins-shave.md diff --git a/.changeset/calm-coins-shave.md b/.changeset/calm-coins-shave.md new file mode 100644 index 000000000..0f8327e42 --- /dev/null +++ b/.changeset/calm-coins-shave.md @@ -0,0 +1,5 @@ +--- +'renterd': minor +--- + +The configuration now has zen-specific suggested/default values for number of contract hosts and shard values. diff --git a/apps/renterd/contexts/config/fields.tsx b/apps/renterd/contexts/config/fields.tsx index c2a9f1a4c..2fd679639 100644 --- a/apps/renterd/contexts/config/fields.tsx +++ b/apps/renterd/contexts/config/fields.tsx @@ -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 @@ -31,6 +26,7 @@ type Categories = type GetFields = { isAutopilotEnabled: boolean + advancedDefaults?: SettingsData showAdvanced: boolean redundancyMultiplier: BigNumber includeRedundancyMaxStoragePrice: boolean @@ -43,6 +39,7 @@ type GetFields = { export function getFields({ isAutopilotEnabled, + advancedDefaults, showAdvanced, redundancyMultiplier, includeRedundancyMaxStoragePrice, @@ -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 @@ -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 @@ -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 @@ -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{' '} - {advancedDefaultAutopilot.autopilotContractSet}. + {advancedDefaults?.autopilotContractSet}. ), hidden: !isAutopilotEnabled || !showAdvanced, @@ -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: {}, @@ -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.`, @@ -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 @@ -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: @@ -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 @@ -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 @@ -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 @@ -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 diff --git a/apps/renterd/contexts/config/index.tsx b/apps/renterd/contexts/config/index.tsx index 36ae3862d..359560d6c 100644 --- a/apps/renterd/contexts/config/index.tsx +++ b/apps/renterd/contexts/config/index.tsx @@ -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, @@ -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, @@ -315,6 +321,7 @@ export function useConfigMain() { }) } return getFields({ + advancedDefaults, isAutopilotEnabled, showAdvanced, redundancyMultiplier, @@ -322,6 +329,7 @@ export function useConfigMain() { includeRedundancyMaxUploadPrice, }) }, [ + renterdState.data, isAutopilotEnabled, showAdvanced, averages.data, @@ -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 { @@ -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 @@ -511,6 +523,7 @@ export function useConfigMain() { } }, [ + renterdState.data, estimatedSpendingPerMonth, showAdvanced, isAutopilotEnabled, diff --git a/apps/renterd/contexts/config/transform.spec.ts b/apps/renterd/contexts/config/transform.spec.ts index 9271c58ba..122dd9c46 100644 --- a/apps/renterd/contexts/config/transform.spec.ts +++ b/apps/renterd/contexts/config/transform.spec.ts @@ -185,6 +185,7 @@ describe('tansforms', () => { it('up autopilot', () => { expect( transformUpAutopilot( + 'Mainnet', { autopilotContractSet: 'autopilot', allowanceMonth: new BigNumber('6006'), @@ -223,10 +224,10 @@ describe('tansforms', () => { }, }) }) - it('up autopilot accepts unknown values', () => { expect( transformUpAutopilot( + 'Mainnet', { autopilotContractSet: 'autopilot', allowanceMonth: new BigNumber('6006'), @@ -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( @@ -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( @@ -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) }) }) diff --git a/apps/renterd/contexts/config/transform.ts b/apps/renterd/contexts/config/transform.ts index 4aeed90be..446fa3d40 100644 --- a/apps/renterd/contexts/config/transform.ts +++ b/apps/renterd/contexts/config/transform.ts @@ -23,7 +23,7 @@ import { AutopilotData, scDecimalPlaces, SettingsData, - advancedDefaultAutopilot, + getAdvancedDefaultAutopilot, ConfigAppData, ContractSetData, defaultConfigApp, @@ -46,6 +46,7 @@ const filterUndefinedKeys = (obj: Record) => { // up export function transformUpAutopilot( + network: 'Mainnet' | 'Zen Testnet', values: AutopilotData, // eslint-disable-next-line @typescript-eslint/no-explicit-any existingValues: AutopilotConfig | undefined @@ -53,7 +54,7 @@ export function transformUpAutopilot( // 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), } diff --git a/apps/renterd/contexts/config/types.ts b/apps/renterd/contexts/config/types.ts index 3e00acbfc..08824c40a 100644 --- a/apps/renterd/contexts/config/types.ts +++ b/apps/renterd/contexts/config/types.ts @@ -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 = { @@ -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), + } } diff --git a/libs/react-renterd/src/siaTypes.ts b/libs/react-renterd/src/siaTypes.ts index 9efe939fa..0eb58e181 100644 --- a/libs/react-renterd/src/siaTypes.ts +++ b/libs/react-renterd/src/siaTypes.ts @@ -257,7 +257,7 @@ export interface Host { interactions: { Downtime: number FailedInteractions: number - LastScan: string + LastScan?: string LastScanSuccess: boolean SecondToLastScanSuccess: boolean SuccessfulInteractions: number