worker

package
v1.0.6 Latest Latest
Warning

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

Go to latest
Published: Mar 12, 2024 License: MIT Imports: 41 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrInsufficientFunds is returned by various RPCs when the renter is
	// unable to provide sufficient payment to the host.
	ErrInsufficientFunds = errors.New("insufficient funds")

	// ErrInsufficientCollateral is returned by various RPCs when the host is
	// unable to provide sufficient collateral.
	ErrInsufficientCollateral = errors.New("insufficient collateral")

	// ErrInvalidMerkleProof is returned by various RPCs when the host supplies
	// an invalid Merkle proof.
	ErrInvalidMerkleProof = errors.New("host supplied invalid Merkle proof")

	// ErrContractLocked is returned by the Lock RPC when the contract in
	// question is already locked by another party. This is a transient error;
	// the caller should retry later.
	ErrContractLocked = errors.New("contract is locked by another party")

	// ErrNoContractLocked is returned by RPCs that require a locked contract
	// when no contract is locked.
	ErrNoContractLocked = errors.New("no contract locked")

	// ErrContractFinalized is returned by the Lock RPC when the contract in
	// question has reached its maximum revision number, meaning the contract
	// can no longer be revised.
	ErrContractFinalized = errors.New("contract cannot be revised further")

	// ErrNoSectorsToPrune is returned when we try to prune a contract that has
	// no sectors to prune.
	ErrNoSectorsToPrune = errors.New("no sectors to prune")
)
View Source
var (
	ErrShuttingDown = errors.New("worker is shutting down")
)

Functions

func New

func New(masterKey [32]byte, id string, b Bus, contractLockingDuration, busFlushInterval, downloadOverdriveTimeout, uploadOverdriveTimeout time.Duration, downloadMaxOverdrive, uploadMaxOverdrive, downloadMaxMemory, uploadMaxMemory uint64, allowPrivateIPs bool, l *zap.Logger) (*worker, error)

New returns an HTTP handler that serves the worker API.

func RPCAccountBalance

func RPCAccountBalance(ctx context.Context, t *transportV3, payment rhpv3.PaymentMethod, account rhpv3.Account, settingsID rhpv3.SettingsID) (bal types.Currency, err error)

RPCAccountBalance calls the AccountBalance RPC.

func RPCAppendSector

func RPCAppendSector(ctx context.Context, t *transportV3, renterKey types.PrivateKey, pt rhpv3.HostPriceTable, rev *types.FileContractRevision, payment rhpv3.PaymentMethod, sectorRoot types.Hash256, sector *[rhpv2.SectorSize]byte) (cost types.Currency, err error)

func RPCFormContract

func RPCFormContract(ctx context.Context, t *rhpv2.Transport, renterKey types.PrivateKey, txnSet []types.Transaction) (_ rhpv2.ContractRevision, _ []types.Transaction, err error)

RPCFormContract forms a contract with a host.

func RPCFundAccount

func RPCFundAccount(ctx context.Context, t *transportV3, payment rhpv3.PaymentMethod, account rhpv3.Account, settingsID rhpv3.SettingsID) (err error)

RPCFundAccount calls the FundAccount RPC.

func RPCLatestRevision

func RPCLatestRevision(ctx context.Context, t *transportV3, contractID types.FileContractID, paymentFunc func(rev *types.FileContractRevision) (rhpv3.HostPriceTable, rhpv3.PaymentMethod, error)) (_ types.FileContractRevision, err error)

RPCLatestRevision calls the LatestRevision RPC. The paymentFunc allows for fetching a pricetable using the fetched revision to pay for it. If paymentFunc returns 'nil' as payment, the host is not paid.

func RPCPriceTable

func RPCPriceTable(ctx context.Context, t *transportV3, paymentFunc PriceTablePaymentFunc) (_ hostdb.HostPriceTable, err error)

RPCPriceTable calls the UpdatePriceTable RPC.

func RPCReadSector

func RPCReadSector(ctx context.Context, t *transportV3, w io.Writer, pt rhpv3.HostPriceTable, payment rhpv3.PaymentMethod, offset, length uint32, merkleRoot types.Hash256) (cost, refund types.Currency, err error)

RPCReadSector calls the ExecuteProgram RPC with a ReadSector instruction.

func RPCSettings

func RPCSettings(ctx context.Context, t *rhpv2.Transport) (settings rhpv2.HostSettings, err error)

RPCSettings calls the Settings RPC, returning the host's reported settings.

func WithGougingChecker

func WithGougingChecker(ctx context.Context, cs ConsensusState, gp api.GougingParams) context.Context

Types

type AccountStore

type AccountStore interface {
	Accounts(ctx context.Context) ([]api.Account, error)
	AddBalance(ctx context.Context, id rhpv3.Account, hk types.PublicKey, amt *big.Int) error

	LockAccount(ctx context.Context, id rhpv3.Account, hostKey types.PublicKey, exclusive bool, duration time.Duration) (api.Account, uint64, error)
	UnlockAccount(ctx context.Context, id rhpv3.Account, lockID uint64) error

	ResetDrift(ctx context.Context, id rhpv3.Account) error
	SetBalance(ctx context.Context, id rhpv3.Account, hk types.PublicKey, amt *big.Int) error
	ScheduleSync(ctx context.Context, id rhpv3.Account, hk types.PublicKey) error
}

An AccountStore manages ephemaral accounts state.

type Client

type Client struct {
	*client.Client
}

re-export the client

func NewClient

func NewClient(address, password string) *Client

type ConsensusState added in v1.0.6

type ConsensusState interface {
	ConsensusState(ctx context.Context) (api.ConsensusState, error)
}

type ContractLocker

type ContractLocker interface {
	AcquireContract(ctx context.Context, fcid types.FileContractID, priority int, d time.Duration) (lockID uint64, err error)
	KeepaliveContract(ctx context.Context, fcid types.FileContractID, lockID uint64, d time.Duration) (err error)
	ReleaseContract(ctx context.Context, fcid types.FileContractID, lockID uint64) (err error)
}

type ContractSpendingRecorder

type ContractSpendingRecorder interface {
	Record(rev types.FileContractRevision, cs api.ContractSpending)
	Stop(context.Context)
}

type ContractStore added in v1.0.2

type ContractStore interface {
	Contract(ctx context.Context, id types.FileContractID) (api.ContractMetadata, error)
	ContractSize(ctx context.Context, id types.FileContractID) (api.ContractSize, error)
	ContractRoots(ctx context.Context, id types.FileContractID) ([]types.Hash256, []types.Hash256, error)
	Contracts(ctx context.Context, opts api.ContractsOpts) ([]api.ContractMetadata, error)
	RenewedContract(ctx context.Context, renewedFrom types.FileContractID) (api.ContractMetadata, error)
}

type GougingChecker

type GougingChecker interface {
	Check(_ *rhpv2.HostSettings, _ *rhpv3.HostPriceTable) api.HostGougingBreakdown
	BlocksUntilBlockHeightGouging(hostHeight uint64) int64
}

func GougingCheckerFromContext

func GougingCheckerFromContext(ctx context.Context, criticalMigration bool) (GougingChecker, error)

func NewGougingChecker

func NewGougingChecker(gs api.GougingSettings, cs api.ConsensusState, txnFee types.Currency, period, renewWindow uint64) GougingChecker

type Host added in v0.7.0

type Host interface {
	PublicKey() types.PublicKey

	DownloadSector(ctx context.Context, w io.Writer, root types.Hash256, offset, length uint32, overpay bool) error
	UploadSector(ctx context.Context, sectorRoot types.Hash256, sector *[rhpv2.SectorSize]byte, rev types.FileContractRevision) error

	FetchPriceTable(ctx context.Context, rev *types.FileContractRevision) (hpt hostdb.HostPriceTable, err error)
	FetchRevision(ctx context.Context, fetchTimeout time.Duration) (types.FileContractRevision, error)

	FundAccount(ctx context.Context, balance types.Currency, rev *types.FileContractRevision) error
	SyncAccount(ctx context.Context, rev *types.FileContractRevision) error

	RenewContract(ctx context.Context, rrr api.RHPRenewRequest) (_ rhpv2.ContractRevision, _ []types.Transaction, _ types.Currency, err error)
}

type HostErrorSet

type HostErrorSet map[types.PublicKey]error

A HostErrorSet is a collection of errors from various hosts.

func (HostErrorSet) Error

func (hes HostErrorSet) Error() string

Error implements error.

func (HostErrorSet) NumGouging added in v0.7.0

func (hes HostErrorSet) NumGouging() (n int)

NumGouging returns numbers of host that errored out due to price gouging.

type HostInteractionRecorder added in v1.0.4

type HostInteractionRecorder interface {
	RecordHostScan(...hostdb.HostScan)
	RecordPriceTableUpdate(...hostdb.PriceTableUpdate)
}

type HostManager added in v0.7.0

type HostManager interface {
	Host(hk types.PublicKey, fcid types.FileContractID, siamuxAddr string) Host
}

type HostStore added in v1.0.3

type HostStore interface {
	RecordHostScans(ctx context.Context, scans []hostdb.HostScan) error
	RecordPriceTables(ctx context.Context, priceTableUpdate []hostdb.PriceTableUpdate) error
	RecordContractSpending(ctx context.Context, records []api.ContractSpendingRecord) error

	Host(ctx context.Context, hostKey types.PublicKey) (hostdb.HostInfo, error)
}

type Memory added in v0.7.0

type Memory interface {
	Release()
	ReleaseSome(amt uint64)
}

type MemoryManager added in v0.7.0

type MemoryManager interface {
	Status() api.MemoryStatus
	AcquireMemory(ctx context.Context, amt uint64) Memory
	Limit(amt uint64) (MemoryManager, error)
}

MemoryManager helps regulate processes that use a lot of memory. Such as uploads and downloads.

type ObjectStore added in v0.7.0

type ObjectStore interface {
	// NOTE: used for download
	DeleteHostSector(ctx context.Context, hk types.PublicKey, root types.Hash256) error
	FetchPartialSlab(ctx context.Context, key object.EncryptionKey, offset, length uint32) ([]byte, error)
	Slab(ctx context.Context, key object.EncryptionKey) (object.Slab, error)

	// NOTE: used for upload
	AddObject(ctx context.Context, bucket, path, contractSet string, o object.Object, opts api.AddObjectOptions) error
	AddMultipartPart(ctx context.Context, bucket, path, contractSet, ETag, uploadID string, partNumber int, slices []object.SlabSlice) (err error)
	AddPartialSlab(ctx context.Context, data []byte, minShards, totalShards uint8, contractSet string) (slabs []object.SlabSlice, slabBufferMaxSizeSoftReached bool, err error)
	AddUploadingSector(ctx context.Context, uID api.UploadID, id types.FileContractID, root types.Hash256) error
	FinishUpload(ctx context.Context, uID api.UploadID) error
	MarkPackedSlabsUploaded(ctx context.Context, slabs []api.UploadedPackedSlab) error
	TrackUpload(ctx context.Context, uID api.UploadID) error
	UpdateSlab(ctx context.Context, s object.Slab, contractSet string) error

	// NOTE: used by worker
	Bucket(_ context.Context, bucket string) (api.Bucket, error)
	Object(ctx context.Context, bucket, path string, opts api.GetObjectOptions) (api.ObjectsResponse, error)
	DeleteObject(ctx context.Context, bucket, path string, opts api.DeleteObjectOptions) error
	MultipartUpload(ctx context.Context, uploadID string) (resp api.MultipartUpload, err error)
	PackedSlabsForUpload(ctx context.Context, lockingDuration time.Duration, minShards, totalShards uint8, set string, limit int) ([]api.PackedSlab, error)
}

type PriceTablePaymentFunc

type PriceTablePaymentFunc func(pt rhpv3.HostPriceTable) (rhpv3.PaymentMethod, error)

PriceTablePaymentFunc is a function that can be passed in to RPCPriceTable. It is called after the price table is received from the host and supposed to create a payment for that table and return it. It can also be used to perform gouging checks before paying for the table.

type SettingStore added in v1.0.6

type SettingStore interface {
	GougingParams(ctx context.Context) (api.GougingParams, error)
	UploadParams(ctx context.Context) (api.UploadParams, error)
}

type Syncer added in v1.0.6

type Syncer interface {
	BroadcastTransaction(ctx context.Context, txns []types.Transaction) error
	SyncerPeers(ctx context.Context) (resp []string, err error)
}

type UploadOption added in v0.6.0

type UploadOption func(*uploadParameters)

func WithBlockHeight added in v0.6.0

func WithBlockHeight(bh uint64) UploadOption

func WithContractSet added in v0.6.0

func WithContractSet(contractSet string) UploadOption

func WithCustomEncryptionOffset added in v0.6.0

func WithCustomEncryptionOffset(offset uint64) UploadOption

func WithCustomKey added in v0.6.0

func WithCustomKey(ec object.EncryptionKey) UploadOption

func WithMimeType added in v0.6.0

func WithMimeType(mimeType string) UploadOption

func WithObjectUserMetadata added in v1.0.3

func WithObjectUserMetadata(metadata api.ObjectUserMetadata) UploadOption

func WithPacking added in v0.6.0

func WithPacking(packing bool) UploadOption

func WithRedundancySettings added in v0.6.0

func WithRedundancySettings(rs api.RedundancySettings) UploadOption

type Wallet added in v1.0.6

type Wallet interface {
	WalletDiscard(ctx context.Context, txn types.Transaction) error
	WalletFund(ctx context.Context, txn *types.Transaction, amount types.Currency, useUnconfirmedTxns bool) ([]types.Hash256, []types.Transaction, error)
	WalletPrepareForm(ctx context.Context, renterAddress types.Address, renterKey types.PublicKey, renterFunds, hostCollateral types.Currency, hostKey types.PublicKey, hostSettings rhpv2.HostSettings, endHeight uint64) (txns []types.Transaction, err error)
	WalletPrepareRenew(ctx context.Context, revision types.FileContractRevision, hostAddress, renterAddress types.Address, renterKey types.PrivateKey, renterFunds, minNewCollateral types.Currency, pt rhpv3.HostPriceTable, endHeight, windowSize, expectedStorage uint64) (api.WalletPrepareRenewResponse, error)
	WalletSign(ctx context.Context, txn *types.Transaction, toSign []types.Hash256, cf types.CoveredFields) error
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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