Skip to content

Commit

Permalink
Merge master -> dev (#1658)
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisSchinnerl authored Nov 7, 2024
2 parents ce6eb6b + bbf6f0f commit c77dcc2
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 7 deletions.
4 changes: 2 additions & 2 deletions api/wallet.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ type (
// A SiacoinElement is a SiacoinOutput along with its ID.
SiacoinElement struct {
types.SiacoinOutput
ID types.Hash256 `json:"id"`
MaturityHeight uint64 `json:"maturityHeight"`
ID types.SiacoinOutputID `json:"id"`
MaturityHeight uint64 `json:"maturityHeight"`
}

// A Transaction is an on-chain transaction relevant to a particular wallet,
Expand Down
15 changes: 14 additions & 1 deletion autopilot/contractor/contractor.go
Original file line number Diff line number Diff line change
Expand Up @@ -888,6 +888,15 @@ func performContractChecks(ctx *mCtx, alerter alerts.Alerter, bus Bus, cc contra
continue
}

// NOTE: if we have a contract with a host that is not scanned, we either
// added the host and contract manually or reset the host scans. In that case,
// we ignore the fact that the host is not scanned for now to avoid churn.
if inSet && check.UsabilityBreakdown.NotCompletingScan {
keepContract(c.ContractMetadata, host)
logger.Info("ignoring contract with unscanned host")
continue // no more checks until host is scanned
}

// check usability
if !check.UsabilityBreakdown.IsUsable() {
reasons := strings.Join(check.UsabilityBreakdown.UnusableReasons(), ",")
Expand Down Expand Up @@ -1021,7 +1030,11 @@ func performContractFormations(ctx *mCtx, bus Bus, cr contractReviser, ipFilter
for _, c := range contracts {
usedHosts[c.HostKey] = struct{}{}
}
allHosts, err := bus.Hosts(ctx, api.HostOptions{})
allHosts, err := bus.Hosts(ctx, api.HostOptions{
AutopilotID: ctx.ApID(),
FilterMode: api.HostFilterModeAllowed,
UsabilityMode: api.UsabilityFilterModeUsable,
})
if err != nil {
return nil, fmt.Errorf("failed to fetch usable hosts: %w", err)
}
Expand Down
6 changes: 6 additions & 0 deletions internal/sql/migrations.go
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,12 @@ var (
return performMigration(ctx, tx, migrationsFs, dbIdentifier, "00025_latest_host", log)
},
},
{
ID: "00019_scan_reset",
Migrate: func(tx Tx) error {
return performMigration(ctx, tx, migrationsFs, dbIdentifier, "00019_scan_reset", log)
},
},
}
}
MetricsMigrations = func(ctx context.Context, migrationsFs embed.FS, log *zap.SugaredLogger) []Migration {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
UPDATE hosts SET settings = '{}', price_table = '{}', last_scan = 0, last_scan_success = 0, second_to_last_scan_success = 0, scanned = 0 WHERE 1=1;
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
UPDATE hosts SET settings = '{}', price_table = '{}', last_scan = 0, last_scan_success = 0, second_to_last_scan_success = 0, scanned = 0 WHERE 1=1;
18 changes: 14 additions & 4 deletions stores/sql/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,8 +207,13 @@ func (h Hash256) Value() (driver.Value, error) {

// Scan scan value into HostSettings, implements sql.Scanner interface.
func (hs *HostSettings) Scan(value interface{}) error {
bytes, ok := value.([]byte)
if !ok {
var bytes []byte
switch value := value.(type) {
case string:
bytes = []byte(value)
case []byte:
bytes = value
default:
return errors.New(fmt.Sprint("failed to unmarshal Settings value:", value))
}
return json.Unmarshal(bytes, hs)
Expand All @@ -224,8 +229,13 @@ func (hs HostSettings) Value() (driver.Value, error) {

// Scan scan value into PriceTable, implements sql.Scanner interface.
func (pt *PriceTable) Scan(value interface{}) error {
bytes, ok := value.([]byte)
if !ok {
var bytes []byte
switch value := value.(type) {
case string:
bytes = []byte(value)
case []byte:
bytes = value
default:
return errors.New(fmt.Sprint("failed to unmarshal PriceTable value:", value))
}
return json.Unmarshal(bytes, pt)
Expand Down

0 comments on commit c77dcc2

Please sign in to comment.