Skip to content

Commit 85447af

Browse files
committed
fix: address review feedback on PR #113
- Check ok from OrdererConfig() and return error when false ('no orderer section in config block') - Remove V3_0 capability gating: reject global orderer endpoints unconditionally in NewOrdererGroup - Remove V3_0 capability gating: require org endpoints unconditionally in NewOrdererOrgGroup - Keep channelCapabilities parameter for future reuse - Update tests for new unconditional validation behavior Signed-off-by: Senthilnathan <cendhu@gmail.com>
1 parent d971c17 commit 85447af

4 files changed

Lines changed: 20 additions & 26 deletions

File tree

common/channelconfig/realconfig_test.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,9 @@ func TestOrgSpecificOrdererEndpoints(t *testing.T) {
6161

6262
cg, err := configtxgen.NewChannelGroup(conf)
6363
require.Nil(t, cg)
64-
require.EqualError(t, err, "could not create orderer group: failed to create orderer org: orderer endpoints for organization SampleOrg are missing and must be configured when capability V3_0 is enabled")
64+
require.EqualError(t, err, "could not create orderer group: "+
65+
"failed to create orderer org: "+
66+
"orderer endpoints for organization SampleOrg are missing and must be configured")
6567

6668
conf.Orderer.Organizations[0].OrdererEndpoints = []*types.OrdererEndpoint{{Host: "127.0.0.1", Port: 7050}}
6769
cg, err = configtxgen.NewChannelGroup(conf)
@@ -102,6 +104,7 @@ func TestOrgSpecificOrdererEndpoints(t *testing.T) {
102104
require.NotEmpty(t, conf.Orderer.Addresses)
103105

104106
_, err := configtxgen.NewChannelGroup(conf)
105-
require.EqualError(t, err, "could not create orderer group: global orderer endpoints exist, but can not be used with V3_0 capability: [globalAddress]")
107+
require.EqualError(t, err, "could not create orderer group: "+
108+
"global orderer endpoints exist, but are not supported: [globalAddress]")
106109
})
107110
}

common/deliverclient/verifier_assembler.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,12 @@ func (bva *BlockVerifierAssembler) VerifierFromConfig(configuration *common.Conf
4343
}
4444

4545
cfg, ok := bundle.OrdererConfig()
46-
bftEnabled := ok && (cfg.ConsensusType() == "BFT" || cfg.ConsensusType() == "arma")
46+
if !ok {
47+
err := errors.New("no orderer section in config block")
48+
return createErrorFunc(err), err
49+
}
50+
51+
bftEnabled := cfg.ConsensusType() == "BFT" || cfg.ConsensusType() == "arma"
4752

4853
var consenters []*common.Consenter
4954
if bftEnabled {

tools/configtxgen/encoder.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -185,8 +185,8 @@ func NewChannelGroup(conf *Profile) (*cb.ConfigGroup, error) {
185185
//
186186
//nolint:gocognit // cognitive complexity 23.
187187
func NewOrdererGroup(conf *Orderer, channelCapabilities map[string]bool) (*cb.ConfigGroup, error) {
188-
if len(conf.Addresses) > 0 && channelCapabilities["V3_0"] {
189-
return nil, errors.Errorf("global orderer endpoints exist, but can not be used with V3_0 capability: %v", conf.Addresses)
188+
if len(conf.Addresses) > 0 {
189+
return nil, errors.Errorf("global orderer endpoints exist, but are not supported: %v", conf.Addresses)
190190
}
191191

192192
ordererGroup := protoutil.NewConfigGroup()
@@ -330,7 +330,6 @@ func NewConsortiumOrgGroup(conf *Organization) (*cb.ConfigGroup, error) {
330330

331331
// NewOrdererOrgGroup returns an orderer org component of the channel configuration. It defines the crypto material for the
332332
// organization (its MSP). It sets the mod_policy of all elements to "Admins".
333-
// channelCapabilities map[string]bool
334333
func NewOrdererOrgGroup(conf *Organization, channelCapabilities map[string]bool) (*cb.ConfigGroup, error) {
335334
ordererOrgGroup := protoutil.NewConfigGroup()
336335
ordererOrgGroup.ModPolicy = channelconfig.AdminsPolicyKey
@@ -356,8 +355,8 @@ func NewOrdererOrgGroup(conf *Organization, channelCapabilities map[string]bool)
356355
endpoints[i] = e.String()
357356
}
358357
addValue(ordererOrgGroup, channelconfig.EndpointsValue(endpoints), channelconfig.AdminsPolicyKey)
359-
} else if channelCapabilities["V3_0"] {
360-
return nil, errors.Errorf("orderer endpoints for organization %s are missing and must be configured when capability V3_0 is enabled", conf.Name)
358+
} else {
359+
return nil, errors.Errorf("orderer endpoints for organization %s are missing and must be configured", conf.Name)
361360
}
362361

363362
return ordererOrgGroup, nil

tools/configtxgen/encoder_test.go

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -521,14 +521,7 @@ var _ = ginkgo.Describe("Encoder", func() {
521521
ginkgo.It("wraps and returns the error", func() {
522522
_, err := NewOrdererGroup(conf, channelCapabilities)
523523
gomega.Expect(err).To(gomega.MatchError("global orderer endpoints exist, " +
524-
"but can not be used with V3_0 capability: [addr1 addr2]"))
525-
})
526-
527-
ginkgo.It("is permitted when V3_0 is false", func() {
528-
delete(channelCapabilities, "V3_0")
529-
channelCapabilities["V2_0"] = true
530-
_, err := NewOrdererGroup(conf, channelCapabilities)
531-
gomega.Expect(err).ToNot(gomega.HaveOccurred())
524+
"but are not supported: [addr1 addr2]"))
532525
})
533526
})
534527
})
@@ -727,17 +720,11 @@ var _ = ginkgo.Describe("Encoder", func() {
727720
conf.OrdererEndpoints = []*types.OrdererEndpoint{}
728721
})
729722

730-
ginkgo.It("does not include the endpoints in the config group with v2_0", func() {
731-
channelCapabilities := map[string]bool{"V2_0": true}
732-
cg, err := NewOrdererOrgGroup(conf, channelCapabilities)
733-
gomega.Expect(err).NotTo(gomega.HaveOccurred())
734-
gomega.Expect(cg.Values["Endpoints"]).To(gomega.BeNil())
735-
})
736-
737-
ginkgo.It("emits an error with v3_0", func() {
738-
channelCapabilities := map[string]bool{"V3_0": true}
739-
cg, err := NewOrdererOrgGroup(conf, channelCapabilities)
723+
ginkgo.It("emits an error when endpoints are missing", func() {
724+
cg, err := NewOrdererOrgGroup(conf, nil)
740725
gomega.Expect(err).To(gomega.HaveOccurred())
726+
gomega.Expect(err).To(gomega.MatchError("orderer endpoints for organization SampleOrg " +
727+
"are missing and must be configured"))
741728
gomega.Expect(cg).To(gomega.BeNil())
742729
})
743730
})

0 commit comments

Comments
 (0)