host

package
v0.19.5 Latest Latest
Warning

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

Go to latest
Published: Aug 24, 2022 License: MIT Imports: 21 Imported by: 0

Documentation

Overview

Package host implements a Sia hosting framework.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrMissingSiacoinOutput is returned when a transaction spends an output that
	// is not in the UTXO set, either because it was created in a transaction not in
	// the blockchain (or transaction pool) or because it has already been spent.
	ErrMissingSiacoinOutput = errors.New("transaction spends a nonexisting siacoin output")
)

Functions

func ContractIsActionable

func ContractIsActionable(c Contract, currentHeight types.BlockHeight) bool

ContractIsActionable returns true if any of a Contract's transactions are ready and have not been confirmed on chain.

func StorageProofSegment

func StorageProofSegment(bid types.BlockID, fcid types.FileContractID, filesize uint64) uint64

StorageProofSegment returns the segment index for which a storage proof must be provided, given a contract and the block at the beginning of its proof window.

Types

type ChainWatcher

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

A ChainWatcher watches the blockchain and submits necessary contract transactions, including formations, renewals, revisions, and storage proofs.

func NewChainWatcher

func NewChainWatcher(tp TransactionPool, w Wallet, cs ContractStore, ss SectorStore) *ChainWatcher

NewChainWatcher returns an initialized ChainWatcher.

func (*ChainWatcher) Announce

func (cw *ChainWatcher) Announce(addr modules.NetAddress, key ed25519.PrivateKey) error

Announce creates, signs, and submits a host announcement transaction.

func (*ChainWatcher) Close

func (cw *ChainWatcher) Close() error

Close shuts down the ChainWatcher.

func (*ChainWatcher) ProcessConsensusChange

func (cw *ChainWatcher) ProcessConsensusChange(cc modules.ConsensusChange)

ProcessConsensusChange implements modules.ConsensusSetSubscriber.

type Contract

type Contract struct {
	Revision   types.FileContractRevision
	Signatures [2]types.TransactionSignature

	FormationSet    []types.Transaction
	FinalizationSet []types.Transaction
	ProofSet        []types.Transaction

	FormationConfirmed    bool
	FinalizationConfirmed bool
	ProofConfirmed        bool

	FormationHeight    types.BlockHeight
	FinalizationHeight types.BlockHeight
	ProofHeight        types.BlockHeight
	ProofSegment       uint64

	// Non-nil, with explanatory error message, if it is no longer possible to
	// submit a valid storage proof for the Contract.
	FatalError error
}

A Contract is a file contract paired with various metadata.

func (*Contract) ID

func (c *Contract) ID() types.FileContractID

ID returns the contract's ID.

func (Contract) MarshalJSON

func (c Contract) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler.

func (*Contract) RenterKey

func (c *Contract) RenterKey() types.SiaPublicKey

RenterKey returns the renter's public key.

func (*Contract) UnmarshalJSON

func (c *Contract) UnmarshalJSON(b []byte) error

UnmarshalJSON implements json.Unmarshaler.

type ContractStore

type ContractStore interface {
	// SigningKey returns the private key used to sign contract revisions.
	SigningKey() ed25519.PrivateKey
	// Contract returns the contract with the specified ID.
	Contract(id types.FileContractID) (Contract, error)
	// AddContract stores the provided contract, overwriting any previous
	// contract with the same ID.
	AddContract(c Contract) error
	// ReviseContract updates the current revision associated with a contract.
	ReviseContract(rev types.FileContractRevision, renterSig, hostSig []byte) error
	// UpdateContractTransactions updates the contract's various transactions.
	//
	// This method does not return an error. If a contract cannot be saved to
	// the store, the method should panic or exit with an error.
	UpdateContractTransactions(id types.FileContractID, finalization, proof []types.Transaction, err error)
	// ActionableContracts returns all of the store's contracts for which
	// ContractIsActionable returns true (as of the current block height).
	//
	// This method does not return an error. If contracts cannot be loaded from
	// the store, the method should panic or exit with an error.
	ActionableContracts() []Contract
	// ApplyConsensusChange integrates a ProcessedConsensusChange into the
	// store.
	ApplyConsensusChange(reverted, applied ProcessedConsensusChange, ccid modules.ConsensusChangeID)
	// ConsensusChangeID returns the ID of the last ProcessedConsensusChange
	// that was integrated by the store.
	ConsensusChangeID() modules.ConsensusChangeID
	// Height returns the current block height.
	Height() types.BlockHeight
}

A ContractStore stores file contracts, along with some chain metadata.

type Metric

type Metric interface {
	// contains filtered or unexported methods
}

A Metric contains metadata relating to a session event, such as the completion of the initial handshake or the initiation of an RPC.

type MetricHandshake

type MetricHandshake struct {
	Err error
}

MetricHandshake is recorded upon completion of the renter-host protocol handshake.

type MetricRPCEnd

type MetricRPCEnd struct {
	ID        renterhost.Specifier
	Elapsed   time.Duration
	UpBytes   uint64
	DownBytes uint64
	Err       error
}

MetricRPCEnd is recorded upon completion of an RPC.

type MetricRPCStart

type MetricRPCStart struct {
	ID        renterhost.Specifier
	Timestamp time.Time
}

MetricRPCStart is recorded upon initiation of an RPC.

type MetricSessionEnd

type MetricSessionEnd struct {
	Err error
}

MetricSessionEnd is recorded upon termination of the session.

type MetricsRecorder

type MetricsRecorder interface {
	RecordSessionMetric(ctx *SessionContext, m Metric)
}

A MetricsRecorder records various metrics relating to a renter-host protocol session.

type ProcessedConsensusChange

type ProcessedConsensusChange struct {
	Contracts []types.FileContractID
	Revisions []types.FileContractID
	Proofs    []types.FileContractID
	BlockIDs  []types.BlockID
}

ProcessedConsensusChange is a filtered version of modules.ConsensusChange, containing only the information relevant to contract transactions.

type SectorStore

type SectorStore interface {
	AddSector(root crypto.Hash, sector *[renterhost.SectorSize]byte) error
	ContractRoots(id types.FileContractID) ([]crypto.Hash, error)
	DeleteSector(root crypto.Hash) error
	Sector(root crypto.Hash) (*[renterhost.SectorSize]byte, error)
	SetContractRoots(id types.FileContractID, roots []crypto.Hash) error
}

A SectorStore stores contract sector data.

type SessionContext

type SessionContext struct {
	UID         [16]byte
	RenterIP    string
	Timestamp   time.Time
	Elapsed     time.Duration
	BlockHeight types.BlockHeight
	UpBytes     uint64
	DownBytes   uint64

	Contract types.FileContractRevision
	Settings hostdb.HostSettings
}

SessionContext contains various metadata relating to a renter-host protocol session.

type SessionHandler

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

A SessionHandler serves renter-host protocol sessions.

func NewSessionHandler

NewSessionHandler returns an initialized session manager.

func (*SessionHandler) Serve

func (sh *SessionHandler) Serve(conn net.Conn) (err error)

Serve serves a renter-host protocol session on the provided connection.

type SettingsReporter

type SettingsReporter interface {
	Settings() hostdb.HostSettings
}

A SettingsReporter returns the host's current settings.

type TransactionPool

type TransactionPool interface {
	AcceptTransactionSet(txns []types.Transaction) error
	FeeEstimate() (min, max types.Currency, err error)
	UnconfirmedParents(txn types.Transaction) ([]types.Transaction, error)
}

A TransactionPool broadcasts transaction sets to miners for inclusion in an upcoming block.

type Wallet

type Wallet interface {
	Address() (types.UnlockHash, error)
	FundTransaction(txn *types.Transaction, cost types.Currency) ([]crypto.Hash, func(), error)
	SignTransaction(txn *types.Transaction, toSign []crypto.Hash) error
}

A Wallet provides addresses and funds and signs transactions.

Jump to

Keyboard shortcuts

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