diff --git a/api/types.go b/api/types.go index 37a99194..7508dfe7 100644 --- a/api/types.go +++ b/api/types.go @@ -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 } } diff --git a/internal/chain/tpool.go b/internal/chain/tpool.go index efb1bb67..698c9d62 100644 --- a/internal/chain/tpool.go +++ b/internal/chain/tpool.go @@ -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 } diff --git a/persist/sqlite/registry.go b/persist/sqlite/registry.go index bdffe5c0..af20efa7 100644 --- a/persist/sqlite/registry.go +++ b/persist/sqlite/registry.go @@ -40,10 +40,10 @@ func (s *Store) SetRegistryValue(entry rhp3.RegistryEntry, expiration uint64) er err := tx.QueryRow(selectQuery, sqlHash256(registryKey)).Scan((*sqlHash256)(®istryKey)) 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)(®istryKey)) @@ -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 } diff --git a/rhp/v3/execute.go b/rhp/v3/execute.go index c691bee9..29edb339 100644 --- a/rhp/v3/execute.go +++ b/rhp/v3/execute.go @@ -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) @@ -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 { diff --git a/rhp/v3/payments.go b/rhp/v3/payments.go index f575a548..287b30eb 100644 --- a/rhp/v3/payments.go +++ b/rhp/v3/payments.go @@ -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) @@ -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, @@ -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{ diff --git a/rhp/v3/pricetable.go b/rhp/v3/pricetable.go index 96e3b028..b6ce5fc1 100644 --- a/rhp/v3/pricetable.go +++ b/rhp/v3/pricetable.go @@ -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) } @@ -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,