contractor

package
v0.10.1 Latest Latest
Warning

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

Go to latest
Published: Feb 26, 2024 License: MIT Imports: 32 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// 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.

View Source
const (
	// 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)
)

Constants related to contract formation parameters.

View Source
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

View Source
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's 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's 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's 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's 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's expected
	// download is being set to zero when not cancelling the allowance.
	ErrAllowanceZeroExpectedDownload = errors.New("expected download  must be non-zero")
	// ErrAllowanceWrongRedundancy is returned if the allowance's redundancy
	// parameters are being set to zero.
	ErrAllowanceWrongRedundancy = errors.New("wrong redundancy params")
	// ErrRenterNotFound is returned when no renter matches the provided public
	// key.
	ErrRenterNotFound = errors.New("no renter found with this public key")
)
View Source
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")
)

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(db *sql.DB, cs modules.ConsensusSet, m modules.Manager, tpool modules.TransactionPool, wallet modules.Wallet, hdb modules.HostDB, dir string) (*Contractor, <-chan error)

New returns a new Contractor.

func (*Contractor) AcceptContracts

func (c *Contractor) AcceptContracts(rpk types.PublicKey, contracts []modules.ContractMetadata)

AcceptContracts accepts a set of contracts from the renter and adds them to the contract set.

func (*Contractor) Alerts

func (c *Contractor) Alerts() (crit, err, warn, info []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(rpk types.PublicKey) modules.Allowance

Allowance returns the current allowance of the renter specified.

func (*Contractor) CancelContract

func (c *Contractor) CancelContract(id types.FileContractID) error

CancelContract cancels the Contractor's contract by marking it !GoodForRenew and !GoodForUpload

func (*Contractor) CancelUpload added in v0.9.1

func (c *Contractor) CancelUpload(rpk types.PublicKey, bucket, path []byte)

CancelUpload cancels a running upload.

func (*Contractor) Close

func (c *Contractor) Close() error

Close closes the Contractor.

func (*Contractor) Contract

Contract returns the contract with the given ID.

func (*Contractor) ContractStatus

func (c *Contractor) ContractStatus(fcID types.FileContractID) (modules.ContractWatchStatus, bool)

ContractStatus returns the status of a contract in the watchdog.

func (*Contractor) ContractUtility

func (c *Contractor) ContractUtility(rpk, hpk types.PublicKey) (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.

func (*Contractor) ContractsByRenter

func (c *Contractor) ContractsByRenter(rpk types.PublicKey) []modules.RenterContract

ContractsByRenter returns the contracts belonging to a specific renter.

func (*Contractor) CreateNewRenter

func (c *Contractor) CreateNewRenter(email string, rpk types.PublicKey)

CreateNewRenter inserts a new renter into the map.

func (*Contractor) CurrentPeriod

func (c *Contractor) CurrentPeriod(rpk types.PublicKey) uint64

CurrentPeriod returns the height at which the current allowance period of the renter began.

func (*Contractor) DeleteMetadata

func (c *Contractor) DeleteMetadata(pk types.PublicKey) error

DeleteMetadata deletes the renter's saved file metadata.

func (*Contractor) DeleteObject

func (c *Contractor) DeleteObject(pk types.PublicKey, bucket, path []byte) error

DeleteObject deletes the saved file metadata object.

func (*Contractor) DeleteRenter

func (c *Contractor) DeleteRenter(email string)

DeleteRenter deletes the renter data from the memory.

func (*Contractor) DownloadObject

func (c *Contractor) DownloadObject(w io.Writer, rpk types.PublicKey, bucket, path []byte) error

DownloadObject downloads an object and returns it.

func (*Contractor) FormContract

func (c *Contractor) FormContract(s *modules.RPCSession, rpk, epk, hpk types.PublicKey, funding types.Currency, endHeight uint64) (modules.RenterContract, error)

FormContract forms a contract with the specified host using RSP2, puts it in the contract set, and returns it.

func (*Contractor) FormContracts

func (c *Contractor) FormContracts(rpk types.PublicKey, rsk types.PrivateKey) ([]modules.RenterContract, error)

FormContracts forms contracts according to the renter's allowance, puts them in the contract set, and returns them.

func (*Contractor) GetModifiedSlabs added in v0.8.0

func (c *Contractor) GetModifiedSlabs(rpk types.PublicKey) ([]modules.Slab, error)

GetModifiedSlabs returns all slabs modified since the last retrieval.

func (*Contractor) GetRenter

func (c *Contractor) GetRenter(rpk types.PublicKey) (modules.Renter, error)

GetRenter returns the renter with the specified public key.

func (*Contractor) IsOffline

func (c *Contractor) IsOffline(pk types.PublicKey) bool

IsOffline indicates whether a contract's host should be considered offline, based on its scan metrics.

func (*Contractor) MarkContractBad

func (c *Contractor) MarkContractBad(id types.FileContractID) error

MarkContractBad will mark a specific contract as bad.

func (*Contractor) OldContracts

func (c *Contractor) OldContracts() []modules.RenterContract

OldContracts returns the contracts formed by the contractor that have expired.

func (*Contractor) OldContractsByRenter

func (c *Contractor) OldContractsByRenter(rpk types.PublicKey) []modules.RenterContract

OldContractsByRenter returns the old contracts of a specific renter.

func (*Contractor) PeriodSpending

func (c *Contractor) PeriodSpending(rpk types.PublicKey) (modules.RenterSpending, error)

PeriodSpending returns the amount spent by the renter 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) RefreshedContract

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

func (c *Contractor) RenewContract(s *modules.RPCSession, rpk types.PublicKey, contract modules.RenterContract, funding types.Currency, endHeight uint64) (modules.RenterContract, error)

RenewContract tries to renew the given contract using RSP2.

func (*Contractor) RenewContracts

func (c *Contractor) RenewContracts(rpk types.PublicKey, rsk types.PrivateKey, contracts []types.FileContractID) ([]modules.RenterContract, error)

RenewContracts tries to renew a given set of contracts.

func (*Contractor) RenewedFrom

func (c *Contractor) RenewedFrom(fcid types.FileContractID) types.FileContractID

RenewedFrom returns the ID of the contract the given contract was renewed from, if any.

func (*Contractor) Renters

func (c *Contractor) Renters() []modules.Renter

Renters returns the list of renters.

func (*Contractor) RetrieveMetadata

func (c *Contractor) RetrieveMetadata(pk types.PublicKey, present []modules.BucketFiles) (fm []modules.FileMetadata, err error)

RetrieveMetadata retrieves the file metadata from the database.

func (*Contractor) SetAllowance

func (c *Contractor) SetAllowance(rpk types.PublicKey, 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.

If a is the empty allowance, SetAllowance will archive the current contract set. The contracts 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) StartUploading added in v0.9.1

func (c *Contractor) StartUploading()

StartUploading initiates uploading buffered files.

func (*Contractor) Synced

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) UnlockBalance

func (c *Contractor) UnlockBalance(fcid types.FileContractID)

UnlockBalance unlocks the renter funds after the contract ends.

func (*Contractor) UpdateContract

func (c *Contractor) UpdateContract(rev types.FileContractRevision, sigs []types.TransactionSignature, uploads, downloads, fundAccount types.Currency) error

UpdateContract updates the contract with the new revision.

func (*Contractor) UpdateMetadata

func (c *Contractor) UpdateMetadata(pk types.PublicKey, fm modules.FileMetadata) error

UpdateMetadata updates the file metadata in the database.

func (*Contractor) UpdateRenter

func (c *Contractor) UpdateRenter(renter modules.Renter) error

UpdateRenter updates the renter record in the database. The record must have already been created.

func (*Contractor) UpdateRenterSettings

func (c *Contractor) UpdateRenterSettings(rpk types.PublicKey, settings modules.RenterSettings, sk, ak types.PrivateKey) error

UpdateRenterSettings updates the renter's opt-in settings.

func (*Contractor) UpdateSlab

func (c *Contractor) UpdateSlab(rpk types.PublicKey, slab modules.Slab, packed bool) error

UpdateSlab updates a file slab after a successful migration.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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