-
Notifications
You must be signed in to change notification settings - Fork 11
/
defaults.go
117 lines (98 loc) · 3.67 KB
/
defaults.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
// Copyright 2019 DxChain, All rights reserved.
// Use of this source code is governed by an Apache
// License 2.0 that can be found in the LICENSE file.
package storagehost
import (
"strconv"
"github.com/DxChainNetwork/godx/common"
"github.com/DxChainNetwork/godx/common/unit"
"github.com/DxChainNetwork/godx/core/types"
"github.com/DxChainNetwork/godx/crypto/merkle"
"github.com/DxChainNetwork/godx/storage"
)
const (
// PersistHostDir is dir path for storing the host log, json, and etc.
PersistHostDir = "storagehost"
// Version is the version of the storage host
Version = "1.0"
// HostSettingFile is the file name for saving the setting of host
HostSettingFile = "host.json"
// HostDB is the database dir for storing host obligation
databaseFile = "hostdb"
// StorageManager is a dir for storagemanager related topic
StorageManager = "storagemanager"
)
const (
// storage responsibility related constants
postponedExecution = 3 //Total length of time to start a test task
confirmedBufferHeight = 40 //signing transaction not confirmed maximum time
//prefixStorageResponsibility db prefix for StorageResponsibility
prefixStorageResponsibility = "StorageResponsibility-"
//prefixHeight db prefix for task
prefixHeight = "height-"
//Total time to sign the contract
postponedExecutionBuffer = 12 * unit.BlocksPerHour
)
var (
// sectorHeight is the parameter used in caching merkle roots
sectorHeight uint64
storageHostMeta = common.Metadata{
Header: "DxChain StorageHost JSON",
Version: "V1.0",
}
//Storage contract should not be empty
emptyStorageContract = types.StorageContract{}
)
// init set the initial value for sector height
func init() {
sectorHeight = calculateSectorHeight()
}
// calculateSectorHeight calculate the sector height for specified sector size and leaf size
func calculateSectorHeight() uint64 {
height := uint64(0)
for 1<<height < (storage.SectorSize / merkle.LeafSize) {
height++
}
return height
}
// defaultConfig loads the default setting when
// it is the first time use the host service, or cannot find the setting file
func defaultConfig() storage.HostIntConfig {
return storage.HostIntConfig{
MaxDownloadBatchSize: uint64(storage.DefaultMaxDownloadBatchSize),
MaxDuration: uint64(storage.DefaultMaxDuration),
MaxReviseBatchSize: uint64(storage.DefaultMaxReviseBatchSize),
WindowSize: uint64(storage.ProofWindowSize),
Deposit: storage.DefaultDeposit,
DepositBudget: storage.DefaultDepositBudget,
MaxDeposit: storage.DefaultMaxDeposit,
BaseRPCPrice: storage.DefaultBaseRPCPrice,
ContractPrice: storage.DefaultContractPrice,
DownloadBandwidthPrice: storage.DefaultDownloadBandwidthPrice,
SectorAccessPrice: storage.DefaultSectorAccessPrice,
StoragePrice: storage.DefaultStoragePrice,
UploadBandwidthPrice: storage.DefaultUploadBandwidthPrice,
}
}
const (
// responsibility status
responsibilityUnresolved storageResponsibilityStatus = iota //Storage responsibility is initialization, no meaning
responsibilityRejected //Storage responsibility never begins
responsibilitySucceeded // Successful storage responsibility
responsibilityFailed //Failed storage responsibility
)
type storageResponsibilityStatus uint64
func (i storageResponsibilityStatus) String() string {
switch i {
case 0:
return "responsibilityUnresolved"
case 1:
return "responsibilityRejected"
case 2:
return "responsibilitySucceeded"
case 3:
return "responsibilityFailed"
default:
return "storageResponsibilityStatus(" + strconv.FormatInt(int64(i), 10) + ")"
}
}