Skip to content

Commit

Permalink
add helper to host to check if it represents a successful scan
Browse files Browse the repository at this point in the history
  • Loading branch information
chris124567 committed Nov 22, 2024
1 parent ebcf140 commit bf7754c
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
5 changes: 5 additions & 0 deletions explorer/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down
6 changes: 1 addition & 5 deletions persist/sqlite/consensus.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit bf7754c

Please sign in to comment.