gitlab.com/SiaPrime/SiaPrime@v1.4.1/modules/host.go (about) 1 package modules 2 3 import ( 4 "gitlab.com/SiaPrime/SiaPrime/types" 5 ) 6 7 const ( 8 // HostDir names the directory that contains the host persistence. 9 HostDir = "host" 10 ) 11 12 var ( 13 // BlockBytesPerMonthTerabyte is the conversion rate between block-bytes and month-TB. 14 // 15 // TODO: Convert to `BytesPerTerabyte.Mul64(types.BlocksPerMonth)` - not a 16 // simple change because it means the number for testing changes from 4320 17 // to 2592e3, and this breaks some of the tests. 18 BlockBytesPerMonthTerabyte = BytesPerTerabyte.Mul64(4320) 19 20 // BytesPerTerabyte is the conversion rate between bytes and terabytes. 21 BytesPerTerabyte = types.NewCurrency64(1e12) 22 ) 23 24 var ( 25 // HostConnectabilityStatusChecking is returned from ConnectabilityStatus() 26 // if the host is still determining if it is connectable. 27 HostConnectabilityStatusChecking = HostConnectabilityStatus("checking") 28 29 // HostConnectabilityStatusConnectable is returned from 30 // ConnectabilityStatus() if the host is connectable at its configured 31 // netaddress. 32 HostConnectabilityStatusConnectable = HostConnectabilityStatus("connectable") 33 34 // HostConnectabilityStatusNotConnectable is returned from 35 // ConnectabilityStatus() if the host is not connectable at its configured 36 // netaddress. 37 HostConnectabilityStatusNotConnectable = HostConnectabilityStatus("not connectable") 38 39 // HostWorkingStatusChecking is returned from WorkingStatus() if the host is 40 // still determining if it is working, that is, if settings calls are 41 // incrementing. 42 HostWorkingStatusChecking = HostWorkingStatus("checking") 43 44 // HostWorkingStatusNotWorking is returned from WorkingStatus() if the host 45 // has not received any settings calls over the duration of 46 // workingStatusFrequency. 47 HostWorkingStatusNotWorking = HostWorkingStatus("not working") 48 49 // HostWorkingStatusWorking is returned from WorkingStatus() if the host has 50 // received more than workingThreshold settings calls over the duration of 51 // workingStatusFrequency. 52 HostWorkingStatusWorking = HostWorkingStatus("working") 53 ) 54 55 type ( 56 // HostFinancialMetrics provides financial statistics for the host, 57 // including money that is locked in contracts. Though verbose, these 58 // statistics should provide a clear picture of where the host's money is 59 // currently being used. The front end can consolidate stats where desired. 60 // Potential revenue refers to revenue that is available in a file 61 // contract for which the file contract window has not yet closed. 62 HostFinancialMetrics struct { 63 // Every time a renter forms a contract with a host, a contract fee is 64 // paid by the renter. These stats track the total contract fees. 65 ContractCount uint64 `json:"contractcount"` 66 ContractCompensation types.Currency `json:"contractcompensation"` 67 PotentialContractCompensation types.Currency `json:"potentialcontractcompensation"` 68 69 // Metrics related to storage proofs, collateral, and submitting 70 // transactions to the blockchain. 71 LockedStorageCollateral types.Currency `json:"lockedstoragecollateral"` 72 LostRevenue types.Currency `json:"lostrevenue"` 73 LostStorageCollateral types.Currency `json:"loststoragecollateral"` 74 PotentialStorageRevenue types.Currency `json:"potentialstoragerevenue"` 75 RiskedStorageCollateral types.Currency `json:"riskedstoragecollateral"` 76 StorageRevenue types.Currency `json:"storagerevenue"` 77 TransactionFeeExpenses types.Currency `json:"transactionfeeexpenses"` 78 79 // Bandwidth financial metrics. 80 DownloadBandwidthRevenue types.Currency `json:"downloadbandwidthrevenue"` 81 PotentialDownloadBandwidthRevenue types.Currency `json:"potentialdownloadbandwidthrevenue"` 82 PotentialUploadBandwidthRevenue types.Currency `json:"potentialuploadbandwidthrevenue"` 83 UploadBandwidthRevenue types.Currency `json:"uploadbandwidthrevenue"` 84 } 85 86 // HostInternalSettings contains a list of settings that can be changed. 87 HostInternalSettings struct { 88 AcceptingContracts bool `json:"acceptingcontracts"` 89 MaxDownloadBatchSize uint64 `json:"maxdownloadbatchsize"` 90 MaxDuration types.BlockHeight `json:"maxduration"` 91 MaxReviseBatchSize uint64 `json:"maxrevisebatchsize"` 92 NetAddress NetAddress `json:"netaddress"` 93 WindowSize types.BlockHeight `json:"windowsize"` 94 95 Collateral types.Currency `json:"collateral"` 96 CollateralBudget types.Currency `json:"collateralbudget"` 97 MaxCollateral types.Currency `json:"maxcollateral"` 98 99 MinBaseRPCPrice types.Currency `json:"minbaserpcprice"` 100 MinContractPrice types.Currency `json:"mincontractprice"` 101 MinDownloadBandwidthPrice types.Currency `json:"mindownloadbandwidthprice"` 102 MinSectorAccessPrice types.Currency `json:"minsectoraccessprice"` 103 MinStoragePrice types.Currency `json:"minstorageprice"` 104 MinUploadBandwidthPrice types.Currency `json:"minuploadbandwidthprice"` 105 } 106 107 // HostNetworkMetrics reports the quantity of each type of RPC call that 108 // has been made to the host. 109 HostNetworkMetrics struct { 110 DownloadCalls uint64 `json:"downloadcalls"` 111 ErrorCalls uint64 `json:"errorcalls"` 112 FormContractCalls uint64 `json:"formcontractcalls"` 113 RenewCalls uint64 `json:"renewcalls"` 114 ReviseCalls uint64 `json:"revisecalls"` 115 SettingsCalls uint64 `json:"settingscalls"` 116 UnrecognizedCalls uint64 `json:"unrecognizedcalls"` 117 } 118 119 // StorageObligation contains information about a storage obligation that 120 // the host has accepted. 121 StorageObligation struct { 122 ContractCost types.Currency `json:"contractcost"` 123 DataSize uint64 `json:"datasize"` 124 LockedCollateral types.Currency `json:"lockedcollateral"` 125 ObligationId types.FileContractID `json:"obligationid"` 126 PotentialDownloadRevenue types.Currency `json:"potentialdownloadrevenue"` 127 PotentialStorageRevenue types.Currency `json:"potentialstoragerevenue"` 128 PotentialUploadRevenue types.Currency `json:"potentialuploadrevenue"` 129 RiskedCollateral types.Currency `json:"riskedcollateral"` 130 SectorRootsCount uint64 `json:"sectorrootscount"` 131 TransactionFeesAdded types.Currency `json:"transactionfeesadded"` 132 TransactionID types.TransactionID `json:"transactionid"` 133 134 // The negotiation height specifies the block height at which the file 135 // contract was negotiated. The expiration height and the proof deadline 136 // are equal to the window start and window end. Between the expiration height 137 // and the proof deadline, the host must submit the storage proof. 138 ExpirationHeight types.BlockHeight `json:"expirationheight"` 139 NegotiationHeight types.BlockHeight `json:"negotiationheight"` 140 ProofDeadLine types.BlockHeight `json:"proofdeadline"` 141 142 // Variables indicating whether the critical transactions in a storage 143 // obligation have been confirmed on the blockchain. 144 ObligationStatus string `json:"obligationstatus"` 145 OriginConfirmed bool `json:"originconfirmed"` 146 ProofConfirmed bool `json:"proofconfirmed"` 147 ProofConstructed bool `json:"proofconstructed"` 148 RevisionConfirmed bool `json:"revisionconfirmed"` 149 RevisionConstructed bool `json:"revisionconstructed"` 150 } 151 152 // HostWorkingStatus reports the working state of a host. Can be one of 153 // "checking", "working", or "not working". 154 HostWorkingStatus string 155 156 // HostConnectabilityStatus reports the connectability state of a host. Can be 157 // one of "checking", "connectable", or "not connectable" 158 HostConnectabilityStatus string 159 160 // A Host can take storage from disk and offer it to the network, managing 161 // things such as announcements, settings, and implementing all of the RPCs 162 // of the host protocol. 163 Host interface { 164 // Announce submits a host announcement to the blockchain. 165 Announce() error 166 167 // AnnounceAddress submits an announcement using the given address. 168 AnnounceAddress(NetAddress) error 169 170 // ExternalSettings returns the settings of the host as seen by an 171 // untrusted node querying the host for settings. 172 ExternalSettings() HostExternalSettings 173 174 // FinancialMetrics returns the financial statistics of the host. 175 FinancialMetrics() HostFinancialMetrics 176 177 // InternalSettings returns the host's internal settings, including 178 // potentially private or sensitive information. 179 InternalSettings() HostInternalSettings 180 181 // NetworkMetrics returns information on the types of RPC calls that 182 // have been made to the host. 183 NetworkMetrics() HostNetworkMetrics 184 185 // PruneStaleStorageObligations will delete storage obligations from the host 186 // that, for whatever reason, did not make it on the block chain. 187 // As these stale storage obligations have an impact on the host financial metrics, 188 // this method updates the host financial metrics to show the correct values. 189 PruneStaleStorageObligations() error 190 191 // PublicKey returns the public key of the host. 192 PublicKey() types.SiaPublicKey 193 194 // SetInternalSettings sets the hosting parameters of the host. 195 SetInternalSettings(HostInternalSettings) error 196 197 // StorageObligations returns the set of storage obligations held by 198 // the host. 199 StorageObligations() []StorageObligation 200 201 // ConnectabilityStatus returns the connectability status of the host, that 202 // is, if it can connect to itself on the configured NetAddress. 203 ConnectabilityStatus() HostConnectabilityStatus 204 205 // WorkingStatus returns the working state of the host, determined by if 206 // settings calls are increasing. 207 WorkingStatus() HostWorkingStatus 208 209 // The storage manager provides an interface for adding and removing 210 // storage folders and data sectors to the host. 211 StorageManager 212 } 213 )