github.com/johnathanhowell/sia@v0.5.1-beta.0.20160524050156-83dcc3d37c94/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  	// defaultCollateral defines the amount of money that the host puts up as
    38  	// collateral per-byte by default. The collateral should be considered as
    39  	// an absolute instead of as a percentage, because low prices result in
    40  	// collaterals which may be significant by percentage, but insignificant
    41  	// overall. A default of 25 KS / TB / Month has been chosen, which is 2.5x
    42  	// the default price for storage. The host is expected to put up a
    43  	// significant amount of collateral as a commitment to faithfulness,
    44  	// because this guarantees that the incentives are aligned for the host to
    45  	// keep the data even if the price of siacoin fluctuates, the price of raw
    46  	// storage fluctuates, or the host realizes that there is unexpected
    47  	// opportunity cost in being a host.
    48  	defaultCollateral = types.SiacoinPrecision.Mul64(25e3).Div(modules.BlockBytesPerMonthTerabyte) // 25 KS / TB / Month
    49  
    50  	// defaultCollateralBudget defines the maximum number of siacoins that the
    51  	// host is going to allocate towards collateral. The number has been chosen
    52  	// as a number that is large, but not so large that someone would be
    53  	// furious for losing access to it for a few weeks.
    54  	defaultCollateralBudget = types.SiacoinPrecision.Mul64(5e6)
    55  
    56  	// defaultContractPrice defines the default price of creating a contract
    57  	// with the host. The default is set to 30 siacoins, which the file
    58  	// contract revision can have 15 siacoins put towards it, and the storage
    59  	// proof can have 15 siacoins put towards it.
    60  	defaultContractPrice = types.SiacoinPrecision.Mul64(30) // 30 siacoins
    61  
    62  	// defaultDownloadBandwidthPrice defines the default price of upload
    63  	// bandwidth. The default is set to 10 siacoins per gigabyte, because
    64  	// download bandwidth is expected to be plentiful but also in-demand.
    65  	defaultDownloadBandwidthPrice = types.SiacoinPrecision.Mul64(10e3).Div(modules.BytesPerTerabyte) // 10k SC / TB
    66  
    67  	// defaultMaxDownloadBatchSize defines the maximum number of bytes that the
    68  	// host will allow to be requested by a single download request. 17 MiB has
    69  	// been chosen because it's 4 full sectors plus some wiggle room. 17 MiB is
    70  	// a conservative default, most hosts will be fine with a number like 65
    71  	// MiB.
    72  	defaultMaxDownloadBatchSize = 17 * (1 << 20)
    73  
    74  	// defaultMaxReviseBatchSize defines the maximum number of bytes that the
    75  	// host will allow to be sent during a single batch update in a revision
    76  	// RPC. 17 MiB has been chosen because it's four full sectors, plus some
    77  	// wiggle room for the extra data or a few delete operations. The whole
    78  	// batch will be held in memory, so the batch size should only be increased
    79  	// substantially if the host has a lot of memory. Additionally, the whole
    80  	// batch is sent in one network connection. Additionally, the renter can
    81  	// steal funds for upload bandwidth all the way out to the size of a batch.
    82  	// 17 MiB is a conservative default, most hosts are likely to be just fine
    83  	// with a number like 65 MiB.
    84  	defaultMaxReviseBatchSize = 17 * (1 << 20)
    85  
    86  	// defaultMaxCollateral defines the maximum amount of collateral that the
    87  	// host is comfortable putting into a single file contract. 10e3 is a
    88  	// relatively small file contract, but millions of siacoins could be locked
    89  	// away by only a few hundred file contracts. As the ecosystem matures, it
    90  	// is expected that the safe default for this value will increase quite a
    91  	// bit.
    92  	defaultMaxCollateral = types.SiacoinPrecision.Mul64(250e3)
    93  
    94  	// defaultStoragePrice defines the starting price for hosts selling
    95  	// storage. We try to match a number that is both reasonably profitable and
    96  	// reasonably competitive.
    97  	defaultStoragePrice = types.SiacoinPrecision.Mul64(10e3).Div(modules.BlockBytesPerMonthTerabyte) // 10k SC / TB / Month
    98  
    99  	// defaultUploadBandwidthPrice defines the default price of upload
   100  	// bandwidth. The default is set to 1 siacoin per GB, because the host is
   101  	// presumed to have a large amount of downstream bandwidth. Furthermore,
   102  	// the host is typically only downloading data if it is planning to store
   103  	// the data, meaning that the host serves to profit from accepting the
   104  	// data.
   105  	defaultUploadBandwidthPrice = types.SiacoinPrecision.Mul64(1e3).Div(modules.BytesPerTerabyte) // 1 SC / TB
   106  
   107  	// defaultWindowSize is the size of the proof of storage window requested
   108  	// by the host. The host will not delete any obligations until the window
   109  	// has closed and buried under several confirmations. For release builds,
   110  	// the default is set to 144 blocks, or about 1 day. This gives the host
   111  	// flexibility to experience downtime without losing file contracts. The
   112  	// optimal default, especially as the network matures, is probably closer
   113  	// to 36 blocks. An experienced or high powered host should not be
   114  	// frustrated by lost coins due to long periods of downtime.
   115  	defaultWindowSize = func() types.BlockHeight {
   116  		if build.Release == "dev" {
   117  			return 36 // 3.6 minutes.
   118  		}
   119  		if build.Release == "standard" {
   120  			return 144 // 1 day.
   121  		}
   122  		if build.Release == "testing" {
   123  			return 5 // 5 seconds.
   124  		}
   125  		panic("unrecognized release constant in host - defaultWindowSize")
   126  	}()
   127  
   128  	// maximumLockedStorageObligations sets the maximum number of storage
   129  	// obligations that are allowed to be locked at a time. The map uses an
   130  	// in-memory lock, but also a locked storage obligation could be reading a
   131  	// whole sector into memory, which could use a bunch of system resources.
   132  	maximumLockedStorageObligations = func() uint64 {
   133  		if build.Release == "dev" {
   134  			return 20
   135  		}
   136  		if build.Release == "standard" {
   137  			return 100
   138  		}
   139  		if build.Release == "testing" {
   140  			return 5
   141  		}
   142  		panic("unrecognized release constant in host - maximumLockedStorageObligations")
   143  	}()
   144  
   145  	// revisionSubmissionBuffer describes the number of blocks ahead of time
   146  	// that the host will submit a file contract revision. The host will not
   147  	// accept any more revisions once inside the submission buffer.
   148  	revisionSubmissionBuffer = func() types.BlockHeight {
   149  		if build.Release == "dev" {
   150  			return 20 // About 2 minutes
   151  		}
   152  		if build.Release == "standard" {
   153  			return 288 // 2 days.
   154  		}
   155  		if build.Release == "testing" {
   156  			return 4
   157  		}
   158  		panic("unrecognized release constant in host - revision submission buffer")
   159  	}()
   160  )
   161  
   162  // All of the following variables define the names of buckets used by the host
   163  // in the database.
   164  var (
   165  	// bucketActionItems maps a blockchain height to a list of storage
   166  	// obligations that need to be managed in some way at that height. The
   167  	// height is stored as a big endian uint64, which means that bolt will
   168  	// store the heights sorted in numerical order. The action item itself is
   169  	// an array of file contract ids. The host is able to contextually figure
   170  	// out what the necessary actions for that item are based on the file
   171  	// contract id and the associated storage obligation that can be retrieved
   172  	// using the id.
   173  	bucketActionItems = []byte("BucketActionItems")
   174  
   175  	// bucketStorageObligations contains a set of serialized
   176  	// 'storageObligations' sorted by their file contract id.
   177  	bucketStorageObligations = []byte("BucketStorageObligations")
   178  )
   179  
   180  // init runs a series of sanity checks to verify that the constants have sane
   181  // values.
   182  func init() {
   183  	// The revision submission buffer should be greater than the resubmission
   184  	// timeout, because there should be time to perform resubmission if the
   185  	// first attempt to submit the revision fails.
   186  	if revisionSubmissionBuffer < resubmissionTimeout {
   187  		build.Critical("revision submission buffer needs to be larger than or equal to the resubmission timeout")
   188  	}
   189  }