Skip to content

Commit

Permalink
refactor(types): move HostSettings and HostPriceTable to core types
Browse files Browse the repository at this point in the history
  • Loading branch information
telestrial committed Nov 20, 2024
1 parent ecec83f commit dfcfdff
Show file tree
Hide file tree
Showing 7 changed files with 159 additions and 73 deletions.
7 changes: 7 additions & 0 deletions .changeset/fresh-plants-shave.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'@siafoundation/renterd-types': minor
'@siafoundation/types': minor
'@siafoundation/renterd': minor
---

Moved HostSettings and HostPriceTable to core types.
3 changes: 1 addition & 2 deletions apps/renterd/contexts/hosts/columns.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
2 changes: 1 addition & 1 deletion apps/renterd/contexts/hosts/types.tsx
Original file line number Diff line number Diff line change
@@ -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'

Expand Down
8 changes: 4 additions & 4 deletions libs/renterd-types/src/bus.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import {
Block,
Currency,
HostSettings,
FileContractID,
FileContractRevision,
PublicKey,
Transaction,
FileContractRevision,
FileContractID,
Block,
TransactionID,
WalletEvent,
} from '@siafoundation/types'
Expand All @@ -14,7 +15,6 @@ import {
Contract,
ContractRevision,
Host,
HostSettings,
Obj,
ObjectMetadata,
SettingsGouging,
Expand Down
69 changes: 4 additions & 65 deletions libs/renterd-types/src/types.ts
Original file line number Diff line number Diff line change
@@ -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'

Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion libs/renterd-types/src/worker.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { HostSettings } from './types'
import { HostSettings } from '@siafoundation/types'
import { BusStateResponse } from './bus'

export const workerStateRoute = '/worker/state'
Expand Down
141 changes: 141 additions & 0 deletions libs/types/src/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

0 comments on commit dfcfdff

Please sign in to comment.