host.go 9.24 KB
Newer Older
David Vorick's avatar
David Vorick committed
1
package modules
2 3

import (
4
	"gitlab.com/NebulousLabs/Sia/types"
5 6
)

David Vorick's avatar
David Vorick committed
7
const (
David Vorick's avatar
David Vorick committed
8 9
	// HostDir names the directory that contains the host persistence.
	HostDir = "host"
10 11
)

12
var (
13 14 15
	// BlockBytesPerMonthTerabyte is the conversion rate between block-bytes and month-TB.
	BlockBytesPerMonthTerabyte = BytesPerTerabyte.Mul64(4320)

16
	// BytesPerTerabyte is the conversion rate between bytes and terabytes.
17 18
	BytesPerTerabyte = types.NewCurrency64(1e12)

19 20 21 22 23 24 25 26 27 28 29 30 31
	// HostConnectabilityStatusChecking is returned from ConnectabilityStatus()
	// if the host is still determining if it is connectable.
	HostConnectabilityStatusChecking = HostConnectabilityStatus("checking")

	// HostConnectabilityStatusConnectable is returned from
	// ConnectabilityStatus() if the host is connectable at its configured
	// netaddress.
	HostConnectabilityStatusConnectable = HostConnectabilityStatus("connectable")

	// HostConnectabilityStatusNotConnectable is returned from
	// ConnectabilityStatus() if the host is not connectable at its configured
	// netaddress.
	HostConnectabilityStatusNotConnectable = HostConnectabilityStatus("not connectable")
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46

	// HostWorkingStatusChecking is returned from WorkingStatus() if the host is
	// still determining if it is working, that is, if settings calls are
	// incrementing.
	HostWorkingStatusChecking = HostWorkingStatus("checking")

	// HostWorkingStatusNotWorking is returned from WorkingStatus() if the host
	// has not received any settings calls over the duration of
	// workingStatusFrequency.
	HostWorkingStatusNotWorking = HostWorkingStatus("not working")

	// HostWorkingStatusWorking is returned from WorkingStatus() if the host has
	// received more than workingThreshold settings calls over the duration of
	// workingStatusFrequency.
	HostWorkingStatusWorking = HostWorkingStatus("working")
47 48
)

David Vorick's avatar
David Vorick committed
49
type (
50 51 52 53 54
	// HostFinancialMetrics provides financial statistics for the host,
	// including money that is locked in contracts. Though verbose, these
	// statistics should provide a clear picture of where the host's money is
	// currently being used. The front end can consolidate stats where desired.
	// Potential revenue refers to revenue that is available in a file
55
	// contract for which the file contract window has not yet closed.
56
	HostFinancialMetrics struct {
57 58
		// Every time a renter forms a contract with a host, a contract fee is
		// paid by the renter. These stats track the total contract fees.
59
		ContractCount                 uint64         `json:"contractcount"`
60 61 62
		ContractCompensation          types.Currency `json:"contractcompensation"`
		PotentialContractCompensation types.Currency `json:"potentialcontractcompensation"`

63
		// Metrics related to storage proofs, collateral, and submitting
64 65
		// transactions to the blockchain.
		LockedStorageCollateral types.Currency `json:"lockedstoragecollateral"`
66
		LostRevenue             types.Currency `json:"lostrevenue"`
67
		LostStorageCollateral   types.Currency `json:"loststoragecollateral"`
Jane Maunsell's avatar
Jane Maunsell committed
68
		PotentialStorageRevenue types.Currency `json:"potentialstoragerevenue"`
69
		RiskedStorageCollateral types.Currency `json:"riskedstoragecollateral"`
70 71 72 73 74 75 76 77
		StorageRevenue          types.Currency `json:"storagerevenue"`
		TransactionFeeExpenses  types.Currency `json:"transactionfeeexpenses"`

		// Bandwidth financial metrics.
		DownloadBandwidthRevenue          types.Currency `json:"downloadbandwidthrevenue"`
		PotentialDownloadBandwidthRevenue types.Currency `json:"potentialdownloadbandwidthrevenue"`
		PotentialUploadBandwidthRevenue   types.Currency `json:"potentialuploadbandwidthrevenue"`
		UploadBandwidthRevenue            types.Currency `json:"uploadbandwidthrevenue"`
David Vorick's avatar
David Vorick committed
78 79
	}

80 81
	// HostInternalSettings contains a list of settings that can be changed.
	HostInternalSettings struct {
David Vorick's avatar
David Vorick committed
82 83
		AcceptingContracts   bool              `json:"acceptingcontracts"`
		MaxDownloadBatchSize uint64            `json:"maxdownloadbatchsize"`
84
		MaxDuration          types.BlockHeight `json:"maxduration"`
David Vorick's avatar
David Vorick committed
85 86 87
		MaxReviseBatchSize   uint64            `json:"maxrevisebatchsize"`
		NetAddress           NetAddress        `json:"netaddress"`
		WindowSize           types.BlockHeight `json:"windowsize"`
88

89 90 91
		Collateral       types.Currency `json:"collateral"`
		CollateralBudget types.Currency `json:"collateralbudget"`
		MaxCollateral    types.Currency `json:"maxcollateral"`
92

93 94 95 96
		MinContractPrice          types.Currency `json:"mincontractprice"`
		MinDownloadBandwidthPrice types.Currency `json:"mindownloadbandwidthprice"`
		MinStoragePrice           types.Currency `json:"minstorageprice"`
		MinUploadBandwidthPrice   types.Currency `json:"minuploadbandwidthprice"`
97 98
	}

99 100 101
	// HostNetworkMetrics reports the quantity of each type of RPC call that
	// has been made to the host.
	HostNetworkMetrics struct {
102
		DownloadCalls     uint64 `json:"downloadcalls"`
103 104
		ErrorCalls        uint64 `json:"errorcalls"`
		FormContractCalls uint64 `json:"formcontractcalls"`
105 106 107
		RenewCalls        uint64 `json:"renewcalls"`
		ReviseCalls       uint64 `json:"revisecalls"`
		SettingsCalls     uint64 `json:"settingscalls"`
108
		UnrecognizedCalls uint64 `json:"unrecognizedcalls"`
109 110
	}

111 112 113
	// StorageObligation contains information about a storage obligation that
	// the host has accepted.
	StorageObligation struct {
114
		ContractCost             types.Currency       `json:"contractcost"`
115
		DataSize                 uint64               `json:"datasize"`
116
		LockedCollateral         types.Currency       `json:"lockedcollateral"`
117
		ObligationId             types.FileContractID `json:"obligationid"`
118 119 120 121
		PotentialDownloadRevenue types.Currency       `json:"potentialdownloadrevenue"`
		PotentialStorageRevenue  types.Currency       `json:"potentialstoragerevenue"`
		PotentialUploadRevenue   types.Currency       `json:"potentialuploadrevenue"`
		RiskedCollateral         types.Currency       `json:"riskedcollateral"`
Niels Castien's avatar
Niels Castien committed
122
		SectorRootsCount         uint64               `json:"sectorrootscount"`
123
		TransactionFeesAdded     types.Currency       `json:"transactionfeesadded"`
124
		TransactionID            types.TransactionID  `json:"transactionid"`
125 126 127 128 129 130

		// The negotiation height specifies the block height at which the file
		// contract was negotiated. The expiration height and the proof deadline
		// are equal to the window start and window end. Between the expiration height
		// and the proof deadline, the host must submit the storage proof.
		ExpirationHeight  types.BlockHeight `json:"expirationheight"`
131
		NegotiationHeight types.BlockHeight `json:"negotiationheight"`
132
		ProofDeadLine     types.BlockHeight `json:"proofdeadline"`
133

134 135
		// Variables indicating whether the critical transactions in a storage
		// obligation have been confirmed on the blockchain.
136
		ObligationStatus    string `json:"obligationstatus"`
137 138
		OriginConfirmed     bool   `json:"originconfirmed"`
		ProofConfirmed      bool   `json:"proofconfirmed"`
139
		ProofConstructed    bool   `json:"proofconstructed"`
Niels Castien's avatar
Niels Castien committed
140 141
		RevisionConfirmed   bool   `json:"revisionconfirmed"`
		RevisionConstructed bool   `json:"revisionconstructed"`
142 143
	}

144
	// HostWorkingStatus reports the working state of a host. Can be one of
Niels Castien's avatar
Niels Castien committed
145
	// "checking", "working", or "not working".
146
	HostWorkingStatus string
147

148
	// HostConnectabilityStatus reports the connectability state of a host. Can be
149
	// one of "checking", "connectable", or "not connectable"
150
	HostConnectabilityStatus string
151

152 153 154
	// A Host can take storage from disk and offer it to the network, managing
	// things such as announcements, settings, and implementing all of the RPCs
	// of the host protocol.
David Vorick's avatar
David Vorick committed
155
	Host interface {
156
		// Announce submits a host announcement to the blockchain.
157 158 159 160
		Announce() error

		// AnnounceAddress submits an announcement using the given address.
		AnnounceAddress(NetAddress) error
161

162 163
		// ExternalSettings returns the settings of the host as seen by an
		// untrusted node querying the host for settings.
164
		ExternalSettings() HostExternalSettings
165

166
		// FinancialMetrics returns the financial statistics of the host.
167
		FinancialMetrics() HostFinancialMetrics
David Vorick's avatar
David Vorick committed
168

169 170
		// InternalSettings returns the host's internal settings, including
		// potentially private or sensitive information.
David Vorick's avatar
David Vorick committed
171 172
		InternalSettings() HostInternalSettings

173 174 175
		// NetworkMetrics returns information on the types of RPC calls that
		// have been made to the host.
		NetworkMetrics() HostNetworkMetrics
176

177
		// PruneStaleStorageObligations will delete storage obligations from the host
178 179 180 181 182
		// that, for whatever reason, did not make it on the block chain.
		// As these stale storage obligations have an impact on the host financial metrics,
		// this method updates the host financial metrics to show the correct values.
		PruneStaleStorageObligations() error

183 184 185
		// PublicKey returns the public key of the host.
		PublicKey() types.SiaPublicKey

186
		// SetInternalSettings sets the hosting parameters of the host.
187
		SetInternalSettings(HostInternalSettings) error
David Vorick's avatar
David Vorick committed
188

189 190 191 192
		// StorageObligations returns the set of storage obligations held by
		// the host.
		StorageObligations() []StorageObligation

193
		// ConnectabilityStatus returns the connectability status of the host, that
194
		// is, if it can connect to itself on the configured NetAddress.
195
		ConnectabilityStatus() HostConnectabilityStatus
196

197
		// WorkingStatus returns the working state of the host, determined by if
198
		// settings calls are increasing.
199
		WorkingStatus() HostWorkingStatus
200

201 202
		// The storage manager provides an interface for adding and removing
		// storage folders and data sectors to the host.
203
		StorageManager
David Vorick's avatar
David Vorick committed
204 205
	}
)