rhp

package
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Dec 4, 2024 License: MIT Imports: 26 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrContractRevisionLimit is returned when a contract revision would
	// exceed the maximum revision number.
	ErrContractRevisionLimit = errors.New("max revision number reached")
	// ErrContractProofWindowStarted is returned when a contract revision is
	// attempted after the proof window has started.
	ErrContractProofWindowStarted = errors.New("proof window has started")
	// ErrContractExpired is returned when a contract revision is attempted
	// after the contract has expired.
	ErrContractExpired = errors.New("contract has expired")

	// ErrInvalidSectorLength is returned when a sector is not the correct
	// length.
	ErrInvalidSectorLength = errors.New("length of sector data must be exactly 4MiB")

	// ErrTrimOutOfBounds is returned when a trim operation exceeds the total
	// number of sectors
	ErrTrimOutOfBounds = errors.New("trim size exceeds number of sectors")
	// ErrSwapOutOfBounds is returned when one of the swap indices exceeds the
	// total number of sectors
	ErrSwapOutOfBounds = errors.New("swap index is out of bounds")
	// ErrUpdateOutOfBounds is returned when the update index exceeds the total
	// number of sectors
	ErrUpdateOutOfBounds = errors.New("update index is out of bounds")
	// ErrOffsetOutOfBounds is returned when the offset exceeds and length
	// exceed the sector size.
	ErrOffsetOutOfBounds = errors.New("update section is out of bounds")
	// ErrUpdateProofSize is returned when a proof is requested for an update
	// operation that is not a multiple of 64 bytes.
	ErrUpdateProofSize = errors.New("update section is not a multiple of the segment size")
)
View Source
var (
	// ErrTxnMissingContract is returned if the transaction set does not contain
	// any transactions or if the transaction does not contain exactly one
	// contract.
	ErrTxnMissingContract = errors.New("transaction set does not contain a file contract")
	// ErrHostInternalError is returned if the host encountered an error during
	// an RPC that doesn't need to be broadcast to the renter (e.g. insufficient
	// funds).
	ErrHostInternalError = errors.New("internal error")
	// ErrInvalidRenterSignature is returned when a contract's renter signature
	// is invalid.
	ErrInvalidRenterSignature = errors.New("invalid renter signature")
	// ErrNotAcceptingContracts is returned when the host is not accepting
	// contracts.
	ErrNotAcceptingContracts = errors.New("host is not accepting contracts")

	// ErrV2Hardfork is returned when a renter tries to form or renew a contract
	// after the v2 hardfork has been activated.
	ErrV2Hardfork = errors.New("hardfork v2 is active")

	// ErrAfterV2Hardfork is returned when a renter tries to form or renew a
	// contract that ends after the v2 hardfork has been activated.
	ErrAfterV2Hardfork = errors.New("proof window after hardfork v2 activation")
)
View Source
var (
	// ErrContractRequired is returned when a contract is required to execute a
	// program but is not provided
	ErrContractRequired = errors.New("contract required")
)
View Source
var (
	// ErrNoPriceTable is returned if a price table is requested but the UID
	// does not exist or has expired.
	ErrNoPriceTable = errors.New("no price table found")
)

Functions

This section is empty.

Types

type AccountManager

type AccountManager interface {
	Balance(accountID rhp3.Account) (types.Currency, error)
	Credit(req accounts.FundAccountWithContract, refund bool) (balance types.Currency, err error)
	Budget(accountID rhp3.Account, amount types.Currency) (*accounts.Budget, error)
}

An AccountManager manages deposits and withdrawals for accounts.

type ChainManager

type ChainManager interface {
	Tip() types.ChainIndex
	TipState() consensus.State
	UnconfirmedParents(txn types.Transaction) []types.Transaction
	AddPoolTransactions([]types.Transaction) (known bool, err error)
	AddV2PoolTransactions(types.ChainIndex, []types.V2Transaction) (known bool, err error)
	RecommendedFee() types.Currency
}

A ChainManager provides access to the current state of the blockchain.

type ContractManager

type ContractManager interface {
	// Contract returns the last revision of the contract with the given ID.
	Contract(id types.FileContractID) (contracts.Contract, error)

	// Lock locks the contract with the given ID. Will wait for the given
	// duration before giving up. Unlock must be called to unlock the
	// contract.
	Lock(ctx context.Context, id types.FileContractID) (contracts.SignedRevision, error)
	// Unlock unlocks the contract with the given ID.
	Unlock(id types.FileContractID)

	// AddContract adds a new contract to the manager.
	AddContract(revision contracts.SignedRevision, formationSet []types.Transaction, lockedCollateral types.Currency, initialUsage contracts.Usage) error
	// RenewContract renews an existing contract.
	RenewContract(renewal contracts.SignedRevision, existing contracts.SignedRevision, formationSet []types.Transaction, lockedCollateral types.Currency, clearingUsage, renewalUsage contracts.Usage) error
	// ReviseContract atomically revises a contract and its sector roots
	ReviseContract(contractID types.FileContractID) (*contracts.ContractUpdater, error)
}

A ContractManager manages the set of contracts that the host is currently storing data for

type RegistryManager

type RegistryManager interface {
	Get(key rhp3.RegistryKey) (rhp3.RegistryValue, error)
	Put(value rhp3.RegistryEntry, expirationHeight uint64) (rhp3.RegistryValue, error)
	Entries() (count uint64, max uint64, err error)
}

A RegistryManager manages registry entries stored in a RegistryStore.

type SessionHandler

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

A SessionHandler handles the host side of the renter-host protocol and manages renter sessions

func NewSessionHandler

func NewSessionHandler(l net.Listener, hostKey types.PrivateKey, chain ChainManager, syncer Syncer, wallet Wallet, accounts AccountManager, contracts ContractManager, registry RegistryManager, storage StorageManager, settings SettingsReporter, log *zap.Logger) *SessionHandler

NewSessionHandler creates a new SessionHandler

func (*SessionHandler) Close

func (sh *SessionHandler) Close() error

Close closes the session handler and stops accepting new connections.

func (*SessionHandler) HostKey

func (sh *SessionHandler) HostKey() types.UnlockKey

HostKey returns the host's ed25519 public key

func (*SessionHandler) LocalAddr

func (sh *SessionHandler) LocalAddr() string

LocalAddr returns the address the host is listening on.

func (*SessionHandler) Serve

func (sh *SessionHandler) Serve() error

Serve starts the host RPC server.

type SettingsReporter

type SettingsReporter interface {
	AcceptingContracts() bool
	RHP2Settings() (rhp2.HostSettings, error)
	RHP3PriceTable() (rhp3.HostPriceTable, error)
}

A SettingsReporter reports the host's current configuration.

type StorageManager

type StorageManager interface {
	// LockSector locks the sector with the given root. If the sector does not
	// exist, an error is returned. Release must be called when the sector is no
	// longer needed.
	LockSector(root types.Hash256) (func() error, error)
	// Write writes a sector to persistent storage. release should only be
	// called after the contract roots have been committed to prevent the
	// sector from being deleted.
	Write(root types.Hash256, data *[rhp2.SectorSize]byte) (release func() error, _ error)
	// Read reads the sector with the given root from the manager.
	Read(root types.Hash256) (*[rhp2.SectorSize]byte, error)
	// Sync syncs the data files of changed volumes.
	Sync() error

	// AddTemporarySectors adds the given sectors to the storage manager.
	// as temporary sectors. Temporary sectors are short-lived sectors not
	// associated with a contract.
	AddTemporarySectors([]storage.TempSector) error
}

A StorageManager manages the storage of sectors on disk.

type Syncer

type Syncer interface {
	BroadcastTransactionSet([]types.Transaction)
	BroadcastV2TransactionSet(types.ChainIndex, []types.V2Transaction)
}

A Syncer broadcasts transactions to the network

type Wallet

type Wallet interface {
	Address() types.Address
	FundTransaction(txn *types.Transaction, amount types.Currency, unconfirmed bool) ([]types.Hash256, error)
	SignTransaction(txn *types.Transaction, toSign []types.Hash256, cf types.CoveredFields)
	ReleaseInputs(txn []types.Transaction, v2txn []types.V2Transaction)
}

A Wallet manages funds and signs transactions

Jump to

Keyboard shortcuts

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