Skip to content

Commit

Permalink
add capabilities to encoder.NewOrdererOrgGroup
Browse files Browse the repository at this point in the history
Signed-off-by: Yoav Tock <[email protected]>
  • Loading branch information
tock-ibm committed May 26, 2024
1 parent 7d6a686 commit 36639fa
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 13 deletions.
3 changes: 2 additions & 1 deletion cmd/configtxgen/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,8 @@ func doPrintOrg(t *genesisconfig.TopLevel, printOrg string) error {
if org.Name == printOrg {
if len(org.OrdererEndpoints) > 0 {
// An Orderer OrgGroup
og, err := encoder.NewOrdererOrgGroup(org)
channelCapabilities := t.Capabilities["Channel"]
og, err := encoder.NewOrdererOrgGroup(org, channelCapabilities)
if err != nil {
return errors.Wrapf(err, "bad org definition for org %s", org.Name)
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/configtxgen/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ func TestBftOrdererTypeWithoutV3CapabilitiesShouldRaiseAnError(t *testing.T) {
config.Capabilities["V3_0"] = false

// ### Act & Assert
require.EqualError(t, doOutputBlock(config, "testChannelId", blockDest), "could not create bootstrapper: could not create channel group: could not create orderer group: orderer type BFT must be used with V3_0 capability")
require.EqualError(t, doOutputBlock(config, "testChannelId", blockDest), "could not create bootstrapper: could not create channel group: could not create orderer group: orderer type BFT must be used with V3_0 channel capability: map[V3_0:false]")
}

func TestBftOrdererTypeWithV3CapabilitiesShouldNotRaiseAnError(t *testing.T) {
Expand Down
9 changes: 5 additions & 4 deletions internal/configtxgen/encoder/encoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ func NewOrdererGroup(conf *genesisconfig.Orderer, channelCapabilities map[string

for _, org := range conf.Organizations {
var err error
ordererGroup.Groups[org.Name], err = NewOrdererOrgGroup(org)
ordererGroup.Groups[org.Name], err = NewOrdererOrgGroup(org, channelCapabilities)
if err != nil {
return nil, errors.Wrap(err, "failed to create orderer org")
}
Expand Down Expand Up @@ -309,7 +309,8 @@ func NewConsortiumOrgGroup(conf *genesisconfig.Organization) (*cb.ConfigGroup, e

// NewOrdererOrgGroup returns an orderer org component of the channel configuration. It defines the crypto material for the
// organization (its MSP). It sets the mod_policy of all elements to "Admins".
func NewOrdererOrgGroup(conf *genesisconfig.Organization) (*cb.ConfigGroup, error) {
// channelCapabilities map[string]bool
func NewOrdererOrgGroup(conf *genesisconfig.Organization, channelCapabilities map[string]bool) (*cb.ConfigGroup, error) {
ordererOrgGroup := protoutil.NewConfigGroup()
ordererOrgGroup.ModPolicy = channelconfig.AdminsPolicyKey

Expand All @@ -330,8 +331,8 @@ func NewOrdererOrgGroup(conf *genesisconfig.Organization) (*cb.ConfigGroup, erro

if len(conf.OrdererEndpoints) > 0 {
addValue(ordererOrgGroup, channelconfig.EndpointsValue(conf.OrdererEndpoints), channelconfig.AdminsPolicyKey)
} else {
return nil, errors.Errorf("orderer endpoints for organization %s are missing and must be cofigured", conf.Name)
} else if channelCapabilities["V3_0"] {
return nil, errors.Errorf("orderer endpoints for organization %s are missing and must be configured when capability V3_0 is enabled", conf.Name)
}

return ordererOrgGroup, nil
Expand Down
22 changes: 15 additions & 7 deletions internal/configtxgen/encoder/encoder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -675,7 +675,7 @@ var _ = Describe("Encoder", func() {
})

It("translates the config into a config group", func() {
cg, err := encoder.NewOrdererOrgGroup(conf)
cg, err := encoder.NewOrdererOrgGroup(conf, nil)
Expect(err).NotTo(HaveOccurred())
Expect(len(cg.Values)).To(Equal(2))
Expect(cg.Values["MSP"]).NotTo(BeNil())
Expand All @@ -692,7 +692,7 @@ var _ = Describe("Encoder", func() {
})

It("returns an empty org group with mod policy set", func() {
cg, err := encoder.NewOrdererOrgGroup(conf)
cg, err := encoder.NewOrdererOrgGroup(conf, nil)
Expect(err).NotTo(HaveOccurred())
Expect(len(cg.Values)).To(Equal(0))
Expect(len(cg.Policies)).To(Equal(0))
Expand All @@ -704,7 +704,7 @@ var _ = Describe("Encoder", func() {
})

It("returns without error", func() {
_, err := encoder.NewOrdererOrgGroup(conf)
_, err := encoder.NewOrdererOrgGroup(conf, nil)
Expect(err).NotTo(HaveOccurred())
})
})
Expand All @@ -715,8 +715,16 @@ var _ = Describe("Encoder", func() {
conf.OrdererEndpoints = []string{}
})

It("does not include the endpoints in the config group", func() {
cg, err := encoder.NewOrdererOrgGroup(conf)
It("does not include the endpoints in the config group with v2_0", func() {
channelCapabilities := map[string]bool{"V2_0": true}
cg, err := encoder.NewOrdererOrgGroup(conf, channelCapabilities)
Expect(err).NotTo(HaveOccurred())
Expect(cg.Values["Endpoints"]).To(BeNil())
})

It("emits an error with v3_0", func() {
channelCapabilities := map[string]bool{"V3_0": true}
cg, err := encoder.NewOrdererOrgGroup(conf, channelCapabilities)
Expect(err).To(HaveOccurred())
Expect(cg).To(BeNil())
})
Expand All @@ -728,7 +736,7 @@ var _ = Describe("Encoder", func() {
})

It("does not produce an error", func() {
_, err := encoder.NewOrdererOrgGroup(conf)
_, err := encoder.NewOrdererOrgGroup(conf, nil)
Expect(err).NotTo(HaveOccurred())
})
})
Expand All @@ -739,7 +747,7 @@ var _ = Describe("Encoder", func() {
})

It("wraps and returns the error", func() {
_, err := encoder.NewOrdererOrgGroup(conf)
_, err := encoder.NewOrdererOrgGroup(conf, nil)
Expect(err).To(MatchError("error adding policies to orderer org group 'SampleOrg': invalid implicit meta policy rule 'garbage': expected two space separated tokens, but got 1"))
})
})
Expand Down

0 comments on commit 36639fa

Please sign in to comment.