Skip to content

Commit

Permalink
sql: insert empty v2_settings in UpdateHost
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisSchinnerl committed Nov 15, 2024
1 parent 0d20bc4 commit f623e42
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 11 deletions.
8 changes: 2 additions & 6 deletions api/host.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"encoding/json"
"errors"
"fmt"
"sort"
"strings"
"time"

Expand Down Expand Up @@ -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]
}
Expand Down
5 changes: 3 additions & 2 deletions stores/sql/mysql/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -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,
Expand Down
5 changes: 3 additions & 2 deletions stores/sql/sqlite/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,15 +213,16 @@ 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
RETURNING id`,
time.Now().UTC(),
ssql.PublicKey(hk),
ssql.HostSettings{},
ssql.V2HostSettings{},
ssql.PriceTable{},
0,
0,
Expand Down
2 changes: 1 addition & 1 deletion stores/sql/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down

0 comments on commit f623e42

Please sign in to comment.