gitlab.com/SiaPrime/SiaPrime@v1.4.1/modules/host/consts.go (about)

     1  package host
     2  
     3  import (
     4  	"gitlab.com/SiaPrime/SiaPrime/build"
     5  	"gitlab.com/SiaPrime/SiaPrime/modules"
     6  	"gitlab.com/SiaPrime/SiaPrime/types"
     7  
     8  	"time"
     9  )
    10  
    11  const (
    12  	// defaultMaxDuration defines the maximum number of blocks into the future
    13  	// that the host will accept for the duration of an incoming file contract
    14  	// obligation. 3 months are chosen as the network is in buildout.
    15  	defaultMaxDuration = 144 * 30 * 3 // 3 months.
    16  
    17  	// fileContractNegotiationTimeout indicates the amount of time that a
    18  	// renter has to negotiate a file contract with the host. A timeout is
    19  	// necessary to limit the impact of DoS attacks.
    20  	fileContractNegotiationTimeout = 120 * time.Second
    21  
    22  	// iteratedConnectionTime is the amount of time that is allowed to pass
    23  	// before the host will stop accepting new iterations on an iterated
    24  	// connection.
    25  	iteratedConnectionTime = 1200 * time.Second
    26  
    27  	// resubmissionTimeout defines the number of blocks that a host will wait
    28  	// before attempting to resubmit a transaction to the blockchain.
    29  	// Typically, this transaction will contain either a file contract, a file
    30  	// contract revision, or a storage proof.
    31  	resubmissionTimeout = 3
    32  
    33  	// rpcRequestInterval is the amount of time that the renter has to send
    34  	// the next RPC ID in the new RPC loop. (More time is alloted for sending
    35  	// the actual RPC request object.)
    36  	rpcRequestInterval = 2 * time.Minute
    37  
    38  	// keyExchangeMaxLen is the maximum number of bytes the host will read
    39  	// from the renter during the RPC key exchange.
    40  	keyExchangeMaxLen = 256
    41  
    42  	// maxObligationLockTimeout is the maximum amount of time the host will wait
    43  	// to lock a storage obligation.
    44  	maxObligationLockTimeout = 10 * time.Minute
    45  )
    46  
    47  var (
    48  	// connectablityCheckFirstWait defines how often the host's connectability
    49  	// check is run.
    50  	connectabilityCheckFirstWait = build.Select(build.Var{
    51  		Standard: time.Minute * 2,
    52  		Dev:      time.Minute * 1,
    53  		Testing:  time.Second * 3,
    54  	}).(time.Duration)
    55  
    56  	// connectablityCheckFrequency defines how often the host's connectability
    57  	// check is run.
    58  	connectabilityCheckFrequency = build.Select(build.Var{
    59  		Standard: time.Minute * 10,
    60  		Dev:      time.Minute * 5,
    61  		Testing:  time.Second * 10,
    62  	}).(time.Duration)
    63  
    64  	// connectabilityCheckTimeout defines how long a connectability check's dial
    65  	// will be allowed to block before it times out.
    66  	connectabilityCheckTimeout = build.Select(build.Var{
    67  		Standard: time.Minute * 2,
    68  		Dev:      time.Minute * 5,
    69  		Testing:  time.Second * 90,
    70  	}).(time.Duration)
    71  
    72  	// defaultBaseRPCPrice is the default price of talking to the host. It is
    73  	// roughly equal to the default bandwidth cost of exchanging a pair of
    74  	// 4096-byte messages.
    75  	defaultBaseRPCPrice = types.SiacoinPrecision.Mul64(100).Div64(1e9) // 100 nS
    76  
    77  	// defaultCollateral defines the amount of money that the host puts up as
    78  	// collateral per-byte by default. The collateral should be considered as
    79  	// an absolute instead of as a percentage, because low prices result in
    80  	// collaterals which may be significant by percentage, but insignificant
    81  	// overall. A default of 25 KS / TB / Month has been chosen, which is 2.5x
    82  	// the default price for storage. The host is expected to put up a
    83  	// significant amount of collateral as a commitment to faithfulness,
    84  	// because this guarantees that the incentives are aligned for the host to
    85  	// keep the data even if the price of SCP fluctuates, the price of raw
    86  	// storage fluctuates, or the host realizes that there is unexpected
    87  	// opportunity cost in being a host.
    88  	defaultCollateral = types.SiacoinPrecision.Mul64(20e3).Div(modules.BlockBytesPerMonthTerabyte) // 20000 SCP / TB / Month
    89  
    90  	// defaultCollateralBudget defines the maximum number of SCP that the
    91  	// host is going to allocate towards collateral. The number has been chosen
    92  	// as a number that is large, but not so large that someone would be
    93  	// furious for losing access to it for a few weeks.
    94  	defaultCollateralBudget = types.SiacoinPrecision.Mul64(4e6) //4 MS
    95  
    96  	// defaultContractPrice defines the default price of creating a contract
    97  	// with the host. The current default is 0.1. This was chosen since it is
    98  	// the minimum fee estimation of the transactionpool for a filecontract
    99  	// transaction..
   100  	// the minimum fee estimation of the transactionpool for 10e3 bytes.
   101  	defaultContractPrice = types.SiacoinPrecision.Div64(10) // 0.1 SCP
   102  	// TODO: Check this Sia contract price estimation later:
   103  	//	defaultContractPrice = types.SiacoinPrecision.Div64(100).Div64(1e3).Mul64(modules.EstimatedFileContractRevisionAndProofTransactionSetSize)
   104  
   105  	// defaultDownloadBandwidthPrice defines the default price of upload
   106  	// bandwidth. The default is set to 500 SCP per gigabyte, because
   107  	// download bandwidth is expected to be plentiful but also in-demand.
   108  	defaultDownloadBandwidthPrice = types.SiacoinPrecision.Mul64(2500).Div(modules.BytesPerTerabyte) // 2500 SCP / TB
   109  
   110  	// defaultMaxCollateral defines the maximum amount of collateral that the
   111  	// host is comfortable putting into a single file contract. 10e3 is a
   112  	// relatively small file contract, but millions of SCP could be locked
   113  	// away by only a few hundred file contracts. As the ecosystem matures, it
   114  	// is expected that the safe default for this value will increase quite a
   115  	// bit.
   116  	defaultMaxCollateral = types.SiacoinPrecision.Mul64(2e5) // 200 KS
   117  
   118  	// defaultMaxDownloadBatchSize defines the maximum number of bytes that the
   119  	// host will allow to be requested by a single download request. 17 MiB has
   120  	// been chosen because it's 4 full sectors plus some wiggle room. 17 MiB is
   121  	// a conservative default, most hosts will be fine with a number like 65
   122  	// MiB.
   123  	defaultMaxDownloadBatchSize = 17 * (1 << 20)
   124  
   125  	// defaultMaxReviseBatchSize defines the maximum number of bytes that the
   126  	// host will allow to be sent during a single batch update in a revision
   127  	// RPC. 17 MiB has been chosen because it's four full sectors, plus some
   128  	// wiggle room for the extra data or a few delete operations. The whole
   129  	// batch will be held in memory, so the batch size should only be increased
   130  	// substantially if the host has a lot of memory. Additionally, the whole
   131  	// batch is sent in one network connection. Additionally, the renter can
   132  	// steal funds for upload bandwidth all the way out to the size of a batch.
   133  	// 17 MiB is a conservative default, most hosts are likely to be just fine
   134  	// with a number like 65 MiB.
   135  	defaultMaxReviseBatchSize = 17 * (1 << 20)
   136  
   137  	// defaultSectorAccessPrice defines the default price of a sector access. It
   138  	// is roughly equal to the cost of downloading 64 KiB.
   139  	defaultSectorAccessPrice = types.SiacoinPrecision.Mul64(2).Div64(1e6) // 2 uS
   140  
   141  	// defaultStoragePrice defines the starting price for hosts selling
   142  	// storage. We try to match a number that is both reasonably profitable and
   143  	// reasonably competitive.
   144  	defaultStoragePrice = types.SiacoinPrecision.Mul64(10e3).Div(modules.BlockBytesPerMonthTerabyte) // 10 KS / TB / Month
   145  
   146  	// defaultUploadBandwidthPrice defines the default price of upload
   147  	// bandwidth. The default is set to 250 SCP per GB, because the host is
   148  	// presumed to have a large amount of downstream bandwidth. Furthermore,
   149  	// the host is typically only downloading data if it is planning to store
   150  	// the data, meaning that the host serves to profit from accepting the
   151  	// data.
   152  	defaultUploadBandwidthPrice = types.SiacoinPrecision.Mul64(250).Div(modules.BytesPerTerabyte) // 250 SCP / TB
   153  
   154  	// defaultWindowSize is the size of the proof of storage window requested
   155  	// by the host. The host will not delete any obligations until the window
   156  	// has closed and buried under several confirmations. For release builds,
   157  	// the default is set to 144 blocks, or about 1 day. This gives the host
   158  	// flexibility to experience downtime without losing file contracts. The
   159  	// optimal default, especially as the network matures, is probably closer
   160  	// to 36 blocks. An experienced or high powered host should not be
   161  	// frustrated by lost coins due to long periods of downtime.
   162  	defaultWindowSize = build.Select(build.Var{
   163  		Dev:      types.BlockHeight(36),  // 3.6 minutes.
   164  		Standard: types.BlockHeight(144), // 1 day.
   165  		Testing:  types.BlockHeight(5),   // 5 seconds.
   166  	}).(types.BlockHeight)
   167  
   168  	// logAllLimit is the number of errors of each type that the host will log
   169  	// before switching to probabilistic logging. If there are not many errors,
   170  	// it is reasonable that all errors get logged. If there are lots of
   171  	// errors, to cut down on the noise only some of the errors get logged.
   172  	logAllLimit = build.Select(build.Var{
   173  		Dev:      uint64(50),
   174  		Standard: uint64(250),
   175  		Testing:  uint64(100),
   176  	}).(uint64)
   177  
   178  	// logFewLimit is the number of errors of each type that the host will log
   179  	// before substantially constricting the amount of logging that it is
   180  	// doing.
   181  	logFewLimit = build.Select(build.Var{
   182  		Dev:      uint64(500),
   183  		Standard: uint64(2500),
   184  		Testing:  uint64(500),
   185  	}).(uint64)
   186  
   187  	// maximumLockedStorageObligations sets the maximum number of storage
   188  	// obligations that are allowed to be locked at a time. The map uses an
   189  	// in-memory lock, but also a locked storage obligation could be reading a
   190  	// whole sector into memory, which could use a bunch of system resources.
   191  	maximumLockedStorageObligations = build.Select(build.Var{
   192  		Dev:      uint64(20),
   193  		Standard: uint64(100),
   194  		Testing:  uint64(5),
   195  	}).(uint64)
   196  
   197  	// obligationLockTimeout defines how long a thread will wait to get a lock
   198  	// on a storage obligation before timing out and reporting an error to the
   199  	// renter.
   200  	obligationLockTimeout = build.Select(build.Var{
   201  		Dev:      time.Second * 20,
   202  		Standard: time.Second * 60,
   203  		Testing:  time.Second * 3,
   204  	}).(time.Duration)
   205  
   206  	// revisionSubmissionBuffer describes the number of blocks ahead of time
   207  	// that the host will submit a file contract revision. The host will not
   208  	// accept any more revisions once inside the submission buffer.
   209  	revisionSubmissionBuffer = build.Select(build.Var{
   210  		Dev:      types.BlockHeight(20),  // About 4 minutes
   211  		Standard: types.BlockHeight(144), // 1 day.
   212  		Testing:  types.BlockHeight(4),
   213  	}).(types.BlockHeight)
   214  
   215  	// rpcRatelimit prevents someone from spamming the host with connections,
   216  	// causing it to spin up enough goroutines to crash.
   217  	rpcRatelimit = build.Select(build.Var{
   218  		Dev:      time.Millisecond * 10,
   219  		Standard: time.Millisecond * 50,
   220  		Testing:  time.Millisecond,
   221  	}).(time.Duration)
   222  
   223  	// workingStatusFirstCheck defines how frequently the Host's working status
   224  	// check runs
   225  	workingStatusFirstCheck = build.Select(build.Var{
   226  		Standard: time.Minute * 3,
   227  		Dev:      time.Minute * 1,
   228  		Testing:  time.Second * 3,
   229  	}).(time.Duration)
   230  
   231  	// workingStatusFrequency defines how frequently the Host's working status
   232  	// check runs
   233  	workingStatusFrequency = build.Select(build.Var{
   234  		Standard: time.Minute * 10,
   235  		Dev:      time.Minute * 5,
   236  		Testing:  time.Second * 10,
   237  	}).(time.Duration)
   238  
   239  	// workingStatusThreshold defines how many settings calls must occur over the
   240  	// workingStatusFrequency for the host to be considered working.
   241  	workingStatusThreshold = build.Select(build.Var{
   242  		Standard: uint64(3),
   243  		Dev:      uint64(1),
   244  		Testing:  uint64(1),
   245  	}).(uint64)
   246  )
   247  
   248  // All of the following variables define the names of buckets used by the host
   249  // in the database.
   250  var (
   251  	// bucketActionItems maps a blockchain height to a list of storage
   252  	// obligations that need to be managed in some way at that height. The
   253  	// height is stored as a big endian uint64, which means that bolt will
   254  	// store the heights sorted in numerical order. The action item itself is
   255  	// an array of file contract ids. The host is able to contextually figure
   256  	// out what the necessary actions for that item are based on the file
   257  	// contract id and the associated storage obligation that can be retrieved
   258  	// using the id.
   259  	bucketActionItems = []byte("BucketActionItems")
   260  
   261  	// bucketStorageObligations contains a set of serialized
   262  	// 'storageObligations' sorted by their file contract id.
   263  	bucketStorageObligations = []byte("BucketStorageObligations")
   264  )
   265  
   266  // init runs a series of sanity checks to verify that the constants have sane
   267  // values.
   268  func init() {
   269  	// The revision submission buffer should be greater than the resubmission
   270  	// timeout, because there should be time to perform resubmission if the
   271  	// first attempt to submit the revision fails.
   272  	if revisionSubmissionBuffer < resubmissionTimeout {
   273  		build.Critical("revision submission buffer needs to be larger than or equal to the resubmission timeout")
   274  	}
   275  }