worker

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Sep 4, 2023 License: MIT Imports: 43 Imported by: 5

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

Functions

func New

func New(masterKey [32]byte, id string, b Bus, contractLockingDuration, busFlushInterval, downloadOverdriveTimeout, uploadOverdriveTimeout time.Duration, downloadMaxOverdrive, uploadMaxOverdrive 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, sector *[rhpv2.SectorSize]byte) (sectorRoot types.Hash256, 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) (pt rhpv3.HostPriceTable, err error)

RPCPriceTable calls the UpdatePriceTable RPC.

func RPCReadRegistry

func RPCReadRegistry(ctx context.Context, t *transportV3, payment rhpv3.PaymentMethod, key rhpv3.RegistryKey) (rv rhpv3.RegistryValue, err error)

RPCReadRegistry calls the ExecuteProgram RPC with an MDM program that reads the specified registry value.

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 RPCRenew

func RPCRenew(ctx context.Context, rrr api.RHPRenewRequest, bus Bus, t *transportV3, pt *rhpv3.HostPriceTable, rev types.FileContractRevision, renterKey types.PrivateKey, l *zap.SugaredLogger) (_ rhpv2.ContractRevision, _ []types.Transaction, err error)

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 RPCUpdateRegistry

func RPCUpdateRegistry(ctx context.Context, t *transportV3, payment rhpv3.PaymentMethod, key rhpv3.RegistryKey, value rhpv3.RegistryValue) (err error)

RPCUpdateRegistry calls the ExecuteProgram RPC with an MDM program that updates the specified registry value.

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
}

type Bus

type Bus interface {
	alerts.Alerter

	webhooks.Broadcaster

	AccountStore
	ContractLocker

	SyncerPeers(ctx context.Context) (resp []string, err error)

	BroadcastTransaction(ctx context.Context, txns []types.Transaction) error

	Contract(ctx context.Context, id types.FileContractID) (api.ContractMetadata, error)
	ContractRoots(ctx context.Context, id types.FileContractID) ([]types.Hash256, []types.Hash256, error)
	Contracts(ctx context.Context) ([]api.ContractMetadata, error)
	ContractSetContracts(ctx context.Context, set string) ([]api.ContractMetadata, error)
	RecordHostScans(ctx context.Context, scans []hostdb.HostScan) error
	RecordPriceTables(ctx context.Context, priceTableUpdate []hostdb.PriceTableUpdate) error
	RecordContractSpending(ctx context.Context, records []api.ContractSpendingRecord) error
	RenewedContract(ctx context.Context, renewedFrom types.FileContractID) (api.ContractMetadata, error)

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

	GougingParams(ctx context.Context) (api.GougingParams, error)
	UploadParams(ctx context.Context) (api.UploadParams, error)

	Object(ctx context.Context, path string, opts ...api.ObjectsOption) (api.Object, []api.ObjectMetadata, error)
	AddObject(ctx context.Context, path, contractSet string, o object.Object, usedContracts map[types.PublicKey]types.FileContractID) error
	DeleteObject(ctx context.Context, path string, batch bool) error

	AddPartialSlab(ctx context.Context, data []byte, minShards, totalShards uint8, contractSet string) (slabs []object.PartialSlab, err error)
	FetchPartialSlab(ctx context.Context, key object.EncryptionKey, offset, length uint32) ([]byte, error)
	Slab(ctx context.Context, key object.EncryptionKey) (object.Slab, error)

	MarkPackedSlabsUploaded(ctx context.Context, slabs []api.UploadedPackedSlab, usedContracts map[types.PublicKey]types.FileContractID) error
	PackedSlabsForUpload(ctx context.Context, lockingDuration time.Duration, minShards, totalShards uint8, set string, limit int) ([]api.PackedSlab, error)

	Accounts(ctx context.Context) ([]api.Account, error)
	UpdateSlab(ctx context.Context, s object.Slab, contractSet string, goodContracts map[types.PublicKey]types.FileContractID) error

	TrackUpload(ctx context.Context, uID api.UploadID) error
	AddUploadingSector(ctx context.Context, uID api.UploadID, id types.FileContractID, root types.Hash256) error
	FinishUpload(ctx context.Context, uID api.UploadID) error

	WalletDiscard(ctx context.Context, txn types.Transaction) error
	WalletFund(ctx context.Context, txn *types.Transaction, amount types.Currency) ([]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, newCollateral types.Currency, hostKey types.PublicKey, pt rhpv3.HostPriceTable, endHeight, windowSize uint64) (api.WalletPrepareRenewResponse, error)
	WalletSign(ctx context.Context, txn *types.Transaction, toSign []types.Hash256, cf types.CoveredFields) error
	// contains filtered or unexported methods
}

A Bus is the source of truth within a renterd system.

type Client

type Client struct {
	// contains filtered or unexported fields
}

A Client provides methods for interacting with a renterd API server.

func NewClient

func NewClient(addr, password string) *Client

NewClient returns a client that communicates with a renterd worker server listening on the specified address.

func (*Client) Account

func (c *Client) Account(ctx context.Context, hostKey types.PublicKey) (account rhpv3.Account, err error)

Account returns the account id for a given host.

func (*Client) Contracts

func (c *Client) Contracts(ctx context.Context, hostTimeout time.Duration) (resp api.ContractsResponse, err error)

Contracts returns all contracts from the worker. These contracts decorate a bus contract with the contract's latest revision.

func (*Client) DeleteObject

func (c *Client) DeleteObject(ctx context.Context, path string, batch bool) (err error)

DeleteObject deletes the object at the given path.

func (*Client) DownloadObject

func (c *Client) DownloadObject(ctx context.Context, w io.Writer, path string, opts ...api.DownloadObjectOption) (err error)

DownloadObject downloads the object at the given path, writing its data to w.

func (*Client) DownloadStats

func (c *Client) DownloadStats() (resp api.DownloadStatsResponse, err error)

DownloadStats returns the upload stats.

func (*Client) ID

func (c *Client) ID(ctx context.Context) (id string, err error)

func (*Client) MigrateSlab

func (c *Client) MigrateSlab(ctx context.Context, slab object.Slab, set string) error

MigrateSlab migrates the specified slab.

func (*Client) ObjectEntries

func (c *Client) ObjectEntries(ctx context.Context, path, prefix string, offset, limit int) (entries []api.ObjectMetadata, err error)

ObjectEntries returns the entries at the given path, which must end in /.

func (*Client) RHPBroadcast

func (c *Client) RHPBroadcast(ctx context.Context, fcid types.FileContractID) (err error)

RHPBroadcast broadcasts the latest revision for a contract.

func (*Client) RHPContractRoots

func (c *Client) RHPContractRoots(ctx context.Context, fcid types.FileContractID) (roots []types.Hash256, err error)

RHPContractRoots fetches the roots of the contract with given id.

func (*Client) RHPForm

func (c *Client) RHPForm(ctx context.Context, endHeight uint64, hk types.PublicKey, hostIP string, renterAddress types.Address, renterFunds types.Currency, hostCollateral types.Currency) (rhpv2.ContractRevision, []types.Transaction, error)

RHPForm forms a contract with a host.

func (*Client) RHPFund

func (c *Client) RHPFund(ctx context.Context, contractID types.FileContractID, hostKey types.PublicKey, hostIP, siamuxAddr string, balance types.Currency) (err error)

RHPFund funds an ephemeral account using the supplied contract.

func (*Client) RHPPriceTable

func (c *Client) RHPPriceTable(ctx context.Context, hostKey types.PublicKey, siamuxAddr string, timeout time.Duration) (pt hostdb.HostPriceTable, err error)

RHPPriceTable fetches a price table for a host.

func (*Client) RHPReadRegistry

func (c *Client) RHPReadRegistry(ctx context.Context, hostKey types.PublicKey, siamuxAddr string, key rhpv3.RegistryKey, payment rhpv3.PayByEphemeralAccountRequest) (resp rhpv3.RegistryValue, err error)

RHPReadRegistry reads a registry value.

func (*Client) RHPRenew

func (c *Client) RHPRenew(ctx context.Context, fcid types.FileContractID, endHeight uint64, hk types.PublicKey, siamuxAddr string, hostAddress, renterAddress types.Address, renterFunds, newCollateral types.Currency, windowSize uint64) (rhpv2.ContractRevision, []types.Transaction, error)

RHPRenew renews an existing contract with a host.

func (*Client) RHPScan

func (c *Client) RHPScan(ctx context.Context, hostKey types.PublicKey, hostIP string, timeout time.Duration) (resp api.RHPScanResponse, err error)

RHPScan scans a host, returning its current settings.

func (*Client) RHPSync

func (c *Client) RHPSync(ctx context.Context, contractID types.FileContractID, hostKey types.PublicKey, hostIP, siamuxAddr string) (err error)

RHPSync funds an ephemeral account using the supplied contract.

func (*Client) RHPUpdateRegistry

func (c *Client) RHPUpdateRegistry(ctx context.Context, hostKey types.PublicKey, key rhpv3.RegistryKey, value rhpv3.RegistryValue) (err error)

RHPUpdateRegistry updates a registry value.

func (*Client) State

func (c *Client) State() (state api.WorkerStateResponse, err error)

State returns the current state of the worker.

func (*Client) UploadObject

func (c *Client) UploadObject(ctx context.Context, r io.Reader, path string, opts ...api.UploadOption) (err error)

UploadObject uploads the data in r, creating an object at the given path.

func (*Client) UploadStats

func (c *Client) UploadStats() (resp api.UploadStatsResponse, err error)

UploadStats returns the upload stats.

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(fcid types.FileContractID, revisionNumber, size uint64, cs api.ContractSpending)
}

A ContractSpendingRecorder records the spending of a contract.

type GougingChecker

type GougingChecker interface {
	Check(*rhpv2.HostSettings, *rhpv3.HostPriceTable) api.HostGougingBreakdown
}

func GougingCheckerFromContext

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

func NewGougingChecker

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

type HostError

type HostError struct {
	HostKey types.PublicKey
	Err     error
}

A HostError associates an error with a given host.

func (HostError) Error

func (he HostError) Error() string

Error implements error.

func (HostError) Unwrap

func (he HostError) Unwrap() error

Unwrap returns the underlying error.

type HostErrorSet

type HostErrorSet []*HostError

A HostErrorSet is a collection of errors from various hosts.

func (HostErrorSet) Error

func (hes HostErrorSet) Error() string

Error implements error.

type MetricHostScan

type MetricHostScan struct {
	// contains filtered or unexported fields
}

MetricHostScan is a metric that contains the result of a host scan.

func (MetricHostScan) HostKey

func (m MetricHostScan) HostKey() types.PublicKey

func (MetricHostScan) IsSuccess

func (m MetricHostScan) IsSuccess() bool

func (MetricHostScan) Result

func (m MetricHostScan) Result() interface{}

func (MetricHostScan) Timestamp

func (m MetricHostScan) Timestamp() time.Time

func (MetricHostScan) Type

func (m MetricHostScan) Type() string

type MetricPriceTableUpdate

type MetricPriceTableUpdate struct {
	// contains filtered or unexported fields
}

MetricPriceTableUpdate is a metric that contains the result of fetching a price table.

func (MetricPriceTableUpdate) HostKey

func (m MetricPriceTableUpdate) HostKey() types.PublicKey

func (MetricPriceTableUpdate) IsSuccess

func (m MetricPriceTableUpdate) IsSuccess() bool

func (MetricPriceTableUpdate) Result

func (m MetricPriceTableUpdate) Result() interface{}

func (MetricPriceTableUpdate) Timestamp

func (m MetricPriceTableUpdate) Timestamp() time.Time

func (MetricPriceTableUpdate) Type

func (m MetricPriceTableUpdate) Type() string

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.

Jump to

Keyboard shortcuts

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