Skip to content

Commit

Permalink
autopilot: allow for setting optional MinProtocolVersion
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisSchinnerl committed Mar 28, 2024
1 parent 3f946f1 commit 5067545
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 3 deletions.
9 changes: 9 additions & 0 deletions api/autopilot.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ package api

import (
"errors"
"fmt"

"go.sia.tech/core/types"
"go.sia.tech/siad/build"
)

const (
Expand All @@ -13,6 +15,10 @@ const (

// DefaultAutopilotID is the id of the autopilot.
DefaultAutopilotID = "autopilot"

// MinProtocolVersion is the minimum protocol version of a host that we
// accept.
MinProtocolVersion = "1.5.9"
)

var (
Expand Down Expand Up @@ -55,6 +61,7 @@ type (
HostsConfig struct {
AllowRedundantIPs bool `json:"allowRedundantIPs"`
MaxDowntimeHours uint64 `json:"maxDowntimeHours"`
MinProtocolVersion string `json:"minProtocolVersion"`
MinRecentScanFailures uint64 `json:"minRecentScanFailures"`
ScoreOverrides map[types.PublicKey]float64 `json:"scoreOverrides"`
}
Expand Down Expand Up @@ -123,6 +130,8 @@ type (
func (c AutopilotConfig) Validate() error {
if c.Hosts.MaxDowntimeHours > 99*365*24 {
return ErrMaxDowntimeHoursTooHigh
} else if c.Hosts.MinProtocolVersion != "" && !build.IsVersion(c.Hosts.MinProtocolVersion) {
return fmt.Errorf("invalid min protocol version '%s'", c.Hosts.MinProtocolVersion)
}
return nil
}
15 changes: 12 additions & 3 deletions autopilot/hostscore.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func hostScore(cfg api.AutopilotConfig, h api.Host, storedData uint64, expectedR
Prices: priceAdjustmentScore(hostPeriodCost, cfg),
StorageRemaining: storageRemainingScore(h.Settings, storedData, allocationPerHost),
Uptime: uptimeScore(h),
Version: versionScore(h.Settings),
Version: versionScore(h.Settings, cfg.Hosts.MinProtocolVersion),
}
}

Expand Down Expand Up @@ -237,12 +237,21 @@ func uptimeScore(h api.Host) float64 {
return math.Pow(ratio, 200*math.Min(1-ratio, 0.30))
}

func versionScore(settings rhpv2.HostSettings) float64 {
func versionScore(settings rhpv2.HostSettings, minProtocolVersion string) float64 {
if minProtocolVersion == "" {
minProtocolVersion = api.MinProtocolVersion
}
versions := []struct {
version string
penalty float64
}{
{"1.6.0", 0.99},
// latest protocol version
{"1.6.0", 0.10},

// user-defined minimum
{minProtocolVersion, 0.00},

// absolute minimum
{"1.5.9", 0.00},
}
weight := 1.0
Expand Down
1 change: 1 addition & 0 deletions autopilot/hostscore_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ var cfg = api.AutopilotConfig{
},
Hosts: api.HostsConfig{
MaxDowntimeHours: 24 * 7 * 2,
MinProtocolVersion: api.MinProtocolVersion,
MinRecentScanFailures: 10,
},
}
Expand Down
1 change: 1 addition & 0 deletions internal/test/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ var (
Hosts: api.HostsConfig{
MaxDowntimeHours: 10,
MinRecentScanFailures: 10,
MinProtocolVersion: api.MinProtocolVersion,
AllowRedundantIPs: true, // allow for integration tests by default
},
}
Expand Down
1 change: 1 addition & 0 deletions stores/autopilot_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ func TestAutopilotStore(t *testing.T) {
Hosts: api.HostsConfig{
MaxDowntimeHours: 10,
MinRecentScanFailures: 10,
MinProtocolVersion: api.MinProtocolVersion,
AllowRedundantIPs: true, // allow for integration tests by default
},
}
Expand Down

0 comments on commit 5067545

Please sign in to comment.