Documentation ¶
Index ¶
- Constants
- Variables
- type Contractor
- func (c *Contractor) Alerts() (crit, err, warn []modules.Alert)
- func (c *Contractor) Allowance() modules.Allowance
- func (c *Contractor) CancelContract(id types.FileContractID) error
- func (c *Contractor) ChurnStatus() modules.ContractorChurnStatus
- func (c *Contractor) Close() error
- func (c *Contractor) ContractByPublicKey(pk types.SiaPublicKey) (modules.RenterContract, bool)
- func (c *Contractor) ContractPublicKey(pk types.SiaPublicKey) (crypto.PublicKey, bool)
- func (c *Contractor) ContractStatus(fcID types.FileContractID) (modules.ContractWatchStatus, bool)
- func (c *Contractor) ContractUtility(pk types.SiaPublicKey) (modules.ContractUtility, bool)
- func (c *Contractor) Contracts() []modules.RenterContract
- func (c *Contractor) CurrentPeriod() types.BlockHeight
- func (c *Contractor) Downloader(pk types.SiaPublicKey, cancel <-chan struct{}) (_ Downloader, err error)
- func (c *Contractor) Editor(pk types.SiaPublicKey, cancel <-chan struct{}) (_ Editor, err error)
- func (c *Contractor) InitRecoveryScan() (err error)
- func (c *Contractor) IsOffline(pk types.SiaPublicKey) bool
- func (c *Contractor) MarkContractBad(id types.FileContractID) error
- func (c *Contractor) OldContracts() []modules.RenterContract
- func (c *Contractor) PeriodSpending() (modules.ContractorSpending, error)
- func (c *Contractor) ProcessConsensusChange(cc modules.ConsensusChange)
- func (c *Contractor) ProvidePayment(stream io.ReadWriter, pt *modules.RPCPriceTable, details PaymentDetails) error
- func (c *Contractor) RecoverableContracts() []modules.RecoverableContract
- func (c *Contractor) RecoveryScanStatus() (bool, types.BlockHeight)
- func (c *Contractor) RefreshedContract(fcid types.FileContractID) bool
- func (c *Contractor) RenewContract(conn net.Conn, fcid types.FileContractID, params modules.ContractParams, ...) (modules.RenterContract, []types.Transaction, error)
- func (c *Contractor) Session(pk types.SiaPublicKey, cancel <-chan struct{}) (_ Session, err error)
- func (c *Contractor) SetAllowance(a modules.Allowance) error
- func (c *Contractor) Synced() <-chan struct{}
- func (c *Contractor) UpdateWorkerPool(wp modules.WorkerPool)
- type Downloader
- type Editor
- type PaymentDetails
- type Session
- type WalletBridge
- func (ws *WalletBridge) NextAddress() (types.UnlockConditions, error)
- func (ws *WalletBridge) PrimarySeed() (modules.Seed, uint64, error)
- func (ws *WalletBridge) RegisterTransaction(t types.Transaction, parents []types.Transaction) (transactionBuilder, error)
- func (ws *WalletBridge) StartTransaction() (transactionBuilder, error)
- func (ws *WalletBridge) Unlocked() (bool, error)
Constants ¶
const MaxCriticalRenewFailThreshold = 0.2
MaxCriticalRenewFailThreshold is the maximum number of contracts failing to renew as fraction of the total hosts in the allowance before renew alerts are made critical.
Variables ¶
var ( // ErrAllowanceZeroFunds is returned if the allowance funds are being set to // zero when not cancelling the allowance ErrAllowanceZeroFunds = errors.New("funds must be non-zero") // ErrAllowanceZeroPeriod is returned if the allowance period is being set // to zero when not cancelling the allowance ErrAllowanceZeroPeriod = errors.New("period must be non-zero") // ErrAllowanceZeroWindow is returned if the allowance renew window is being // set to zero when not cancelling the allowance ErrAllowanceZeroWindow = errors.New("renew window must be non-zero") // ErrAllowanceNoHosts is returned if the allowance hosts are being set to // zero when not cancelling the allowance ErrAllowanceNoHosts = errors.New("hosts must be non-zero") // ErrAllowanceZeroExpectedStorage is returned if the allowance expected // storage is being set to zero when not cancelling the allowance ErrAllowanceZeroExpectedStorage = errors.New("expected storage must be non-zero") // ErrAllowanceZeroExpectedUpload is returned if the allowance expected // upload is being set to zero when not cancelling the allowance ErrAllowanceZeroExpectedUpload = errors.New("expected upload must be non-zero") // ErrAllowanceZeroExpectedDownload is returned if the allowance expected // download is being set to zero when not cancelling the allowance ErrAllowanceZeroExpectedDownload = errors.New("expected download must be non-zero") // ErrAllowanceZeroExpectedRedundancy is returned if the allowance expected // redundancy is being set to zero when not cancelling the allowance ErrAllowanceZeroExpectedRedundancy = errors.New("expected redundancy must be non-zero") // ErrAllowanceZeroMaxPeriodChurn is returned if the allowance max period // churn is being set to zero when not cancelling the allowance ErrAllowanceZeroMaxPeriodChurn = errors.New("max period churn must be non-zero") )
var ( // AlertCauseInsufficientAllowanceFunds indicates that the cause for the // alert was insufficient allowance funds remaining AlertCauseInsufficientAllowanceFunds = "Insufficient allowance funds remaining" // AlertMSGAllowanceLowFunds indicates that forming/renewing a contract during // contract maintenance isn't possible due to the allowance being low on // funds. AlertMSGAllowanceLowFunds = "At least one contract formation/renewal failed due to the allowance being low on funds" // AlertMSGFailedContractRenewal indicates that the contract renewal failed AlertMSGFailedContractRenewal = "Contractor is attempting to renew/refresh contracts but failed" // AlertMSGWalletLockedDuringMaintenance indicates that forming/renewing a // contract during contract maintenance isn't possible due to a locked wallet. AlertMSGWalletLockedDuringMaintenance = "At least one contract failed to form/renew due to the wallet being locked" )
Constants related to the contractor's alerts.
var ( // ContractFeeFundingMulFactor is the multiplying factor for contract fees // to determine the funding for a new contract ContractFeeFundingMulFactor = uint64(10) // MaxInitialContractFundingDivFactor is the dividing factor for determining // the maximum amount of funds to put into a new contract MaxInitialContractFundingDivFactor = uint64(3) // MaxInitialContractFundingMulFactor is the multiplying factor for // determining the maximum amount of funds to put into a new contract MaxInitialContractFundingMulFactor = uint64(2) // MinInitialContractFundingDivFactor is the dividing factor for determining // the minimum amount of funds to put into a new contract MinInitialContractFundingDivFactor = uint64(20) // MinContractFundRenewalThreshold defines the ratio of remaining funds to // total contract cost below which the contractor will prematurely renew a // contract. // // This number is deliberately a little higher than the // minContractFundUploadThreshold because we want to make sure that renewals // will kick in before uploading stops. MinContractFundRenewalThreshold = float64(0.06) // 6% // minContractFundUploadThreshold is the percentage of contract funds // remaining at which the contract gets marked !GoodForUpload. The number is // high so that there is plenty of money available for downloading, so that // urgent repairs can be performed and also so that user file access is not // interrupted until after uploading progress is interrupted. Structuring // things this way essentially allows the user to experience the failure // mode of 'can't store additional stuff' before the user experiences the // failure mode of 'can't retrieve stuff already uploaded'. MinContractFundUploadThreshold = float64(0.05) // 5% )
Constants related to contract formation parameters.
var ErrContractRenewing = errors.New("currently renewing that contract")
ErrContractRenewing is returned by operations that can't be completed due to the contract being renewed.
var ( // ErrInsufficientAllowance indicates that the renter's allowance is less // than the amount necessary to store at least one sector ErrInsufficientAllowance = errors.New("allowance is not large enough to cover fees of contract creation") )
var ( // PersistFilename is the filename to be used when persisting contractor // information to a JSON file PersistFilename = "contractor.json" )
Functions ¶
This section is empty.
Types ¶
type Contractor ¶
type Contractor struct {
// contains filtered or unexported fields
}
A Contractor negotiates, revises, renews, and provides access to file contracts.
func New ¶
func New(cs modules.ConsensusSet, wallet modules.Wallet, tpool modules.TransactionPool, hdb modules.HostDB, rl *ratelimit.RateLimit, persistDir string) (*Contractor, <-chan error)
New returns a new Contractor.
func NewCustomContractor ¶ added in v1.3.3
func NewCustomContractor(cs modules.ConsensusSet, w modules.Wallet, tp modules.TransactionPool, hdb modules.HostDB, persistDir string, contractSet *proto.ContractSet, l *persist.Logger, deps modules.Dependencies) (*Contractor, <-chan error)
NewCustomContractor creates a Contractor using the provided dependencies.
func (*Contractor) Alerts ¶ added in v1.4.2
func (c *Contractor) Alerts() (crit, err, warn []modules.Alert)
Alerts implements the modules.Alerter interface for the contractor. It returns all alerts of the contractor.
func (*Contractor) Allowance ¶
func (c *Contractor) Allowance() modules.Allowance
Allowance returns the current allowance.
func (*Contractor) CancelContract ¶ added in v1.3.4
func (c *Contractor) CancelContract(id types.FileContractID) error
CancelContract cancels the Contractor's contract by marking it !GoodForRenew and !GoodForUpload
func (*Contractor) ChurnStatus ¶ added in v1.4.2
func (c *Contractor) ChurnStatus() modules.ContractorChurnStatus
ChurnStatus returns the current period's aggregate churn and the max churn per period.
func (*Contractor) Close ¶ added in v1.1.1
func (c *Contractor) Close() error
Close closes the Contractor.
func (*Contractor) ContractByPublicKey ¶ added in v1.3.4
func (c *Contractor) ContractByPublicKey(pk types.SiaPublicKey) (modules.RenterContract, bool)
ContractByPublicKey returns the contract with the key specified, if it exists. The contract will be resolved if possible to the most recent child contract.
func (*Contractor) ContractPublicKey ¶ added in v1.5.0
func (c *Contractor) ContractPublicKey(pk types.SiaPublicKey) (crypto.PublicKey, bool)
ContractPublicKey returns the public key capable of verifying the renter's signature on a contract.
func (*Contractor) ContractStatus ¶ added in v1.4.2
func (c *Contractor) ContractStatus(fcID types.FileContractID) (modules.ContractWatchStatus, bool)
ContractStatus returns the status of a contract in the watchdog.
func (*Contractor) ContractUtility ¶ added in v1.3.1
func (c *Contractor) ContractUtility(pk types.SiaPublicKey) (modules.ContractUtility, bool)
ContractUtility returns the utility fields for the given contract.
func (*Contractor) Contracts ¶
func (c *Contractor) Contracts() []modules.RenterContract
Contracts returns the contracts formed by the contractor in the current allowance period. Only contracts formed with currently online hosts are returned.
func (*Contractor) CurrentPeriod ¶ added in v1.1.0
func (c *Contractor) CurrentPeriod() types.BlockHeight
CurrentPeriod returns the height at which the current allowance period began.
func (*Contractor) Downloader ¶
func (c *Contractor) Downloader(pk types.SiaPublicKey, cancel <-chan struct{}) (_ Downloader, err error)
Downloader returns a Downloader object that can be used to download sectors from a host.
func (*Contractor) Editor ¶
func (c *Contractor) Editor(pk types.SiaPublicKey, cancel <-chan struct{}) (_ Editor, err error)
Editor returns a Editor object that can be used to upload, modify, and delete sectors on a host.
func (*Contractor) InitRecoveryScan ¶ added in v1.4.0
func (c *Contractor) InitRecoveryScan() (err error)
InitRecoveryScan starts scanning the whole blockchain for recoverable contracts within a separate thread.
func (*Contractor) IsOffline ¶ added in v1.1.0
func (c *Contractor) IsOffline(pk types.SiaPublicKey) bool
IsOffline indicates whether a contract's host should be considered offline, based on its scan metrics.
func (*Contractor) MarkContractBad ¶ added in v1.4.2
func (c *Contractor) MarkContractBad(id types.FileContractID) error
MarkContractBad will mark a specific contract as bad.
func (*Contractor) OldContracts ¶ added in v1.3.4
func (c *Contractor) OldContracts() []modules.RenterContract
OldContracts returns the contracts formed by the contractor that have expired
func (*Contractor) PeriodSpending ¶ added in v1.3.1
func (c *Contractor) PeriodSpending() (modules.ContractorSpending, error)
PeriodSpending returns the amount spent on contracts during the current billing period.
func (*Contractor) ProcessConsensusChange ¶
func (c *Contractor) ProcessConsensusChange(cc modules.ConsensusChange)
ProcessConsensusChange will be called by the consensus set every time there is a change in the blockchain. Updates will always be called in order.
func (*Contractor) ProvidePayment ¶ added in v1.4.8
func (c *Contractor) ProvidePayment(stream io.ReadWriter, pt *modules.RPCPriceTable, details PaymentDetails) error
ProvidePayment takes a stream and a set of payment details and handles the payment for an RPC by sending and processing payment request and response objects to the host. It returns an error in case of failure.
func (*Contractor) RecoverableContracts ¶ added in v1.4.0
func (c *Contractor) RecoverableContracts() []modules.RecoverableContract
RecoverableContracts returns the contracts that the contractor deems recoverable. That means they are not expired yet and also not part of the active contracts. Usually this should return an empty slice unless the host isn't available for recovery or something went wrong.
func (*Contractor) RecoveryScanStatus ¶ added in v1.4.0
func (c *Contractor) RecoveryScanStatus() (bool, types.BlockHeight)
RecoveryScanStatus returns a bool indicating if a scan for recoverable contracts is in progress and if it is, the current progress of the scan.
func (*Contractor) RefreshedContract ¶ added in v1.4.1
func (c *Contractor) RefreshedContract(fcid types.FileContractID) bool
RefreshedContract returns a bool indicating if the contract was a refreshed contract. A refreshed contract refers to a contract that ran out of funds prior to the end height and so was renewed with the host in the same period. Both the old and the new contract have the same end height
func (*Contractor) RenewContract ¶ added in v1.5.4
func (c *Contractor) RenewContract(conn net.Conn, fcid types.FileContractID, params modules.ContractParams, txnBuilder modules.TransactionBuilder, tpool modules.TransactionPool, hdb modules.HostDB, pt *modules.RPCPriceTable) (modules.RenterContract, []types.Transaction, error)
RenewContract takes an established connection to a host and renews the contract with that host.
func (*Contractor) Session ¶ added in v1.4.0
func (c *Contractor) Session(pk types.SiaPublicKey, cancel <-chan struct{}) (_ Session, err error)
Session returns a Session object that can be used to upload, modify, and delete sectors on a host.
func (*Contractor) SetAllowance ¶
func (c *Contractor) SetAllowance(a modules.Allowance) error
SetAllowance sets the amount of money the Contractor is allowed to spend on contracts over a given time period, divided among the number of hosts specified. Note that Contractor can start forming contracts as soon as SetAllowance is called; that is, it may block.
In most cases, SetAllowance will renew existing contracts instead of forming new ones. This preserves the data on those hosts. When this occurs, the renewed contracts will atomically replace their previous versions. If SetAllowance is interrupted, renewed contracts may be lost, though the allocated funds will eventually be returned.
If a is the empty allowance, SetAllowance will archive the current contract set. The contracts cannot be used to create Editors or Downloads, and will not be renewed.
NOTE: At this time, transaction fees are not counted towards the allowance. This means the contractor may spend more than allowance.Funds.
func (*Contractor) Synced ¶ added in v1.4.2
func (c *Contractor) Synced() <-chan struct{}
Synced returns a channel that is closed when the contractor is synced with the peer-to-peer network.
func (*Contractor) UpdateWorkerPool ¶ added in v1.5.5
func (c *Contractor) UpdateWorkerPool(wp modules.WorkerPool)
UpdateWorkerPool updates the workerpool currently in use by the contractor.
type Downloader ¶
type Downloader interface { // Download requests the specified sector data. Download(root crypto.Hash, offset, length uint32) ([]byte, error) // HostSettings returns the settings that are active in the current // downloader session. HostSettings() modules.HostExternalSettings // Close terminates the connection to the host. Close() error }
An Downloader retrieves sectors from with a host. It requests one sector at a time, and revises the file contract to transfer money to the host proportional to the data retrieved.
type Editor ¶
type Editor interface { // Upload revises the underlying contract to store the new data. It // returns the Merkle root of the data. Upload(data []byte) (root crypto.Hash, err error) // Address returns the address of the host. Address() modules.NetAddress // ContractID returns the FileContractID of the contract. ContractID() types.FileContractID // EndHeight returns the height at which the contract ends. EndHeight() types.BlockHeight // Close terminates the connection to the host. Close() error // HostSettings returns the host settings that are currently active for the // underlying session. HostSettings() modules.HostExternalSettings }
An Editor modifies a Contract by communicating with a host. It uses the contract revision protocol to send modification requests to the host. Editors are the means by which the renter uploads data to hosts.
type PaymentDetails ¶ added in v1.5.6
type PaymentDetails struct { // destination details Host types.SiaPublicKey // payment details Amount types.Currency RefundAccount modules.AccountID // spending details SpendingDetails modules.SpendingDetails }
PaymentDetails is a helper struct that contains extra information on a payment. Most notably it includes a breakdown of the spending details for a payment, the contractor uses this information to update its spending details accordingly.
type Session ¶ added in v1.4.0
type Session interface { // Address returns the address of the host. Address() modules.NetAddress // Close terminates the connection to the host. Close() error // ContractID returns the FileContractID of the contract. ContractID() types.FileContractID // Download requests the specified sector data. Download(root crypto.Hash, offset, length uint32) ([]byte, error) // DownloadIndex requests data from the sector with the specified index // within the contract. DownloadIndex(index uint64, offset, length uint32) ([]byte, error) // EndHeight returns the height at which the contract ends. EndHeight() types.BlockHeight // Replace replaces the sector at the specified index with data. The old // sector is swapped to the end of the contract data, and is deleted if the // trim flag is set. Replace(data []byte, sectorIndex uint64, trim bool) (crypto.Hash, error) // HostSettings will return the currently active host settings for a // session, which allows the workers to check for price gouging and // determine whether or not an operation should continue. HostSettings() modules.HostExternalSettings // Settings calls the Session RPC and updates the active host settings. Settings() (modules.HostExternalSettings, error) // Upload revises the underlying contract to store the new data. It // returns the Merkle root of the data. Upload(data []byte) (crypto.Hash, error) }
A Session modifies a Contract by communicating with a host. It uses the renter-host protocol to send modification requests to the host. Among other things, Sessions are the means by which the renter transfers file data to and from hosts.
type WalletBridge ¶ added in v1.3.3
type WalletBridge struct {
W walletShim
}
WalletBridge is a bridge for the wallet because wallet is not directly compatible with modules.Wallet (wrong type signature for StartTransaction), we must provide a bridge type.
func (*WalletBridge) NextAddress ¶ added in v1.3.3
func (ws *WalletBridge) NextAddress() (types.UnlockConditions, error)
NextAddress computes and returns the next address of the wallet.
func (*WalletBridge) PrimarySeed ¶ added in v1.4.0
func (ws *WalletBridge) PrimarySeed() (modules.Seed, uint64, error)
PrimarySeed returns the primary wallet seed.
func (*WalletBridge) RegisterTransaction ¶ added in v1.4.2
func (ws *WalletBridge) RegisterTransaction(t types.Transaction, parents []types.Transaction) (transactionBuilder, error)
RegisterTransaction creates a new transactionBuilder from a transaction and parent transactions.
func (*WalletBridge) StartTransaction ¶ added in v1.3.3
func (ws *WalletBridge) StartTransaction() (transactionBuilder, error)
StartTransaction creates a new transactionBuilder that can be used to create and sign a transaction.
func (*WalletBridge) Unlocked ¶ added in v1.4.1
func (ws *WalletBridge) Unlocked() (bool, error)
Unlocked reports whether the wallet bridge is unlocked.