github.com/ewagmig/fabric@v2.1.1+incompatible/common/channelconfig/api.go (about)

     1  /*
     2  Copyright IBM Corp. All Rights Reserved.
     3  
     4  SPDX-License-Identifier: Apache-2.0
     5  */
     6  
     7  package channelconfig
     8  
     9  import (
    10  	"time"
    11  
    12  	cb "github.com/hyperledger/fabric-protos-go/common"
    13  	ab "github.com/hyperledger/fabric-protos-go/orderer"
    14  	pb "github.com/hyperledger/fabric-protos-go/peer"
    15  	"github.com/hyperledger/fabric/common/configtx"
    16  	"github.com/hyperledger/fabric/common/policies"
    17  	"github.com/hyperledger/fabric/msp"
    18  )
    19  
    20  // Org stores the common organizational config
    21  type Org interface {
    22  	// Name returns the name this org is referred to in config
    23  	Name() string
    24  
    25  	// MSPID returns the MSP ID associated with this org
    26  	MSPID() string
    27  
    28  	// MSP returns the MSP implementation for this org.
    29  	MSP() msp.MSP
    30  }
    31  
    32  // ApplicationOrg stores the per org application config
    33  type ApplicationOrg interface {
    34  	Org
    35  
    36  	// AnchorPeers returns the list of gossip anchor peers
    37  	AnchorPeers() []*pb.AnchorPeer
    38  }
    39  
    40  // OrdererOrg stores the per org orderer config.
    41  type OrdererOrg interface {
    42  	Org
    43  
    44  	// Endpoints returns the endpoints of orderer nodes.
    45  	Endpoints() []string
    46  }
    47  
    48  // Application stores the common shared application config
    49  type Application interface {
    50  	// Organizations returns a map of org ID to ApplicationOrg
    51  	Organizations() map[string]ApplicationOrg
    52  
    53  	// APIPolicyMapper returns a PolicyMapper that maps API names to policies
    54  	APIPolicyMapper() PolicyMapper
    55  
    56  	// Capabilities defines the capabilities for the application portion of a channel
    57  	Capabilities() ApplicationCapabilities
    58  }
    59  
    60  // Channel gives read only access to the channel configuration
    61  type Channel interface {
    62  	// HashingAlgorithm returns the default algorithm to be used when hashing
    63  	// such as computing block hashes, and CreationPolicy digests
    64  	HashingAlgorithm() func(input []byte) []byte
    65  
    66  	// BlockDataHashingStructureWidth returns the width to use when constructing the
    67  	// Merkle tree to compute the BlockData hash
    68  	BlockDataHashingStructureWidth() uint32
    69  
    70  	// OrdererAddresses returns the list of valid orderer addresses to connect to to invoke Broadcast/Deliver
    71  	OrdererAddresses() []string
    72  
    73  	// Capabilities defines the capabilities for a channel
    74  	Capabilities() ChannelCapabilities
    75  }
    76  
    77  // Consortiums represents the set of consortiums serviced by an ordering service
    78  type Consortiums interface {
    79  	// Consortiums returns the set of consortiums
    80  	Consortiums() map[string]Consortium
    81  }
    82  
    83  // Consortium represents a group of orgs which may create channels together
    84  type Consortium interface {
    85  	// ChannelCreationPolicy returns the policy to check when instantiating a channel for this consortium
    86  	ChannelCreationPolicy() *cb.Policy
    87  
    88  	// Organizations returns the organizations for this consortium
    89  	Organizations() map[string]Org
    90  }
    91  
    92  // Orderer stores the common shared orderer config
    93  type Orderer interface {
    94  	// ConsensusType returns the configured consensus type
    95  	ConsensusType() string
    96  
    97  	// ConsensusMetadata returns the metadata associated with the consensus type.
    98  	ConsensusMetadata() []byte
    99  
   100  	// ConsensusState returns the consensus-type state.
   101  	ConsensusState() ab.ConsensusType_State
   102  
   103  	// BatchSize returns the maximum number of messages to include in a block
   104  	BatchSize() *ab.BatchSize
   105  
   106  	// BatchTimeout returns the amount of time to wait before creating a batch
   107  	BatchTimeout() time.Duration
   108  
   109  	// MaxChannelsCount returns the maximum count of channels to allow for an ordering network
   110  	MaxChannelsCount() uint64
   111  
   112  	// KafkaBrokers returns the addresses (IP:port notation) of a set of "bootstrap"
   113  	// Kafka brokers, i.e. this is not necessarily the entire set of Kafka brokers
   114  	// used for ordering
   115  	KafkaBrokers() []string
   116  
   117  	// Organizations returns the organizations for the ordering service
   118  	Organizations() map[string]OrdererOrg
   119  
   120  	// Capabilities defines the capabilities for the orderer portion of a channel
   121  	Capabilities() OrdererCapabilities
   122  }
   123  
   124  // ChannelCapabilities defines the capabilities for a channel
   125  type ChannelCapabilities interface {
   126  	// Supported returns an error if there are unknown capabilities in this channel which are required
   127  	Supported() error
   128  
   129  	// MSPVersion specifies the version of the MSP this channel must understand, including the MSP types
   130  	// and MSP principal types.
   131  	MSPVersion() msp.MSPVersion
   132  
   133  	// ConsensusTypeMigration return true if consensus-type migration is permitted in both orderer and peer.
   134  	ConsensusTypeMigration() bool
   135  
   136  	// OrgSpecificOrdererEndpoints return true if the channel config processing allows orderer orgs to specify their own endpoints
   137  	OrgSpecificOrdererEndpoints() bool
   138  }
   139  
   140  // ApplicationCapabilities defines the capabilities for the application portion of a channel
   141  type ApplicationCapabilities interface {
   142  	// Supported returns an error if there are unknown capabilities in this channel which are required
   143  	Supported() error
   144  
   145  	// ForbidDuplicateTXIdInBlock specifies whether two transactions with the same TXId are permitted
   146  	// in the same block or whether we mark the second one as TxValidationCode_DUPLICATE_TXID
   147  	ForbidDuplicateTXIdInBlock() bool
   148  
   149  	// ACLs returns true is ACLs may be specified in the Application portion of the config tree
   150  	ACLs() bool
   151  
   152  	// PrivateChannelData returns true if support for private channel data (a.k.a. collections) is enabled.
   153  	// In v1.1, the private channel data is experimental and has to be enabled explicitly.
   154  	// In v1.2, the private channel data is enabled by default.
   155  	PrivateChannelData() bool
   156  
   157  	// CollectionUpgrade returns true if this channel is configured to allow updates to
   158  	// existing collection or add new collections through chaincode upgrade (as introduced in v1.2)
   159  	CollectionUpgrade() bool
   160  
   161  	// V1_1Validation returns true is this channel is configured to perform stricter validation
   162  	// of transactions (as introduced in v1.1).
   163  	V1_1Validation() bool
   164  
   165  	// V1_2Validation returns true is this channel is configured to perform stricter validation
   166  	// of transactions (as introduced in v1.2).
   167  	V1_2Validation() bool
   168  
   169  	// V1_3Validation returns true if this channel supports transaction validation
   170  	// as introduced in v1.3. This includes:
   171  	//  - policies expressible at a ledger key granularity, as described in FAB-8812
   172  	//  - new chaincode lifecycle, as described in FAB-11237
   173  	V1_3Validation() bool
   174  
   175  	// StorePvtDataOfInvalidTx() returns true if the peer needs to store the pvtData of
   176  	// invalid transactions (as introduced in v142).
   177  	StorePvtDataOfInvalidTx() bool
   178  
   179  	// V2_0Validation returns true if this channel supports transaction validation
   180  	// as introduced in v2.0. This includes:
   181  	//  - new chaincode lifecycle
   182  	//  - implicit per-org collections
   183  	V2_0Validation() bool
   184  
   185  	// LifecycleV20 indicates whether the peer should use the deprecated and problematic
   186  	// v1.x lifecycle, or whether it should use the newer per channel approve/commit definitions
   187  	// process introduced in v2.0.  Note, this should only be used on the endorsing side
   188  	// of peer processing, so that we may safely remove all checks against it in v2.1.
   189  	LifecycleV20() bool
   190  
   191  	// MetadataLifecycle always returns false
   192  	MetadataLifecycle() bool
   193  
   194  	// KeyLevelEndorsement returns true if this channel supports endorsement
   195  	// policies expressible at a ledger key granularity, as described in FAB-8812
   196  	KeyLevelEndorsement() bool
   197  }
   198  
   199  // OrdererCapabilities defines the capabilities for the orderer portion of a channel
   200  type OrdererCapabilities interface {
   201  	// PredictableChannelTemplate specifies whether the v1.0 undesirable behavior of setting the /Channel
   202  	// group's mod_policy to "" and copy versions from the orderer system channel config should be fixed or not.
   203  	PredictableChannelTemplate() bool
   204  
   205  	// Resubmission specifies whether the v1.0 non-deterministic commitment of tx should be fixed by re-submitting
   206  	// the re-validated tx.
   207  	Resubmission() bool
   208  
   209  	// Supported returns an error if there are unknown capabilities in this channel which are required
   210  	Supported() error
   211  
   212  	// ExpirationCheck specifies whether the orderer checks for identity expiration checks
   213  	// when validating messages
   214  	ExpirationCheck() bool
   215  
   216  	// ConsensusTypeMigration checks whether the orderer permits a consensus-type migration.
   217  	ConsensusTypeMigration() bool
   218  
   219  	// UseChannelCreationPolicyAsAdmins checks whether the orderer should use more sophisticated
   220  	// channel creation logic using channel creation policy as the Admins policy if
   221  	// the creation transaction appears to support it.
   222  	UseChannelCreationPolicyAsAdmins() bool
   223  }
   224  
   225  // PolicyMapper is an interface for
   226  type PolicyMapper interface {
   227  	// PolicyRefForAPI takes the name of an API, and returns the policy name
   228  	// or the empty string if the API is not found
   229  	PolicyRefForAPI(apiName string) string
   230  }
   231  
   232  // Resources is the common set of config resources for all channels
   233  // Depending on whether chain is used at the orderer or at the peer, other
   234  // config resources may be available
   235  type Resources interface {
   236  	// ConfigtxValidator returns the configtx.Validator for the channel
   237  	ConfigtxValidator() configtx.Validator
   238  
   239  	// PolicyManager returns the policies.Manager for the channel
   240  	PolicyManager() policies.Manager
   241  
   242  	// ChannelConfig returns the config.Channel for the chain
   243  	ChannelConfig() Channel
   244  
   245  	// OrdererConfig returns the config.Orderer for the channel
   246  	// and whether the Orderer config exists
   247  	OrdererConfig() (Orderer, bool)
   248  
   249  	// ConsortiumsConfig() returns the config.Consortiums for the channel
   250  	// and whether the consortiums config exists
   251  	ConsortiumsConfig() (Consortiums, bool)
   252  
   253  	// ApplicationConfig returns the configtxapplication.SharedConfig for the channel
   254  	// and whether the Application config exists
   255  	ApplicationConfig() (Application, bool)
   256  
   257  	// MSPManager returns the msp.MSPManager for the chain
   258  	MSPManager() msp.MSPManager
   259  
   260  	// ValidateNew should return an error if a new set of configuration resources is incompatible with the current one
   261  	ValidateNew(resources Resources) error
   262  }