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 27, 2024
1 parent d408037 commit ed0cb85
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 21 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
5 changes: 2 additions & 3 deletions common/channelconfig/realconfig_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ func TestWithRealConfigtx(t *testing.T) {
require.NoError(t, err)
}

// TODO: maybe add more test cases
func TestOrgSpecificOrdererEndpoints(t *testing.T) {
t.Run("could not create channel orderer config with empty organization endpoints", func(t *testing.T) {
conf := genesisconfig.Load(genesisconfig.SampleDevModeSoloProfile, configtest.GetDevConfigDir())
Expand All @@ -56,7 +55,7 @@ func TestOrgSpecificOrdererEndpoints(t *testing.T) {

cg, err := encoder.NewChannelGroup(conf)
require.Nil(t, cg)
require.EqualError(t, err, "could not create orderer group: failed to create orderer org: orderer endpoints for organization SampleOrg are missing and must be cofigured")
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")

conf.Orderer.Organizations[0].OrdererEndpoints = []string{"127.0.0.1:7050"}
cg, err = encoder.NewChannelGroup(conf)
Expand All @@ -68,7 +67,7 @@ func TestOrgSpecificOrdererEndpoints(t *testing.T) {
require.NoError(t, err)
})

t.Run("With_V2_Capability", func(t *testing.T) {
t.Run("With V2_0 Capability", func(t *testing.T) {
conf := genesisconfig.Load(genesisconfig.SampleDevModeSoloProfile, configtest.GetDevConfigDir())
conf.Capabilities = map[string]bool{"V2_0": true}
require.NotEmpty(t, conf.Orderer.Organizations[0].OrdererEndpoints)
Expand Down
2 changes: 1 addition & 1 deletion common/deliverclient/blocksprovider/bft_deliverer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -636,7 +636,7 @@ func TestBFTDeliverer_DeliverRetries(t *testing.T) {
setup.fakeDeliverStreamer.DeliverReturns(nil, fmt.Errorf("deliver-error"))

setup.start()
setup.gWithT.Eventually(setup.fakeDialer.DialCallCount).Should(BeNumerically(">=", 40))
setup.gWithT.Eventually(setup.fakeDialer.DialCallCount, 10*time.Second, 100*time.Millisecond).Should(BeNumerically(">=", 40))
setup.stop()

t.Log("Exponential backoff after every round, with saturation of 10s")
Expand Down
8 changes: 4 additions & 4 deletions common/deliverclient/blocksprovider/deliverer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ var _ = Describe("CFT-Deliverer", func() {
})

It("hits the maximum sleep time value in an exponential fashion and retries until exceeding the max retry duration", func() {
Eventually(fakeDurationExceededHandler.DurationExceededHandlerCallCount, 5*time.Second).Should(BeNumerically(">", 0))
Eventually(fakeDurationExceededHandler.DurationExceededHandlerCallCount, 10*time.Second).Should(BeNumerically(">", 0))
Eventually(endC).Should(BeClosed())
Eventually(fakeSleeper.SleepCallCount, 5*time.Second).Should(Equal(380))
Expect(fakeSleeper.SleepArgsForCall(25)).To(Equal(9539 * time.Millisecond))
Expand Down Expand Up @@ -381,7 +381,7 @@ var _ = Describe("CFT-Deliverer", func() {
})

It("hits the maximum sleep time value in an exponential fashion and retries but does not exceed the max retry duration", func() {
Eventually(fakeSleeper.SleepCallCount, 10*time.Second).Should(Equal(897))
Eventually(fakeSleeper.SleepCallCount, 20*time.Second).Should(Equal(897))
Expect(fakeSleeper.SleepArgsForCall(0)).To(Equal(100 * time.Millisecond))
Expect(fakeSleeper.SleepArgsForCall(25)).To(Equal(9539 * time.Millisecond))
Expect(fakeSleeper.SleepArgsForCall(26)).To(Equal(10 * time.Second))
Expand All @@ -403,7 +403,7 @@ var _ = Describe("CFT-Deliverer", func() {
})

It("hits the maximum sleep time value in an exponential fashion and retries indefinitely", func() {
Eventually(fakeSleeper.SleepCallCount, 5*time.Second).Should(Equal(500))
Eventually(fakeSleeper.SleepCallCount, 20*time.Second).Should(Equal(500))
Expect(fakeSleeper.SleepArgsForCall(25)).To(Equal(9539 * time.Millisecond))
Expect(fakeSleeper.SleepArgsForCall(26)).To(Equal(10 * time.Second))
Expect(fakeSleeper.SleepArgsForCall(27)).To(Equal(10 * time.Second))
Expand Down Expand Up @@ -707,7 +707,7 @@ var _ = Describe("CFT-Deliverer", func() {
Expect(len(orgsAddresses)).To(Equal(1))
orgAddr, ok := orgsAddresses["SampleOrg"]
Expect(ok).To(BeTrue())
Expect(orgAddr.Addresses).To(Equal([]string{"127.0.0.1:7050"}))
Expect(orgAddr.Addresses).To(Equal([]string{"127.0.0.1:7050", "127.0.0.1:7051", "127.0.0.1:7052"}))
Expect(len(orgAddr.RootCerts)).To(Equal(2))
})
})
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 ed0cb85

Please sign in to comment.