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

Fix default settings not being used consistently #1761

Merged
merged 2 commits into from
Dec 19, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
bus: add helper for fetching settings from store
ChrisSchinnerl committed Dec 19, 2024

Verified

This commit was signed with the committer’s verified signature.
ChrisSchinnerl Christopher Schinnerl
commit 864213564fe9ac44c5939db235b70f75a46d9bd6
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
default: patch
---

# Fix default settings not being used everywhere if settings are not found in database
47 changes: 17 additions & 30 deletions bus/routes.go
Original file line number Diff line number Diff line change
@@ -1406,10 +1406,8 @@ func (b *Bus) packedSlabsHandlerDonePOST(jc jape.Context) {
}

func (b *Bus) settingsGougingHandlerGET(jc jape.Context) {
gs, err := b.store.GougingSettings(jc.Request.Context())
if errors.Is(err, sql.ErrSettingNotFound) {
gs = api.DefaultGougingSettings
} else if err != nil {
gs, err := b.gougingSettings(jc.Request.Context())
if err != nil {
jc.Error(err, http.StatusInternalServerError)
return
}
@@ -1432,10 +1430,8 @@ func (b *Bus) settingsGougingHandlerPUT(jc jape.Context) {
}

func (b *Bus) settingsPinnedHandlerGET(jc jape.Context) {
ps, err := b.store.PinnedSettings(jc.Request.Context())
if errors.Is(err, sql.ErrSettingNotFound) {
ps = api.DefaultPinnedSettings
} else if err != nil {
ps, err := b.pinnedSettings(jc.Request.Context())
if err != nil {
jc.Error(err, http.StatusInternalServerError)
return
}
@@ -1461,10 +1457,8 @@ func (b *Bus) settingsPinnedHandlerPUT(jc jape.Context) {
}

func (b *Bus) settingsUploadHandlerGET(jc jape.Context) {
us, err := b.store.UploadSettings(jc.Request.Context())
if errors.Is(err, sql.ErrSettingNotFound) {
us = api.DefaultUploadSettings(b.cm.TipState().Network.Name)
} else if err != nil {
us, err := b.uploadSettings(jc.Request.Context())
if err != nil {
jc.Error(err, http.StatusInternalServerError)
return
}
@@ -1485,10 +1479,8 @@ func (b *Bus) settingsUploadHandlerPUT(jc jape.Context) {
}

func (b *Bus) settingsS3HandlerGET(jc jape.Context) {
s3s, err := b.store.S3Settings(jc.Request.Context())
if errors.Is(err, sql.ErrSettingNotFound) {
s3s = api.DefaultS3Settings
} else if err != nil {
s3s, err := b.s3Settings(jc.Request.Context())
if err != nil {
jc.Error(err, http.StatusInternalServerError)
return
}
@@ -1656,7 +1648,7 @@ func (b *Bus) slabsPartialHandlerPOST(jc jape.Context) {
if jc.Check("failed to add partial slab", err) != nil {
return
}
us, err := b.store.UploadSettings(jc.Request.Context())
us, err := b.uploadSettings(jc.Request.Context())
if err != nil {
jc.Error(fmt.Errorf("could not get upload packing settings: %w", err), http.StatusInternalServerError)
return
@@ -1751,16 +1743,15 @@ func (b *Bus) paramsHandlerUploadGET(jc jape.Context) {
return
}

var uploadPacking bool
us, err := b.store.UploadSettings(jc.Request.Context())
if jc.Check("could not get upload settings", err) == nil {
uploadPacking = us.Packing.Enabled
us, err := b.uploadSettings(jc.Request.Context())
if jc.Check("could not get upload settings", err) != nil {
return
}

api.WriteResponse(jc, api.UploadParams{
CurrentHeight: b.cm.TipState().Index.Height,
GougingParams: gp,
UploadPacking: uploadPacking,
UploadPacking: us.Packing.Enabled,
})
}

@@ -1792,17 +1783,13 @@ func (b *Bus) paramsHandlerGougingGET(jc jape.Context) {
}

func (b *Bus) gougingParams(ctx context.Context) (api.GougingParams, error) {
gs, err := b.store.GougingSettings(ctx)
if errors.Is(err, sql.ErrSettingNotFound) {
gs = api.DefaultGougingSettings
} else if err != nil {
gs, err := b.gougingSettings(ctx)
if err != nil {
return api.GougingParams{}, err
}

us, err := b.store.UploadSettings(ctx)
if errors.Is(err, sql.ErrSettingNotFound) {
us = api.DefaultUploadSettings(b.cm.TipState().Network.Name)
} else if err != nil {
us, err := b.uploadSettings(ctx)
if err != nil {
return api.GougingParams{}, err
}

49 changes: 49 additions & 0 deletions bus/settings.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package bus

import (
"context"
"errors"

"go.sia.tech/renterd/api"
"go.sia.tech/renterd/stores/sql"
)

func (b Bus) gougingSettings(ctx context.Context) (api.GougingSettings, error) {
gs, err := b.store.GougingSettings(ctx)
if errors.Is(err, sql.ErrSettingNotFound) {
gs = api.DefaultGougingSettings
} else if err != nil {
return api.GougingSettings{}, err
}
return gs, nil
}

func (b Bus) pinnedSettings(ctx context.Context) (api.PinnedSettings, error) {
ps, err := b.store.PinnedSettings(ctx)
if errors.Is(err, sql.ErrSettingNotFound) {
ps = api.DefaultPinnedSettings
} else if err != nil {
return api.PinnedSettings{}, err
}
return ps, nil
}

func (b Bus) s3Settings(ctx context.Context) (api.S3Settings, error) {
s3s, err := b.store.S3Settings(ctx)
if errors.Is(err, sql.ErrSettingNotFound) {
s3s = api.DefaultS3Settings
} else if err != nil {
return api.S3Settings{}, err
}
return s3s, nil
}

func (b Bus) uploadSettings(ctx context.Context) (api.UploadSettings, error) {
us, err := b.store.UploadSettings(ctx)
if errors.Is(err, sql.ErrSettingNotFound) {
us = api.DefaultUploadSettings(b.cm.TipState().Network.Name)
} else if err != nil {
return api.UploadSettings{}, err
}
return us, nil
}

Unchanged files with check annotations Beta

// check that we have 1 archived contract for every contract we had before
var archivedContracts []api.ContractMetadata
tt.Retry(100, 100*time.Millisecond, func() error {

Check failure on line 2999 in internal/test/e2e/cluster_test.go

GitHub Actions / test-sqlite-v2 (1.22)

Test go.sia.tech/renterd/internal/test/e2e/TestV1ToV2Transition failed in 14.9s

cluster_test.go:2999: expected 2 archived contracts, got 3
archivedContracts, err = cluster.Bus.Contracts(context.Background(), api.ContractsOpts{FilterMode: api.ContractFilterModeArchived})
tt.OK(err)
if len(archivedContracts) != nHosts-1 {