github.com/lzy4123/fabric@v2.1.1+incompatible/internal/peer/node/config.go (about) 1 /* 2 Copyright IBM Corp. 2016 All Rights Reserved. 3 4 SPDX-License-Identifier: Apache-2.0 5 */ 6 7 package node 8 9 import ( 10 "path/filepath" 11 12 coreconfig "github.com/hyperledger/fabric/core/config" 13 "github.com/hyperledger/fabric/core/ledger" 14 "github.com/hyperledger/fabric/core/ledger/util/couchdb" 15 "github.com/spf13/viper" 16 ) 17 18 func ledgerConfig() *ledger.Config { 19 // set defaults 20 warmAfterNBlocks := 1 21 if viper.IsSet("ledger.state.couchDBConfig.warmIndexesAfterNBlocks") { 22 warmAfterNBlocks = viper.GetInt("ledger.state.couchDBConfig.warmIndexesAfterNBlocks") 23 } 24 internalQueryLimit := 1000 25 if viper.IsSet("ledger.state.couchDBConfig.internalQueryLimit") { 26 internalQueryLimit = viper.GetInt("ledger.state.couchDBConfig.internalQueryLimit") 27 } 28 maxBatchUpdateSize := 500 29 if viper.IsSet("ledger.state.couchDBConfig.maxBatchUpdateSize") { 30 maxBatchUpdateSize = viper.GetInt("ledger.state.couchDBConfig.maxBatchUpdateSize") 31 } 32 collElgProcMaxDbBatchSize := 5000 33 if viper.IsSet("ledger.pvtdataStore.collElgProcMaxDbBatchSize") { 34 collElgProcMaxDbBatchSize = viper.GetInt("ledger.pvtdataStore.collElgProcMaxDbBatchSize") 35 } 36 collElgProcDbBatchesInterval := 1000 37 if viper.IsSet("ledger.pvtdataStore.collElgProcDbBatchesInterval") { 38 collElgProcDbBatchesInterval = viper.GetInt("ledger.pvtdataStore.collElgProcDbBatchesInterval") 39 } 40 purgeInterval := 100 41 if viper.IsSet("ledger.pvtdataStore.purgeInterval") { 42 purgeInterval = viper.GetInt("ledger.pvtdataStore.purgeInterval") 43 } 44 45 rootFSPath := filepath.Join(coreconfig.GetPath("peer.fileSystemPath"), "ledgersData") 46 conf := &ledger.Config{ 47 RootFSPath: rootFSPath, 48 StateDBConfig: &ledger.StateDBConfig{ 49 StateDatabase: viper.GetString("ledger.state.stateDatabase"), 50 CouchDB: &couchdb.Config{}, 51 }, 52 PrivateDataConfig: &ledger.PrivateDataConfig{ 53 MaxBatchSize: collElgProcMaxDbBatchSize, 54 BatchesInterval: collElgProcDbBatchesInterval, 55 PurgeInterval: purgeInterval, 56 }, 57 HistoryDBConfig: &ledger.HistoryDBConfig{ 58 Enabled: viper.GetBool("ledger.history.enableHistoryDatabase"), 59 }, 60 } 61 62 if conf.StateDBConfig.StateDatabase == "CouchDB" { 63 conf.StateDBConfig.CouchDB = &couchdb.Config{ 64 Address: viper.GetString("ledger.state.couchDBConfig.couchDBAddress"), 65 Username: viper.GetString("ledger.state.couchDBConfig.username"), 66 Password: viper.GetString("ledger.state.couchDBConfig.password"), 67 MaxRetries: viper.GetInt("ledger.state.couchDBConfig.maxRetries"), 68 MaxRetriesOnStartup: viper.GetInt("ledger.state.couchDBConfig.maxRetriesOnStartup"), 69 RequestTimeout: viper.GetDuration("ledger.state.couchDBConfig.requestTimeout"), 70 InternalQueryLimit: internalQueryLimit, 71 MaxBatchUpdateSize: maxBatchUpdateSize, 72 WarmIndexesAfterNBlocks: warmAfterNBlocks, 73 CreateGlobalChangesDB: viper.GetBool("ledger.state.couchDBConfig.createGlobalChangesDB"), 74 RedoLogPath: filepath.Join(rootFSPath, "couchdbRedoLogs"), 75 UserCacheSizeMBs: viper.GetInt("ledger.state.couchDBConfig.cacheSize"), 76 } 77 } 78 return conf 79 }