Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow for downloading from hosts which are gouging as long as they are not download gouging #1170

Merged
merged 3 commits into from Apr 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 3 additions & 5 deletions internal/test/e2e/gouging_test.go
Expand Up @@ -4,6 +4,7 @@ import (
"bytes"
"context"
"fmt"
"io"
"testing"
"time"

Expand Down Expand Up @@ -90,11 +91,8 @@ func TestGouging(t *testing.T) {
// again, this is necessary for the host to be considered price gouging
time.Sleep(defaultHostSettings.PriceTableValidity)

// download the data - should fail
buffer.Reset()
if err := w.DownloadObject(context.Background(), &buffer, api.DefaultBucketName, path, api.DownloadObjectOptions{}); err == nil {
t.Fatal("expected download to fail", err)
}
// download the data - should still work
tt.OKAll(w.DownloadObject(context.Background(), io.Discard, api.DefaultBucketName, path, api.DownloadObjectOptions{}))

// try optimising gouging settings
resp, err := cluster.Autopilot.EvaluateConfig(context.Background(), test.AutopilotConfig, gs, test.RedundancySettings)
Expand Down
17 changes: 9 additions & 8 deletions worker/host.go
Expand Up @@ -88,8 +88,8 @@ func (h *host) DownloadSector(ctx context.Context, w io.Writer, root types.Hash2
if err != nil {
return err
}
if breakdown := gc.Check(nil, &hpt); breakdown.Gouging() {
return fmt.Errorf("%w: %v", errPriceTableGouging, breakdown)
if breakdown := gc.Check(nil, &hpt); breakdown.DownloadErr != "" {
return fmt.Errorf("%w: %v", errPriceTableGouging, breakdown.DownloadErr)
}

// return errBalanceInsufficient if balance insufficient
Expand Down Expand Up @@ -235,26 +235,27 @@ func (h *host) FundAccount(ctx context.Context, balance types.Currency, rev *typ
}

// check whether we have money left in the contract
if pt.FundAccountCost.Cmp(rev.ValidRenterPayout()) >= 0 {
return fmt.Errorf("insufficient funds to fund account: %v <= %v", rev.ValidRenterPayout(), pt.FundAccountCost)
cost := types.NewCurrency64(1)
ChrisSchinnerl marked this conversation as resolved.
Show resolved Hide resolved
if cost.Cmp(rev.ValidRenterPayout()) >= 0 {
return fmt.Errorf("insufficient funds to fund account: %v <= %v", rev.ValidRenterPayout(), cost)
}
availableFunds := rev.ValidRenterPayout().Sub(pt.FundAccountCost)
availableFunds := rev.ValidRenterPayout().Sub(cost)

// cap the deposit amount by the money that's left in the contract
if deposit.Cmp(availableFunds) > 0 {
deposit = availableFunds
}

// create the payment
amount := deposit.Add(pt.FundAccountCost)
amount := deposit.Add(cost)
payment, err := payByContract(rev, amount, rhpv3.Account{}, h.renterKey) // no account needed for funding
if err != nil {
return err
}

// fund the account
if err := RPCFundAccount(ctx, t, &payment, h.acc.id, pt.UID); err != nil {
return fmt.Errorf("failed to fund account with %v (excluding cost %v);%w", deposit, pt.FundAccountCost, err)
return fmt.Errorf("failed to fund account with %v (excluding cost %v);%w", deposit, cost, err)
}

// record the spend
Expand All @@ -277,7 +278,7 @@ func (h *host) SyncAccount(ctx context.Context, rev *types.FileContractRevision)
return h.acc.WithSync(ctx, func() (types.Currency, error) {
var balance types.Currency
err := h.transportPool.withTransportV3(ctx, h.hk, h.siamuxAddr, func(ctx context.Context, t *transportV3) error {
payment, err := payByContract(rev, pt.AccountBalanceCost, h.acc.id, h.renterKey)
payment, err := payByContract(rev, types.NewCurrency64(1), h.acc.id, h.renterKey)
if err != nil {
return err
}
Expand Down