Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move host info to the bus #1077

Merged
merged 34 commits into from
Mar 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
b8c5648
stores: add dbHostInfo
peterjan Mar 18, 2024
d70d47f
autopilot: calculate host info and update in the bus
peterjan Mar 18, 2024
a97e602
Merge branch 'dev' of github.com:SiaFoundation/renterd into pj/host-i…
peterjan Mar 19, 2024
f0ce1c8
autopilot: add compatV105HostInfo
peterjan Mar 19, 2024
8efc718
autopilot: add compatV105UsabilityFilterModeCheck
peterjan Mar 19, 2024
50b7d76
stores: remove usability unknonwn
peterjan Mar 19, 2024
37c725e
api: fix japecheck errors
peterjan Mar 19, 2024
758f9ba
Merge branch 'pj/host-filter-mode' of github.com:SiaFoundation/renter…
peterjan Mar 19, 2024
c011dc8
autopilot: update host filter
peterjan Mar 19, 2024
61c7c97
contractor: remove cached fields
peterjan Mar 19, 2024
06070ac
autopilot: remove TODO
peterjan Mar 19, 2024
0d438a7
lint: fix
peterjan Mar 19, 2024
fb44490
autopilot: update comment
peterjan Mar 19, 2024
d79cab9
Merge branch 'dev' of github.com:SiaFoundation/renterd into pj/host-i…
peterjan Mar 20, 2024
864c08b
contractor: fetch all hosts
peterjan Mar 20, 2024
8916dcc
Merge branch 'dev' of github.com:SiaFoundation/renterd into pj/host-i…
peterjan Mar 25, 2024
535a4d9
stores: add autopilot and usability filter to SearchHosts
peterjan Mar 25, 2024
104731b
bus: fix typo
peterjan Mar 25, 2024
a6b5d16
autopilot: fix response types
peterjan Mar 25, 2024
8484bb0
bus: fix route
peterjan Mar 25, 2024
65c330d
stores: add retry to UpdateHostCheck
peterjan Mar 25, 2024
6983036
autopilot: fix SearchHostOptions usage
peterjan Mar 25, 2024
d3c4283
hostdb: move host to api package
peterjan Mar 25, 2024
419b21e
stores: update SearchHosts
peterjan Mar 25, 2024
2666f0f
Merge branch 'pj/host-infos' into pj/merge-host-types
peterjan Mar 25, 2024
c68a88c
lint: fix nesting
peterjan Mar 25, 2024
59d6009
contractor: remove error check
peterjan Mar 26, 2024
39c9a5d
Merge host types (#1103)
ChrisSchinnerl Mar 27, 2024
2f42d58
api: omit unusablereasons if empty
peterjan Mar 27, 2024
c58cc7a
Merge branch 'pj/host-infos' of github.com:SiaFoundation/renterd into…
peterjan Mar 27, 2024
c5cde12
Merge branch 'dev' into pj/host-infos
peterjan Mar 27, 2024
65f8e42
Merge branch 'dev' of github.com:SiaFoundation/renterd into pj/host-i…
peterjan Mar 28, 2024
6d126d8
Merge branch 'pj/host-infos' of github.com:SiaFoundation/renterd into…
peterjan Mar 28, 2024
da9d3e7
Merge branch 'dev' into pj/host-infos
ChrisSchinnerl Mar 28, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .github/workflows/project-add.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,3 @@ jobs:
add-to-project:
uses: SiaFoundation/workflows/.github/workflows/project-add.yml@master
secrets: inherit

16 changes: 0 additions & 16 deletions api/autopilot.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"errors"

"go.sia.tech/core/types"
"go.sia.tech/renterd/hostdb"
)

const (
Expand Down Expand Up @@ -119,21 +118,6 @@ type (
}
Recommendation *ConfigRecommendation `json:"recommendation,omitempty"`
}

// HostHandlerResponse is the response type for the /host/:hostkey endpoint.
HostHandlerResponse struct {
Host hostdb.Host `json:"host"`
Checks *HostHandlerResponseChecks `json:"checks,omitempty"`
}

HostHandlerResponseChecks struct {
Gouging bool `json:"gouging"`
GougingBreakdown HostGougingBreakdown `json:"gougingBreakdown"`
Score float64 `json:"score"`
ScoreBreakdown HostScoreBreakdown `json:"scoreBreakdown"`
Usable bool `json:"usable"`
UnusableReasons []string `json:"unusableReasons"`
}
)

func (c AutopilotConfig) Validate() error {
Expand Down
138 changes: 132 additions & 6 deletions api/host.go
ChrisSchinnerl marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@ import (
"fmt"
"net/url"
"strings"
"time"

rhpv2 "go.sia.tech/core/rhp/v2"
rhpv3 "go.sia.tech/core/rhp/v3"
"go.sia.tech/core/types"
"go.sia.tech/renterd/hostdb"
)

const (
Expand All @@ -26,15 +28,27 @@ var (
ErrHostNotFound = errors.New("host doesn't exist in hostdb")
)

var (
ErrUsabilityHostBlocked = errors.New("host is blocked")
ErrUsabilityHostNotFound = errors.New("host not found")
ErrUsabilityHostOffline = errors.New("host is offline")
ErrUsabilityHostLowScore = errors.New("host's score is below minimum")
ErrUsabilityHostRedundantIP = errors.New("host has redundant IP")
ErrUsabilityHostPriceGouging = errors.New("host is price gouging")
ErrUsabilityHostNotAcceptingContracts = errors.New("host is not accepting contracts")
ErrUsabilityHostNotCompletingScan = errors.New("host is not completing scan")
ErrUsabilityHostNotAnnounced = errors.New("host is not announced")
)

type (
// HostsScanRequest is the request type for the /hosts/scans endpoint.
HostsScanRequest struct {
Scans []hostdb.HostScan `json:"scans"`
Scans []HostScan `json:"scans"`
}

// HostsPriceTablesRequest is the request type for the /hosts/pricetables endpoint.
HostsPriceTablesRequest struct {
PriceTableUpdates []hostdb.PriceTableUpdate `json:"priceTableUpdates"`
PriceTableUpdates []HostPriceTableUpdate `json:"priceTableUpdates"`
}

// HostsRemoveRequest is the request type for the /hosts/remove endpoint.
Expand All @@ -48,11 +62,28 @@ type (
SearchHostsRequest struct {
Offset int `json:"offset"`
Limit int `json:"limit"`
AutopilotID string `json:"autopilotID"`
FilterMode string `json:"filterMode"`
UsabilityMode string `json:"usabilityMode"`
AddressContains string `json:"addressContains"`
KeyIn []types.PublicKey `json:"keyIn"`
}

// HostResponse is the response type for the GET
// /api/autopilot/host/:hostkey endpoint.
HostResponse struct {
Host Host `json:"host"`
Checks *HostChecks `json:"checks,omitempty"`
}

HostChecks struct {
Gouging bool `json:"gouging"`
GougingBreakdown HostGougingBreakdown `json:"gougingBreakdown"`
Score float64 `json:"score"`
ScoreBreakdown HostScoreBreakdown `json:"scoreBreakdown"`
Usable bool `json:"usable"`
UnusableReasons []string `json:"unusableReasons,omitempty"`
}
)

type (
Expand Down Expand Up @@ -84,8 +115,10 @@ type (
}

SearchHostOptions struct {
AutopilotID string
AddressContains string
FilterMode string
UsabilityMode string
KeyIn []types.PublicKey
Limit int
Offset int
Expand Down Expand Up @@ -115,9 +148,54 @@ func (opts HostsForScanningOptions) Apply(values url.Values) {

type (
Host struct {
hostdb.Host
Blocked bool `json:"blocked"`
Checks map[string]HostCheck `json:"checks"`
KnownSince time.Time `json:"knownSince"`
LastAnnouncement time.Time `json:"lastAnnouncement"`
PublicKey types.PublicKey `json:"publicKey"`
NetAddress string `json:"netAddress"`
PriceTable HostPriceTable `json:"priceTable"`
Settings rhpv2.HostSettings `json:"settings"`
Interactions HostInteractions `json:"interactions"`
Scanned bool `json:"scanned"`
Blocked bool `json:"blocked"`
Checks map[string]HostCheck `json:"checks"`
}

HostAddress struct {
PublicKey types.PublicKey `json:"publicKey"`
NetAddress string `json:"netAddress"`
}

HostInteractions struct {
TotalScans uint64 `json:"totalScans"`
LastScan time.Time `json:"lastScan"`
LastScanSuccess bool `json:"lastScanSuccess"`
LostSectors uint64 `json:"lostSectors"`
SecondToLastScanSuccess bool `json:"secondToLastScanSuccess"`
Uptime time.Duration `json:"uptime"`
Downtime time.Duration `json:"downtime"`

SuccessfulInteractions float64 `json:"successfulInteractions"`
FailedInteractions float64 `json:"failedInteractions"`
}

HostScan struct {
HostKey types.PublicKey `json:"hostKey"`
Success bool
Timestamp time.Time
Settings rhpv2.HostSettings
PriceTable rhpv3.HostPriceTable
}

HostPriceTable struct {
rhpv3.HostPriceTable
Expiry time.Time `json:"expiry"`
}

HostPriceTableUpdate struct {
HostKey types.PublicKey `json:"hostKey"`
Success bool
Timestamp time.Time
PriceTable HostPriceTable
}

HostCheck struct {
Expand Down Expand Up @@ -156,6 +234,21 @@ type (
}
)

// IsAnnounced returns whether the host has been announced.
func (h Host) IsAnnounced() bool {
return !h.LastAnnouncement.IsZero()
}

// IsOnline returns whether a host is considered online.
func (h Host) IsOnline() bool {
if h.Interactions.TotalScans == 0 {
return false
} else if h.Interactions.TotalScans == 1 {
return h.Interactions.LastScanSuccess
}
return h.Interactions.LastScanSuccess || h.Interactions.SecondToLastScanSuccess
}

func (sb HostScoreBreakdown) String() string {
return fmt.Sprintf("Age: %v, Col: %v, Int: %v, SR: %v, UT: %v, V: %v, Pr: %v", sb.Age, sb.Collateral, sb.Interactions, sb.StorageRemaining, sb.Uptime, sb.Version, sb.Prices)
}
Expand Down Expand Up @@ -194,3 +287,36 @@ func (hgb HostGougingBreakdown) String() string {
func (sb HostScoreBreakdown) Score() float64 {
return sb.Age * sb.Collateral * sb.Interactions * sb.StorageRemaining * sb.Uptime * sb.Version * sb.Prices
}

func (ub HostUsabilityBreakdown) IsUsable() bool {
return !ub.Blocked && !ub.Offline && !ub.LowScore && !ub.RedundantIP && !ub.Gouging && !ub.NotAcceptingContracts && !ub.NotAnnounced && !ub.NotCompletingScan
}

func (ub HostUsabilityBreakdown) UnusableReasons() []string {
var reasons []string
if ub.Blocked {
reasons = append(reasons, ErrUsabilityHostBlocked.Error())
}
if ub.Offline {
reasons = append(reasons, ErrUsabilityHostOffline.Error())
}
if ub.LowScore {
reasons = append(reasons, ErrUsabilityHostLowScore.Error())
}
if ub.RedundantIP {
reasons = append(reasons, ErrUsabilityHostRedundantIP.Error())
}
if ub.Gouging {
reasons = append(reasons, ErrUsabilityHostPriceGouging.Error())
}
if ub.NotAcceptingContracts {
reasons = append(reasons, ErrUsabilityHostNotAcceptingContracts.Error())
}
if ub.NotAnnounced {
reasons = append(reasons, ErrUsabilityHostNotAnnounced.Error())
}
if ub.NotCompletingScan {
reasons = append(reasons, ErrUsabilityHostNotCompletingScan.Error())
}
return reasons
}
Loading
Loading