rhp

package
v0.1.0-alpha.1 Latest Latest
Warning

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

Go to latest
Published: May 22, 2023 License: MIT Imports: 19 Imported by: 1

Documentation

Index

Constants

View Source
const (

	// Version is the current version of the RHP2 protocol.
	Version = "1.6.0"
)

Variables

View Source
var (
	// ErrNoContractLocked is returned when a contract revision is attempted
	// without a contract being locked.
	ErrNoContractLocked = errors.New("no contract locked")
	// 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("host internal error")
	// ErrInvalidRenterSignature is returned when a contract's renter signature
	// is invalid.
	ErrInvalidRenterSignature = errors.New("invalid renter signature")
	// ErrContractAlreadyLocked is returned when a renter tries to lock
	// a contract before unlocking the previous one.
	ErrContractAlreadyLocked = errors.New("contract already locked")
	// ErrNotAcceptingContracts is returned when the host is not accepting
	// contracts.
	ErrNotAcceptingContracts = errors.New("host is not accepting contracts")
)

Functions

This section is empty.

Types

type ChainManager

type ChainManager interface {
	TipState() consensus.State
}

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

type ContractManager

type ContractManager interface {
	// 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)

	// SectorRoots returns the sector roots of the contract with the given ID.
	SectorRoots(id types.FileContractID, limit, offset uint64) ([]types.Hash256, error)
}

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

type EventContractFormed

type EventContractFormed struct {
	SessionUID UniqueID                   `json:"sessionUID"`
	ContractID types.FileContractID       `json:"contractID"`
	Contract   types.FileContractRevision `json:"contract"`
}

EventContractFormed records the formation of a new contract

type EventContractRenewed

type EventContractRenewed struct {
	SessionUID          UniqueID                   `json:"sessionUID"`
	ContractID          types.FileContractID       `json:"contractID"`
	FinalizedContractID types.FileContractID       `json:"finalizedContractID"`
	Contract            types.FileContractRevision `json:"contract"`
	FinalizedContract   types.FileContractRevision `json:"finalizedContract"`
}

EventContractRenewed records the renewal of a contract.

type EventRPCEnd

type EventRPCEnd struct {
	RPC        types.Specifier `json:"rpc"`
	SessionUID UniqueID        `json:"sessionUID"`
	Error      error           `json:"error"`

	Spending   types.Currency `json:"spending"`
	ReadBytes  uint64         `json:"readBytes"`
	WriteBytes uint64         `json:"writeBytes"`

	Elapsed   time.Duration `json:"elapsed"`
	Timestamp time.Time     `json:"timestamp"`
}

EventRPCEnd records the end of an RPC.

type EventRPCStart

type EventRPCStart struct {
	RPC        types.Specifier `json:"rpc"`
	SessionUID UniqueID        `json:"sessionUID"`
	Timestamp  time.Time       `json:"timestamp"`
}

EventRPCStart records the start of an RPC.

type EventSessionEnd

type EventSessionEnd struct {
	UID       UniqueID      `json:"uid"`
	Timestamp time.Time     `json:"timestamp"`
	Elapsed   time.Duration `json:"elapsed"`
}

EventSessionEnd records the end of a renter session.

type EventSessionStart

type EventSessionStart struct {
	UID       UniqueID  `json:"uid"`
	RenterIP  string    `json:"renterIP"`
	Timestamp time.Time `json:"timestamp"`
}

EventSessionStart records the start of a new renter session.

type FinancialReporter

type FinancialReporter interface {
	Add(financials.Record) error
}

A FinancialReporter records financial transactions on the host.

type MetricReporter

type MetricReporter interface {
	Report(any) error
}

MetricReporter records metrics from the host

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, rhp3Addr string, cm ChainManager, tpool TransactionPool, wallet Wallet, contracts ContractManager, settings SettingsReporter, storage StorageManager, monitor rhp.DataMonitor, metrics MetricReporter, log *zap.Logger) (*SessionHandler, error)

NewSessionHandler creates a new RHP2 SessionHandler

func (*SessionHandler) Close

func (sh *SessionHandler) Close() error

Close closes the listener and stops accepting new connections

func (*SessionHandler) LocalAddr

func (sh *SessionHandler) LocalAddr() string

LocalAddr returns the listener's listen address

func (*SessionHandler) Serve

func (sh *SessionHandler) Serve() error

Serve starts listening for new connections and blocks until closed

func (*SessionHandler) Settings

func (sh *SessionHandler) Settings() (rhpv2.HostSettings, error)

Settings returns the host's current settings

type SettingsReporter

type SettingsReporter interface {
	DiscoveredRHP2Address() string
	Settings() settings.Settings
	BandwidthLimiters() (ingress, egress *rate.Limiter)
}

A SettingsReporter reports the host's current configuration.

type StorageManager

type StorageManager interface {
	Usage() (used, total uint64, _ 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 *[rhpv2.SectorSize]byte) (release func() error, _ error)
	// Read reads the sector with the given root from the manager.
	Read(root types.Hash256) (*[rhpv2.SectorSize]byte, error)
	// Sync syncs the data files of changed volumes.
	Sync() error
}

A StorageManager manages the storage of sectors on disk.

type TransactionPool

type TransactionPool interface {
	AcceptTransactionSet([]types.Transaction) error
	RecommendedFee() types.Currency
}

A TransactionPool broadcasts transactions to the network.

type UniqueID

type UniqueID [8]byte

A UniqueID is a unique identifier for an RPC or Session.

func (UniqueID) MarshalJSON

func (u UniqueID) MarshalJSON() ([]byte, error)

MarshalJSON marshals the UniqueID to JSON.

func (UniqueID) String

func (u UniqueID) String() string

String returns a string representation of the UniqueID.

type Wallet

type Wallet interface {
	Address() types.Address
	FundTransaction(txn *types.Transaction, amount types.Currency) ([]types.Hash256, func(), error)
	SignTransaction(cs consensus.State, txn *types.Transaction, toSign []types.Hash256, cf types.CoveredFields) error
}

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