modules

package
v0.1.0-beta Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 23, 2023 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const BytesPerTerabyte = 1024 * 1024 * 1024 * 1024

BytesPerTerabyte is how many bytes are there in one TiB.

View Source
const SatelliteOverhead = 1.1

SatelliteOverhead determines how much extra a renter is charged for using the service. This should include any payment processing fees.

Variables

View Source
var (
	// MaxRPCPrice is how much the Satellite is willing to pay
	// for a single RPC call.
	MaxRPCPrice = types.SiacoinPrecision.MulFloat(1e-7)

	// MaxSectorAccessPrice is how much the Satellite is willing
	// to pay to download a single sector.
	MaxSectorAccessPrice = types.SiacoinPrecision.MulFloat(1e-6)
)
View Source
var DefaultAllowance = Allowance{
	Funds:       types.SiacoinPrecision.Mul64(2500),
	Hosts:       50,
	Period:      2 * types.BlocksPerMonth,
	RenewWindow: types.BlocksPerMonth,

	ExpectedStorage:   1e12,
	ExpectedUpload:    uint64(200e9) / uint64(types.BlocksPerMonth),
	ExpectedDownload:  uint64(100e9) / uint64(types.BlocksPerMonth),
	MinShards:         10,
	TotalShards:       30,
	BlockHeightLeeway: types.BlockHeight(3),
}

DefaultAllowance is the set of default allowance settings that will be used when allowances are not set or not fully set.

Functions

func CheckGouging

func CheckGouging(a Allowance, height types.BlockHeight, hes *smodules.HostExternalSettings, pt *rhpv3.HostPriceTable, txnFee types.Currency) (err error)

CheckGouging performs a number of gouging checks before forming a contract with the host.

func ConvertCurrency

func ConvertCurrency(c types.Currency) core.Currency

ConvertCurrency converts a siad currency to a core currency.

func ConvertPriceTable

func ConvertPriceTable(pt rhpv3.HostPriceTable) smodules.RPCPriceTable

ConvertPriceTable converts a core price table to siad.

func ConvertPublicKey

func ConvertPublicKey(spk types.SiaPublicKey) (pk core.PublicKey)

ConvertPublicKey converts a siad public key to a core public key.

func CurrencyUnits

func CurrencyUnits(c types.Currency) string

CurrencyUnits converts a types.Currency to a string with human-readable units. The unit used will be the largest unit that results in a value greater than 1. The value is rounded to 4 significant digits.

func DeriveEphemeralKey

func DeriveEphemeralKey(rsk crypto.SecretKey, hpk types.SiaPublicKey) crypto.SecretKey

DeriveEphemeralKey derives a secret key to be used by the renter for the exchange with the hosts.

func DeriveRenterSeed

func DeriveRenterSeed(walletSeed smodules.Seed, email string) smodules.RenterSeed

DeriveRenterSeed derives a seed to be used by the renter for accessing the file contracts. NOTE: The seed returned by this function should be wiped once it's no longer in use.

func GenerateKeyPair

func GenerateKeyPair(seed crypto.Hash) (sk crypto.SecretKey, pk crypto.PublicKey)

GenerateKeyPair generates a private/public keypair from a seed.

func ReadCurrency

func ReadCurrency(s string) types.Currency

ReadCurrency converts a string to types.Currency.

func ReadPublicKey

func ReadPublicKey(s string) types.SiaPublicKey

ReadPublicKey converts a string to types.SiaPublicKey.

func TaxAdjustedPayout

func TaxAdjustedPayout(target types.Currency) types.Currency

TaxAdjustedPayout calculates the tax-adjusted payout.

Types

type Allowance

type Allowance struct {
	Funds       types.Currency    `json:"funds"`
	Hosts       uint64            `json:"hosts"`
	Period      types.BlockHeight `json:"period"`
	RenewWindow types.BlockHeight `json:"renewwindow"`

	// ExpectedStorage is the amount of data that we expect to have in a contract.
	ExpectedStorage uint64 `json:"expectedstorage"`

	// ExpectedUpload is the expected amount of data uploaded through the API,
	// before redundancy, per block.
	ExpectedUpload uint64 `json:"expectedupload"`

	// ExpectedDownload is the expected amount of data downloaded through the
	// API per block.
	ExpectedDownload uint64 `json:"expecteddownload"`

	// Erasure coding parameters.
	MinShards   uint64 `json:"minshards"`
	TotalShards uint64 `json:"totalshards"`

	// The following fields provide price gouging protection for the user. By
	// setting a particular maximum price for each mechanism that a host can use
	// to charge users, the workers know to avoid hosts that go outside of the
	// safety range.
	MaxRPCPrice               types.Currency    `json:"maxrpcprice"`
	MaxContractPrice          types.Currency    `json:"maxcontractprice"`
	MaxDownloadBandwidthPrice types.Currency    `json:"maxdownloadbandwidthprice"`
	MaxSectorAccessPrice      types.Currency    `json:"maxsectoraccessprice"`
	MaxStoragePrice           types.Currency    `json:"maxstorageprice"`
	MaxUploadBandwidthPrice   types.Currency    `json:"maxuploadbandwidthprice"`
	MinMaxCollateral          types.Currency    `json:"minmaxcollateral"`
	BlockHeightLeeway         types.BlockHeight `json:"blockheightleeway"`
}

An Allowance dictates how much the renter is allowed to spend in a given period. Note that funds are spent on both storage and bandwidth.

func (Allowance) Active

func (a Allowance) Active() bool

Active returns true if and only if this allowance has been set in the contractor.

type ContractFormer

ContractFormer is the minimal interface to be used by Provider.

type ContractParams

type ContractParams struct {
	Allowance     Allowance
	Host          smodules.HostDBEntry
	Funding       types.Currency
	StartHeight   types.BlockHeight
	EndHeight     types.BlockHeight
	RefundAddress types.UnlockHash
	PublicKey     types.SiaPublicKey
	SecretKey     crypto.SecretKey
}

ContractParams are supplied as an argument to FormContracts.

type CreditData

type CreditData struct {
	Amount    float64 `json:"amount"`
	Remaining uint64  `json:"remaining"`
}

CreditData contains the information about any running promotion.

type FundLocker

type FundLocker interface {
	// LockSiacoins moves a part of the balance to "locked".
	LockSiacoins(string, float64) error

	// UnlockSiacoins moves a part of the amount from "locked" to "available",
	// while the other part (fees and other spent funds) is "burned".
	UnlockSiacoins(string, float64, float64, types.BlockHeight) error
}

FundLocker is the minimal interface needed to lock and unlock funds.

type HostAverages

type HostAverages struct {
	NumHosts               uint64            `json:"numhosts"`
	Duration               types.BlockHeight `json:"height"`
	StoragePrice           types.Currency    `json:"storageprice"`
	Collateral             types.Currency    `json:"collateral"`
	DownloadBandwidthPrice types.Currency    `json:"downloadprice"`
	UploadBandwidthPrice   types.Currency    `json:"uploadprice"`
	ContractPrice          types.Currency    `json:"contractprice"`
	BaseRPCPrice           types.Currency    `json:"baserpcprice"`
	SectorAccessPrice      types.Currency    `json:"sectoraccessprice"`
}

HostAverages contains the host network averages from HostDB.

type HostDB

type HostDB interface {
	smodules.Alerter

	// ActiveHosts returns the list of hosts that are actively being selected
	// from.
	ActiveHosts() ([]smodules.HostDBEntry, error)

	// AllHosts returns the full list of hosts known to the hostdb, sorted in
	// order of preference.
	AllHosts() ([]smodules.HostDBEntry, error)

	// CheckForIPViolations accepts a number of host public keys and returns the
	// ones that violate the rules of the addressFilter.
	CheckForIPViolations([]types.SiaPublicKey) ([]types.SiaPublicKey, error)

	// Close closes the hostdb.
	Close() error

	// EstimateHostScore returns the estimated score breakdown of a host with the
	// provided settings.
	EstimateHostScore(smodules.HostDBEntry, Allowance) (smodules.HostScoreBreakdown, error)

	// Filter returns the hostdb's filterMode and filteredHosts.
	Filter() (smodules.FilterMode, map[string]types.SiaPublicKey, []string, error)

	// SetFilterMode sets the renter's hostdb filter mode.
	SetFilterMode(smodules.FilterMode, []types.SiaPublicKey, []string) error

	// Host returns the HostDBEntry for a given host.
	Host(pk types.SiaPublicKey) (smodules.HostDBEntry, bool, error)

	// IncrementSuccessfulInteractions increments the number of successful
	// interactions with a host for a given key
	IncrementSuccessfulInteractions(types.SiaPublicKey) error

	// IncrementFailedInteractions increments the number of failed interactions with
	// a host for a given key
	IncrementFailedInteractions(types.SiaPublicKey) error

	// initialScanComplete returns a boolean indicating if the initial scan of the
	// hostdb is completed and the current block height of the hostdb.
	InitialScanComplete() (bool, types.BlockHeight, error)

	// IPViolationsCheck returns a boolean indicating if the IP violation check is
	// enabled or not.
	IPViolationsCheck() (bool, error)

	// RandomHosts returns a set of random hosts, weighted by their estimated
	// usefulness / attractiveness to the renter. RandomHosts will not return
	// any offline or inactive hosts.
	RandomHosts(int, []types.SiaPublicKey, []types.SiaPublicKey) ([]smodules.HostDBEntry, error)

	// RandomHostsWithAllowance is the same as RandomHosts but accepts an
	// allowance as an argument to be used instead of the allowance set in the
	// manager.
	RandomHostsWithAllowance(int, []types.SiaPublicKey, []types.SiaPublicKey, Allowance) ([]smodules.HostDBEntry, error)

	// RandomHostsWithLimits works as RandomHostsWithAllowance but uses the
	// limits set in the allowance instead of calculating the weight function.
	RandomHostsWithLimits(int, []types.SiaPublicKey, []types.SiaPublicKey, Allowance) ([]smodules.HostDBEntry, error)

	// ScoreBreakdown returns a detailed explanation of the various properties
	// of the host.
	ScoreBreakdown(smodules.HostDBEntry) (smodules.HostScoreBreakdown, error)

	// SetAllowance updates the allowance used by the hostdb for weighing hosts by
	// updating the host weight function. It will completely rebuild the hosttree so
	// it should be used with care.
	SetAllowance(Allowance) error

	// SetIPViolationCheck enables/disables the IP violation check within the
	// hostdb.
	SetIPViolationCheck(enabled bool) error

	// LoadingComplete indicates if the HostDB has finished loading the hosts
	// from the database.
	LoadingComplete() bool

	// UpdateContracts rebuilds the knownContracts of the HostBD using the
	// provided contracts.
	UpdateContracts([]RenterContract) error
}

A HostDB is a database of hosts that the manager can use for figuring out who to upload to, and download from.

type Manager

type Manager interface {
	smodules.Alerter

	// Close safely shuts down the manager.
	Close() error

	// PriceEstimation estimates the cost in siacoins of performing various
	// storage and data operations. The estimation will be done using the provided
	// allowance. The final allowance used will be returned.
	PriceEstimation(Allowance) (float64, Allowance, error)
}

Manager implements the methods necessary to communicate with the hosts.

type Portal

type Portal interface {
	smodules.Alerter

	// Close safely shuts down the portal.
	Close() error

	// GetCredits retrieves the credits data.
	GetCredits() CreditData

	// SetCredits updates the credit data.
	SetCredits(CreditData)
}

Portal implements the portal server.

type Provider

type Provider interface {
	smodules.Alerter

	// Close safely shuts down the provider.
	Close() error
}

Provider implements the methods necessary to communicate with the renters.

type RecoverableContract

type RecoverableContract struct {
	types.FileContract
	// ID is the FileContract's ID.
	ID types.FileContractID `json:"id"`
	// RenterPublicKey is the public key of the renter that formed this contract.
	RenterPublicKey types.SiaPublicKey `json:"renterpublickey"`
	// HostPublicKey is the public key of the host we formed this contract
	// with.
	HostPublicKey types.SiaPublicKey `json:"hostpublickey"`
	// InputParentID is the ParentID of the first SiacoinInput of the
	// transaction that contains this contract.
	InputParentID types.SiacoinOutputID `json:"inputparentid"`
	// StartHeight is the estimated startheight of a recoverable contract.
	StartHeight types.BlockHeight `json:"startheight"`
	// TxnFee of the transaction which contains the contract.
	TxnFee types.Currency `json:"txnfee"`
}

RecoverableContract is a types.FileContract as it appears on the blockchain with additional fields which contain the information required to recover its latest revision from a host.

type Renter

type Renter struct {
	Allowance     Allowance          `json:"allowance"`
	CurrentPeriod types.BlockHeight  `json:"currentperiod"`
	PublicKey     types.SiaPublicKey `json:"publickey"`
	Email         string             `json:"email"` // Link to the user account.
}

Renter holds the data related to the specific renter.

func (*Renter) ContractEndHeight

func (r *Renter) ContractEndHeight() types.BlockHeight

contractEndHeight returns the height at which the renter's contracts end.

type RenterContract

type RenterContract struct {
	ID              types.FileContractID
	HostPublicKey   types.SiaPublicKey
	RenterPublicKey types.SiaPublicKey
	Transaction     types.Transaction

	StartHeight types.BlockHeight
	EndHeight   types.BlockHeight

	// RenterFunds is the amount remaining in the contract that the renter can
	// spend.
	RenterFunds types.Currency

	// The FileContract does not indicate what funds were spent on, so we have
	// to track the various costs manually.
	DownloadSpending    types.Currency
	FundAccountSpending types.Currency
	MaintenanceSpending smodules.MaintenanceSpending
	StorageSpending     types.Currency
	UploadSpending      types.Currency

	// Utility contains utility information about the renter.
	Utility smodules.ContractUtility

	// TotalCost indicates the amount of money that the renter spent and/or
	// locked up while forming a contract. This includes fees, and includes
	// funds which were allocated (but not necessarily committed) to spend on
	// uploads/downloads/storage.
	TotalCost types.Currency

	// ContractFee is the amount of money paid to the host to cover potential
	// future transaction fees that the host may incur, and to cover any other
	// overheads the host may have.
	//
	// TxnFee is the amount of money spent on the transaction fee when putting
	// the renter contract on the blockchain.
	//
	// SiafundFee is the amount of money spent on siafund fees when creating the
	// contract. The siafund fee that the renter pays covers both the renter and
	// the host portions of the contract, and therefore can be unexpectedly high
	// if the the host collateral is high.
	ContractFee types.Currency
	TxnFee      types.Currency
	SiafundFee  types.Currency
}

A RenterContract contains metadata about a file contract. It is read-only; modifying a RenterContract does not modify the actual file contract.

func (*RenterContract) Size

func (rc *RenterContract) Size() uint64

Size returns the contract size.

type Satellite

type Satellite interface {
	smodules.Alerter

	// ActiveHosts provides the list of hosts that the manager is selecting,
	// sorted by preference.
	ActiveHosts() ([]smodules.HostDBEntry, error)

	// AllHosts returns the full list of hosts known to the manager.
	AllHosts() ([]smodules.HostDBEntry, error)

	// Close safely shuts down the satellite.
	Close() error

	// DeleteRenter deletes the renter data from the memory.
	DeleteRenter(string)

	// EstimateHostScore will return the score for a host with the provided
	// settings, assuming perfect age and uptime adjustments.
	EstimateHostScore(smodules.HostDBEntry, Allowance) (smodules.HostScoreBreakdown, error)

	// Filter returns the hostdb's filterMode and filteredHosts.
	Filter() (smodules.FilterMode, map[string]types.SiaPublicKey, []string, error)

	// SetFilterMode sets the hostdb's filter mode.
	SetFilterMode(smodules.FilterMode, []types.SiaPublicKey, []string) error

	// Host provides the DB entry and score breakdown for the requested host.
	Host(types.SiaPublicKey) (smodules.HostDBEntry, bool, error)

	// InitialScanComplete returns a boolean indicating if the initial scan of
	// the hostdb is completed.
	InitialScanComplete() (bool, types.BlockHeight, error)

	// ScoreBreakdown will return the score for a host db entry using the
	// hostdb's weighting algorithm.
	ScoreBreakdown(smodules.HostDBEntry) (smodules.HostScoreBreakdown, error)

	// RandomHosts picks up to the specified number of random hosts from the
	// hostdb sorted by weight.
	RandomHosts(uint64, Allowance) ([]smodules.HostDBEntry, error)

	// PublicKey returns the satellite's public key.
	PublicKey() types.SiaPublicKey

	// SecretKey returns the satellite's secret key.
	SecretKey() crypto.SecretKey

	// GetAverages retrieves the host network averages.
	GetAverages() HostAverages

	// FeeEstimation returns the minimum and the maximum estimated fees for
	// a transaction.
	FeeEstimation() (min, max types.Currency)

	// GetWalletSeed returns the wallet seed.
	GetWalletSeed() (smodules.Seed, error)

	// GetRenter returns the renter by the public key.
	GetRenter(types.SiaPublicKey) (Renter, error)

	// Renters retrieves the list of renters.
	Renters() []Renter

	// GetBalance retrieves the balance information on the account.
	GetBalance(string) (*UserBalance, error)

	// Contracts returns storage contracts.
	Contracts() []RenterContract

	// ContractsByRenter returns storage contracts filtered by the renter.
	ContractsByRenter(types.SiaPublicKey) []RenterContract

	// RefreshedContract returns a bool indicating if the contract was refreshed.
	RefreshedContract(types.FileContractID) bool

	// OldContracts returns the contracts that have expired.
	OldContracts() []RenterContract

	// OldContractsByRenter returns expired contracts filtered by the renter.
	OldContractsByRenter(types.SiaPublicKey) []RenterContract

	// RetrieveSpendings retrieves the user's spendings.
	RetrieveSpendings(string, string) (*UserSpendings, error)
}

Satellite implements the methods necessary to communicate both with the renters and the hosts.

type UserBalance

type UserBalance struct {
	IsUser     bool    `json:"isuser"`
	Subscribed bool    `json:"subscribed"`
	Balance    float64 `json:"balance"`
	Locked     float64 `json:"locked"`
	Currency   string  `json:"currency"`
	SCBalance  float64 `json:"scbalance"`
	StripeID   string  `json:"stripeid"`
}

userBalance holds the current balance as well as the data on the chosen payment scheme.

type UserSpendings

type UserSpendings struct {
	CurrentLocked   float64 `json:"currentlocked"`
	CurrentUsed     float64 `json:"currentused"`
	CurrentOverhead float64 `json:"currentoverhead"`
	PrevLocked      float64 `json:"prevlocked"`
	PrevUsed        float64 `json:"prevused"`
	PrevOverhead    float64 `json:"prevoverhead"`
}

UserSpendings contains the spendings in the current and the previous months.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL