Skip to content

Commit 256479e

Browse files
refactor(fabric): remove import of common/channelconfig
This commit moves common/channelconfig imported from fabric into a local package, including tests. Signed-off-by: Marcus Brandenburger <bur@zurich.ibm.com>
1 parent 35a0bd4 commit 256479e

37 files changed

+3189
-65
lines changed

go.mod

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ require (
2121
github.com/grpc-ecosystem/go-grpc-middleware v1.4.0
2222
github.com/hyperledger/fabric v1.4.0-rc1.0.20250510200036-435a7f1a780a
2323
github.com/hyperledger/fabric-chaincode-go/v2 v2.3.0
24+
github.com/hyperledger/fabric-config v0.3.0
2425
github.com/hyperledger/fabric-contract-api-go/v2 v2.2.0
2526
github.com/hyperledger/fabric-lib-go v1.1.3-0.20240523144151-25edd1eaf5f5
2627
github.com/hyperledger/fabric-protos-go-apiv2 v0.3.7
@@ -101,7 +102,7 @@ require (
101102
github.com/containerd/errdefs v1.0.0
102103
github.com/containerd/errdefs/pkg v0.3.0 // indirect
103104
github.com/containerd/log v0.1.0 // indirect
104-
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
105+
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc
105106
github.com/davidlazar/go-crypto v0.0.0-20200604182044-b73af7476f6c // indirect
106107
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.4.0 // indirect
107108
github.com/distribution/reference v0.6.0 // indirect
@@ -165,7 +166,7 @@ require (
165166
github.com/klauspost/compress v1.18.0 // indirect
166167
github.com/klauspost/cpuid/v2 v2.3.0 // indirect
167168
github.com/koron/go-ssdp v0.0.6 // indirect
168-
github.com/kr/pretty v0.3.1 // indirect
169+
github.com/kr/pretty v0.3.1
169170
github.com/kr/text v0.2.0 // indirect
170171
github.com/leodido/go-urn v1.4.0 // indirect
171172
github.com/libp2p/go-buffer-pool v0.1.0 // indirect

platform/fabric/core/generic/committer/config.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -138,11 +138,6 @@ func (c *Committer) CommitConfig(ctx context.Context, blockNumber driver.BlockNu
138138
return errors.Errorf("invalid configtx's [%s] status [%d]", txID, vc)
139139
}
140140

141-
// validate config as a dry update of the membership service
142-
if err := c.MembershipService.DryUpdate(env); err != nil {
143-
return errors.Wrapf(err, "config update error, block number [%d]", blockNumber)
144-
}
145-
146141
// when validation passes, we can commit the config transaction
147142
if err := c.commitConfig(ctx, txID, blockNumber, txNum, raw); err != nil {
148143
return errors.Wrapf(err, "failed committing configtx to the vault")
Lines changed: 230 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,230 @@
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+
}
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
/*
2+
Copyright IBM Corp. 2017 All Rights Reserved.
3+
4+
SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
package channelconfig
8+
9+
import (
10+
"github.com/hyperledger-labs/fabric-smart-client/pkg/utils/errors"
11+
cb "github.com/hyperledger/fabric-protos-go-apiv2/common"
12+
pb "github.com/hyperledger/fabric-protos-go-apiv2/peer"
13+
)
14+
15+
const (
16+
// ApplicationGroupKey is the group name for the Application config
17+
ApplicationGroupKey = "Application"
18+
19+
// ACLsKey is the name of the ACLs config
20+
ACLsKey = "ACLs"
21+
)
22+
23+
// ApplicationProtos is used as the source of the ApplicationConfig
24+
type ApplicationProtos struct {
25+
ACLs *pb.ACLs
26+
Capabilities *cb.Capabilities
27+
}
28+
29+
// ApplicationConfig implements the Application interface
30+
type ApplicationConfig struct {
31+
applicationOrgs map[string]ApplicationOrg
32+
protos *ApplicationProtos
33+
}
34+
35+
// NewApplicationConfig creates config from an Application config group
36+
func NewApplicationConfig(appGroup *cb.ConfigGroup, mspConfig *MSPConfigHandler) (*ApplicationConfig, error) {
37+
ac := &ApplicationConfig{
38+
applicationOrgs: make(map[string]ApplicationOrg),
39+
protos: &ApplicationProtos{},
40+
}
41+
42+
if err := DeserializeProtoValuesFromGroup(appGroup, ac.protos); err != nil {
43+
return nil, errors.Wrap(err, "failed to deserialize values")
44+
}
45+
46+
var err error
47+
for orgName, orgGroup := range appGroup.Groups {
48+
ac.applicationOrgs[orgName], err = NewApplicationOrgConfig(orgName, orgGroup, mspConfig)
49+
if err != nil {
50+
return nil, err
51+
}
52+
}
53+
54+
return ac, nil
55+
}
56+
57+
// Organizations returns a map of org ID to ApplicationOrg
58+
func (ac *ApplicationConfig) Organizations() map[string]ApplicationOrg {
59+
return ac.applicationOrgs
60+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/*
2+
Copyright IBM Corp. 2017 All Rights Reserved.
3+
4+
SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
package channelconfig
8+
9+
import (
10+
"testing"
11+
12+
"github.com/hyperledger-labs/fabric-smart-client/pkg/utils/proto"
13+
"github.com/hyperledger-labs/fabric-smart-client/platform/fabric/core/generic/membership/channelconfig/capabilities"
14+
"github.com/hyperledger-labs/fabric-smart-client/platform/fabric/protoutil"
15+
cb "github.com/hyperledger/fabric-protos-go-apiv2/common"
16+
. "github.com/onsi/gomega"
17+
)
18+
19+
func TestApplicationInterface(t *testing.T) {
20+
_ = Application((*ApplicationConfig)(nil))
21+
}
22+
23+
func TestACL(t *testing.T) {
24+
g := NewGomegaWithT(t)
25+
cgt := &cb.ConfigGroup{
26+
Values: map[string]*cb.ConfigValue{
27+
ACLsKey: {
28+
Value: protoutil.MarshalOrPanic(
29+
ACLValues(map[string]string{}).Value(),
30+
),
31+
},
32+
CapabilitiesKey: {
33+
Value: protoutil.MarshalOrPanic(
34+
CapabilitiesValue(map[string]bool{
35+
capabilities.ApplicationV1_2: true,
36+
}).Value(),
37+
),
38+
},
39+
},
40+
}
41+
42+
t.Run("Success", func(t *testing.T) {
43+
cg := proto.Clone(cgt).(*cb.ConfigGroup)
44+
_, err := NewApplicationConfig(proto.Clone(cg).(*cb.ConfigGroup), nil)
45+
g.Expect(err).NotTo(HaveOccurred())
46+
})
47+
}

0 commit comments

Comments
 (0)