From 5067545366d848979ad3be088b06173784c32e02 Mon Sep 17 00:00:00 2001 From: Chris Schinnerl Date: Thu, 28 Mar 2024 14:46:17 +0100 Subject: [PATCH] autopilot: allow for setting optional MinProtocolVersion --- api/autopilot.go | 9 +++++++++ autopilot/hostscore.go | 15 ++++++++++++--- autopilot/hostscore_test.go | 1 + internal/test/config.go | 1 + stores/autopilot_test.go | 1 + 5 files changed, 24 insertions(+), 3 deletions(-) diff --git a/api/autopilot.go b/api/autopilot.go index 23425aacf0..5c21926ee0 100644 --- a/api/autopilot.go +++ b/api/autopilot.go @@ -2,8 +2,10 @@ package api import ( "errors" + "fmt" "go.sia.tech/core/types" + "go.sia.tech/siad/build" ) const ( @@ -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 ( @@ -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"` } @@ -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 } diff --git a/autopilot/hostscore.go b/autopilot/hostscore.go index fc98499f1a..48923997bc 100644 --- a/autopilot/hostscore.go +++ b/autopilot/hostscore.go @@ -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), } } @@ -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 diff --git a/autopilot/hostscore_test.go b/autopilot/hostscore_test.go index bc5f61b8a6..5de0092ab2 100644 --- a/autopilot/hostscore_test.go +++ b/autopilot/hostscore_test.go @@ -26,6 +26,7 @@ var cfg = api.AutopilotConfig{ }, Hosts: api.HostsConfig{ MaxDowntimeHours: 24 * 7 * 2, + MinProtocolVersion: api.MinProtocolVersion, MinRecentScanFailures: 10, }, } diff --git a/internal/test/config.go b/internal/test/config.go index 68a5fff5b0..27e70dc4b9 100644 --- a/internal/test/config.go +++ b/internal/test/config.go @@ -29,6 +29,7 @@ var ( Hosts: api.HostsConfig{ MaxDowntimeHours: 10, MinRecentScanFailures: 10, + MinProtocolVersion: api.MinProtocolVersion, AllowRedundantIPs: true, // allow for integration tests by default }, } diff --git a/stores/autopilot_test.go b/stores/autopilot_test.go index ef94d7d8f3..0cf98e21aa 100644 --- a/stores/autopilot_test.go +++ b/stores/autopilot_test.go @@ -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 }, }