Skip to content

Commit

Permalink
fix configtxgen
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 13, 2024
1 parent 5cb9196 commit f8f280e
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 12 deletions.
21 changes: 17 additions & 4 deletions cmd/configtxgen/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (

"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-lib-go/bccsp/factory"
"github.com/hyperledger/fabric-lib-go/common/flogging"
cb "github.com/hyperledger/fabric-protos-go/common"
Expand Down Expand Up @@ -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
Expand Down
18 changes: 10 additions & 8 deletions integration/lifecycle/lifecycle_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,14 @@ package lifecycle

import (
"bytes"
"encoding/json"
"os"
"path/filepath"
"syscall"

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"
Expand Down Expand Up @@ -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{
Expand All @@ -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")
Expand Down

0 comments on commit f8f280e

Please sign in to comment.