diff --git a/cmd/configtxgen/main.go b/cmd/configtxgen/main.go index 26d45e423d2..a0c4dcb9c1e 100644 --- a/cmd/configtxgen/main.go +++ b/cmd/configtxgen/main.go @@ -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) } diff --git a/cmd/configtxgen/main_test.go b/cmd/configtxgen/main_test.go index 20c880f4e82..d9cf5673041 100644 --- a/cmd/configtxgen/main_test.go +++ b/cmd/configtxgen/main_test.go @@ -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) { diff --git a/common/channelconfig/realconfig_test.go b/common/channelconfig/realconfig_test.go index 11091122a88..5e5decae465 100644 --- a/common/channelconfig/realconfig_test.go +++ b/common/channelconfig/realconfig_test.go @@ -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()) @@ -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) @@ -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) diff --git a/common/deliverclient/blocksprovider/bft_deliverer_test.go b/common/deliverclient/blocksprovider/bft_deliverer_test.go index 8237cb09d57..6b0184a6db6 100644 --- a/common/deliverclient/blocksprovider/bft_deliverer_test.go +++ b/common/deliverclient/blocksprovider/bft_deliverer_test.go @@ -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") diff --git a/common/deliverclient/blocksprovider/deliverer_test.go b/common/deliverclient/blocksprovider/deliverer_test.go index a6fd93bba13..c1d9cc8422f 100644 --- a/common/deliverclient/blocksprovider/deliverer_test.go +++ b/common/deliverclient/blocksprovider/deliverer_test.go @@ -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)) @@ -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)) @@ -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)) @@ -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)) }) }) diff --git a/internal/configtxgen/encoder/encoder.go b/internal/configtxgen/encoder/encoder.go index 706c20b54f4..929db6711e0 100644 --- a/internal/configtxgen/encoder/encoder.go +++ b/internal/configtxgen/encoder/encoder.go @@ -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") } @@ -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 @@ -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 diff --git a/internal/configtxgen/encoder/encoder_test.go b/internal/configtxgen/encoder/encoder_test.go index c773adbbf8b..b9ff743710a 100644 --- a/internal/configtxgen/encoder/encoder_test.go +++ b/internal/configtxgen/encoder/encoder_test.go @@ -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()) @@ -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)) @@ -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()) }) }) @@ -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()) }) @@ -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()) }) }) @@ -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")) }) })