github.com/yimialmonte/fabric@v2.1.1+incompatible/gossip/service/config.go (about)

     1  /*
     2  Copyright IBM Corp. All Rights Reserved.
     3  
     4  SPDX-License-Identifier: Apache-2.0
     5  */
     6  package service
     7  
     8  import (
     9  	"time"
    10  
    11  	"github.com/hyperledger/fabric/gossip/election"
    12  	"github.com/hyperledger/fabric/gossip/util"
    13  	"github.com/spf13/viper"
    14  )
    15  
    16  const (
    17  	btlPullMarginDefault           = 10
    18  	transientBlockRetentionDefault = 1000
    19  )
    20  
    21  // ServiceConfig is the config struct for gossip services
    22  type ServiceConfig struct {
    23  	// PeerTLSEnabled enables/disables Peer TLS.
    24  	PeerTLSEnabled bool
    25  	// Endpoint which overrides the endpoint the peer publishes to peers in its organization.
    26  	Endpoint              string
    27  	NonBlockingCommitMode bool
    28  	// UseLeaderElection defines whenever peer will initialize dynamic algorithm for "leader" selection.
    29  	UseLeaderElection bool
    30  	// OrgLeader statically defines peer to be an organization "leader".
    31  	OrgLeader bool
    32  	// ElectionStartupGracePeriod is the longest time peer waits for stable membership during leader
    33  	// election startup (unit: second).
    34  	ElectionStartupGracePeriod time.Duration
    35  	// ElectionMembershipSampleInterval is the time interval for gossip membership samples to check its stability (unit: second).
    36  	ElectionMembershipSampleInterval time.Duration
    37  	// ElectionLeaderAliveThreshold is the time passes since last declaration message before peer decides to
    38  	// perform leader election (unit: second).
    39  	ElectionLeaderAliveThreshold time.Duration
    40  	// ElectionLeaderElectionDuration is the time passes since last declaration message before peer decides to perform
    41  	// leader election (unit: second).
    42  	ElectionLeaderElectionDuration time.Duration
    43  	// PvtDataPullRetryThreshold determines the maximum duration of time private data corresponding for
    44  	// a given block.
    45  	PvtDataPullRetryThreshold time.Duration
    46  	// PvtDataPushAckTimeout is the maximum time to wait for the acknoledgement from each peer at private
    47  	// data push at endorsement time.
    48  	PvtDataPushAckTimeout time.Duration
    49  	// BtlPullMargin is the block to live pulling margin, used as a buffer to prevent peer from trying to pull private data
    50  	// from peers that is soon to be purged in next N blocks.
    51  	BtlPullMargin uint64
    52  	// TransientstoreMaxBlockRetention defines the maximum difference between the current ledger's height upon commit,
    53  	// and the private data residing inside the transient store that is guaranteed not to be purged.
    54  	TransientstoreMaxBlockRetention uint64
    55  	// SkipPullingInvalidTransactionsDuringCommit is a flag that indicates whether pulling of invalid
    56  	// transaction's private data from other peers need to be skipped during the commit time and pulled
    57  	// only through reconciler.
    58  	SkipPullingInvalidTransactionsDuringCommit bool
    59  }
    60  
    61  func GlobalConfig() *ServiceConfig {
    62  	c := &ServiceConfig{}
    63  	c.loadGossipConfig()
    64  	return c
    65  }
    66  
    67  func (c *ServiceConfig) loadGossipConfig() {
    68  
    69  	c.PeerTLSEnabled = viper.GetBool("peer.tls.enabled")
    70  	c.Endpoint = viper.GetString("peer.gossip.endpoint")
    71  	c.NonBlockingCommitMode = viper.GetBool("peer.gossip.nonBlockingCommitMode")
    72  	c.UseLeaderElection = viper.GetBool("peer.gossip.useLeaderElection")
    73  	c.OrgLeader = viper.GetBool("peer.gossip.orgLeader")
    74  
    75  	c.ElectionStartupGracePeriod = util.GetDurationOrDefault("peer.gossip.election.startupGracePeriod", election.DefStartupGracePeriod)
    76  	c.ElectionMembershipSampleInterval = util.GetDurationOrDefault("peer.gossip.election.membershipSampleInterval", election.DefMembershipSampleInterval)
    77  	c.ElectionLeaderAliveThreshold = util.GetDurationOrDefault("peer.gossip.election.leaderAliveThreshold", election.DefLeaderAliveThreshold)
    78  	c.ElectionLeaderElectionDuration = util.GetDurationOrDefault("peer.gossip.election.leaderElectionDuration", election.DefLeaderElectionDuration)
    79  
    80  	c.PvtDataPushAckTimeout = viper.GetDuration("peer.gossip.pvtData.pushAckTimeout")
    81  	c.PvtDataPullRetryThreshold = viper.GetDuration("peer.gossip.pvtData.pullRetryThreshold")
    82  	c.SkipPullingInvalidTransactionsDuringCommit = viper.GetBool("peer.gossip.pvtData.skipPullingInvalidTransactionsDuringCommit")
    83  
    84  	c.BtlPullMargin = btlPullMarginDefault
    85  	if viper.IsSet("peer.gossip.pvtData.btlPullMargin") {
    86  		btlMarginVal := viper.GetInt("peer.gossip.pvtData.btlPullMargin")
    87  		if btlMarginVal >= 0 {
    88  			c.BtlPullMargin = uint64(btlMarginVal)
    89  		}
    90  	}
    91  
    92  	c.TransientstoreMaxBlockRetention = uint64(viper.GetInt("peer.gossip.pvtData.transientstoreMaxBlockRetention"))
    93  	if c.TransientstoreMaxBlockRetention == 0 {
    94  		logger.Warning("Configuration key peer.gossip.pvtData.transientstoreMaxBlockRetention isn't set, defaulting to", transientBlockRetentionDefault)
    95  		c.TransientstoreMaxBlockRetention = transientBlockRetentionDefault
    96  	}
    97  }