github.com/hechain20/hechain@v0.0.0-20220316014945-b544036ba106/internal/peer/node/config.go (about)

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