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