Skip to content

Commit

Permalink
fix: renterd uploads require sync
Browse files Browse the repository at this point in the history
  • Loading branch information
alexfreska committed Dec 1, 2023
1 parent eae7d2f commit 40419ce
Show file tree
Hide file tree
Showing 4 changed files with 102 additions and 23 deletions.
5 changes: 5 additions & 0 deletions .changeset/shiny-clouds-obey.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'renterd': minor
---

File uploads are now disabled if the blockchain is not fully synced.
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@ export function FilesFilterDirectoryMenu() {
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [debouncedSearch])

console.log('hi')

return (
<div className="flex gap-1 flex-1">
<TextField
Expand All @@ -41,7 +39,7 @@ export function FilesFilterDirectoryMenu() {
placeholder="Filter files in current directory"
value={search}
onChange={(e) => setSearch(e.currentTarget.value)}
className="w-full"
className="w-full !pl-0"
/>
{!!search.length && (
<>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {
Button,
Code,
Paragraph,
Popover,
Separator,
Expand All @@ -8,15 +9,74 @@ import {
import { Warning16 } from '@siafoundation/react-icons'
import { useContractSetMismatch } from '../checks/useContractSetMismatch'
import { useMemo } from 'react'
import { useSyncStatus } from '../../../hooks/useSyncStatus'
import { useAutopilotNotConfigured } from '../checks/useAutopilotNotConfigured'
import { useNotEnoughContracts } from '../checks/useNotEnoughContracts'

export function FilesStatsMenuWarnings() {
const syncStatus = useSyncStatus()
const contractSetMismatch = useContractSetMismatch()
const autopilotNotConfigured = useAutopilotNotConfigured()
const notEnoughContracts = useNotEnoughContracts()

const syncStatusEl = useMemo(() => {
if (!syncStatus.isSynced) {
return (
<div className="flex flex-col gap-1">
<Text size="12" font="mono" weight="medium" color="amber">
Uploads are disabled until renterd is synced.
</Text>
<Paragraph size="12">
The blockchain must be fully synced before uploading files. This can
take a while depending on your hardware and network connection.
</Paragraph>
</div>
)
}
return null
}, [syncStatus.isSynced])

const autopilotNotConfiguredEl = useMemo(() => {
if (autopilotNotConfigured.active) {
return (
<div className="flex flex-col gap-1">
<Text size="12" font="mono" weight="medium" color="amber">
Uploads are disabled until settings are configured.
</Text>
<Paragraph size="12">
Before you can upload files you must configure your settings. Once
configured, <Code>renterd</Code> will find contracts with hosts
based on the settings you choose. <Code>renterd</Code> will also
repair your data as hosts come and go.
</Paragraph>
</div>
)
}
return null
}, [autopilotNotConfigured.active])

const notEnoughContractsEl = useMemo(() => {
if (notEnoughContracts.active) {
return (
<div className="flex flex-col gap-1">
<Text size="12" font="mono" weight="medium" color="amber">
Uploads are disabled until settings are configured.
</Text>
<Paragraph size="12">
There are not enough contracts to upload data yet. Redundancy is
configured to use {notEnoughContracts.required} shards which means
at least that many contracts are required.
</Paragraph>
</div>
)
}
return null
}, [notEnoughContracts])

const contractSetMismatchEl = useMemo(() => {
// warn about contract set mismatch
if (contractSetMismatch.active) {
return (
<div className="flex flex-col gap-2">
<div className="flex flex-col gap-1">
<Text size="12" font="mono" weight="medium" color="amber">
Uploaded data will not be managed by autopilot.
</Text>
Expand All @@ -33,22 +93,35 @@ export function FilesStatsMenuWarnings() {
return null
}, [contractSetMismatch.active])

if (!contractSetMismatchEl) {
return null
}

return (
<>
<Popover
trigger={
<Button variant="ghost" icon="contrast" color="amber">
<Warning16 />
</Button>
}
>
<div className="px-1 py-2">{contractSetMismatchEl}</div>
</Popover>
<Separator variant="vertical" className="h-full" />
</>
const warningList = useMemo(
() =>
[
syncStatusEl,
autopilotNotConfiguredEl,
notEnoughContractsEl,
contractSetMismatchEl,
].filter(Boolean),
[
syncStatusEl,
autopilotNotConfiguredEl,
notEnoughContractsEl,
contractSetMismatchEl,
]
)

if (warningList.length)
return (
<>
<Popover
trigger={
<Button variant="ghost" icon="contrast" color="amber">
<Warning16 />
</Button>
}
>
<div className="flex flex-col gap-3 px-1 py-2">{warningList}</div>
</Popover>
<Separator variant="vertical" className="h-full" />
</>
)
}
5 changes: 4 additions & 1 deletion apps/renterd/components/Files/useCanUpload.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
import { useSyncStatus } from '../../hooks/useSyncStatus'
import { useFiles } from '../../contexts/files'
import { useAutopilotNotConfigured } from './checks/useAutopilotNotConfigured'
import { useNotEnoughContracts } from './checks/useNotEnoughContracts'

export function useCanUpload() {
const { isViewingABucket } = useFiles()
const syncStatus = useSyncStatus()
const autopilotNotConfigured = useAutopilotNotConfigured()
const notEnoughContracts = useNotEnoughContracts()
return (
isViewingABucket &&
!autopilotNotConfigured.active &&
!notEnoughContracts.active
!notEnoughContracts.active &&
syncStatus.isSynced
)
}

0 comments on commit 40419ce

Please sign in to comment.