gitlab.com/jokerrs1/Sia@v1.3.2/modules/host/consts.go (about)

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