Skip to content

Commit

Permalink
Merge pull request #848 from SiaFoundation/dev
Browse files Browse the repository at this point in the history
Merge 'dev' -> 'master'
  • Loading branch information
ChrisSchinnerl authored Dec 21, 2023
2 parents 4b7995d + 5d8faf1 commit 941827a
Show file tree
Hide file tree
Showing 44 changed files with 1,179 additions and 947 deletions.
6 changes: 6 additions & 0 deletions api/contract.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ type (
RenewedFrom types.FileContractID `json:"renewedFrom"`
Spending ContractSpending `json:"spending"`
TotalCost types.Currency `json:"totalCost"`

ContractSets []string `json:"contractsets"`
}

// ContractPrunableData wraps a contract's size information with its id.
Expand Down Expand Up @@ -176,6 +178,10 @@ type (
TotalPrunable uint64 `json:"totalPrunable"`
TotalSize uint64 `json:"totalSize"`
}

ContractsOpts struct {
ContractSet string `json:"contractset"`
}
)

// Add returns the sum of the current and given contract spending.
Expand Down
12 changes: 7 additions & 5 deletions api/object.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,11 +113,13 @@ type (

// ObjectsStatsResponse is the response type for the /bus/stats/objects endpoint.
ObjectsStatsResponse struct {
NumObjects uint64 `json:"numObjects"` // number of objects
MinHealth float64 `json:"minHealth"` // minimum health of all objects
TotalObjectsSize uint64 `json:"totalObjectsSize"` // size of all objects
TotalSectorsSize uint64 `json:"totalSectorsSize"` // uploaded size of all objects
TotalUploadedSize uint64 `json:"totalUploadedSize"` // uploaded size of all objects including redundant sectors
NumObjects uint64 `json:"numObjects"` // number of objects
NumUnfinishedObjects uint64 `json:"numUnfinishedObjects"` // number of unfinished objects
MinHealth float64 `json:"minHealth"` // minimum health of all objects
TotalObjectsSize uint64 `json:"totalObjectsSize"` // size of all objects
TotalUnfinishedObjectsSize uint64 `json:"totalUnfinishedObjectsSize"` // size of all unfinished objects
TotalSectorsSize uint64 `json:"totalSectorsSize"` // uploaded size of all objects
TotalUploadedSize uint64 `json:"totalUploadedSize"` // uploaded size of all objects including redundant sectors
}
)

Expand Down
38 changes: 5 additions & 33 deletions autopilot/accounts.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,9 @@ import (
"sync"
"time"

"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/codes"
rhpv3 "go.sia.tech/core/rhp/v3"
"go.sia.tech/core/types"
"go.sia.tech/renterd/api"
"go.sia.tech/renterd/tracing"
"go.uber.org/zap"
)

Expand Down Expand Up @@ -44,8 +41,7 @@ type AccountStore interface {
}

type ContractStore interface {
Contracts(ctx context.Context) ([]api.ContractMetadata, error)
ContractSetContracts(ctx context.Context, set string) ([]api.ContractMetadata, error)
Contracts(ctx context.Context, opts api.ContractsOpts) ([]api.ContractMetadata, error)
}

func newAccounts(ap *Autopilot, a AccountStore, c ContractStore, w *workerPool, l *zap.SugaredLogger, refillInterval time.Duration) *accounts {
Expand Down Expand Up @@ -95,7 +91,7 @@ func (a *accounts) refillWorkersAccountsLoop(ctx context.Context) {
}

a.w.withWorker(func(w Worker) {
a.refillWorkerAccounts(w)
a.refillWorkerAccounts(ctx, w)
})
}
}
Expand All @@ -105,38 +101,29 @@ func (a *accounts) refillWorkersAccountsLoop(ctx context.Context) {
// is used for every host. If a slow host's account is still being refilled by a
// goroutine from a previous call, refillWorkerAccounts will skip that account
// until the previously launched goroutine returns.
func (a *accounts) refillWorkerAccounts(w Worker) {
ctx, span := tracing.Tracer.Start(context.Background(), "refillWorkerAccounts")
defer span.End()

func (a *accounts) refillWorkerAccounts(ctx context.Context, w Worker) {
// fetch config
state := a.ap.State()

// fetch worker id
workerID, err := w.ID(ctx)
if err != nil {
span.RecordError(err)
span.SetStatus(codes.Error, "failed to fetch worker id")
a.l.Errorw(fmt.Sprintf("failed to fetch worker id for refill: %v", err))
return
}

// fetch all contracts
contracts, err := a.c.Contracts(ctx)
contracts, err := a.c.Contracts(ctx, api.ContractsOpts{})
if err != nil {
span.RecordError(err)
span.SetStatus(codes.Error, "failed to fetch contracts")
a.l.Errorw(fmt.Sprintf("failed to fetch contracts for refill: %v", err))
return
} else if len(contracts) == 0 {
return
}

// fetch all contract set contracts
contractSetContracts, err := a.c.ContractSetContracts(ctx, state.cfg.Contracts.Set)
contractSetContracts, err := a.c.Contracts(ctx, api.ContractsOpts{ContractSet: state.cfg.Contracts.Set})
if err != nil {
span.RecordError(err)
span.SetStatus(codes.Error, fmt.Sprintf("failed to fetch contracts for set '%s'", state.cfg.Contracts.Set))
a.l.Errorw(fmt.Sprintf("failed to fetch contract set contracts: %v", err))
return
}
Expand Down Expand Up @@ -212,17 +199,6 @@ func refillWorkerAccount(ctx context.Context, a AccountStore, w Worker, workerID
}
}

// add tracing
ctx, span := tracing.Tracer.Start(ctx, "refillAccount")
span.SetAttributes(attribute.Stringer("host", contract.HostKey))
defer func() {
if rerr != nil {
span.RecordError(rerr.err)
span.SetStatus(codes.Error, "failed to refill account")
}
span.End()
}()

// fetch the account
accountID, err := w.Account(ctx, contract.HostKey)
if err != nil {
Expand All @@ -236,10 +212,6 @@ func refillWorkerAccount(ctx context.Context, a AccountStore, w Worker, workerID
return
}

// update span
span.SetAttributes(attribute.Stringer("account", account.ID))
span.SetAttributes(attribute.Stringer("balance", account.Balance))

// check if a host is potentially cheating before refilling.
// We only check against the max drift if the account's drift is
// negative because we don't care if we have more money than
Expand Down
Loading

0 comments on commit 941827a

Please sign in to comment.