-
Notifications
You must be signed in to change notification settings - Fork 8.8k
/
ledger_config.go
136 lines (113 loc) · 4.4 KB
/
ledger_config.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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
/*
Copyright IBM Corp. 2016 All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package ledgerconfig
import (
"path/filepath"
"github.com/hyperledger/fabric/core/config"
"github.com/spf13/viper"
)
//IsCouchDBEnabled exposes the useCouchDB variable
func IsCouchDBEnabled() bool {
stateDatabase := viper.GetString("ledger.state.stateDatabase")
if stateDatabase == "CouchDB" {
return true
}
return false
}
const confPeerFileSystemPath = "peer.fileSystemPath"
const confLedgersData = "ledgersData"
const confLedgerProvider = "ledgerProvider"
const confStateleveldb = "stateLeveldb"
const confHistoryLeveldb = "historyLeveldb"
const confPvtWritesetStore = "pvtWritesetStore"
const confChains = "chains"
const confPvtdataStore = "pvtdataStore"
const confQueryLimit = "ledger.state.couchDBConfig.queryLimit"
const confEnableHistoryDatabase = "ledger.history.enableHistoryDatabase"
const confMaxBatchSize = "ledger.state.couchDBConfig.maxBatchUpdateSize"
const confAutoWarmIndexes = "ledger.state.couchDBConfig.autoWarmIndexes"
// GetRootPath returns the filesystem path.
// All ledger related contents are expected to be stored under this path
func GetRootPath() string {
sysPath := config.GetPath(confPeerFileSystemPath)
return filepath.Join(sysPath, confLedgersData)
}
// GetLedgerProviderPath returns the filesystem path for storing ledger ledgerProvider contents
func GetLedgerProviderPath() string {
return filepath.Join(GetRootPath(), confLedgerProvider)
}
// GetStateLevelDBPath returns the filesystem path that is used to maintain the state level db
func GetStateLevelDBPath() string {
return filepath.Join(GetRootPath(), confStateleveldb)
}
// GetHistoryLevelDBPath returns the filesystem path that is used to maintain the history level db
func GetHistoryLevelDBPath() string {
return filepath.Join(GetRootPath(), confHistoryLeveldb)
}
// GetPvtWritesetStorePath returns the filesystem path that is used for permanent storage of privare write-sets
func GetPvtWritesetStorePath() string {
return filepath.Join(GetRootPath(), confPvtWritesetStore)
}
// GetBlockStorePath returns the filesystem path that is used for the chain block stores
func GetBlockStorePath() string {
return filepath.Join(GetRootPath(), confChains)
}
// GetPvtdataStorePath returns the filesystem path that is used for permanent storage of private write-sets
func GetPvtdataStorePath() string {
return filepath.Join(GetRootPath(), confPvtdataStore)
}
// GetMaxBlockfileSize returns maximum size of the block file
func GetMaxBlockfileSize() int {
return 64 * 1024 * 1024
}
//GetQueryLimit exposes the queryLimit variable
func GetQueryLimit() int {
queryLimit := viper.GetInt(confQueryLimit)
// if queryLimit was unset, default to 10000
if !viper.IsSet(confQueryLimit) {
queryLimit = 10000
}
return queryLimit
}
//GetMaxBatchUpdateSize exposes the maxBatchUpdateSize variable
func GetMaxBatchUpdateSize() int {
maxBatchUpdateSize := viper.GetInt(confMaxBatchSize)
// if maxBatchUpdateSize was unset, default to 500
if !viper.IsSet(confMaxBatchSize) {
maxBatchUpdateSize = 500
}
return maxBatchUpdateSize
}
//IsHistoryDBEnabled exposes the historyDatabase variable
func IsHistoryDBEnabled() bool {
return viper.GetBool(confEnableHistoryDatabase)
}
// IsQueryReadsHashingEnabled enables or disables computing of hash
// of range query results for phantom item validation
func IsQueryReadsHashingEnabled() bool {
return true
}
// GetMaxDegreeQueryReadsHashing return the maximum degree of the merkle tree for hashes of
// of range query results for phantom item validation
// For more details - see description in kvledger/txmgmt/rwset/query_results_helper.go
func GetMaxDegreeQueryReadsHashing() uint32 {
return 50
}
//IsAutoWarmIndexesEnabled exposes the autoWarmIndexes variable
func IsAutoWarmIndexesEnabled() bool {
//Return the value set in core.yaml, if not set, the return true
if viper.IsSet(confAutoWarmIndexes) {
return viper.GetBool(confAutoWarmIndexes)
}
return true
}