/
config.go
79 lines (72 loc) · 3.04 KB
/
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
/*
Copyright IBM Corp. 2016 All Rights Reserved.
SPDX-License-Identifier: Apache-2.0
*/
package node
import (
"path/filepath"
coreconfig "github.com/hyperledger/fabric/core/config"
"github.com/hyperledger/fabric/core/ledger"
"github.com/hyperledger/fabric/core/ledger/util/couchdb"
"github.com/spf13/viper"
)
func ledgerConfig() *ledger.Config {
// set defaults
warmAfterNBlocks := 1
if viper.IsSet("ledger.state.couchDBConfig.warmIndexesAfterNBlocks") {
warmAfterNBlocks = viper.GetInt("ledger.state.couchDBConfig.warmIndexesAfterNBlocks")
}
internalQueryLimit := 1000
if viper.IsSet("ledger.state.couchDBConfig.internalQueryLimit") {
internalQueryLimit = viper.GetInt("ledger.state.couchDBConfig.internalQueryLimit")
}
maxBatchUpdateSize := 500
if viper.IsSet("ledger.state.couchDBConfig.maxBatchUpdateSize") {
maxBatchUpdateSize = viper.GetInt("ledger.state.couchDBConfig.maxBatchUpdateSize")
}
collElgProcMaxDbBatchSize := 5000
if viper.IsSet("ledger.pvtdataStore.collElgProcMaxDbBatchSize") {
collElgProcMaxDbBatchSize = viper.GetInt("ledger.pvtdataStore.collElgProcMaxDbBatchSize")
}
collElgProcDbBatchesInterval := 1000
if viper.IsSet("ledger.pvtdataStore.collElgProcDbBatchesInterval") {
collElgProcDbBatchesInterval = viper.GetInt("ledger.pvtdataStore.collElgProcDbBatchesInterval")
}
purgeInterval := 100
if viper.IsSet("ledger.pvtdataStore.purgeInterval") {
purgeInterval = viper.GetInt("ledger.pvtdataStore.purgeInterval")
}
rootFSPath := filepath.Join(coreconfig.GetPath("peer.fileSystemPath"), "ledgersData")
conf := &ledger.Config{
RootFSPath: rootFSPath,
StateDBConfig: &ledger.StateDBConfig{
StateDatabase: viper.GetString("ledger.state.stateDatabase"),
CouchDB: &couchdb.Config{},
},
PrivateDataConfig: &ledger.PrivateDataConfig{
MaxBatchSize: collElgProcMaxDbBatchSize,
BatchesInterval: collElgProcDbBatchesInterval,
PurgeInterval: purgeInterval,
},
HistoryDBConfig: &ledger.HistoryDBConfig{
Enabled: viper.GetBool("ledger.history.enableHistoryDatabase"),
},
}
if conf.StateDBConfig.StateDatabase == "CouchDB" {
conf.StateDBConfig.CouchDB = &couchdb.Config{
Address: viper.GetString("ledger.state.couchDBConfig.couchDBAddress"),
Username: viper.GetString("ledger.state.couchDBConfig.username"),
Password: viper.GetString("ledger.state.couchDBConfig.password"),
MaxRetries: viper.GetInt("ledger.state.couchDBConfig.maxRetries"),
MaxRetriesOnStartup: viper.GetInt("ledger.state.couchDBConfig.maxRetriesOnStartup"),
RequestTimeout: viper.GetDuration("ledger.state.couchDBConfig.requestTimeout"),
InternalQueryLimit: internalQueryLimit,
MaxBatchUpdateSize: maxBatchUpdateSize,
WarmIndexesAfterNBlocks: warmAfterNBlocks,
CreateGlobalChangesDB: viper.GetBool("ledger.state.couchDBConfig.createGlobalChangesDB"),
RedoLogPath: filepath.Join(rootFSPath, "couchdbRedoLogs"),
UserCacheSizeMBs: viper.GetInt("ledger.state.couchDBConfig.cacheSize"),
}
}
return conf
}