Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Orderer v3: Remove system channel usage from integration tests: configtx #3905

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
111 changes: 28 additions & 83 deletions integration/configtx/configtx_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,22 @@ import (
"github.com/golang/protobuf/proto"
"github.com/hyperledger/fabric-config/configtx"
"github.com/hyperledger/fabric-protos-go/common"
"github.com/hyperledger/fabric/integration/channelparticipation"
"github.com/hyperledger/fabric/integration/nwo"
"github.com/hyperledger/fabric/integration/nwo/commands"
"github.com/hyperledger/fabric/integration/ordererclient"
"github.com/tedsuo/ifrit"

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"github.com/tedsuo/ifrit"
ginkgomon "github.com/tedsuo/ifrit/ginkgomon_v2"
)

var _ = Describe("ConfigTx", func() {
var (
client *docker.Client
testDir string
network *nwo.Network
process ifrit.Process
client *docker.Client
testDir string
network *nwo.Network
ordererRunner *ginkgomon.Runner
ordererProcess, peerProcess ifrit.Process
)

BeforeEach(func() {
Expand All @@ -44,23 +45,33 @@ var _ = Describe("ConfigTx", func() {
client, err = docker.NewClientFromEnv()
Expect(err).NotTo(HaveOccurred())

network = nwo.New(nwo.BasicEtcdRaft(), testDir, client, StartPort(), components)
config := nwo.BasicEtcdRaftNoSysChan()
// disable all anchor peers
for _, p := range config.Peers {
for _, pc := range p.Channels {
pc.Anchor = false
}
}
network = nwo.New(config, testDir, client, StartPort(), components)

// Generate config
network.GenerateConfigTree()

// bootstrap the network
network.Bootstrap()

networkRunner := network.NetworkGroupRunner()
process = ifrit.Invoke(networkRunner)
Eventually(process.Ready(), network.EventuallyTimeout).Should(BeClosed())
// Start all the fabric processes
ordererRunner, ordererProcess, peerProcess = network.StartSingleOrdererNetwork("orderer")
})

AfterEach(func() {
if process != nil {
process.Signal(syscall.SIGTERM)
Eventually(process.Wait(), network.EventuallyTimeout).Should(Receive())
if ordererProcess != nil {
ordererProcess.Signal(syscall.SIGTERM)
Eventually(ordererProcess.Wait(), network.EventuallyTimeout).Should(Receive())
}
if peerProcess != nil {
peerProcess.Signal(syscall.SIGTERM)
Eventually(peerProcess.Wait(), network.EventuallyTimeout).Should(Receive())
}
if network != nil {
network.Cleanup()
Expand All @@ -71,76 +82,9 @@ var _ = Describe("ConfigTx", func() {

It("creates channels and updates them using fabric-config/configtx", func() {
orderer := network.Orderer("orderer")
org1peer0 := network.Peer("Org1", "peer0")

By("setting up the channel")
channel := configtx.Channel{
Consortium: "SampleConsortium",
Application: configtx.Application{
Organizations: []configtx.Organization{
{
Name: "Org1",
},
{
Name: "Org2",
},
},
Capabilities: []string{"V1_3"},
ACLs: map[string]string{"event/Block": "/Channel/Application/Readers"},
Policies: map[string]configtx.Policy{
configtx.ReadersPolicyKey: {
Type: configtx.ImplicitMetaPolicyType,
Rule: "ANY Readers",
},
configtx.WritersPolicyKey: {
Type: configtx.ImplicitMetaPolicyType,
Rule: "ANY Writers",
},
configtx.AdminsPolicyKey: {
Type: configtx.ImplicitMetaPolicyType,
Rule: "MAJORITY Admins",
},
configtx.EndorsementPolicyKey: {
Type: configtx.ImplicitMetaPolicyType,
Rule: "MAJORITY Endorsement",
},
configtx.LifecycleEndorsementPolicyKey: {
Type: configtx.ImplicitMetaPolicyType,
Rule: "MAJORITY Endorsement",
},
},
},
}

channelID := "testchannel"
createChannelUpdate, err := configtx.NewMarshaledCreateChannelTx(channel, channelID)
Expect(err).NotTo(HaveOccurred())

envelope, err := configtx.NewEnvelope(createChannelUpdate)
Expect(err).NotTo(HaveOccurred())
envBytes, err := proto.Marshal(envelope)
Expect(err).NotTo(HaveOccurred())
channelCreateTxPath := network.CreateChannelTxPath("testchannel")
err = ioutil.WriteFile(channelCreateTxPath, envBytes, 0o644)
Expect(err).NotTo(HaveOccurred())

By("creating the channel")
createChannel := func() int {
sess, err := network.PeerAdminSession(org1peer0, commands.ChannelCreate{
ChannelID: "testchannel",
Orderer: network.OrdererAddress(orderer, nwo.ListenPort),
File: channelCreateTxPath,
OutputBlock: "/dev/null",
ClientAuth: network.ClientAuthRequired,
})
Expect(err).NotTo(HaveOccurred())
return sess.Wait(network.EventuallyTimeout).ExitCode()
}
Eventually(createChannel, network.EventuallyTimeout).Should(Equal(0))

By("joining all peers to the channel")
testPeers := network.PeersWithChannel("testchannel")
network.JoinChannel("testchannel", orderer, testPeers...)
channelparticipation.JoinOrdererJoinPeersAppChannel(network, "testchannel", orderer, ordererRunner)

By("getting the current channel config")
org2peer0 := network.Peer("Org2", "peer0")
Expand Down Expand Up @@ -214,6 +158,7 @@ var _ = Describe("ConfigTx", func() {
Expect(err).NotTo(HaveOccurred())

By("creating detached signatures for each peer")
testPeers := network.PeersWithChannel("testchannel")
signingIdentities := make([]configtx.SigningIdentity, len(testPeers))
signatures := make([]*common.ConfigSignature, len(testPeers))
for i, p := range testPeers {
Expand Down Expand Up @@ -249,7 +194,7 @@ var _ = Describe("ConfigTx", func() {
Expect(proto.Equal(c.UpdatedConfig(), updatedChannelConfig)).To(BeTrue())

By("adding the anchor peer for each org")
for _, peer := range network.AnchorsForChannel("testchannel") {
for _, peer := range testPeers {
By("getting the current channel config")
channelConfig = nwo.GetConfig(network, peer, orderer, "testchannel")
c = configtx.New(channelConfig)
Expand Down
26 changes: 12 additions & 14 deletions integration/configtx/consenter_mapping_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,23 @@ package configtx

import (
"io/ioutil"
"os"

"github.com/golang/protobuf/proto"
"github.com/hyperledger/fabric-protos-go/common"
"github.com/hyperledger/fabric/integration/nwo"
"github.com/hyperledger/fabric/internal/configtxgen/encoder"
"github.com/hyperledger/fabric/internal/configtxgen/genesisconfig"
"github.com/hyperledger/fabric/protoutil"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
)

var _ = Describe("ConfigTx ConsenterMapping", func() {
It("generates genesis block and checks it contains the ConsenterMapping", func() {
var err error
It("generates an application channel genesis block and checks it contains the ConsenterMapping", func() {
testDir, err := ioutil.TempDir("", "configtx")
Expect(err).NotTo(HaveOccurred())
defer os.RemoveAll(testDir)

network := nwo.New(nwo.MultiNodeBFT(), testDir, nil, StartPort(), components)

channelName := network.Channels[0].Name
network := nwo.New(nwo.MultiNodeBFTNoSysChan(), testDir, nil, StartPort(), components)

// Generate config
network.GenerateConfigTree()
Expand All @@ -36,15 +33,16 @@ var _ = Describe("ConfigTx ConsenterMapping", func() {
network.Bootstrap()

// check the config transaction in the genesis block contains the ConsenterMapping
sysProfile := genesisconfig.Load("SampleDevModeBFT", network.RootDir)
Expect(sysProfile.Orderer).NotTo(BeNil())
pgen := encoder.New(sysProfile)
genesisBlock := pgen.GenesisBlockForChannel(channelName)
Expect(genesisBlock.GetData().GetData()).NotTo(BeNil())
env, err := protoutil.UnmarshalEnvelope(genesisBlock.Data.Data[0])
// get the genesis block
configBlock := nwo.UnmarshalBlockFromFile(network.OutputBlockPath("testchannel"))
envelope, err := protoutil.GetEnvelopeFromBlock(configBlock.Data.Data[0])
Expect(err).NotTo(HaveOccurred())
payload, err := protoutil.UnmarshalPayload(env.Payload)

// unmarshal the payload bytes
payload, err := protoutil.UnmarshalPayload(envelope.Payload)
Expect(err).NotTo(HaveOccurred())

// unmarshal the config envelope bytes
configEnv, err := protoutil.UnmarshalConfigEnvelope(payload.GetData())
Expect(err).NotTo(HaveOccurred())
group := configEnv.GetConfig().GetChannelGroup().GetGroups()["Orderer"]
Expand Down
3 changes: 0 additions & 3 deletions integration/nwo/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,6 @@ import (
"text/template"
"time"

"github.com/hyperledger/fabric-protos-go/common"
"github.com/hyperledger/fabric/protoutil"

docker "github.com/fsouza/go-dockerclient"
"github.com/golang/protobuf/proto"
"github.com/hyperledger/fabric-protos-go/common"
Expand Down
50 changes: 25 additions & 25 deletions integration/nwo/standard_networks.go
Original file line number Diff line number Diff line change
Expand Up @@ -230,31 +230,6 @@ func MultiNodeEtcdRaft() *Config {
return config
}

func MultiNodeBFT() *Config {
config := BasicConfig()

config.Consensus.Type = "BFT"
config.Orderers = []*Orderer{
{Name: "orderer1", Organization: "OrdererOrg"},
{Name: "orderer2", Organization: "OrdererOrg"},
{Name: "orderer3", Organization: "OrdererOrg"},
}
config.Profiles = []*Profile{
{
Name: "SampleDevModeBFT",
Orderers: []string{"orderer1", "orderer2", "orderer3"},
},
{
Name: "TwoOrgsChannel",
Consortium: "SampleConsortium",
Organizations: []string{"Org1", "Org2"},
},
}
config.SystemChannel.Profile = "SampleDevModeBFT"

return config
}

// Utility methods for tests without the system channel.
// These methods start from BasicConfig() and only use each other progressively.

Expand Down Expand Up @@ -358,3 +333,28 @@ func FullEtcdRaftNoSysChan() *Config {

return config
}

func MultiNodeBFTNoSysChan() *Config {
config := BasicConfig()

config.Consensus.Type = "BFT"
config.Orderers = []*Orderer{
{Name: "orderer1", Organization: "OrdererOrg"},
{Name: "orderer2", Organization: "OrdererOrg"},
{Name: "orderer3", Organization: "OrdererOrg"},
}
config.Profiles = []*Profile{
{
Name: "TwoOrgsAppChannelBFT",
Consortium: "SampleConsortium",
Organizations: []string{"Org1", "Org2"},
Orderers: []string{"orderer1", "orderer2", "orderer3"},
},
}
config.SystemChannel = nil
config.Consensus.ChannelParticipationEnabled = true
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should eventually remove ChannelParticipationEnabled option since it's the only way... both here and in the orderer.yaml

Copy link
Contributor Author

@tock-ibm tock-ibm Jan 11, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is correct. I added a comment about that to the issue #3515

config.Consensus.BootstrapMethod = "none"
config.Channels = []*Channel{{Name: "testchannel", Profile: "TwoOrgsAppChannelBFT"}}

return config
}