diff --git a/explorer/types.go b/explorer/types.go index a78969f..f5d6d9a 100644 --- a/explorer/types.go +++ b/explorer/types.go @@ -354,6 +354,11 @@ func (h Host) IsV2() bool { return len(h.V2NetAddresses) > 0 } +// IsScan returns whether a host object contains a successful scan or not. +func (h Host) IsScan() bool { + return (h.Settings != rhpv2.HostSettings{}) || (h.PriceTable != rhpv3.HostPriceTable{}) || (h.RHPV4Settings != rhpv4.HostSettings{}) +} + // HostMetrics represents averages of scanned information from hosts. type HostMetrics struct { ActiveHosts uint64 `json:"activeHosts"` diff --git a/persist/sqlite/consensus.go b/persist/sqlite/consensus.go index 722c0b3..46f6d8b 100644 --- a/persist/sqlite/consensus.go +++ b/persist/sqlite/consensus.go @@ -7,10 +7,6 @@ import ( "errors" "fmt" - rhpv2 "go.sia.tech/core/rhp/v2" - rhpv3 "go.sia.tech/core/rhp/v3" - rhpv4 "go.sia.tech/core/rhp/v4" - "go.sia.tech/core/types" "go.sia.tech/coreutils/chain" "go.sia.tech/explored/explorer" @@ -1146,7 +1142,7 @@ func addHosts(tx *txn, scans []explorer.Host) error { s, p := scan.Settings, scan.PriceTable sV4, pV4 := scan.RHPV4Settings, scan.RHPV4Settings.Prices - if (scan.Settings == rhpv2.HostSettings{}) && (scan.PriceTable == rhpv3.HostPriceTable{}) && (scan.RHPV4Settings == rhpv4.HostSettings{}) { + if !scan.IsScan() { // Either we have an initial host announcement or the scan was // unsuccessful. In this case we do not overwrite the previous // settings/price table data.