Skip to content

Commit

Permalink
Merge branch 'its-happening' of github.com:SiaFoundation/renterd into…
Browse files Browse the repository at this point in the history
… pj/subscription-api
  • Loading branch information
peterjan committed May 7, 2024
2 parents 7c6d1a0 + bf5791e commit 98940a7
Show file tree
Hide file tree
Showing 9 changed files with 40 additions and 40 deletions.
30 changes: 15 additions & 15 deletions autopilot/contractor/contractor.go
Original file line number Diff line number Diff line change
Expand Up @@ -1068,17 +1068,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 @@ -1543,25 +1543,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 @@ -169,8 +169,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)
}
}
}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ 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.20.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1649,8 +1649,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
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 @@ -2893,11 +2893,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 @@ -3964,11 +3964,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 98940a7

Please sign in to comment.