From dfcfdff73162bf729861a88f84636eb1814e3a36 Mon Sep 17 00:00:00 2001 From: John Williams Date: Wed, 20 Nov 2024 15:56:40 -0500 Subject: [PATCH] refactor(types): move HostSettings and HostPriceTable to core types --- .changeset/fresh-plants-shave.md | 7 ++ apps/renterd/contexts/hosts/columns.tsx | 3 +- apps/renterd/contexts/hosts/types.tsx | 2 +- libs/renterd-types/src/bus.ts | 8 +- libs/renterd-types/src/types.ts | 69 +----------- libs/renterd-types/src/worker.ts | 2 +- libs/types/src/core.ts | 141 ++++++++++++++++++++++++ 7 files changed, 159 insertions(+), 73 deletions(-) create mode 100644 .changeset/fresh-plants-shave.md diff --git a/.changeset/fresh-plants-shave.md b/.changeset/fresh-plants-shave.md new file mode 100644 index 000000000..b5cea920e --- /dev/null +++ b/.changeset/fresh-plants-shave.md @@ -0,0 +1,7 @@ +--- +'@siafoundation/renterd-types': minor +'@siafoundation/types': minor +'@siafoundation/renterd': minor +--- + +Moved HostSettings and HostPriceTable to core types. diff --git a/apps/renterd/contexts/hosts/columns.tsx b/apps/renterd/contexts/hosts/columns.tsx index cba864a73..53bb8fbef 100644 --- a/apps/renterd/contexts/hosts/columns.tsx +++ b/apps/renterd/contexts/hosts/columns.tsx @@ -21,11 +21,10 @@ import { format, formatDistance, formatRelative } from 'date-fns' import { HostContextMenu } from '../../components/Hosts/HostContextMenu' import { useWorkflows } from '@siafoundation/react-core' import { - HostPriceTable, - HostSettings, RhpScanPayload, workerRhpScanRoute, } from '@siafoundation/renterd-types' +import { HostPriceTable, HostSettings } from '@siafoundation/types' import { useHostsAllowlist } from '@siafoundation/renterd-react' import BigNumber from 'bignumber.js' import React, { memo } from 'react' diff --git a/apps/renterd/contexts/hosts/types.tsx b/apps/renterd/contexts/hosts/types.tsx index 5418cfbe5..4606035e7 100644 --- a/apps/renterd/contexts/hosts/types.tsx +++ b/apps/renterd/contexts/hosts/types.tsx @@ -1,4 +1,4 @@ -import { HostPriceTable, HostSettings } from '@siafoundation/renterd-types' +import { HostPriceTable, HostSettings } from '@siafoundation/types' import BigNumber from 'bignumber.js' import { ContractData } from '../contracts/types' diff --git a/libs/renterd-types/src/bus.ts b/libs/renterd-types/src/bus.ts index 2cf23fdde..c1bd89687 100644 --- a/libs/renterd-types/src/bus.ts +++ b/libs/renterd-types/src/bus.ts @@ -1,10 +1,11 @@ import { + Block, Currency, + HostSettings, + FileContractID, + FileContractRevision, PublicKey, Transaction, - FileContractRevision, - FileContractID, - Block, TransactionID, WalletEvent, } from '@siafoundation/types' @@ -14,7 +15,6 @@ import { Contract, ContractRevision, Host, - HostSettings, Obj, ObjectMetadata, SettingsGouging, diff --git a/libs/renterd-types/src/types.ts b/libs/renterd-types/src/types.ts index d4969580c..5a11d3df7 100644 --- a/libs/renterd-types/src/types.ts +++ b/libs/renterd-types/src/types.ts @@ -1,11 +1,13 @@ import { CurrencyId } from '@siafoundation/react-core' import { ChainIndex, - FileContractRevision, - Transaction, Currency, EncryptionKey, + FileContractRevision, + HostSettings, + HostPriceTable, PublicKey, + Transaction, TransactionSignature, } from '@siafoundation/types' @@ -20,69 +22,6 @@ export type ContractRevision = { signatures: TransactionSignature[] } -export type HostSettings = { - acceptingcontracts: boolean - maxdownloadbatchsize: number - maxduration: number - maxrevisebatchsize: number - netaddress: string - remainingstorage: number - sectorsize: number - totalstorage: number - unlockhash: string - windowsize: number - collateral: Currency - maxcollateral: Currency - baserpcprice: Currency - contractprice: Currency - downloadbandwidthprice: Currency - sectoraccessprice: Currency - storageprice: Currency - uploadbandwidthprice: Currency - ephemeralaccountexpiry: number - maxephemeralaccountbalance: Currency - revisionnumber: number - version: string - siamuxport: string -} - -export type HostPriceTable = { - accountbalancecost: string - collateralcost: string - contractprice: string - downloadbandwidthcost: string - dropsectorsbasecost: string - dropsectorsunitcost: string - expiry: string // date - fundaccountcost: string - hassectorbasecost: string - hostblockheight: number - initbasecost: string - latestrevisioncost: string - maxcollateral: string - maxduration: number - memorytimecost: string - readbasecost: string - readlengthcost: string - registryentriesleft: number - registryentriestotal: number - renewcontractcost: string - revisionbasecost: string - subscriptionmemorycost: string - subscriptionnotificationcost: string - swapsectorcost: string - txnfeemaxrecommended: string - txnfeeminrecommended: string - uid: string - updatepricetablecost: string - uploadbandwidthcost: string - validity: number - windowsize: number - writebasecost: string - writelengthcost: string - writestorecost: string -} - export type Sector = { host: string root: string diff --git a/libs/renterd-types/src/worker.ts b/libs/renterd-types/src/worker.ts index 0338f837d..92a4550f9 100644 --- a/libs/renterd-types/src/worker.ts +++ b/libs/renterd-types/src/worker.ts @@ -1,4 +1,4 @@ -import { HostSettings } from './types' +import { HostSettings } from '@siafoundation/types' import { BusStateResponse } from './bus' export const workerStateRoute = '/worker/state' diff --git a/libs/types/src/core.ts b/libs/types/src/core.ts index 51b0404ab..c859977e4 100644 --- a/libs/types/src/core.ts +++ b/libs/types/src/core.ts @@ -198,3 +198,144 @@ export type ConsensusState = { } attestations: number } + +/** + * HostSettings are the settings and prices used when interacting with a host. + */ +export type HostSettings = { + acceptingcontracts: boolean + maxdownloadbatchsize: number + maxduration: number + maxrevisebatchsize: number + netaddress: string + remainingstorage: number + sectorsize: number + totalstorage: number + unlockhash: Address + windowsize: number + collateral: Currency + maxcollateral: Currency + baserpcprice: Currency + contractprice: Currency + downloadbandwidthprice: Currency + sectoraccessprice: Currency + storageprice: Currency + uploadbandwidthprice: Currency + ephemeralaccountexpiry: string + maxephemeralaccountbalance: Currency + revisionnumber: number + version: string + release: string + siamuxport: string +} + +/** + * An HostPriceTable contains the host's current prices for each RPC. + */ +export type HostPriceTable = { + // UID is a unique specifier that identifies this price table + uid: string + + // Validity is a duration that specifies how long the host guarantees these + // prices for and are thus considered valid. + validity: string + + // HostBlockHeight is the block height of the host. This allows the renter + // to create valid withdrawal messages in case it is not synced yet. + hostblockheight: number + + // UpdatePriceTableCost refers to the cost of fetching a new price table + // from the host. + updatepricetablecost: Currency + + // AccountBalanceCost refers to the cost of fetching the balance of an + // ephemeral account. + accountbalancecost: Currency + + // FundAccountCost refers to the cost of funding an ephemeral account on the + // host. + fundaccountcost: Currency + + // LatestRevisionCost refers to the cost of asking the host for the latest + // revision of a contract. + latestrevisioncost: Currency + + // SubscriptionMemoryCost is the cost of storing a byte of data for + // SubscriptionPeriod time. + subscriptionmemorycost: Currency + + // SubscriptionNotificationCost is the cost of a single notification on top + // of what is charged for bandwidth. + subscriptionnotificationcost: Currency + + // MDM related costs + // + // InitBaseCost is the amount of cost that is incurred when an MDM program + // starts to run. This doesn't include the memory used by the program data. + // The total cost to initialize a program is calculated as + // InitCost = InitBaseCost + MemoryTimeCost * Time + initbasecost: Currency + + // MemoryTimeCost is the amount of cost per byte per time that is incurred + // by the memory consumption of the program. + memorytimecost: Currency + + // Cost values specific to the bandwidth consumption. + downloadbandwidthcost: Currency + uploadbandwidthcost: Currency + + // Cost values specific to the DropSectors instruction. + dropsectorsbasecost: Currency + dropsectorsunitcost: Currency + + // Cost values specific to the HasSector command. + hassectorbasecost: Currency + + // Cost values specific to the Read instruction. + readbasecost: Currency + readlengthcost: Currency + + // Cost values specific to the RenewContract instruction. + renewcontractcost: Currency + + // Cost values specific to the Revision command. + revisionbasecost: Currency + + // SwapSectorBaseCost is the cost of swapping 2 full sectors by root. + swapsectorcost: Currency + + // Cost values specific to the Write instruction. + writebasecost: Currency + writelengthcost: Currency + writestorecost: Currency + + // TxnFee estimations. + txnfeeminrecommended: Currency + txnfeemaxrecommended: Currency + + // ContractPrice is the additional fee a host charges when forming/renewing + // a contract to cover the miner fees when submitting the contract and + // revision to the blockchain. + contractprice: Currency + + // CollateralCost is the amount of money per byte the host is promising to + // lock away as collateral when adding new data to a contract. It's paid out + // to the host regardless of the outcome of the storage proof. + collateralcost: Currency + + // MaxCollateral is the maximum amount of collateral the host is willing to + // put into a single file contract. + maxcollateral: Currency + + // MaxDuration is the max duration for which the host is willing to form a + // contract. + maxduration: number + + // WindowSize is the minimum time in blocks the host requests the + // renewWindow of a new contract to be. + windowsize: number + + // Registry related fields. + registryentriesleft: number + registryentriestotal: number +}