diff --git a/api/host.go b/api/host.go index 4a6aee473..d658a318e 100644 --- a/api/host.go +++ b/api/host.go @@ -4,7 +4,6 @@ import ( "encoding/json" "errors" "fmt" - "sort" "strings" "time" @@ -228,11 +227,8 @@ func (h Host) IsV2() bool { } func (h Host) V2SiamuxAddr() string { - // NOTE: eventually this can be smarter about picking an address but right now - // we just prioritize IPv4 over IPv6 - sort.Slice(h.V2SiamuxAddresses, func(i, j int) bool { - return len(h.V2SiamuxAddresses[i]) < len(h.V2SiamuxAddresses[j]) - }) + // NOTE: eventually we can improve this by implementing a dialer wrapper that + // can be created from a slice of addresses and tries them in order. if len(h.V2SiamuxAddresses) > 0 { return h.V2SiamuxAddresses[0] } diff --git a/stores/sql/mysql/chain.go b/stores/sql/mysql/chain.go index 2870be00e..3ffaa8a17 100644 --- a/stores/sql/mysql/chain.go +++ b/stores/sql/mysql/chain.go @@ -210,8 +210,8 @@ func (c chainUpdateTx) UpdateHost(hk types.PublicKey, v1Addr string, v2Ha chain. // create the host var hostID int64 if res, err := c.tx.Exec(c.ctx, ` - INSERT INTO hosts (created_at, public_key, settings, price_table, total_scans, last_scan, last_scan_success, second_to_last_scan_success, scanned, uptime, downtime, recent_downtime, recent_scan_failures, successful_interactions, failed_interactions, lost_sectors, last_announcement, net_address) - VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) + INSERT INTO hosts (created_at, public_key, settings, v2_settings, price_table, total_scans, last_scan, last_scan_success, second_to_last_scan_success, scanned, uptime, downtime, recent_downtime, recent_scan_failures, successful_interactions, failed_interactions, lost_sectors, last_announcement, net_address) + VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) ON DUPLICATE KEY UPDATE last_announcement = VALUES(last_announcement), net_address = VALUES(net_address), @@ -220,6 +220,7 @@ func (c chainUpdateTx) UpdateHost(hk types.PublicKey, v1Addr string, v2Ha chain. time.Now().UTC(), ssql.PublicKey(hk), ssql.HostSettings{}, + ssql.V2HostSettings{}, ssql.PriceTable{}, 0, 0, diff --git a/stores/sql/sqlite/chain.go b/stores/sql/sqlite/chain.go index e97b8c1aa..eb46844a9 100644 --- a/stores/sql/sqlite/chain.go +++ b/stores/sql/sqlite/chain.go @@ -213,8 +213,8 @@ func (c chainUpdateTx) UpdateHost(hk types.PublicKey, v1Addr string, v2Ha chain. // create the host var hostID int64 if err := c.tx.QueryRow(c.ctx, ` - INSERT INTO hosts (created_at, public_key, settings, price_table, total_scans, last_scan, last_scan_success, second_to_last_scan_success, scanned, uptime, downtime, recent_downtime, recent_scan_failures, successful_interactions, failed_interactions, lost_sectors, last_announcement, net_address) - VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) + INSERT INTO hosts (created_at, public_key, settings, v2_settings, price_table, total_scans, last_scan, last_scan_success, second_to_last_scan_success, scanned, uptime, downtime, recent_downtime, recent_scan_failures, successful_interactions, failed_interactions, lost_sectors, last_announcement, net_address) + VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) ON CONFLICT(public_key) DO UPDATE SET last_announcement = EXCLUDED.last_announcement, net_address = EXCLUDED.net_address @@ -222,6 +222,7 @@ func (c chainUpdateTx) UpdateHost(hk types.PublicKey, v1Addr string, v2Ha chain. time.Now().UTC(), ssql.PublicKey(hk), ssql.HostSettings{}, + ssql.V2HostSettings{}, ssql.PriceTable{}, 0, 0, diff --git a/stores/sql/types.go b/stores/sql/types.go index 8cf706c5d..043667600 100644 --- a/stores/sql/types.go +++ b/stores/sql/types.go @@ -559,7 +559,7 @@ func (hs *V2HostSettings) Scan(value interface{}) error { case []byte: bytes = value default: - return errors.New(fmt.Sprint("failed to unmarshal Settings value:", value)) + return errors.New(fmt.Sprint("failed to unmarshal V2Settings value:", value)) } return json.Unmarshal(bytes, hs) }