Skip to content

Commit

Permalink
fix(cluster): cluster and types
Browse files Browse the repository at this point in the history
  • Loading branch information
alexfreska committed Dec 6, 2024
1 parent 0973fec commit 5581662
Show file tree
Hide file tree
Showing 23 changed files with 55 additions and 44 deletions.
6 changes: 3 additions & 3 deletions apps/hostd-e2e/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
"executor": "nx:run-commands",
"options": {
"commands": [
"cd internal/cluster && go get -u go.sia.tech/hostd@master",
"cd internal/cluster && go get -u go.sia.tech/renterd@dev",
"cd internal/cluster && go get -u go.sia.tech/walletd@master",
// "cd internal/cluster && go get -u go.sia.tech/hostd@master",
// "cd internal/cluster && go get -u go.sia.tech/renterd@dev",
// "cd internal/cluster && go get -u go.sia.tech/walletd@master",
"cd internal/cluster && go mod tidy",
"cd internal/cluster && go build -o bin/clusterd ./cmd/clusterd || echo 'BUILD FAILED'",
"git checkout internal/cluster/go.mod internal/cluster/go.sum",
Expand Down
2 changes: 1 addition & 1 deletion apps/hostd/contexts/contracts/dataset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Contract } from '@siafoundation/hostd-types'
import { useContracts } from '@siafoundation/hostd-react'
import { ContractData } from './types'
import BigNumber from 'bignumber.js'
import { Maybe } from '@siafoundation/design-system'
import { Maybe } from '@siafoundation/types'

export function useDataset({
response,
Expand Down
2 changes: 1 addition & 1 deletion apps/hostd/contexts/contracts/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import {
useDatasetEmptyState,
useServerFilters,
getContractsTimeRangeBlockHeight,
Maybe,
useMultiSelect,
} from '@siafoundation/design-system'
import { Maybe } from '@siafoundation/types'
import { useRouter } from 'next/router'
import { ContractStatus } from '@siafoundation/hostd-types'
import { useContracts as useContractsData } from '@siafoundation/hostd-react'
Expand Down
6 changes: 3 additions & 3 deletions apps/renterd-e2e/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
"executor": "nx:run-commands",
"options": {
"commands": [
"cd internal/cluster && go get -u go.sia.tech/hostd@master",
"cd internal/cluster && go get -u go.sia.tech/renterd@dev",
"cd internal/cluster && go get -u go.sia.tech/walletd@master",
// "cd internal/cluster && go get -u go.sia.tech/hostd@master",
// "cd internal/cluster && go get -u go.sia.tech/renterd@dev",
// "cd internal/cluster && go get -u go.sia.tech/walletd@master",
"cd internal/cluster && go mod tidy",
"cd internal/cluster && go build -o bin/clusterd ./cmd/clusterd || echo 'BUILD FAILED'",
"git checkout internal/cluster/go.mod internal/cluster/go.sum",
Expand Down
4 changes: 1 addition & 3 deletions apps/renterd-e2e/src/specs/contracts.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,7 @@ test('contracts bulk delete', async ({ page }) => {
const dialog = page.getByRole('dialog')
await dialog.getByRole('button', { name: 'Delete' }).click()

await expect(
page.getByText('There are currently no active contracts')
).toBeVisible()
await expect(page.getByText('3 contracts deleted')).toBeVisible()
})

test('contracts bulk allowlist', async ({ page }) => {
Expand Down
2 changes: 1 addition & 1 deletion apps/renterd/components/Config/RebalancePrices.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import { useConfig } from '../../contexts/config'
import {
Button,
formSetFields,
Maybe,
Text,
Tooltip,
} from '@siafoundation/design-system'
import { Maybe } from '@siafoundation/types'
import { InputValues } from '../../contexts/config/types'
import BigNumber from 'bignumber.js'
import { derivePricingFromSpendingEstimate } from '../../contexts/config/spending'
Expand Down
12 changes: 8 additions & 4 deletions apps/renterd/contexts/alerts/columns.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {
Badge,
Button,
ControlGroup,
objectEntries,
Panel,
Separator,
TableColumn,
Expand Down Expand Up @@ -86,8 +87,8 @@ export const columns: AlertsTableColumn[] = [
// Collect data for data fields
const datums = useMemo(
() =>
Object.keys(dataFields)
.map((key) => {
objectEntries(dataFields)
.map(([key]) => {
const value = data[key]
if (
value === undefined ||
Expand All @@ -98,14 +99,17 @@ export const columns: AlertsTableColumn[] = [
}
return { key, value }
})
.filter(Boolean) as { key: string; value: unknown }[],
// eslint-disable-next-line @typescript-eslint/no-explicit-any
.filter((data) => data) as { key: string; value: any }[],
[data]
)
return (
<div className="py-4 w-full">
<Panel color="subtle" className="flex flex-col gap-1 w-full py-1">
{datums.map(({ key, value }, i) => {
const Component = dataFields?.[key]?.render
const Component: // eslint-disable-next-line @typescript-eslint/no-explicit-any
((props: { value: any }) => React.ReactNode) | undefined =
dataFields?.[key as keyof AlertData['data']]?.render
if (!Component) {
return null
}
Expand Down
7 changes: 5 additions & 2 deletions apps/renterd/contexts/alerts/types.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
export type AlertSeverity = 'info' | 'warning' | 'error' | 'critical'
import {
AlertSeverity,
AlertData as AlertDataField,
} from '@siafoundation/renterd-types'

export type AlertData = {
id: string
severity: AlertSeverity
message: string
timestamp: string
data: Record<string, unknown>
data: AlertDataField
dismiss: () => void
}

Expand Down
2 changes: 1 addition & 1 deletion apps/renterd/contexts/config/fields.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
import {
Code,
ConfigFields,
Maybe,
toFixedMaxString,
} from '@siafoundation/design-system'
import { Maybe } from '@siafoundation/types'
import { hoursInDays, secondsInMinutes } from '@siafoundation/units'
import BigNumber from 'bignumber.js'
import React from 'react'
Expand Down
2 changes: 1 addition & 1 deletion apps/renterd/contexts/config/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { NoUndefined } from '@siafoundation/design-system'
import { NoUndefined } from '@siafoundation/types'
import { CurrencyId } from '@siafoundation/react-core'
import BigNumber from 'bignumber.js'

Expand Down
2 changes: 1 addition & 1 deletion apps/renterd/contexts/config/useSpendingEstimate.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useConfig } from '.'
import { useMemo } from 'react'
import { Maybe } from '@siafoundation/design-system'
import { Maybe } from '@siafoundation/types'
import BigNumber from 'bignumber.js'
import { useRedundancyMultiplier } from './useRedundancyMultiplier'
import { calculateSpendingEstimate } from './spending'
Expand Down
2 changes: 1 addition & 1 deletion apps/renterd/contexts/contracts/dataset.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { useSyncStatus } from '../../hooks/useSyncStatus'
import { blockHeightToTime } from '@siafoundation/units'
import { defaultDatasetRefreshInterval } from '../../config/swr'
import { usePrunableContractSizes } from './usePrunableContractSizes'
import { Maybe } from '@siafoundation/design-system'
import { Maybe } from '@siafoundation/types'

export function useDataset() {
const response = useContractsData({
Expand Down
2 changes: 1 addition & 1 deletion apps/renterd/contexts/contracts/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import {
useClientFilters,
useClientFilteredDataset,
useMultiSelect,
Maybe,
} from '@siafoundation/design-system'
import { Maybe } from '@siafoundation/types'
import { useRouter } from 'next/router'
import { useContracts as useContractsData } from '@siafoundation/renterd-react'
import { createContext, useContext, useMemo, useState } from 'react'
Expand Down
3 changes: 2 additions & 1 deletion apps/renterd/contexts/hosts/dataset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ import {
} from '@siafoundation/renterd-react'
import { ContractData } from '../contracts/types'
import { SiaCentralHost } from '@siafoundation/sia-central-types'
import { Maybe, objectEntries } from '@siafoundation/design-system'
import { Maybe } from '@siafoundation/types'
import { objectEntries } from '@siafoundation/design-system'

export function useDataset({
response,
Expand Down
6 changes: 3 additions & 3 deletions apps/walletd-e2e/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
"executor": "nx:run-commands",
"options": {
"commands": [
"cd internal/cluster && go get -u go.sia.tech/hostd@master",
"cd internal/cluster && go get -u go.sia.tech/renterd@dev",
"cd internal/cluster && go get -u go.sia.tech/walletd@master",
// "cd internal/cluster && go get -u go.sia.tech/hostd@master",
// "cd internal/cluster && go get -u go.sia.tech/renterd@dev",
// "cd internal/cluster && go get -u go.sia.tech/walletd@master",
"cd internal/cluster && go mod tidy",
"cd internal/cluster && go build -o bin/clusterd ./cmd/clusterd || echo 'BUILD FAILED'",
"git checkout internal/cluster/go.mod internal/cluster/go.sum",
Expand Down
3 changes: 2 additions & 1 deletion libs/clusterd/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
"axios": "^0.27.2",
"@siafoundation/renterd-js": "0.11.0",
"@siafoundation/units": "3.2.0",
"@siafoundation/hostd-js": "0.3.1"
"@siafoundation/hostd-js": "0.3.1",
"@siafoundation/types": "0.6.0"
},
"types": "./src/index.d.ts"
}
19 changes: 11 additions & 8 deletions libs/clusterd/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import Axios from 'axios'
import { Bus } from '@siafoundation/renterd-js'
import { pluralize } from '@siafoundation/units'
import { Hostd } from '@siafoundation/hostd-js'
import { Maybe } from '@siafoundation/types'

type Node = {
type: string
Expand Down Expand Up @@ -52,12 +53,12 @@ export async function setupCluster({
const addr = `http://localhost:${clusterd.managementPort}/nodes`
try {
const nodes = await Axios.get<
{ type: string; apiAddress: string; password: string }[]
Maybe<{ type: string; apiAddress: string; password: string }[]>
>(`http://localhost:${clusterd.managementPort}/nodes`)
const runningCount = nodes.data.length
const runningCount = nodes.data?.length
const totalCount = renterdCount + hostdCount + walletdCount
if (nodes.data.length === renterdCount + hostdCount + walletdCount) {
clusterd.nodes = nodes.data.map((n) => ({
if (nodes.data?.length === renterdCount + hostdCount + walletdCount) {
clusterd.nodes = nodes.data?.map((n) => ({
...n,
apiAddress: n.apiAddress.replace('[::]', '127.0.0.1'),
}))
Expand Down Expand Up @@ -112,12 +113,14 @@ export async function renterdWaitForContracts({
},
})
const contracts = await bus.contracts()

const hostCount = hosts.data?.length || 0
const contractCount = contracts.data?.length || 0

console.log(
`usable hosts: ${hosts.data.length}/${hostdCount} - active contracts: ${contracts.data.length}/${hostdCount}`
)
return (
hosts.data.length >= hostdCount && contracts.data.length >= hostdCount
`usable hosts: ${hostCount}/${hostdCount} - active contracts: ${contractCount}/${hostdCount}`
)
return hostCount >= hostdCount && contractCount >= hostdCount
},
{
timeout: maxTimeWaitingForContractsToForm,
Expand Down
1 change: 0 additions & 1 deletion libs/design-system/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -192,4 +192,3 @@ export * from './lib/nodeToImage'
export * from './lib/colors'
export * from './lib/object'
export * from './lib/handleBatchOperation'
export type * from './lib/types'
2 changes: 1 addition & 1 deletion libs/renterd-js/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export async function example() {
},
})

hosts.data.forEach((host) => {
hosts.data?.forEach((host) => {
console.log(host.publicKey, host.priceTable)
})

Expand Down
2 changes: 1 addition & 1 deletion libs/renterd-js/src/example.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export async function example() {
},
})

hosts.data.forEach((host) => {
hosts.data?.forEach((host) => {
console.log(host.publicKey, host.priceTable)
})

Expand Down
5 changes: 3 additions & 2 deletions libs/renterd-types/src/bus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
Transaction,
TransactionID,
WalletEvent,
Maybe,
} from '@siafoundation/types'
import {
ConsensusState,
Expand Down Expand Up @@ -231,7 +232,7 @@ export type HostsPayload = {
limit?: number
maxLastScan?: string
}
export type HostsResponse = Host[]
export type HostsResponse = Maybe<Host[]>

export type HostParams = { hostkey: string }
export type HostPayload = Host
Expand Down Expand Up @@ -290,7 +291,7 @@ export type HostScanResponse = {

export type ContractsParams = void
export type ContractsPayload = void
export type ContractsResponse = Contract[]
export type ContractsResponse = Maybe<Contract[]>

export type ContractAcquireParams = {
id: string
Expand Down
7 changes: 4 additions & 3 deletions libs/types/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export * from './core'
export * from './events'
export * from './v2'
export type * from './core'
export type * from './events'
export type * from './utils'
export type * from './v2'
File renamed without changes.

0 comments on commit 5581662

Please sign in to comment.