From 0a60cd23b9bada9056d7eba2dce2ef7a870034c8 Mon Sep 17 00:00:00 2001 From: Yoav Tock Date: Mon, 13 May 2024 10:23:49 +0300 Subject: [PATCH] fix configtxgen Signed-off-by: Yoav Tock --- cmd/configtxgen/main.go | 21 +++++++++++++++++---- integration/lifecycle/lifecycle_test.go | 18 ++++++++++-------- 2 files changed, 27 insertions(+), 12 deletions(-) diff --git a/cmd/configtxgen/main.go b/cmd/configtxgen/main.go index 59359fde5c2..16f1ee47cb4 100644 --- a/cmd/configtxgen/main.go +++ b/cmd/configtxgen/main.go @@ -9,6 +9,7 @@ package main import ( "flag" "fmt" + "github.com/hyperledger/fabric-config/protolator/protoext/peerext" "os" "path/filepath" "strings" @@ -118,13 +119,25 @@ func doInspectChannelCreateTx(inspectChannelCreateTx string) error { func doPrintOrg(t *genesisconfig.TopLevel, printOrg string) error { for _, org := range t.Organizations { if org.Name == printOrg { - org.OrdererEndpoints = []string{"127.0.0.1:7050"} - og, err := encoder.NewOrdererOrgGroup(org) + if len(org.OrdererEndpoints) > 0 { + // An Orderer OrgGroup + og, err := encoder.NewOrdererOrgGroup(org) + if err != nil { + return errors.Wrapf(err, "bad org definition for org %s", org.Name) + } + + if err := protolator.DeepMarshalJSON(os.Stdout, &ordererext.DynamicOrdererOrgGroup{ConfigGroup: og}); err != nil { + return errors.Wrapf(err, "malformed org definition for org: %s", org.Name) + } + return nil + } + + // Otherwise assume it is an Application OrgGroup, where the encoder is not strict whether anchor peers exist or not + ag, err := encoder.NewApplicationOrgGroup(org) if err != nil { return errors.Wrapf(err, "bad org definition for org %s", org.Name) } - - if err := protolator.DeepMarshalJSON(os.Stdout, &ordererext.DynamicOrdererOrgGroup{ConfigGroup: og}); err != nil { + if err := protolator.DeepMarshalJSON(os.Stdout, &peerext.DynamicApplicationOrgGroup{ConfigGroup: ag}); err != nil { return errors.Wrapf(err, "malformed org definition for org: %s", org.Name) } return nil diff --git a/integration/lifecycle/lifecycle_test.go b/integration/lifecycle/lifecycle_test.go index 597a8365722..aa69ee61d0f 100644 --- a/integration/lifecycle/lifecycle_test.go +++ b/integration/lifecycle/lifecycle_test.go @@ -8,7 +8,6 @@ package lifecycle import ( "bytes" - "encoding/json" "os" "path/filepath" "syscall" @@ -16,7 +15,7 @@ import ( docker "github.com/fsouza/go-dockerclient" "github.com/golang/protobuf/proto" "github.com/hyperledger/fabric-config/protolator" - "github.com/hyperledger/fabric-config/protolator/protoext/ordererext" + "github.com/hyperledger/fabric-config/protolator/protoext/peerext" "github.com/hyperledger/fabric-protos-go/common" "github.com/hyperledger/fabric/integration/channelparticipation" "github.com/hyperledger/fabric/integration/nwo" @@ -296,10 +295,10 @@ var _ = Describe("Lifecycle", func() { By("updating the channel config to include org3") // get the current channel config currentConfig := nwo.GetConfig(network, testPeers[0], orderer, "testchannel") - updatedConfig := proto.Clone(currentConfig).(*common.Config) + //jsonObj, _ := json.MarshalIndent(currentConfig, "", " ") + //_ = os.WriteFile("currentConfig.json", jsonObj, 0o644) - jsonObj, _ := json.MarshalIndent(updatedConfig, "", " ") - _ = os.WriteFile("updatedConfig.json", jsonObj, 0o644) + updatedConfig := proto.Clone(currentConfig).(*common.Config) // get the configtx info for org3 sess, err = network.ConfigTxGen(commands.PrintOrg{ @@ -308,16 +307,19 @@ var _ = Describe("Lifecycle", func() { }) Expect(err).NotTo(HaveOccurred()) Eventually(sess, network.EventuallyTimeout).Should(gexec.Exit(0)) - org3Group := &ordererext.DynamicOrdererOrgGroup{ConfigGroup: &common.ConfigGroup{}} + org3Group := &peerext.DynamicApplicationOrgGroup{ConfigGroup: &common.ConfigGroup{}} err = protolator.DeepUnmarshalJSON(bytes.NewBuffer(sess.Out.Contents()), org3Group) Expect(err).NotTo(HaveOccurred()) // delete(org3Group.Values, "Endpoints") - jsonObj, _ = json.MarshalIndent(org3Group, "", " ") - _ = os.WriteFile("org3Group.json", jsonObj, 0o644) + //jsonObj, _ = json.MarshalIndent(org3Group, "", " ") + //_ = os.WriteFile("org3Group.json", jsonObj, 0o644) // update the channel config to include org3 updatedConfig.ChannelGroup.Groups["Application"].Groups["Org3"] = org3Group.ConfigGroup + //jsonObj, _ = json.MarshalIndent(updatedConfig, "", " ") + //_ = os.WriteFile("updatedConfig.json", jsonObj, 0o644) + nwo.UpdateConfig(network, orderer, "testchannel", currentConfig, updatedConfig, true, testPeers[0], testPeers...) By("joining the org3 peers to the channel")