Skip to content

Commit

Permalink
Isolate rhp2 worker code into rhp2 client (#1440)
Browse files Browse the repository at this point in the history
This PR refactors 2 things:

1. rhp2 code is moved to `internal` into a `Client`
2. gouging code is moved to `internal` to be able to pass gouging
checkers to client

This is a preparation for when the bus also needs access to rhp clients
and gouging code.
  • Loading branch information
ChrisSchinnerl authored Aug 16, 2024
2 parents bc4abd8 + fee500c commit aa777b2
Show file tree
Hide file tree
Showing 12 changed files with 1,023 additions and 923 deletions.
6 changes: 3 additions & 3 deletions autopilot/contractor/evaluate.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ import (

"go.sia.tech/core/types"
"go.sia.tech/renterd/api"
"go.sia.tech/renterd/worker"
"go.sia.tech/renterd/internal/gouging"
)

var ErrMissingRequiredFields = errors.New("missing required fields in configuration, both allowance and amount must be set")

func countUsableHosts(cfg api.AutopilotConfig, cs api.ConsensusState, fee types.Currency, period uint64, rs api.RedundancySettings, gs api.GougingSettings, hosts []api.Host) (usables uint64) {
gc := worker.NewGougingChecker(gs, cs, fee, period, cfg.Contracts.RenewWindow)
gc := gouging.NewChecker(gs, cs, fee, &period, &cfg.Contracts.RenewWindow)
for _, host := range hosts {
hc := checkHost(gc, scoreHost(host, cfg, rs.Redundancy()), minValidScore)
if hc.Usability.IsUsable() {
Expand All @@ -31,7 +31,7 @@ func EvaluateConfig(cfg api.AutopilotConfig, cs api.ConsensusState, fee types.Cu
}

period := cfg.Contracts.Period
gc := worker.NewGougingChecker(gs, cs, fee, period, cfg.Contracts.RenewWindow)
gc := gouging.NewChecker(gs, cs, fee, &period, &cfg.Contracts.RenewWindow)

resp.Hosts = uint64(len(hosts))
for i, host := range hosts {
Expand Down
4 changes: 2 additions & 2 deletions autopilot/contractor/hostfilter.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
rhpv3 "go.sia.tech/core/rhp/v3"
"go.sia.tech/core/types"
"go.sia.tech/renterd/api"
"go.sia.tech/renterd/worker"
"go.sia.tech/renterd/internal/gouging"
)

const (
Expand Down Expand Up @@ -220,7 +220,7 @@ func isUpForRenewal(cfg api.AutopilotConfig, r types.FileContractRevision, block
}

// checkHost performs a series of checks on the host.
func checkHost(gc worker.GougingChecker, sh scoredHost, minScore float64) *api.HostCheck {
func checkHost(gc gouging.Checker, sh scoredHost, minScore float64) *api.HostCheck {
h := sh.host

// prepare host breakdown fields
Expand Down
7 changes: 4 additions & 3 deletions autopilot/contractor/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (

"go.sia.tech/core/types"
"go.sia.tech/renterd/api"
"go.sia.tech/renterd/worker"
"go.sia.tech/renterd/internal/gouging"
)

type (
Expand Down Expand Up @@ -73,8 +73,9 @@ func (ctx *mCtx) Err() error {
return ctx.ctx.Err()
}

func (ctx *mCtx) GougingChecker(cs api.ConsensusState) worker.GougingChecker {
return worker.NewGougingChecker(ctx.state.GS, cs, ctx.state.Fee, ctx.Period(), ctx.RenewWindow())
func (ctx *mCtx) GougingChecker(cs api.ConsensusState) gouging.Checker {
period, renewWindow := ctx.Period(), ctx.RenewWindow()
return gouging.NewChecker(ctx.state.GS, cs, ctx.state.Fee, &period, &renewWindow)
}

func (ctx *mCtx) HostScore(h api.Host) (sb api.HostScoreBreakdown, err error) {
Expand Down
Loading

0 comments on commit aa777b2

Please sign in to comment.