Skip to content

Commit

Permalink
fix lint issues
Browse files Browse the repository at this point in the history
  • Loading branch information
n8maninger committed May 3, 2024
1 parent 1c2523f commit dafc054
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 25 deletions.
4 changes: 2 additions & 2 deletions api/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -285,9 +285,9 @@ func SetMaxCollateral(collateral types.Currency) Setting {
}

// SetMaxAccountBalance sets the MaxAccountBalance
func SetMaxAccountBalance(max types.Currency) Setting {
func SetMaxAccountBalance(value types.Currency) Setting {
return func(v map[string]any) {
v[settingMaxAccountBalance] = max
v[settingMaxAccountBalance] = value
}
}

Expand Down
4 changes: 2 additions & 2 deletions internal/chain/tpool.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ type TransactionPool struct {

// RecommendedFee returns the recommended fee per byte.
func (tp *TransactionPool) 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
10 changes: 5 additions & 5 deletions persist/sqlite/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@ func (s *Store) SetRegistryValue(entry rhp3.RegistryEntry, expiration uint64) er
err := tx.QueryRow(selectQuery, sqlHash256(registryKey)).Scan((*sqlHash256)(&registryKey))
if errors.Is(err, sql.ErrNoRows) {
// key doesn't exist, insert it
count, max, err := registryLimits(tx)
count, limit, err := registryLimits(tx)
if err != nil {
return fmt.Errorf("failed to get registry limits: %w", err)
} else if count >= max {
} else if count >= limit {
return registry.ErrNotEnoughSpace
}
err = tx.QueryRow(insertQuery, sqlHash256(registryKey), sqlUint64(entry.Revision), entry.Type, sqlHash512(entry.Signature), entry.Data, sqlUint64(expiration)).Scan((*sqlHash256)(&registryKey))
Expand All @@ -62,11 +62,11 @@ func (s *Store) SetRegistryValue(entry rhp3.RegistryEntry, expiration uint64) er

// RegistryEntries returns the current number of entries as well as the
// maximum number of entries the registry can hold.
func (s *Store) RegistryEntries() (count, max uint64, err error) {
func (s *Store) RegistryEntries() (count, limit uint64, err error) {
return registryLimits(&dbTxn{s})
}

func registryLimits(tx txn) (count, max uint64, err error) {
err = tx.QueryRow(`SELECT COALESCE(COUNT(re.registry_key), 0), COALESCE(hs.registry_limit, 0) FROM host_settings hs LEFT JOIN registry_entries re ON (true);`).Scan(&count, &max)
func registryLimits(tx txn) (count, limit uint64, err error) {
err = tx.QueryRow(`SELECT COALESCE(COUNT(re.registry_key), 0), COALESCE(hs.registry_limit, 0) FROM host_settings hs LEFT JOIN registry_entries re ON (true);`).Scan(&count, &limit)
return
}
4 changes: 2 additions & 2 deletions rhp/v3/execute.go
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ func (pe *programExecutor) executeSwapSector(instr *rhp3.InstrSwapSector, log *z
return output, proof, nil
}

func (pe *programExecutor) executeUpdateSector(instr *rhp3.InstrUpdateSector, log *zap.Logger) ([]byte, []types.Hash256, error) {
func (pe *programExecutor) executeUpdateSector(instr *rhp3.InstrUpdateSector, _ *zap.Logger) ([]byte, []types.Hash256, error) {
offset, length := instr.Offset, instr.Length
// read the patch
patch, err := pe.programData.Bytes(instr.DataOffset, length)
Expand Down Expand Up @@ -419,7 +419,7 @@ func (pe *programExecutor) executeStoreSector(instr *rhp3.InstrStoreSector, log
return root[:], nil
}

func (pe *programExecutor) executeRevision(instr *rhp3.InstrRevision) ([]byte, error) {
func (pe *programExecutor) executeRevision(*rhp3.InstrRevision) ([]byte, error) {
// pay for execution
cost := pe.priceTable.RevisionCost()
if err := pe.payForExecution(cost, costToAccountUsage(cost)); err != nil {
Expand Down
12 changes: 1 addition & 11 deletions rhp/v3/payments.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
)

// processContractPayment initializes an RPC budget using funds from a contract.
func (sh *SessionHandler) processContractPayment(s *rhp3.Stream, height uint64) (rhp3.Account, types.Currency, error) {
func (sh *SessionHandler) processContractPayment(s *rhp3.Stream, _ uint64) (rhp3.Account, types.Currency, error) {
var req rhp3.PayByContractRequest
if err := s.ReadRequest(&req, maxRequestSize); err != nil {
return rhp3.ZeroAccount, types.ZeroCurrency, fmt.Errorf("failed to read contract payment request: %w", err)
Expand Down Expand Up @@ -60,11 +60,6 @@ func (sh *SessionHandler) processContractPayment(s *rhp3.Stream, height uint64)
}

settings := sh.settings.Settings()
if err != nil {
s.WriteResponseErr(ErrHostInternalError)
return rhp3.ZeroAccount, types.ZeroCurrency, fmt.Errorf("failed to get host settings: %w", err)
}

hostSig := sh.privateKey.SignHash(sigHash)
fundReq := accounts.FundAccountWithContract{
Account: req.RefundAccount,
Expand Down Expand Up @@ -205,11 +200,6 @@ func (sh *SessionHandler) processFundAccountPayment(pt rhp3.HostPriceTable, s *r
}

settings := sh.settings.Settings()
if err != nil {
s.WriteResponseErr(ErrHostInternalError)
return types.ZeroCurrency, types.ZeroCurrency, fmt.Errorf("failed to get host settings: %w", err)
}

// credit the account with the deposit
hostSig := sh.privateKey.SignHash(sigHash)
fundReq := accounts.FundAccountWithContract{
Expand Down
6 changes: 3 additions & 3 deletions rhp/v3/pricetable.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ func (pm *priceTableManager) Register(pt rhp3.HostPriceTable) {
// PriceTable returns the session handler's current price table.
func (sh *SessionHandler) PriceTable() (rhp3.HostPriceTable, error) {
settings := sh.settings.Settings()
count, max, err := sh.registry.Entries()
count, limit, err := sh.registry.Entries()
if err != nil {
return rhp3.HostPriceTable{}, fmt.Errorf("failed to get registry entries: %w", err)
}
Expand Down Expand Up @@ -158,8 +158,8 @@ func (sh *SessionHandler) PriceTable() (rhp3.HostPriceTable, error) {
RenewContractCost: types.Siacoins(100).Div64(1e9),

// Registry related fields.
RegistryEntriesLeft: max - count,
RegistryEntriesTotal: max,
RegistryEntriesLeft: limit - count,
RegistryEntriesTotal: limit,

// Subscription related fields.
SubscriptionMemoryCost: oneHasting,
Expand Down

0 comments on commit dafc054

Please sign in to comment.