Skip to content

Commit

Permalink
Merge branch 'dev' of github.com:SiaFoundation/renterd into its-happe…
Browse files Browse the repository at this point in the history
…ning
  • Loading branch information
peterjan committed May 7, 2024
2 parents 5b98e49 + 26cc954 commit bf5791e
Show file tree
Hide file tree
Showing 9 changed files with 46 additions and 44 deletions.
30 changes: 15 additions & 15 deletions autopilot/contractor/contractor.go
Original file line number Diff line number Diff line change
Expand Up @@ -1054,17 +1054,17 @@ func (c *Contractor) runContractRefreshes(ctx *mCtx, w Worker, toRefresh []contr
return refreshed, nil
}

func (c *Contractor) initialContractFunding(settings rhpv2.HostSettings, txnFee, min, max types.Currency) types.Currency {
if !max.IsZero() && min.Cmp(max) > 0 {
func (c *Contractor) initialContractFunding(settings rhpv2.HostSettings, txnFee, minFunding, maxFunding types.Currency) types.Currency {
if !maxFunding.IsZero() && minFunding.Cmp(maxFunding) > 0 {
panic("given min is larger than max") // developer error
}

funding := settings.ContractPrice.Add(txnFee).Mul64(10) // TODO arbitrary multiplier
if !min.IsZero() && funding.Cmp(min) < 0 {
return min
if !minFunding.IsZero() && funding.Cmp(minFunding) < 0 {
return minFunding
}
if !max.IsZero() && funding.Cmp(max) > 0 {
return max
if !maxFunding.IsZero() && funding.Cmp(maxFunding) > 0 {
return maxFunding
}
return funding
}
Expand Down Expand Up @@ -1529,25 +1529,25 @@ func addLeeway(n uint64, pct float64) uint64 {
return uint64(math.Ceil(float64(n) * pct))
}

func initialContractFunding(settings rhpv2.HostSettings, txnFee, min, max types.Currency) types.Currency {
if !max.IsZero() && min.Cmp(max) > 0 {
func initialContractFunding(settings rhpv2.HostSettings, txnFee, minFunding, maxFunding types.Currency) types.Currency {
if !maxFunding.IsZero() && minFunding.Cmp(maxFunding) > 0 {
panic("given min is larger than max") // developer error
}

funding := settings.ContractPrice.Add(txnFee).Mul64(10) // TODO arbitrary multiplier
if !min.IsZero() && funding.Cmp(min) < 0 {
return min
if !minFunding.IsZero() && funding.Cmp(minFunding) < 0 {
return minFunding
}
if !max.IsZero() && funding.Cmp(max) > 0 {
return max
if !maxFunding.IsZero() && funding.Cmp(maxFunding) > 0 {
return maxFunding
}
return funding
}

func initialContractFundingMinMax(cfg api.AutopilotConfig) (min types.Currency, max types.Currency) {
func initialContractFundingMinMax(cfg api.AutopilotConfig) (minFunding types.Currency, maxFunding types.Currency) {
allowance := cfg.Contracts.Allowance.Div64(cfg.Contracts.Amount)
min = allowance.Div64(minInitialContractFundingDivisor)
max = allowance.Div64(maxInitialContractFundingDivisor)
minFunding = allowance.Div64(minInitialContractFundingDivisor)
maxFunding = allowance.Div64(maxInitialContractFundingDivisor)
return
}

Expand Down
4 changes: 2 additions & 2 deletions autopilot/contractor/hostfilter.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,8 @@ func isOutOfFunds(cfg api.AutopilotConfig, pt rhpv3.HostPriceTable, c api.Contra
// the contract is below a certain threshold of the collateral we would try to
// put into a contract upon renew.
func isOutOfCollateral(cfg api.AutopilotConfig, rs api.RedundancySettings, c api.Contract, s rhpv2.HostSettings, pt rhpv3.HostPriceTable) bool {
min := minRemainingCollateral(cfg, rs, c.RenterFunds(), s, pt)
return c.RemainingCollateral().Cmp(min) < 0
minCollateral := minRemainingCollateral(cfg, rs, c.RenterFunds(), s, pt)
return c.RemainingCollateral().Cmp(minCollateral) < 0
}

// minNewCollateral returns the minimum amount of unallocated collateral that a
Expand Down
6 changes: 3 additions & 3 deletions autopilot/contractor/hostfilter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,9 @@ func TestMinRemainingCollateral(t *testing.T) {
for i, test := range tests {
cfg.Contracts.Storage = test.expectedStorage
s.RemainingStorage = test.remainingStorage
min := minRemainingCollateral(cfg, rs, test.renterFunds, s, pt)
if min.Cmp(test.expected) != 0 {
t.Fatalf("%v: expected %v, got %v", i+1, test.expected, min)
minCollateral := minRemainingCollateral(cfg, rs, test.renterFunds, s, pt)
if minCollateral.Cmp(test.expected) != 0 {
t.Fatalf("%v: expected %v, got %v", i+1, test.expected, minCollateral)
}
}
}
6 changes: 3 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ require (
go.sia.tech/jape v0.11.2-0.20240124024603-93559895d640
go.sia.tech/mux v1.2.0
go.sia.tech/siad v1.5.10-0.20230228235644-3059c0b930ca
go.sia.tech/web/renterd v0.51.2
go.sia.tech/web/renterd v0.52.0
go.uber.org/zap v1.27.0
golang.org/x/crypto v0.22.0
golang.org/x/sys v0.19.0
golang.org/x/term v0.19.0
golang.org/x/sys v0.20.0
golang.org/x/term v0.20.0
gopkg.in/yaml.v3 v3.0.1
gorm.io/driver/mysql v1.5.6
gorm.io/driver/sqlite v1.5.5
Expand Down
10 changes: 6 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1652,8 +1652,8 @@ go.sia.tech/siad v1.5.10-0.20230228235644-3059c0b930ca h1:aZMg2AKevn7jKx+wlusWQf
go.sia.tech/siad v1.5.10-0.20230228235644-3059c0b930ca/go.mod h1:h/1afFwpxzff6/gG5i1XdAgPK7dEY6FaibhK7N5F86Y=
go.sia.tech/web v0.0.0-20240422221546-c1709d16b6ef h1:X0Xm9AQYHhdd85yi9gqkkCZMb9/WtLwC0nDgv65N90Y=
go.sia.tech/web v0.0.0-20240422221546-c1709d16b6ef/go.mod h1:nGEhGmI8zV/BcC3LOCC5JLVYpidNYJIvLGIqVRWQBCg=
go.sia.tech/web/renterd v0.51.2 h1:+TioJYm4eo5MnMbtDDCUGgGmUkOe+mIk1cbl/9EkAYo=
go.sia.tech/web/renterd v0.51.2/go.mod h1:SWwKoAJvLxiHjTXsNPKX3RLiQzJb/vxwcpku3F78MO8=
go.sia.tech/web/renterd v0.52.0 h1:LD57G2SOLFTD0yk/234szASFpsj868cxOgR49BGVyUA=
go.sia.tech/web/renterd v0.52.0/go.mod h1:SWwKoAJvLxiHjTXsNPKX3RLiQzJb/vxwcpku3F78MO8=
go.uber.org/atomic v1.4.0/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE=
go.uber.org/atomic v1.7.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc=
go.uber.org/goleak v1.1.11/go.mod h1:cwTWslyiVhfpKIDGSZEM2HlOvcqm+tG4zioyIeLoqMQ=
Expand Down Expand Up @@ -1986,8 +1986,9 @@ golang.org/x/sys v0.13.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.14.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.15.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.17.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.19.0 h1:q5f1RH2jigJ1MoAWp2KTp3gm5zAGFUTarQZ5U386+4o=
golang.org/x/sys v0.19.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.20.0 h1:Od9JTbYCk261bKm4M/mw7AklTlFYIa0bIp9BgSm1S8Y=
golang.org/x/sys v0.20.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/telemetry v0.0.0-20240228155512-f48c80bd79b2/go.mod h1:TeRTkGYfJXctD9OcfyVLyj2J3IxLnKwHJR8f4D8a3YE=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/term v0.0.0-20210421210424-b80969c67360/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
Expand All @@ -2008,8 +2009,9 @@ golang.org/x/term v0.13.0/go.mod h1:LTmsnFJwVN6bCy1rVCoS+qHT1HhALEFxKncY3WNNh4U=
golang.org/x/term v0.14.0/go.mod h1:TySc+nGkYR6qt8km8wUhuFRTVSMIX3XPR58y2lC8vww=
golang.org/x/term v0.15.0/go.mod h1:BDl952bC7+uMoWR75FIrCDx79TPU9oHkTZ9yRbYOrX0=
golang.org/x/term v0.17.0/go.mod h1:lLRBjIVuehSbZlaOtGMbcMncT+aqLLLmKrsjNrUguwk=
golang.org/x/term v0.19.0 h1:+ThwsDv+tYfnJFhF4L8jITxu1tdTWRTZpdsWgEgjL6Q=
golang.org/x/term v0.19.0/go.mod h1:2CuTdWZ7KHSQwUzKva0cbMg6q2DMI3Mmxp+gKJbskEk=
golang.org/x/term v0.20.0 h1:VnkxpohqXaOBYJtBmEppKUG6mXpi+4O6purfc2+sMhw=
golang.org/x/term v0.20.0/go.mod h1:8UkIAJTvZgivsXaD6/pH6U9ecQzZ45awqEOzuCvwpFY=
golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
Expand Down
4 changes: 2 additions & 2 deletions internal/node/transactionpool.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ type txpool struct {
}

func (tp txpool) RecommendedFee() (fee types.Currency) {
_, max := tp.tp.FeeEstimation()
convertToCore(&max, (*types.V1Currency)(&fee))
_, maxFee := tp.tp.FeeEstimation()
convertToCore(&maxFee, (*types.V1Currency)(&fee))
return
}

Expand Down
6 changes: 3 additions & 3 deletions stores/metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -2876,11 +2876,11 @@ func sqlConcat(db *gorm.DB, a, b string) string {
return fmt.Sprintf("CONCAT(%s, %s)", a, b)
}

func sqlRandomTimestamp(db *gorm.DB, now time.Time, min, max time.Duration) clause.Expr {
func sqlRandomTimestamp(db *gorm.DB, now time.Time, minDuration, maxDuration time.Duration) clause.Expr {
if isSQLite(db) {
return gorm.Expr("ABS(RANDOM()) % (? - ?) + ?", int(max.Seconds()), int(min.Seconds()), now.Add(min).Unix())
return gorm.Expr("ABS(RANDOM()) % (? - ?) + ?", int(maxDuration.Seconds()), int(minDuration.Seconds()), now.Add(minDuration).Unix())
}
return gorm.Expr("FLOOR(? + RAND() * (? - ?))", now.Add(min).Unix(), int(max.Seconds()), int(min.Seconds()))
return gorm.Expr("FLOOR(? + RAND() * (? - ?))", now.Add(minDuration).Unix(), int(maxDuration.Seconds()), int(minDuration.Seconds()))
}

// nolint:unparam
Expand Down
8 changes: 4 additions & 4 deletions stores/metadata_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3905,11 +3905,11 @@ func TestSlabHealthInvalidation(t *testing.T) {
}

// assert it's validity is within expected bounds
min := now.Add(refreshHealthMinHealthValidity).Add(-time.Second) // avoid NDF
max := now.Add(refreshHealthMaxHealthValidity).Add(time.Second) // avoid NDF
minValidity := now.Add(refreshHealthMinHealthValidity).Add(-time.Second) // avoid NDF
maxValidity := now.Add(refreshHealthMaxHealthValidity).Add(time.Second) // avoid NDF
validUntil := time.Unix(slab.HealthValidUntil, 0)
if !(min.Before(validUntil) && max.After(validUntil)) {
t.Fatal("valid until not in boundaries", min, max, validUntil, now)
if !(minValidity.Before(validUntil) && maxValidity.After(validUntil)) {
t.Fatal("valid until not in boundaries", minValidity, maxValidity, validUntil, now)
}
}
}
Expand Down
16 changes: 8 additions & 8 deletions worker/gouging.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,11 +111,11 @@ func NewGougingChecker(gs api.GougingSettings, cs api.ConsensusState, txnFee typ
func (gc gougingChecker) BlocksUntilBlockHeightGouging(hostHeight uint64) int64 {
blockHeight := gc.consensusState.BlockHeight
leeway := gc.settings.HostBlockHeightLeeway
var min uint64
var minHeight uint64
if blockHeight >= uint64(leeway) {
min = blockHeight - uint64(leeway)
minHeight = blockHeight - uint64(leeway)
}
return int64(hostHeight) - int64(min)
return int64(hostHeight) - int64(minHeight)
}

func (gc gougingChecker) Check(hs *rhpv2.HostSettings, pt *rhpv3.HostPriceTable) api.HostGougingBreakdown {
Expand Down Expand Up @@ -298,13 +298,13 @@ func checkPriceGougingPT(gs api.GougingSettings, cs api.ConsensusState, txnFee t
return fmt.Errorf("consensus not synced and host block height is lower, %v < %v", pt.HostBlockHeight, cs.BlockHeight)
}
} else {
var min uint64
var minHeight uint64
if cs.BlockHeight >= uint64(gs.HostBlockHeightLeeway) {
min = cs.BlockHeight - uint64(gs.HostBlockHeightLeeway)
minHeight = cs.BlockHeight - uint64(gs.HostBlockHeightLeeway)
}
max := cs.BlockHeight + uint64(gs.HostBlockHeightLeeway)
if !(min <= pt.HostBlockHeight && pt.HostBlockHeight <= max) {
return fmt.Errorf("consensus is synced and host block height is not within range, %v-%v %v", min, max, pt.HostBlockHeight)
maxHeight := cs.BlockHeight + uint64(gs.HostBlockHeightLeeway)
if !(minHeight <= pt.HostBlockHeight && pt.HostBlockHeight <= maxHeight) {
return fmt.Errorf("consensus is synced and host block height is not within range, %v-%v %v", minHeight, maxHeight, pt.HostBlockHeight)
}
}

Expand Down

0 comments on commit bf5791e

Please sign in to comment.