Skip to content

Commit

Permalink
[FAB-18127] Chan.Part.API IT: Join as follower (#1861)
Browse files Browse the repository at this point in the history
Signed-off-by: Tiffany Harris <[email protected]>
  • Loading branch information
stephyee authored Oct 2, 2020
1 parent 20eb852 commit fa0213f
Showing 1 changed file with 177 additions and 55 deletions.
232 changes: 177 additions & 55 deletions integration/raft/channel_participation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,21 +141,21 @@ var _ = Describe("ChannelParticipation", func() {
memberRunners := []*ginkgomon.Runner{ordererRunners[0], ordererRunners[1]}
leader := findLeader(memberRunners)

By("ensuring the channel is usable by submitting a transaction to each member")
env := CreateBroadcastEnvelope(network, peer, "participation-trophy", []byte("hello"))
for _, o := range members {
By("submitting transaction to " + o.Name)
expectedChannelInfoPT.Height++
resp, err := ordererclient.Broadcast(network, o, env)
Expect(err).NotTo(HaveOccurred())
Expect(resp.Status).To(Equal(common.Status_SUCCESS))
expectedBlockNumPerChannel := map[string]int{"participation-trophy": int(expectedChannelInfoPT.Height - 1)}
assertBlockReception(expectedBlockNumPerChannel, members, peer, network)
submitTxn(orderer1, peer, network, members, 1, channelparticipation.ChannelInfo{
Name: "participation-trophy",
URL: "/participation/v1/channels/participation-trophy",
Status: "active",
ClusterRelation: "member",
Height: 2,
})

By("checking the channel height")
channelInfo := channelparticipation.ListOne(network, o, "participation-trophy")
Expect(channelInfo).To(Equal(expectedChannelInfoPT))
}
submitTxn(orderer2, peer, network, members, 2, channelparticipation.ChannelInfo{
Name: "participation-trophy",
URL: "/participation/v1/channels/participation-trophy",
Status: "active",
ClusterRelation: "member",
Height: 3,
})

By("joining orderer3 to the channel as a follower")
// make sure we can join using a config block from one of the other orderers
Expand All @@ -171,7 +171,7 @@ var _ = Describe("ChannelParticipation", func() {

By("ensuring orderer3 completes onboarding successfully")
expectedChannelInfoPTFollower.Status = "active"
expectedChannelInfoPTFollower.Height = expectedChannelInfoPT.Height
expectedChannelInfoPTFollower.Height = 3
Eventually(func() channelparticipation.ChannelInfo {
return channelparticipation.ListOne(network, orderer3, "participation-trophy")
}, network.EventuallyTimeout).Should(Equal(expectedChannelInfoPTFollower))
Expand All @@ -185,7 +185,7 @@ var _ = Describe("ChannelParticipation", func() {

By("ensuring orderer3 transitions from follower to member")
// config update above added a block
expectedChannelInfoPT.Height++
expectedChannelInfoPT.Height = 4
Eventually(func() channelparticipation.ChannelInfo {
return channelparticipation.ListOne(network, orderer3, "participation-trophy")
}, network.EventuallyTimeout).Should(Equal(expectedChannelInfoPT))
Expand All @@ -195,12 +195,11 @@ var _ = Describe("ChannelParticipation", func() {
Expect(newLeader).To(Equal(leader))

By("submitting transaction to orderer3 to ensure it is active")
env = CreateBroadcastEnvelope(network, peer, "participation-trophy", []byte("hello-again"))
expectedChannelInfoPT.Height++
env := CreateBroadcastEnvelope(network, peer, "participation-trophy", []byte("hello-again"))
resp, err := ordererclient.Broadcast(network, orderer3, env)
Expect(err).NotTo(HaveOccurred())
Expect(resp.Status).To(Equal(common.Status_SUCCESS))
expectedBlockNumPerChannel := map[string]int{"participation-trophy": int(expectedChannelInfoPT.Height - 1)}
expectedBlockNumPerChannel := map[string]int{"participation-trophy": 4}
assertBlockReception(expectedBlockNumPerChannel, orderers, peer, network)

By("joining orderer1 to another channel as a member")
Expand Down Expand Up @@ -241,21 +240,23 @@ var _ = Describe("ChannelParticipation", func() {
channelparticipation.List(network, orderer1, []string{"another-participation-trophy"})

By("ensuring the channel is still usable by submitting a transaction to each remaining consenter for the channel")
env = CreateBroadcastEnvelope(network, peer, "participation-trophy", []byte("hello"))
orderers = []*nwo.Orderer{orderer2, orderer3}
for _, o := range orderers {
By("submitting transaction to " + o.Name)
expectedChannelInfoPT.Height++
resp, err := ordererclient.Broadcast(network, o, env)
Expect(err).NotTo(HaveOccurred())
Expect(resp.Status).To(Equal(common.Status_SUCCESS))
expectedBlockNumPerChannel := map[string]int{"participation-trophy": int(expectedChannelInfoPT.Height - 1)}
assertBlockReception(expectedBlockNumPerChannel, orderers, peer, network)

By("checking the channel height")
channelInfo = channelparticipation.ListOne(network, o, "participation-trophy")
Expect(channelInfo).To(Equal(expectedChannelInfoPT))
}
submitTxn(orderer2, peer, network, orderers, 5, channelparticipation.ChannelInfo{
Name: "participation-trophy",
URL: "/participation/v1/channels/participation-trophy",
Status: "active",
ClusterRelation: "member",
Height: 6,
})

submitTxn(orderer3, peer, network, orderers, 6, channelparticipation.ChannelInfo{
Name: "participation-trophy",
URL: "/participation/v1/channels/participation-trophy",
Status: "active",
ClusterRelation: "member",
Height: 7,
})

By("attempting to join with an invalid block")
channelparticipationJoinFailure(network, orderer3, "nice-try", &common.Block{}, http.StatusBadRequest, "invalid join block: block is not a config block")
Expand All @@ -277,7 +278,6 @@ var _ = Describe("ChannelParticipation", func() {
orderer2 := network.Orderer("orderer2")
orderer3 := network.Orderer("orderer3")
orderers := []*nwo.Orderer{orderer1, orderer2}
members := []*nwo.Orderer{orderer1, orderer2}
peer := network.Peer("Org1", "peer0")

By("starting two orderers")
Expand All @@ -286,7 +286,7 @@ var _ = Describe("ChannelParticipation", func() {
channelparticipation.List(network, o, nil)
}

genesisBlock := applicationChannelGenesisBlock(network, members, peer, "participation-trophy")
genesisBlock := applicationChannelGenesisBlock(network, orderers, peer, "participation-trophy")
expectedChannelInfoPT := channelparticipation.ChannelInfo{
Name: "participation-trophy",
URL: "/participation/v1/channels/participation-trophy",
Expand All @@ -295,7 +295,7 @@ var _ = Describe("ChannelParticipation", func() {
Height: 1,
}

for _, o := range members {
for _, o := range orderers {
By("joining " + o.Name + " to channel as a member")
channelparticipation.Join(network, o, "participation-trophy", genesisBlock, expectedChannelInfoPT)
channelInfo := channelparticipation.ListOne(network, o, "participation-trophy")
Expand All @@ -306,30 +306,28 @@ var _ = Describe("ChannelParticipation", func() {
memberRunners := []*ginkgomon.Runner{ordererRunners[0], ordererRunners[1]}
leader := findLeader(memberRunners)

By("ensuring the channel is usable by submitting a transaction to each member")
env := CreateBroadcastEnvelope(network, peer, "participation-trophy", []byte("hello"))
for i, o := range members {
By("submitting transaction to " + o.Name)
i++
expectedChannelInfoPT.Height++
resp, err := ordererclient.Broadcast(network, o, env)
Expect(err).NotTo(HaveOccurred())
Expect(resp.Status).To(Equal(common.Status_SUCCESS))
expectedBlockNumPerChannel := map[string]int{"participation-trophy": i}
assertBlockReception(expectedBlockNumPerChannel, members, peer, network)
submitTxn(orderer1, peer, network, orderers, 1, channelparticipation.ChannelInfo{
Name: "participation-trophy",
URL: "/participation/v1/channels/participation-trophy",
Status: "active",
ClusterRelation: "member",
Height: 2,
})

By("checking the channel height")
channelInfo := channelparticipation.ListOne(network, o, "participation-trophy")
Expect(channelInfo).To(Equal(expectedChannelInfoPT))
}
submitTxn(orderer2, peer, network, orderers, 2, channelparticipation.ChannelInfo{
Name: "participation-trophy",
URL: "/participation/v1/channels/participation-trophy",
Status: "active",
ClusterRelation: "member",
Height: 3,
})

By("submitting a channel config update")
channelConfig := nwo.GetConfig(network, peer, orderer1, "participation-trophy")
c := configtx.New(channelConfig)
err := c.Orderer().AddCapability("V1_1")
Expect(err).NotTo(HaveOccurred())
computeSignSubmitConfigUpdate(network, orderer1, peer, c, "participation-trophy")
expectedChannelInfoPT.Height++

currentBlockNumber := nwo.CurrentConfigBlockNumber(network, peer, orderer1, "participation-trophy")
Expect(currentBlockNumber).To(BeNumerically(">", 1))
Expand All @@ -344,7 +342,6 @@ var _ = Describe("ChannelParticipation", func() {
err = c.Orderer().AddConsenter(consenterChannelConfig(network, orderer3))
Expect(err).NotTo(HaveOccurred())
computeSignSubmitConfigUpdate(network, orderer2, peer, c, "participation-trophy")
expectedChannelInfoPT.Height++

By("joining orderer3 to the channel as a member")
// make sure we can join using a config block from one of the other orderers
Expand All @@ -360,7 +357,7 @@ var _ = Describe("ChannelParticipation", func() {

By("ensuring orderer3 completes onboarding successfully")
expectedChannelInfoMember.Status = "active"
expectedChannelInfoMember.Height = expectedChannelInfoPT.Height
expectedChannelInfoMember.Height = 5
Eventually(func() channelparticipation.ChannelInfo {
return channelparticipation.ListOne(network, orderer3, "participation-trophy")
}, network.EventuallyTimeout).Should(Equal(expectedChannelInfoMember))
Expand All @@ -370,18 +367,128 @@ var _ = Describe("ChannelParticipation", func() {
Expect(newLeader).To(Equal(leader))

By("submitting transaction to orderer3 to ensure it is active")
env = CreateBroadcastEnvelope(network, peer, "participation-trophy", []byte("hello-again"))
expectedChannelInfoPT.Height++
env := CreateBroadcastEnvelope(network, peer, "participation-trophy", []byte("hello-again"))
resp, err := ordererclient.Broadcast(network, orderer3, env)
Expect(err).NotTo(HaveOccurred())
Expect(resp.Status).To(Equal(common.Status_SUCCESS))
expectedBlockNumPerChannel := map[string]int{"participation-trophy": 5}
assertBlockReception(expectedBlockNumPerChannel, orderers, peer, network)

By("checking the channel height")
expectedChannelInfoPT.Height = 6
channelInfo := channelparticipation.ListOne(network, orderer3, "participation-trophy")
Expect(channelInfo).To(Equal(expectedChannelInfoPT))
})

It("join application channel with join-block as follower via channel participation api", func() {
orderer1 := network.Orderer("orderer1")
orderer2 := network.Orderer("orderer2")
orderer3 := network.Orderer("orderer3")
orderers := []*nwo.Orderer{orderer1, orderer2}
peer := network.Peer("Org1", "peer0")

By("starting two orderers")
for _, o := range orderers {
startOrderer(o)
channelparticipation.List(network, o, nil)
}

genesisBlock := applicationChannelGenesisBlock(network, orderers, peer, "participation-trophy")
expectedChannelInfoPT := channelparticipation.ChannelInfo{
Name: "participation-trophy",
URL: "/participation/v1/channels/participation-trophy",
Status: "active",
ClusterRelation: "member",
Height: 1,
}

for _, o := range orderers {
By("joining " + o.Name + " to channel as a member")
channelparticipation.Join(network, o, "participation-trophy", genesisBlock, expectedChannelInfoPT)
channelInfo := channelparticipation.ListOne(network, o, "participation-trophy")
Expect(channelInfo).To(Equal(expectedChannelInfoPT))
}

By("waiting for the leader to be ready")
memberRunners := []*ginkgomon.Runner{ordererRunners[0], ordererRunners[1]}
leader := findLeader(memberRunners)

submitTxn(orderer1, peer, network, orderers, 1, channelparticipation.ChannelInfo{
Name: "participation-trophy",
URL: "/participation/v1/channels/participation-trophy",
Status: "active",
ClusterRelation: "member",
Height: 2,
})

submitTxn(orderer2, peer, network, orderers, 2, channelparticipation.ChannelInfo{
Name: "participation-trophy",
URL: "/participation/v1/channels/participation-trophy",
Status: "active",
ClusterRelation: "member",
Height: 3,
})

By("submitting a channel config update")
channelConfig := nwo.GetConfig(network, peer, orderer1, "participation-trophy")
c := configtx.New(channelConfig)
err := c.Orderer().AddCapability("V1_1")
Expect(err).NotTo(HaveOccurred())
computeSignSubmitConfigUpdate(network, orderer1, peer, c, "participation-trophy")

currentBlockNumber := nwo.CurrentConfigBlockNumber(network, peer, orderer1, "participation-trophy")
Expect(currentBlockNumber).To(BeNumerically(">", 1))

By("starting third orderer")
startOrderer(orderer3)
channelparticipation.List(network, orderer3, nil)

By("joining orderer3 to the channel as a follower")
// make sure we can join using a config block from one of the other orderers
configBlockPT := nwo.GetConfigBlock(network, peer, orderer2, "participation-trophy")
expectedChannelInfoPTFollower := channelparticipation.ChannelInfo{
Name: "participation-trophy",
URL: "/participation/v1/channels/participation-trophy",
Status: "onboarding",
ClusterRelation: "follower",
Height: 0,
}
channelparticipation.Join(network, orderer3, "participation-trophy", configBlockPT, expectedChannelInfoPTFollower)

By("ensuring orderer3 completes onboarding successfully")
expectedChannelInfoPTFollower.Status = "active"
expectedChannelInfoPTFollower.Height = 4
Eventually(func() channelparticipation.ChannelInfo {
return channelparticipation.ListOne(network, orderer3, "participation-trophy")
}, network.EventuallyTimeout).Should(Equal(expectedChannelInfoPTFollower))

By("adding orderer3 to the consenters set")
channelConfig = nwo.GetConfig(network, peer, orderer1, "participation-trophy")
c = configtx.New(channelConfig)
err = c.Orderer().AddConsenter(consenterChannelConfig(network, orderer3))
Expect(err).NotTo(HaveOccurred())
computeSignSubmitConfigUpdate(network, orderer1, peer, c, "participation-trophy")

By("ensuring orderer3 transitions from follower to member")
// config update above added a block
expectedChannelInfoPT.Height = 5
Eventually(func() channelparticipation.ChannelInfo {
return channelparticipation.ListOne(network, orderer3, "participation-trophy")
}, network.EventuallyTimeout).Should(Equal(expectedChannelInfoPT))

// make sure orderer3 finds the leader
newLeader := findLeader([]*ginkgomon.Runner{ordererRunners[2]})
Expect(newLeader).To(Equal(leader))

submitTxn(orderer3, peer, network, orderers, 5, channelparticipation.ChannelInfo{
Name: "participation-trophy",
URL: "/participation/v1/channels/participation-trophy",
Status: "active",
ClusterRelation: "member",
Height: 6,
})
})

})

Describe("three node etcdraft network with a system channel", func() {
Expand Down Expand Up @@ -533,6 +640,21 @@ var _ = Describe("ChannelParticipation", func() {
})
})

func submitTxn(o *nwo.Orderer, peer *nwo.Peer, network *nwo.Network, orderers []*nwo.Orderer,
expectedBlkNum int, expectedChannelInfo channelparticipation.ChannelInfo) {
By("submitting a transaction to " + o.Name)
env := CreateBroadcastEnvelope(network, peer, expectedChannelInfo.Name, []byte("hello"))
resp, err := ordererclient.Broadcast(network, o, env)
Expect(err).NotTo(HaveOccurred())
Expect(resp.Status).To(Equal(common.Status_SUCCESS))
expectedBlockNumPerChannel := map[string]int{"participation-trophy": expectedBlkNum}
assertBlockReception(expectedBlockNumPerChannel, orderers, peer, network)

By("checking the channel height")
channelInfo := channelparticipation.ListOne(network, o, expectedChannelInfo.Name)
Expect(channelInfo).To(Equal(expectedChannelInfo))
}

func applicationChannelGenesisBlock(n *nwo.Network, orderers []*nwo.Orderer, p *nwo.Peer, channel string) *common.Block {
ordererOrgs, consenters := ordererOrganizationsAndConsenters(n, orderers)
peerOrgs := peerOrganizations(n, p)
Expand Down

0 comments on commit fa0213f

Please sign in to comment.