github.com/tenywen/fabric@v1.0.0-beta.0.20170620030522-a5b1ed380643/core/ledger/ledgerconfig/ledger_config.go (about)

     1  /*
     2  Copyright IBM Corp. 2016 All Rights Reserved.
     3  
     4  Licensed under the Apache License, Version 2.0 (the "License");
     5  you may not use this file except in compliance with the License.
     6  You may obtain a copy of the License at
     7  
     8  		 http://www.apache.org/licenses/LICENSE-2.0
     9  
    10  Unless required by applicable law or agreed to in writing, software
    11  distributed under the License is distributed on an "AS IS" BASIS,
    12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  See the License for the specific language governing permissions and
    14  limitations under the License.
    15  */
    16  
    17  package ledgerconfig
    18  
    19  import (
    20  	"path/filepath"
    21  
    22  	"github.com/hyperledger/fabric/core/config"
    23  	"github.com/spf13/viper"
    24  )
    25  
    26  //IsCouchDBEnabled exposes the useCouchDB variable
    27  func IsCouchDBEnabled() bool {
    28  	stateDatabase := viper.GetString("ledger.state.stateDatabase")
    29  	if stateDatabase == "CouchDB" {
    30  		return true
    31  	}
    32  	return false
    33  }
    34  
    35  // GetRootPath returns the filesystem path.
    36  // All ledger related contents are expected to be stored under this path
    37  func GetRootPath() string {
    38  	sysPath := config.GetPath("peer.fileSystemPath")
    39  	return filepath.Join(sysPath, "ledgersData")
    40  }
    41  
    42  // GetLedgerProviderPath returns the filesystem path for stroing ledger ledgerProvider contents
    43  func GetLedgerProviderPath() string {
    44  	return filepath.Join(GetRootPath(), "ledgerProvider")
    45  }
    46  
    47  // GetStateLevelDBPath returns the filesystem path that is used to maintain the state level db
    48  func GetStateLevelDBPath() string {
    49  	return filepath.Join(GetRootPath(), "stateLeveldb")
    50  }
    51  
    52  // GetHistoryLevelDBPath returns the filesystem path that is used to maintain the history level db
    53  func GetHistoryLevelDBPath() string {
    54  	return filepath.Join(GetRootPath(), "historyLeveldb")
    55  }
    56  
    57  // GetBlockStorePath returns the filesystem path that is used for the chain block stores
    58  func GetBlockStorePath() string {
    59  	return filepath.Join(GetRootPath(), "chains")
    60  }
    61  
    62  // GetMaxBlockfileSize returns maximum size of the block file
    63  func GetMaxBlockfileSize() int {
    64  	return 64 * 1024 * 1024
    65  }
    66  
    67  //GetQueryLimit exposes the queryLimit variable
    68  func GetQueryLimit() int {
    69  	queryLimit := viper.GetInt("ledger.state.couchDBConfig.queryLimit")
    70  	// if queryLimit was unset, default to 10000
    71  	if !viper.IsSet("ledger.state.couchDBConfig.queryLimit") {
    72  		queryLimit = 10000
    73  	}
    74  	return queryLimit
    75  }
    76  
    77  //IsHistoryDBEnabled exposes the historyDatabase variable
    78  func IsHistoryDBEnabled() bool {
    79  	return viper.GetBool("ledger.history.enableHistoryDatabase")
    80  }
    81  
    82  // IsQueryReadsHashingEnabled enables or disables computing of hash
    83  // of range query results for phantom item validation
    84  func IsQueryReadsHashingEnabled() bool {
    85  	return true
    86  }
    87  
    88  // GetMaxDegreeQueryReadsHashing return the maximum degree of the merkle tree for hashes of
    89  // of range query results for phantom item validation
    90  // For more details - see description in kvledger/txmgmt/rwset/query_results_helper.go
    91  func GetMaxDegreeQueryReadsHashing() uint32 {
    92  	return 50
    93  }