diff --git a/integration/e2e/e2e_test.go b/integration/e2e/e2e_test.go index 4c145d93bc7..4721f1fb689 100644 --- a/integration/e2e/e2e_test.go +++ b/integration/e2e/e2e_test.go @@ -24,10 +24,14 @@ import ( docker "github.com/fsouza/go-dockerclient" "github.com/hyperledger/fabric-lib-go/healthz" + cb "github.com/hyperledger/fabric-protos-go-apiv2/common" + ab "github.com/hyperledger/fabric-protos-go-apiv2/orderer" "github.com/hyperledger/fabric-protos-go-apiv2/orderer/etcdraft" "github.com/hyperledger/fabric/integration/nwo" "github.com/hyperledger/fabric/integration/nwo/commands" "github.com/hyperledger/fabric/integration/nwo/fabricconfig" + "github.com/hyperledger/fabric/integration/ordererclient" + "github.com/hyperledger/fabric/protoutil" . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" "github.com/onsi/gomega/gbytes" @@ -163,6 +167,9 @@ var _ = Describe("EndToEnd", func() { By("setting up the channel") nwo.JoinOrdererJoinPeersAppChannel(network, "testchannel", orderer, ordererRunner) + // A special method call for testing metrics + deliveryBlock(network, network.PeersWithChannel("testchannel")[0], orderer, "testchannel") + By("listing channels with osnadmin") cl = nwo.List(network, orderer) nwo.ChannelListMatcher(cl, []string{"testchannel"}) @@ -933,3 +940,35 @@ func hashFile(file string) string { func chaincodeContainerNameFilter(n *nwo.Network, chaincode nwo.Chaincode) string { return fmt.Sprintf("^/%s-.*-%s-%s$", n.NetworkID, chaincode.Label, hashFile(chaincode.PackageFile)) } + +func deliveryBlock(network *nwo.Network, peer *nwo.Peer, orderer *nwo.Orderer, channelID string) { + By("getting the signer for admin on orderer " + orderer.Name) + signer := network.OrdererUserSigner(orderer, "Admin") + + By("starting delivery on orderer " + orderer.ID()) + deliverEnvelope, err := protoutil.CreateSignedEnvelope( + cb.HeaderType_DELIVER_SEEK_INFO, + channelID, + signer, + &ab.SeekInfo{ + Behavior: ab.SeekInfo_BLOCK_UNTIL_READY, + Start: &ab.SeekPosition{ + Type: &ab.SeekPosition_Specified{ + Specified: &ab.SeekSpecified{Number: 0}, + }, + }, + Stop: &ab.SeekPosition{ + Type: &ab.SeekPosition_Specified{ + Specified: &ab.SeekSpecified{Number: 0}, + }, + }, + }, + 0, + 0, + ) + Expect(err).NotTo(HaveOccurred()) + + blk, err := ordererclient.Deliver(network, orderer, deliverEnvelope) + Expect(err).NotTo(HaveOccurred()) + Expect(blk).ToNot(BeNil()) +} diff --git a/integration/nwo/channel_participation.go b/integration/nwo/channel_participation.go index fa847704351..21010e64ef4 100644 --- a/integration/nwo/channel_participation.go +++ b/integration/nwo/channel_participation.go @@ -21,6 +21,7 @@ import ( "github.com/onsi/gomega/gbytes" "github.com/onsi/gomega/gstruct" "github.com/onsi/gomega/types" + "github.com/pkg/errors" ginkgomon "github.com/tedsuo/ifrit/ginkgomon_v2" "google.golang.org/protobuf/proto" ) @@ -127,7 +128,7 @@ func doBody(client *http.Client, req *http.Request, expectedStatus int) []byte { Expect(err).NotTo(HaveOccurred()) resp.Body.Close() - Expect(resp.StatusCode).To(Equal(expectedStatus), string(bodyBytes)) + Expect(expectedStatus).To(Equal(resp.StatusCode), string(bodyBytes)) return bodyBytes } @@ -171,6 +172,20 @@ func getBody(client *http.Client, url string) func() string { } } +func getBodyBinary(client *http.Client, url string) func() ([]byte, error) { + return func() ([]byte, error) { + resp, err := client.Get(url) + Expect(err).NotTo(HaveOccurred()) + bodyBytes, err := io.ReadAll(resp.Body) + Expect(err).NotTo(HaveOccurred()) + resp.Body.Close() + if resp.StatusCode != http.StatusOK { + return nil, errors.New(string(bodyBytes)) + } + return bodyBytes, nil + } +} + type ChannelInfo struct { Name string `json:"name"` URL string `json:"url"` @@ -195,6 +210,30 @@ func ListOne(n *Network, o *Orderer, channel string) ChannelInfo { return *c } +func Fetch(n *Network, o *Orderer, channel string, blockID string) (*common.Block, error) { + return FetchTimeShift(n, o, channel, blockID, 0) +} + +func FetchTimeShift(n *Network, o *Orderer, channel string, blockID string, timeShift time.Duration) (*common.Block, error) { + authClient, _ := OrdererOperationalClientsTimeShift(n, o, timeShift) + + protocol := "http" + if n.TLSEnabled { + protocol = "https" + } + fetchURL := fmt.Sprintf("%s://127.0.0.1:%d/participation/v1/channels/%s/blocks/%s", protocol, n.OrdererPort(o, AdminPort), channel, blockID) + + body, err := getBodyBinary(authClient, fetchURL)() + if err != nil { + return nil, err + } + + b := &common.Block{} + err = proto.Unmarshal(body, b) + + return b, err +} + func Remove(n *Network, o *Orderer, channel string) { authClient, _ := OrdererOperationalClients(n, o) diff --git a/integration/nwo/configblock.go b/integration/nwo/configblock.go index d108ba5363e..fe28628c8a2 100644 --- a/integration/nwo/configblock.go +++ b/integration/nwo/configblock.go @@ -33,32 +33,28 @@ func GetConfigBlock(n *Network, peer *Peer, orderer *Orderer, channel string) *c defer os.RemoveAll(tempDir) // fetch the config block - output := filepath.Join(tempDir, "config_block.pb") - FetchConfigBlock(n, peer, orderer, channel, output) + configBlock := FetchConfigBlock(n, orderer, channel) - // unmarshal the config block bytes - configBlock := UnmarshalBlockFromFile(output) return configBlock } // FetchConfigBlock fetches latest config block. -func FetchConfigBlock(n *Network, peer *Peer, orderer *Orderer, channel string, output string) { +func FetchConfigBlock(n *Network, orderer *Orderer, channel string) *common.Block { + var ( + err error + b *common.Block + ) fetch := func() int { - sess, err := n.OrdererAdminSession(orderer, peer, commands.ChannelFetch{ - ChannelID: channel, - Block: "config", - Orderer: n.OrdererAddress(orderer, ListenPort), - OutputFile: output, - ClientAuth: n.ClientAuthRequired, - }) - Expect(err).NotTo(HaveOccurred()) - code := sess.Wait(n.EventuallyTimeout).ExitCode() - if code == 0 { - Expect(sess.Err).To(gbytes.Say("Received block: ")) + b, err = Fetch(n, orderer, channel, "config") + if err != nil || b == nil { + return 1 } - return code + + return 0 } Eventually(fetch, n.EventuallyTimeout).Should(Equal(0)) + + return b } // GetConfig retrieves the last config of the given channel. @@ -179,15 +175,12 @@ func CurrentConfigBlockNumber(n *Network, peer *Peer, orderer *Orderer, channel defer os.RemoveAll(tempDir) // fetch the config block - output := filepath.Join(tempDir, "config_block.pb") if orderer == nil { + output := filepath.Join(tempDir, "config_block.pb") return CurrentConfigBlockNumberFromPeer(n, peer, channel, output) } - FetchConfigBlock(n, peer, orderer, channel, output) - - // unmarshal the config block bytes - configBlock := UnmarshalBlockFromFile(output) + configBlock := FetchConfigBlock(n, orderer, channel) return configBlock.Header.Number } diff --git a/integration/nwo/network.go b/integration/nwo/network.go index 42e389c05f5..75814511d69 100644 --- a/integration/nwo/network.go +++ b/integration/nwo/network.go @@ -1150,15 +1150,27 @@ func (n *Network) JoinChannel(name string, o *Orderer, peers ...*Peer) { tempFile.Close() defer os.Remove(tempFile.Name()) - sess, err := n.PeerAdminSession(peers[0], commands.ChannelFetch{ - Block: "0", - ChannelID: name, - Orderer: n.OrdererAddress(o, ListenPort), - OutputFile: tempFile.Name(), - ClientAuth: n.ClientAuthRequired, - }) - Expect(err).NotTo(HaveOccurred()) - Eventually(sess, n.EventuallyTimeout).Should(gexec.Exit(0)) + Eventually(func() string { + block, err := Fetch(n, o, name, "0") + if err != nil { + return fmt.Sprintf("error is %s", err.Error()) + } + + if block == nil { + return "proto: Marshal called with nil" + } + + b, err := proto.Marshal(block) + if err != nil { + return err.Error() + } + + if err = os.WriteFile(tempFile.Name(), b, 0o644); err != nil { + return err.Error() + } + + return "" + }, n.EventuallyTimeout, time.Second).Should(BeEmpty()) for _, p := range peers { sess, err := n.PeerAdminSession(p, commands.ChannelJoin{ diff --git a/integration/ordererclient/orderer_client.go b/integration/ordererclient/orderer_client.go index dbaa5d9ed08..394296263c2 100644 --- a/integration/ordererclient/orderer_client.go +++ b/integration/ordererclient/orderer_client.go @@ -8,6 +8,7 @@ package ordererclient import ( "context" + "reflect" "github.com/hyperledger/fabric-protos-go-apiv2/common" "github.com/hyperledger/fabric-protos-go-apiv2/orderer" @@ -56,10 +57,17 @@ func Deliver(n *nwo.Network, o *nwo.Orderer, env *common.Envelope) (*common.Bloc return nil, err } - blk := resp.GetBlock() - if blk == nil { - return nil, errors.Errorf("block not found") - } + switch t := resp.Type.(type) { + case *orderer.DeliverResponse_Block: + blk := resp.GetBlock() + if blk == nil { + return nil, errors.Errorf("block not found") + } - return blk, nil + return blk, nil + case *orderer.DeliverResponse_Status: + return nil, errors.Errorf("faulty node, received status: %s", common.Status_name[int32(t.Status)]) + default: + return nil, errors.Errorf("response is of type %v, but expected a block", reflect.TypeOf(resp.Type)) + } } diff --git a/integration/pvtdata/pvtdata_test.go b/integration/pvtdata/pvtdata_test.go index d0ee8289bad..3f40eb6b86a 100644 --- a/integration/pvtdata/pvtdata_test.go +++ b/integration/pvtdata/pvtdata_test.go @@ -269,21 +269,22 @@ var _ = Describe("PrivateData", func() { Eventually(p.Ready(), network.EventuallyTimeout).Should(BeClosed()) By("joining peer1.org2 to the channel with its Admin2 user") + block, err := nwo.Fetch(network, orderer, channelID, "0") + Expect(err).NotTo(HaveOccurred()) + Expect(block).NotTo(BeNil()) + tempFile, err := os.CreateTemp("", "genesis-block") Expect(err).NotTo(HaveOccurred()) tempFile.Close() defer os.Remove(tempFile.Name()) - sess, err := network.PeerUserSession(org2Peer1, "Admin2", commands.ChannelFetch{ - Block: "0", - ChannelID: channelID, - Orderer: network.OrdererAddress(orderer, nwo.ListenPort), - OutputFile: tempFile.Name(), - }) + b, err := proto.Marshal(block) + Expect(err).NotTo(HaveOccurred()) + + err = os.WriteFile(tempFile.Name(), b, 0o644) Expect(err).NotTo(HaveOccurred()) - Eventually(sess, network.EventuallyTimeout).Should(gexec.Exit(0)) - sess, err = network.PeerUserSession(org2Peer1, "Admin2", commands.ChannelJoin{ + sess, err := network.PeerUserSession(org2Peer1, "Admin2", commands.ChannelJoin{ BlockPath: tempFile.Name(), }) Expect(err).NotTo(HaveOccurred()) @@ -950,18 +951,11 @@ func addPeer(n *nwo.Network, orderer *nwo.Orderer, peer *nwo.Peer) ifrit.Process n.JoinChannel(channelID, orderer, peer) ledgerHeight := nwo.GetLedgerHeight(n, n.Peers[0], channelID) - sess, err := n.PeerAdminSession( - peer, - commands.ChannelFetch{ - Block: "newest", - ChannelID: channelID, - Orderer: n.OrdererAddress(orderer, nwo.ListenPort), - OutputFile: filepath.Join(n.RootDir, "newest_block.pb"), - }, - ) + + b, err := nwo.Fetch(n, orderer, channelID, "newest") Expect(err).NotTo(HaveOccurred()) - Eventually(sess, n.EventuallyTimeout).Should(gexec.Exit(0)) - Expect(sess.Err).To(gbytes.Say(fmt.Sprintf("Received block: %d", ledgerHeight-1))) + Expect(b).NotTo(BeNil()) + Expect(b.GetHeader().GetNumber()).To(Equal(uint64(ledgerHeight) - 1)) n.Peers = append(n.Peers, peer) nwo.WaitUntilEqualLedgerHeight(n, channelID, nwo.GetLedgerHeight(n, n.Peers[0], channelID), n.Peers...) diff --git a/integration/pvtdatapurge/data_purge_test.go b/integration/pvtdatapurge/data_purge_test.go index dcf848aad75..a598ceb8364 100644 --- a/integration/pvtdatapurge/data_purge_test.go +++ b/integration/pvtdatapurge/data_purge_test.go @@ -27,7 +27,6 @@ import ( . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" "github.com/onsi/gomega/gbytes" - "github.com/onsi/gomega/gexec" "github.com/tedsuo/ifrit" ginkgomon "github.com/tedsuo/ifrit/ginkgomon_v2" "google.golang.org/protobuf/proto" @@ -476,18 +475,10 @@ func startNewPeer(network *nwo.Network, orderer *nwo.Orderer, peer *nwo.Peer, le startPeer(network, processes, runners, peer) network.JoinChannel(channelID, orderer, peer) - sess, err := network.PeerAdminSession( - peer, - commands.ChannelFetch{ - Block: "newest", - ChannelID: channelID, - Orderer: network.OrdererAddress(orderer, nwo.ListenPort), - OutputFile: filepath.Join(network.RootDir, "newest_block.pb"), - }, - ) + + b, err := nwo.Fetch(network, orderer, channelID, "newest") Expect(err).NotTo(HaveOccurred()) - Eventually(sess, network.EventuallyTimeout).Should(gexec.Exit(0)) - Expect(sess.Err).To(gbytes.Say(fmt.Sprintf("Received block: %d", ledgerHeight-1))) + Expect(b.GetHeader().GetNumber()).To(Equal(uint64(ledgerHeight) - 1)) network.Peers = append(network.Peers, peer) nwo.WaitUntilEqualLedgerHeight(network, channelID, ledgerHeight-1, network.Peers...) @@ -499,18 +490,10 @@ func addPeer(n *nwo.Network, orderer *nwo.Orderer, peer *nwo.Peer) ifrit.Process n.JoinChannel(channelID, orderer, peer) ledgerHeight := nwo.GetLedgerHeight(n, n.Peers[0], channelID) - sess, err := n.PeerAdminSession( - peer, - commands.ChannelFetch{ - Block: "newest", - ChannelID: channelID, - Orderer: n.OrdererAddress(orderer, nwo.ListenPort), - OutputFile: filepath.Join(n.RootDir, "newest_block.pb"), - }, - ) + + b, err := nwo.Fetch(n, orderer, channelID, "newest") Expect(err).NotTo(HaveOccurred()) - Eventually(sess, n.EventuallyTimeout).Should(gexec.Exit(0)) - Expect(sess.Err).To(gbytes.Say(fmt.Sprintf("Received block: %d", ledgerHeight-1))) + Expect(b.GetHeader().GetNumber()).To(Equal(uint64(ledgerHeight) - 1)) n.Peers = append(n.Peers, peer) nwo.WaitUntilEqualLedgerHeight(n, channelID, nwo.GetLedgerHeight(n, n.Peers[0], channelID), n.Peers...) diff --git a/integration/raft/cft_test.go b/integration/raft/cft_test.go index d440f63d684..ddf894f5516 100644 --- a/integration/raft/cft_test.go +++ b/integration/raft/cft_test.go @@ -345,8 +345,13 @@ var _ = Describe("EndToEnd Crash Fault Tolerance", func() { ordererCert, err := os.ReadFile(ordererCertificatePath) Expect(err).NotTo(HaveOccurred()) + By("Finding leader") + leaderIndex := FindLeader(ordererRunners) - 1 + if leaderIndex != 0 { + Eventually(ordererRunners[0].Err(), network.EventuallyTimeout, time.Second).Should(gbytes.Say("Store ActiveNodes")) + } + By("Adding new ordering service node") - Consistently(ordererRunners[0].Err(), 5*time.Second, time.Second).ShouldNot(gbytes.Say("active nodes store")) addConsenter(network, peer, orderers[0], "testchannel", &etcdraft.Consenter{ ServerTlsCert: ordererCert, ClientTlsCert: ordererCert, @@ -374,21 +379,19 @@ var _ = Describe("EndToEnd Crash Fault Tolerance", func() { nwo.Join(network, o4, "testchannel", configBlock, expectedChannelInfo) By("Pick ordering service node to be evicted") - victimIdx := FindLeader(ordererRunners) - 1 - victim := orderers[victimIdx] + victim := orderers[leaderIndex] victimCertBytes, err := os.ReadFile(filepath.Join(network.OrdererLocalTLSDir(victim), "server.crt")) Expect(err).NotTo(HaveOccurred()) - assertBlockReception(map[string]int{ - "testchannel": 1, - }, orderers, peer, network) + assertBlockReception(map[string]int{"testchannel": 1}, orderers, network) + Eventually(r4.Err(), network.EventuallyTimeout, time.Second).Should(gbytes.Say("Raft leader changed: 0 -> ")) By("Removing OSN from the channel") remainedOrderers := []*nwo.Orderer{} remainedRunners := []*ginkgomon.Runner{} for i, o := range orderers { - if i == victimIdx { + if i == leaderIndex { continue } remainedOrderers = append(remainedOrderers, o) @@ -398,9 +401,7 @@ var _ = Describe("EndToEnd Crash Fault Tolerance", func() { removeConsenter(network, peer, remainedOrderers[0], "testchannel", victimCertBytes) By("Asserting all remaining nodes got last block") - assertBlockReception(map[string]int{ - "testchannel": 2, - }, remainedOrderers, peer, network) + assertBlockReception(map[string]int{"testchannel": 2}, remainedOrderers, network) By("Making sure OSN was evicted and configuration applied") FindLeader(remainedRunners) @@ -431,9 +432,7 @@ var _ = Describe("EndToEnd Crash Fault Tolerance", func() { Expect(resp.Status).To(Equal(common.Status_SUCCESS)) } - assertBlockReception(map[string]int{ - "testchannel": 10, - }, []*nwo.Orderer{remainedOrderers[2]}, peer, network) + assertBlockReception(map[string]int{"testchannel": 10}, []*nwo.Orderer{remainedOrderers[2]}, network) By("Clean snapshot folder of lagging behind node") snapDir := path.Join(network.RootDir, "orderers", remainedOrderers[0].ID(), "etcdraft", "snapshot") @@ -466,9 +465,7 @@ var _ = Describe("EndToEnd Crash Fault Tolerance", func() { return len(files) }, network.EventuallyTimeout).Should(BeNumerically(">", 0)) - assertBlockReception(map[string]int{ - "testchannel": 10, - }, []*nwo.Orderer{remainedOrderers[0]}, peer, network) + assertBlockReception(map[string]int{"testchannel": 10}, []*nwo.Orderer{remainedOrderers[0]}, network) By("Make sure we can restart and connect to orderer1 with orderer4") ordererProc.Signal(syscall.SIGTERM) @@ -824,12 +821,16 @@ var _ = Describe("EndToEnd Crash Fault Tolerance", func() { Eventually(o3Proc.Ready(), network.EventuallyTimeout).Should(BeClosed()) By("Waiting for a leader to be elected") - FindLeader([]*ginkgomon.Runner{o1Runner, o2Runner, o3Runner}) + ordererRunners := []*ginkgomon.Runner{o1Runner, o2Runner, o3Runner} + leaderIndex := FindLeader(ordererRunners) - 1 By("submitting config updates to orderers with expired TLS certs to replace the expired certs") timeShift := 5 * time.Minute - ordererRunners := []*ginkgomon.Runner{o1Runner, o2Runner, o3Runner} for i, o := range orderers { + if leaderIndex != i { + Eventually(ordererRunners[i].Err(), network.EventuallyTimeout, time.Second).Should(gbytes.Say("Store ActiveNodes")) + } + channelConfig := fetchConfig(network, peer, o, nwo.ClusterPort, "testchannel", timeShift) c := conftx.New(channelConfig) err = c.Orderer().RemoveConsenter(consenterChannelConfig(network, o)) @@ -841,8 +842,11 @@ var _ = Describe("EndToEnd Crash Fault Tolerance", func() { Expect(err).NotTo(HaveOccurred()) By("updating the config for " + o.Name) - Consistently(ordererRunners[i].Err(), 5*time.Second, time.Second).ShouldNot(gbytes.Say("active nodes store")) updateOrdererConfig(network, o, nwo.ClusterPort, "testchannel", timeShift, c.OriginalConfig(), c.UpdatedConfig(), peer, o) + + if i == leaderIndex { + leaderIndex = FindLeader(ordererRunners) - 1 + } } By("Killing orderers #5") @@ -918,7 +922,7 @@ var _ = Describe("EndToEnd Crash Fault Tolerance", func() { assertBlockReception(map[string]int{ "foo": 0, "testchannel": 0, - }, []*nwo.Orderer{o1, o2, o3}, peer, network) + }, []*nwo.Orderer{o1, o2, o3}, network) By("Killing all orderers") for i := range orderers { @@ -951,7 +955,7 @@ var _ = Describe("EndToEnd Crash Fault Tolerance", func() { "foo": 0, "bar": 0, "testchannel": 0, - }, []*nwo.Orderer{o1, o2, o3}, peer, network) + }, []*nwo.Orderer{o1, o2, o3}, network) }) }) @@ -1284,30 +1288,25 @@ func fetchConfig(n *nwo.Network, peer *nwo.Peer, orderer *nwo.Orderer, port nwo. Expect(err).NotTo(HaveOccurred()) defer os.RemoveAll(tempDir) - output := filepath.Join(tempDir, "config_block.pb") - fetchConfigBlock(n, peer, orderer, port, channel, output, tlsHandshakeTimeShift) - configBlock := nwo.UnmarshalBlockFromFile(output) + configBlock := fetchConfigBlock(n, orderer, channel, tlsHandshakeTimeShift) return configFromBlock(configBlock) } -func fetchConfigBlock(n *nwo.Network, peer *nwo.Peer, orderer *nwo.Orderer, port nwo.PortName, channel, output string, tlsHandshakeTimeShift time.Duration) { - fetch := func() int { - sess, err := n.OrdererAdminSession(orderer, peer, commands.ChannelFetch{ - ChannelID: channel, - Block: "config", - Orderer: n.OrdererAddress(orderer, port), - OutputFile: output, - ClientAuth: n.ClientAuthRequired, - TLSHandshakeTimeShift: tlsHandshakeTimeShift, - }) - Expect(err).NotTo(HaveOccurred()) - code := sess.Wait(n.EventuallyTimeout).ExitCode() - if code == 0 { - Expect(sess.Err).To(gbytes.Say("Received block: ")) +func fetchConfigBlock(n *nwo.Network, orderer *nwo.Orderer, channel string, tlsHandshakeTimeShift time.Duration) *common.Block { + var ( + b *common.Block + err error + ) + fetch := func() *common.Block { + b, err = nwo.FetchTimeShift(n, orderer, channel, "config", tlsHandshakeTimeShift) + if err != nil { + return nil } - return code + return b } - Eventually(fetch, n.EventuallyTimeout).Should(Equal(0)) + Eventually(fetch, n.EventuallyTimeout).ShouldNot(BeNil()) + + return b } func currentConfigBlockNumber(n *nwo.Network, peer *nwo.Peer, orderer *nwo.Orderer, port nwo.PortName, channel string, tlsHandshakeTimeShift time.Duration) uint64 { @@ -1315,9 +1314,7 @@ func currentConfigBlockNumber(n *nwo.Network, peer *nwo.Peer, orderer *nwo.Order Expect(err).NotTo(HaveOccurred()) defer os.RemoveAll(tempDir) - output := filepath.Join(tempDir, "config_block.pb") - fetchConfigBlock(n, peer, orderer, port, channel, output, tlsHandshakeTimeShift) - configBlock := nwo.UnmarshalBlockFromFile(output) + configBlock := fetchConfigBlock(n, orderer, channel, tlsHandshakeTimeShift) return configBlock.Header.Number } diff --git a/integration/raft/config_test.go b/integration/raft/config_test.go index 1cc3771d412..4d590feb021 100644 --- a/integration/raft/config_test.go +++ b/integration/raft/config_test.go @@ -515,9 +515,7 @@ var _ = Describe("EndToEnd reconfiguration and onboarding", func() { blockSeq := 0 By("Checking that all orderers are online") - assertBlockReception(map[string]int{ - "testchannel": blockSeq, - }, orderers, peer, network) + assertBlockReception(map[string]int{"testchannel": blockSeq}, orderers, network) By("Preparing new certificates for the orderer nodes") extendNetwork(network) @@ -561,7 +559,7 @@ var _ = Describe("EndToEnd reconfiguration and onboarding", func() { submitterOrderer := network.Orderers[submitter] port := network.OrdererPort(targetOrderer, nwo.ClusterPort) - fmt.Fprintf(GinkgoWriter, "Rotating certificate of orderer node %d\n", target+1) + By("Rotating certificate of orderer node - " + targetOrderer.Name + ". Submit to " + submitterOrderer.Name) swap(submitterOrderer, rotation.oldCert, &etcdraft.Consenter{ ServerTlsCert: rotation.newCert, ClientTlsCert: rotation.newCert, @@ -570,30 +568,18 @@ var _ = Describe("EndToEnd reconfiguration and onboarding", func() { }) By("Waiting for all orderers to sync") - assertBlockReception(map[string]int{ - "testchannel": blockSeq, - }, remainder, peer, network) + assertBlockReception(map[string]int{"testchannel": blockSeq}, remainder, network) By("Waiting for rotated node to be unavailable") - c := commands.ChannelFetch{ - ChannelID: "testchannel", - Block: "newest", - OutputFile: "/dev/null", - Orderer: network.OrdererAddress(targetOrderer, nwo.ClusterPort), - } Eventually(func() string { - sess, err := network.OrdererAdminSession(targetOrderer, peer, c) - Expect(err).NotTo(HaveOccurred()) - Eventually(sess, network.EventuallyTimeout).Should(gexec.Exit()) - if sess.ExitCode() != 0 { - return fmt.Sprintf("exit code is %d: %s", sess.ExitCode(), string(sess.Err.Contents())) + b, err := nwo.Fetch(network, targetOrderer, "testchannel", "newest") + if err != nil { + return fmt.Sprintf("error is %s", err.Error()) } - sessErr := string(sess.Err.Contents()) - expected := fmt.Sprintf("Received block: %d", blockSeq) - if strings.Contains(sessErr, expected) { + if b.GetHeader().GetNumber() == uint64(blockSeq) { return "" } - return sessErr + return "wrong block" }, network.EventuallyTimeout, time.Second).ShouldNot(BeEmpty()) By("Killing the orderer") @@ -602,24 +588,23 @@ var _ = Describe("EndToEnd reconfiguration and onboarding", func() { By("Starting the orderer again") ordererRunner := network.OrdererRunner(targetOrderer) - ordererRunners = append(ordererRunners, ordererRunner) + ordererRunners[target] = ordererRunner ordererProcesses[target] = ifrit.Invoke(ordererRunner) Eventually(ordererProcesses[target].Ready(), network.EventuallyTimeout).Should(BeClosed()) - By("And waiting for it to stabilize") - assertBlockReception(map[string]int{ - "testchannel": blockSeq, - }, orderers, peer, network) + By("And waiting for it to stabilize 1") + assertBlockReception(map[string]int{"testchannel": blockSeq}, orderers, network) + + Eventually(ordererRunner.Err(), network.EventuallyTimeout, time.Second).Should(gbytes.Say("Raft leader changed: 0 -> ")) + Eventually(ordererRunner.Err(), network.EventuallyTimeout, time.Second).Should(gbytes.Say("Store ActiveNodes")) } By(fmt.Sprintf("Rotating cert on leader %d", leader)) - Consistently(ordererRunners[leaderIndex].Err(), 5*time.Second, time.Second).ShouldNot(gbytes.Say("active nodes store")) rotate(leaderIndex) By("Rotating certificates of other orderer nodes") for i := range certificateRotations { if i != leaderIndex { - Consistently(ordererRunners[i].Err(), 5*time.Second, time.Second).ShouldNot(gbytes.Say("active nodes store")) rotate(i) } } @@ -682,41 +667,30 @@ var _ = Describe("EndToEnd reconfiguration and onboarding", func() { By("Finding leader") _ = FindLeader(ordererRunners) + blockSeq := 0 + By("Checking that all orderers are online") - assertBlockReception(map[string]int{ - "testchannel": 0, - }, orderers, peer, network) + assertBlockReception(map[string]int{"testchannel": blockSeq}, orderers, network) By("Preparing new certificates for the orderer nodes") extendNetwork(network) certificateRotations := refreshOrdererPEMs(network) - expectedBlockNumPerChannel := []map[string]int{ - {"testchannel": 1}, - {"testchannel": 2}, - {"testchannel": 3}, - {"testchannel": 4}, - {"testchannel": 5}, - {"testchannel": 6}, - } - for i, rotation := range certificateRotations { o := network.Orderers[i] port := network.OrdererPort(o, nwo.ClusterPort) By(fmt.Sprintf("Adding the future certificate of orderer node %d", i)) - Consistently(ordererRunners[i].Err(), 5*time.Second, time.Second).ShouldNot(gbytes.Say("active nodes store")) - for _, channelName := range []string{"testchannel"} { - addConsenter(network, peer, o, channelName, &etcdraft.Consenter{ - ServerTlsCert: rotation.newCert, - ClientTlsCert: rotation.newCert, - Host: "127.0.0.1", - Port: uint32(port), - }) - } + addConsenter(network, peer, o, "testchannel", &etcdraft.Consenter{ + ServerTlsCert: rotation.newCert, + ClientTlsCert: rotation.newCert, + Host: "127.0.0.1", + Port: uint32(port), + }) + blockSeq++ By("Waiting for all orderers to sync") - assertBlockReception(expectedBlockNumPerChannel[i*2], orderers, peer, network) + assertBlockReception(map[string]int{"testchannel": blockSeq}, orderers, network) By("Killing the orderer") ordererProcesses[i].Signal(syscall.SIGTERM) @@ -729,16 +703,16 @@ var _ = Describe("EndToEnd reconfiguration and onboarding", func() { Eventually(ordererProcesses[i].Ready(), network.EventuallyTimeout).Should(BeClosed()) By("And waiting for it to stabilize") - assertBlockReception(expectedBlockNumPerChannel[i*2], orderers, peer, network) + assertBlockReception(map[string]int{"testchannel": blockSeq}, orderers, network) + + Eventually(ordererRunner.Err(), network.EventuallyTimeout, time.Second).Should(gbytes.Say("Raft leader changed: 0 -> ")) By("Removing the previous certificate of the old orderer") - Consistently(ordererRunner.Err(), 5*time.Second, time.Second).ShouldNot(gbytes.Say("active nodes store")) - for _, channelName := range []string{"testchannel"} { - removeConsenter(network, peer, network.Orderers[(i+1)%len(network.Orderers)], channelName, rotation.oldCert) - } + removeConsenter(network, peer, network.Orderers[(i+1)%len(network.Orderers)], "testchannel", rotation.oldCert) + blockSeq++ By("Waiting for all orderers to sync") - assertBlockReception(expectedBlockNumPerChannel[i*2+1], orderers, peer, network) + assertBlockReception(map[string]int{"testchannel": blockSeq}, orderers, network) } By("Getting the last config block from testchannel and using it as a template for testchannel2 and testchannel3 genesis block") @@ -777,7 +751,7 @@ var _ = Describe("EndToEnd reconfiguration and onboarding", func() { assertBlockReception(map[string]int{ "testchannel2": 0, "testchannel3": 0, - }, orderers, peer, network) + }, orderers, network) o4 := &nwo.Orderer{ Name: "orderer4", @@ -805,21 +779,19 @@ var _ = Describe("EndToEnd reconfiguration and onboarding", func() { Host: "127.0.0.1", Port: uint32(network.OrdererPort(o4, nwo.ClusterPort)), }) + blockSeq++ By("Ensuring all orderers know about orderer4's addition") - assertBlockReception(map[string]int{ - "testchannel": 7, - }, orderers, peer, network) + assertBlockReception(map[string]int{"testchannel": blockSeq}, orderers, network) By("Broadcasting envelope to testchannel") env := ordererclient.CreateBroadcastEnvelope(network, peer, "testchannel", []byte("hello")) resp, err := ordererclient.Broadcast(network, o1, env) Expect(err).NotTo(HaveOccurred()) Expect(resp.Status).To(Equal(common.Status_SUCCESS)) + blockSeq++ - assertBlockReception(map[string]int{ - "testchannel": 8, - }, orderers, peer, network) + assertBlockReception(map[string]int{"testchannel": blockSeq}, orderers, network) By("Corrupting the readers policy of testchannel3") revokeReaderAccess(network, "testchannel3", o3, peer) @@ -846,9 +818,7 @@ var _ = Describe("EndToEnd reconfiguration and onboarding", func() { nwo.Join(network, o4, "testchannel", configBlock, expectedChannelInfo) By("And waiting for it to sync with the rest of the orderers") - assertBlockReception(map[string]int{ - "testchannel": 8, - }, orderers, peer, network) + assertBlockReception(map[string]int{"testchannel": blockSeq}, orderers, network) By("Ensuring orderer4 doesn't serve testchannel2 and testchannel3") env = ordererclient.CreateBroadcastEnvelope(network, peer, "testchannel2", []byte("hello")) @@ -883,9 +853,7 @@ var _ = Describe("EndToEnd reconfiguration and onboarding", func() { nwo.Join(network, o4, "testchannel2", configBlock, expectedChannelInfo) By("Waiting for orderer4 and to replicate testchannel2") - assertBlockReception(map[string]int{ - "testchannel2": 1, - }, []*nwo.Orderer{o4}, peer, network) + assertBlockReception(map[string]int{"testchannel2": 1}, []*nwo.Orderer{o4}, network) By("Ensuring orderer4 doesn't have any errors in the logs") Consistently(orderer4Runner.Err()).ShouldNot(gbytes.Say("ERRO")) @@ -897,9 +865,7 @@ var _ = Describe("EndToEnd reconfiguration and onboarding", func() { Expect(resp.Status).To(Equal(common.Status_SUCCESS)) By("And ensuring it is propagated amongst all orderers") - assertBlockReception(map[string]int{ - "testchannel2": 2, - }, orderers, peer, network) + assertBlockReception(map[string]int{"testchannel2": 2}, orderers, network) By("Adding orderer4 to testchannel3") addConsenter(network, peer, o1, "testchannel3", &etcdraft.Consenter{ @@ -971,9 +937,7 @@ var _ = Describe("EndToEnd reconfiguration and onboarding", func() { _ = FindLeader(ordererRunners[:1]) By("Waiting for the channel to be available") - assertBlockReception(map[string]int{ - "mychannel": 0, - }, []*nwo.Orderer{o1}, peer, network) + assertBlockReception(map[string]int{"mychannel": 0}, []*nwo.Orderer{o1}, network) By("Ensuring only orderer1 services the channel") env := ordererclient.CreateBroadcastEnvelope(network, peer, "mychannel", []byte("hello")) @@ -1013,9 +977,7 @@ var _ = Describe("EndToEnd reconfiguration and onboarding", func() { nwo.Join(network, o2, "mychannel", configBlock, expectedChannelInfo) By("Waiting for orderer2 to join the channel") - assertBlockReception(map[string]int{ - "mychannel": 1, - }, []*nwo.Orderer{o1, o2}, peer, network) + assertBlockReception(map[string]int{"mychannel": 1}, []*nwo.Orderer{o1, o2}, network) By("Adding orderer3 to the channel") ordererCertificatePath = filepath.Join(network.OrdererLocalTLSDir(o3), "server.crt") @@ -1040,9 +1002,7 @@ var _ = Describe("EndToEnd reconfiguration and onboarding", func() { nwo.Join(network, o3, "mychannel", configBlock, expectedChannelInfo) By("Waiting for orderer3 to join the channel") - assertBlockReception(map[string]int{ - "mychannel": 2, - }, orderers, peer, network) + assertBlockReception(map[string]int{"mychannel": 2}, orderers, network) }) }) @@ -1122,7 +1082,8 @@ var _ = Describe("EndToEnd reconfiguration and onboarding", func() { By("Launching the orderers") for _, o := range orderers { - runner := network.OrdererRunner(o, "FABRIC_LOGGING_SPEC=orderer.consensus.etcdraft=debug:info") + runner := network.OrdererRunner(o) + runner.Command.Env = append(runner.Command.Env, "FABRIC_LOGGING_SPEC=orderer.consensus.etcdraft=debug:info") ordererRunners = append(ordererRunners, runner) process := ifrit.Invoke(runner) ordererProcesses = append(ordererProcesses, process) @@ -1154,7 +1115,7 @@ var _ = Describe("EndToEnd reconfiguration and onboarding", func() { Expect(err).To(Not(HaveOccurred())) ordererEvicted1st := network.Orderers[(firstEvictedNode+1)%3] - Consistently(ordererRunners[(firstEvictedNode+1)%3].Err(), 5*time.Second, time.Second).ShouldNot(gbytes.Say("active nodes store")) + Eventually(ordererRunners[(firstEvictedNode+1)%3].Err(), network.EventuallyTimeout, time.Second).Should(gbytes.Say("Store ActiveNodes")) removeConsenter(network, peer, ordererEvicted1st, "testchannel", server1CertBytes) var survivedOrdererRunners []*ginkgomon.Runner @@ -1236,7 +1197,7 @@ var _ = Describe("EndToEnd reconfiguration and onboarding", func() { By("Ensuring re-added orderer starts serving testchannel") assertBlockReception(map[string]int{ "testchannel": 3, - }, []*nwo.Orderer{orderers[firstEvictedNode]}, peer, network) + }, []*nwo.Orderer{orderers[firstEvictedNode]}, network) By("Submitting tx") env := ordererclient.CreateBroadcastEnvelope(network, orderers[survivor], "testchannel", []byte("foo")) @@ -1247,7 +1208,7 @@ var _ = Describe("EndToEnd reconfiguration and onboarding", func() { By("Ensuring re-added orderer starts serving testchannel") assertBlockReception(map[string]int{ "testchannel": 4, - }, []*nwo.Orderer{orderers[firstEvictedNode], orderers[survivor]}, peer, network) + }, []*nwo.Orderer{orderers[firstEvictedNode], orderers[survivor]}, network) }) When("an evicted node is added back while it's offline", func() { @@ -1259,9 +1220,7 @@ var _ = Describe("EndToEnd reconfiguration and onboarding", func() { By("Waiting for them to elect a leader") FindLeader(ordererRunners) - assertBlockReception(map[string]int{ - "testchannel": 0, - }, []*nwo.Orderer{o1, o2, o3}, peer, network) + assertBlockReception(map[string]int{"testchannel": 0}, []*nwo.Orderer{o1, o2, o3}, network) By("Killing the first orderer") ordererProcesses[0].Signal(syscall.SIGTERM) @@ -1269,9 +1228,7 @@ var _ = Describe("EndToEnd reconfiguration and onboarding", func() { // We need to wait for stabilization, as we might have killed the leader OSN. By("Waiting for the channel to stabilize after killing the orderer") - assertBlockReception(map[string]int{ - "testchannel": 0, - }, []*nwo.Orderer{o2, o3}, peer, network) + assertBlockReception(map[string]int{"testchannel": 0}, []*nwo.Orderer{o2, o3}, network) By("observing active nodes to shrink") o2Runner := ordererRunners[1] @@ -1378,9 +1335,7 @@ var _ = Describe("EndToEnd reconfiguration and onboarding", func() { Eventually(assertCatchup(expectedInfo), network.EventuallyTimeout, 100*time.Millisecond).Should(BeTrue()) - assertBlockReception(map[string]int{ - "testchannel": 5, - }, []*nwo.Orderer{o1, o2, o3}, peer, network) + assertBlockReception(map[string]int{"testchannel": 5}, []*nwo.Orderer{o1, o2, o3}, network) }) It("remove channel from all orderers and add channel back", func() { @@ -1391,9 +1346,7 @@ var _ = Describe("EndToEnd reconfiguration and onboarding", func() { By("Waiting for them to elect a leader") FindLeader(ordererRunners) - assertBlockReception(map[string]int{ - "testchannel": 0, - }, network.Orderers, peer, network) + assertBlockReception(map[string]int{"testchannel": 0}, network.Orderers, network) By("Removing channel from all orderers") // TODO the nwo.Remove does not clean up the etcdraft folder. This may prevent the @@ -1440,9 +1393,7 @@ var _ = Describe("EndToEnd reconfiguration and onboarding", func() { FindLeader(ordererRunners) - assertBlockReception(map[string]int{ - "testchannel": 0, - }, network.Orderers, peer, network) + assertBlockReception(map[string]int{"testchannel": 0}, network.Orderers, network) expectedInfo := nwo.ListOne(network, o1, "testchannel") @@ -1465,9 +1416,7 @@ var _ = Describe("EndToEnd reconfiguration and onboarding", func() { Eventually(assertCatchup(expectedInfo), network.EventuallyTimeout, 100*time.Millisecond).Should(BeTrue()) - assertBlockReception(map[string]int{ - "testchannel": 1, - }, []*nwo.Orderer{o1, o2, o3}, peer, network) + assertBlockReception(map[string]int{"testchannel": 1}, []*nwo.Orderer{o1, o2, o3}, network) }) }) @@ -1481,9 +1430,7 @@ var _ = Describe("EndToEnd reconfiguration and onboarding", func() { By("Waiting for them to elect a leader") FindLeader(ordererRunners) - assertBlockReception(map[string]int{ - "testchannel": 0, - }, []*nwo.Orderer{o1, o2, o3}, peer, network) + assertBlockReception(map[string]int{"testchannel": 0}, []*nwo.Orderer{o1, o2, o3}, network) By("Killing the orderer") ordererProcesses[0].Signal(syscall.SIGTERM) @@ -1491,9 +1438,7 @@ var _ = Describe("EndToEnd reconfiguration and onboarding", func() { // We need to wait for stabilization, as we might have killed the leader OSN. By("Waiting for the channel to stabilize after killing the orderer") - assertBlockReception(map[string]int{ - "testchannel": 0, - }, []*nwo.Orderer{o2, o3}, peer, network) + assertBlockReception(map[string]int{"testchannel": 0}, []*nwo.Orderer{o2, o3}, network) By("Removing the first orderer from an application channel") o1cert, err := os.ReadFile(path.Join(network.OrdererLocalTLSDir(o1), "server.crt")) @@ -1610,9 +1555,7 @@ var _ = Describe("EndToEnd reconfiguration and onboarding", func() { leader := FindLeader(ordererRunners[:3]) By("Checking that all orderers are online") - assertBlockReception(map[string]int{ - "testchannel": 0, - }, orderers[:3], peer, network) + assertBlockReception(map[string]int{"testchannel": 0}, orderers[:3], network) By("Configuring orderer[5, 6, 7] in the network") extendNetwork(network) @@ -1659,9 +1602,7 @@ var _ = Describe("EndToEnd reconfiguration and onboarding", func() { nwo.Join(network, orderers[i], "testchannel", configBlock, expectedInfo) By(fmt.Sprintf("Checking that orderer%d has onboarded the network", i+1)) - assertBlockReception(map[string]int{ - "testchannel": blockNum, - }, []*nwo.Orderer{orderers[i]}, peer, network) + assertBlockReception(map[string]int{"testchannel": blockNum}, []*nwo.Orderer{orderers[i]}, network) } Expect(FindLeader(ordererRunners[4:])).To(Equal(leader)) @@ -1691,7 +1632,7 @@ var _ = Describe("EndToEnd reconfiguration and onboarding", func() { assertBlockReception(map[string]int{ "testchannel": blockNum, - }, []*nwo.Orderer{orderers[1], orderers[2], orderers[4], orderers[5], orderers[6]}, peer, network) // alive orderers: 2, 3, 5, 6, 7 + }, []*nwo.Orderer{orderers[1], orderers[2], orderers[4], orderers[5], orderers[6]}, network) // alive orderers: 2, 3, 5, 6, 7 By("Killing orderer[2,3]") for _, i := range []int{1, 2} { @@ -1712,7 +1653,7 @@ var _ = Describe("EndToEnd reconfiguration and onboarding", func() { By("Making sure 4/7 orderers form quorum and serve request") assertBlockReception(map[string]int{ "testchannel": blockNum, - }, []*nwo.Orderer{orderers[0], orderers[3], orderers[4], orderers[5], orderers[6]}, peer, network) // alive orderers: 1, 4, 5, 6, 7 + }, []*nwo.Orderer{orderers[0], orderers[3], orderers[4], orderers[5], orderers[6]}, network) // alive orderers: 1, 4, 5, 6, 7 }) }) @@ -1836,18 +1777,8 @@ var _ = Describe("EndToEnd reconfiguration and onboarding", func() { // With channel participation API, an orderer returns NOT_FOUND for channels it does not serve. // The old implementation with the system channel and inactive chain used to return SERVICE_UNAVAILABLE. func ensureNotFound(evictedOrderer *nwo.Orderer, submitter *nwo.Peer, network *nwo.Network, channel string) { - c := commands.ChannelFetch{ - ChannelID: channel, - Block: "newest", - OutputFile: "/dev/null", - Orderer: network.OrdererAddress(evictedOrderer, nwo.ListenPort), - } - - sess, err := network.OrdererAdminSession(evictedOrderer, submitter, c) - Expect(err).NotTo(HaveOccurred()) - - Eventually(sess, network.EventuallyTimeout).Should(gexec.Exit()) - Expect(sess.Err).To(gbytes.Say("NOT_FOUND")) + _, err := nwo.Fetch(network, evictedOrderer, channel, "newest") + Expect(err).To(HaveOccurred()) } var extendedCryptoConfig = `--- @@ -1987,34 +1918,25 @@ func refreshOrdererPEMs(n *nwo.Network) []*certificateChange { // assertBlockReception asserts that the given orderers have the expected // newest block number for the specified channels -func assertBlockReception(expectedBlockNumPerChannel map[string]int, orderers []*nwo.Orderer, p *nwo.Peer, n *nwo.Network) { +func assertBlockReception(expectedBlockNumPerChannel map[string]int, orderers []*nwo.Orderer, n *nwo.Network) { for channelName, blockNum := range expectedBlockNumPerChannel { for _, orderer := range orderers { - waitForBlockReception(orderer, p, n, channelName, blockNum) + waitForBlockReception(orderer, n, channelName, blockNum) } } } -func waitForBlockReception(o *nwo.Orderer, submitter *nwo.Peer, network *nwo.Network, channelName string, blockNum int) { - c := commands.ChannelFetch{ - ChannelID: channelName, - Block: "newest", - OutputFile: "/dev/null", - Orderer: network.OrdererAddress(o, nwo.ListenPort), - } +func waitForBlockReception(o *nwo.Orderer, network *nwo.Network, channelName string, blockNum int) { Eventually(func() string { - sess, err := network.OrdererAdminSession(o, submitter, c) - Expect(err).NotTo(HaveOccurred()) - Eventually(sess, network.EventuallyTimeout).Should(gexec.Exit()) - if sess.ExitCode() != 0 { - return fmt.Sprintf("exit code is %d: %s", sess.ExitCode(), string(sess.Err.Contents())) + b, err := nwo.Fetch(network, o, channelName, "newest") + if err != nil { + return fmt.Sprintf("error is %s", err.Error()) } - sessErr := string(sess.Err.Contents()) - expected := fmt.Sprintf("Received block: %d", blockNum) - if strings.Contains(sessErr, expected) { + + if b.GetHeader().GetNumber() == uint64(blockNum) { return "" } - return sessErr + return "wrong block" }, network.EventuallyTimeout, time.Second).Should(BeEmpty()) } diff --git a/integration/raft/migration_test.go b/integration/raft/migration_test.go index f920b687281..8314e9f4cbc 100644 --- a/integration/raft/migration_test.go +++ b/integration/raft/migration_test.go @@ -298,7 +298,7 @@ var _ = Describe("ConsensusTypeMigration", func() { // In maintenance mode deliver requests are open to those entities that satisfy the /Channel/Orderer/Readers policy By("1) Verify: delivery request from peer is blocked") - err := checkPeerDeliverRequest(o1, peer, network, "testchannel") + err := checkDeliverRequest(o1, peer, network, "testchannel") Expect(err).To(MatchError(errors.New("FORBIDDEN"))) // === Step 2: config update on standard channel, State=NORMAL, abort === @@ -313,7 +313,7 @@ var _ = Describe("ConsensusTypeMigration", func() { Expect(std1BlockNum).To(Equal(std1EntryBlockNum + 1)) By("2) Verify: standard channel delivery requests from peer unblocked") - err = checkPeerDeliverRequest(o1, peer, network, "testchannel") + err = checkDeliverRequest(o1, peer, network, "testchannel") Expect(err).NotTo(HaveOccurred()) By("2) Verify: Normal TX's on standard channel are permitted again") @@ -337,7 +337,7 @@ var _ = Describe("ConsensusTypeMigration", func() { validateConsensusTypeValue(consensusTypeValue, "etcdraft", protosorderer.ConsensusType_STATE_MAINTENANCE) By("3) Verify: delivery request from peer is blocked") - err = checkPeerDeliverRequest(o1, peer, network, "testchannel") + err = checkDeliverRequest(o1, peer, network, "testchannel") Expect(err).To(MatchError(errors.New("FORBIDDEN"))) By("3) Verify: Normal TX's on standard channel are blocked") @@ -499,7 +499,7 @@ var _ = Describe("ConsensusTypeMigration", func() { // In maintenance mode deliver requests are open to those entities that satisfy the /Channel/Orderer/Readers policy By("1) Verify: delivery request from peer is blocked") - err := checkPeerDeliverRequest(o1, peer, network, "testchannel") + err := checkDeliverRequest(o1, peer, network, "testchannel") Expect(err).To(MatchError(errors.New("FORBIDDEN"))) // === Step 2: config update on standard channel, State=MAINTENANCE, type=etcdraft === @@ -529,14 +529,7 @@ var _ = Describe("ConsensusTypeMigration", func() { Eventually(o1Proc.Ready(), network.EventuallyTimeout).Should(BeClosed()) - assertBlockReception( - map[string]int{ - "testchannel": int(chan1BlockNum), - }, - []*nwo.Orderer{o1}, - peer, - network, - ) + assertBlockReception(map[string]int{"testchannel": int(chan1BlockNum)}, []*nwo.Orderer{o1}, network) Eventually(o1Runner.Err(), network.EventuallyTimeout, time.Second).Should(gbytes.Say("Raft leader changed: 0 -> ")) Eventually(o1Proc.Ready(), network.EventuallyTimeout).Should(BeClosed()) @@ -605,27 +598,41 @@ func updateConfigWithBatchTimeout(updatedConfig *common.Config) { } } -func checkPeerDeliverRequest(o *nwo.Orderer, submitter *nwo.Peer, network *nwo.Network, channelName string) error { - c := commands.ChannelFetch{ - ChannelID: channelName, - Block: "newest", - OutputFile: "/dev/null", - Orderer: network.OrdererAddress(o, nwo.ListenPort), - } +func checkDeliverRequest(orderer *nwo.Orderer, submitter *nwo.Peer, network *nwo.Network, channelName string) error { + signer := network.PeerUserSigner(submitter, "User1") - sess, err := network.PeerUserSession(submitter, "User1", c) + denv, err := protoutil.CreateSignedEnvelope( + common.HeaderType_DELIVER_SEEK_INFO, + channelName, + signer, + &protosorderer.SeekInfo{ + Behavior: protosorderer.SeekInfo_BLOCK_UNTIL_READY, + Start: &protosorderer.SeekPosition{ + Type: &protosorderer.SeekPosition_Newest{ + Newest: &protosorderer.SeekNewest{}, + }, + }, + Stop: &protosorderer.SeekPosition{ + Type: &protosorderer.SeekPosition_Newest{ + Newest: &protosorderer.SeekNewest{}, + }, + }, + }, + 0, + 0, + ) Expect(err).NotTo(HaveOccurred()) - Eventually(sess, network.EventuallyTimeout).Should(gexec.Exit()) - sessErr := string(sess.Err.Contents()) - sessExitCode := sess.ExitCode() - if sessExitCode != 0 && strings.Contains(sessErr, "FORBIDDEN") { - return errors.New("FORBIDDEN") - } - if sessExitCode == 0 && strings.Contains(sessErr, "Received block: ") { - return nil + + _, err = ordererclient.Deliver(network, orderer, denv) + if err != nil { + if strings.Contains(err.Error(), "FORBIDDEN") { + return errors.New("FORBIDDEN") + } else { + return fmt.Errorf("Unexpected result: Err=%v", err) + } } - return fmt.Errorf("Unexpected result: ExitCode=%d, Err=%s", sessExitCode, sessErr) + return nil } func updateOrdererEndpointsConfigFails(n *nwo.Network, orderer *nwo.Orderer, channel string, current, updated *common.Config, peer *nwo.Peer, additionalSigners ...*nwo.Peer) { diff --git a/integration/smartbft/smartbft_block_deliverer_test.go b/integration/smartbft/smartbft_block_deliverer_test.go index 27bbf57afac..e4c98a0d37c 100644 --- a/integration/smartbft/smartbft_block_deliverer_test.go +++ b/integration/smartbft/smartbft_block_deliverer_test.go @@ -67,7 +67,6 @@ var _ = Describe("Smart BFT Block Deliverer", func() { ordererRunners []*ginkgomon.Runner allStreams []ordererProtos.AtomicBroadcast_BroadcastClient channel string - peer *nwo.Peer ) BeforeEach(func() { @@ -75,7 +74,6 @@ var _ = Describe("Smart BFT Block Deliverer", func() { peerProcesses = nil mocksArray = nil ledgerArray = nil - peer = nil ordererRunners = nil allStreams = nil var err error @@ -115,8 +113,6 @@ var _ = Describe("Smart BFT Block Deliverer", func() { Eventually(ordererRunners[2].Err(), network.EventuallyTimeout, time.Second).Should(gbytes.Say("Message from 1")) Eventually(ordererRunners[3].Err(), network.EventuallyTimeout, time.Second).Should(gbytes.Say("Message from 1")) - peer = network.Peers[0] - /* Create a stream with client for each orderer*/ for _, o := range network.Orderers { conn := network.OrdererClientConn(o) @@ -140,7 +136,7 @@ var _ = Describe("Smart BFT Block Deliverer", func() { Expect(err).NotTo(HaveOccurred()) } } - assertBlockReception(map[string]int{channel: 10}, network.Orderers, peer, network) + assertBlockReception(map[string]int{channel: 10}, network.Orderers, network) }) AfterEach(func() { @@ -314,7 +310,7 @@ var _ = Describe("Smart BFT Block Deliverer", func() { Expect(err).NotTo(HaveOccurred()) } } - assertBlockReception(map[string]int{channel: 20}, network.Orderers[:3], peer, network) + assertBlockReception(map[string]int{channel: 20}, network.Orderers[:3], network) By("Stop the rest of the orderers") for i, proc := range ordererProcesses { @@ -386,7 +382,7 @@ var _ = Describe("Smart BFT Block Deliverer", func() { Eventually(o4Runner.Err(), network.EventuallyTimeout).Should(gbytes.Say("Block censorship detected")) By("Assert all block are received") - assertBlockReception(map[string]int{channel: 20}, []*nwo.Orderer{network.Orderers[3]}, peer, network) + assertBlockReception(map[string]int{channel: 20}, []*nwo.Orderer{network.Orderers[3]}, network) close(censoringOrderer.StopDeliveryChannel) }) diff --git a/integration/smartbft/smartbft_test.go b/integration/smartbft/smartbft_test.go index 3d235d96075..1751e8189b9 100644 --- a/integration/smartbft/smartbft_test.go +++ b/integration/smartbft/smartbft_test.go @@ -255,14 +255,14 @@ var _ = Describe("EndToEnd Smart BFT configuration test", func() { batchSize.AbsoluteMaxBytes = 1000000 batchSize.MaxMessageCount = 300 }) - assertBlockReception(map[string]int{"testchannel1": 1}, network.Orderers, peer, network) + assertBlockReception(map[string]int{"testchannel1": 1}, network.Orderers, network) updateBatchSize(network, peer, orderer, channel, func(batchSize *ordererProtos.BatchSize) { batchSize.AbsoluteMaxBytes = 1000000 batchSize.MaxMessageCount = 400 }) - assertBlockReception(map[string]int{"testchannel1": 2}, network.Orderers, peer, network) + assertBlockReception(map[string]int{"testchannel1": 2}, network.Orderers, network) By("Try deploying chaincode") peers := network.PeersWithChannel(channel) @@ -271,7 +271,7 @@ var _ = Describe("EndToEnd Smart BFT configuration test", func() { // deploy the chaincode deployChaincode(network, channel, testDir) - assertBlockReception(map[string]int{"testchannel1": 6}, network.Orderers, peer, network) + assertBlockReception(map[string]int{"testchannel1": 6}, network.Orderers, network) // test the chaincodes invokeQuery(network, peer, orderer, channel, 90) @@ -360,12 +360,12 @@ var _ = Describe("EndToEnd Smart BFT configuration test", func() { }) By("Deployed chaincode successfully") - assertBlockReception(map[string]int{"testchannel1": 4}, network.Orderers, peer, network) + assertBlockReception(map[string]int{"testchannel1": 4}, network.Orderers, network) By("Transacting on testchannel1") invokeQuery(network, peer, orderer, channel, 90) invokeQuery(network, peer, orderer, channel, 80) - assertBlockReception(map[string]int{"testchannel1": 6}, network.Orderers, peer, network) + assertBlockReception(map[string]int{"testchannel1": 6}, network.Orderers, network) By("Adding a new consenter") orderer5 := &nwo.Orderer{ @@ -408,7 +408,7 @@ var _ = Describe("EndToEnd Smart BFT configuration test", func() { Port: uint32(network.OrdererPort(orderer5, nwo.ClusterPort)), }) }) - assertBlockReception(map[string]int{"testchannel1": 7}, network.Orderers[:4], peer, network) + assertBlockReception(map[string]int{"testchannel1": 7}, network.Orderers[:4], network) By("Waiting for followers to see the leader") Eventually(ordererRunners[0].Err(), network.EventuallyTimeout, time.Second).Should(gbytes.Say("Message from 3 channel=testchannel1")) @@ -481,7 +481,7 @@ var _ = Describe("EndToEnd Smart BFT configuration test", func() { Eventually(ordererRunners[0].Err(), network.EventuallyTimeout, time.Second).Should(gbytes.Say("Message from 2 channel=testchannel1")) By("Ensure all nodes are in sync") - assertBlockReception(map[string]int{"testchannel1": 7}, network.Orderers, peer, network) + assertBlockReception(map[string]int{"testchannel1": 7}, network.Orderers, network) By("Transacting on testchannel1 a few times") invokeQuery(network, peer, network.Orderers[4], channel, 70) @@ -491,7 +491,7 @@ var _ = Describe("EndToEnd Smart BFT configuration test", func() { invokeQuery(network, peer, network.Orderers[4], channel, 50) By("Ensure all nodes are in sync") - assertBlockReception(map[string]int{"testchannel1": 10}, network.Orderers, peer, network) + assertBlockReception(map[string]int{"testchannel1": 10}, network.Orderers, network) time.Sleep(time.Second * 5) invokeQuery(network, peer, network.Orderers[4], channel, 40) @@ -500,7 +500,7 @@ var _ = Describe("EndToEnd Smart BFT configuration test", func() { Eventually(ordererRunners[0].Err(), network.EventuallyTimeout, time.Second).Should(gbytes.Say("Deciding on seq 11")) By("Ensure all nodes are in sync, again") - assertBlockReception(map[string]int{"testchannel1": 11}, network.Orderers, peer, network) + assertBlockReception(map[string]int{"testchannel1": 11}, network.Orderers, network) By("Removing the added node from the channels") nwo.UpdateConsenters(network, peer, network.Orderers[2], "testchannel1", func(orderers *common.Orderers) { @@ -509,7 +509,7 @@ var _ = Describe("EndToEnd Smart BFT configuration test", func() { Eventually(ordererRunners[4].Err(), network.EventuallyTimeout, time.Second).Should(gbytes.Say("Evicted in reconfiguration, shutting down channel=testchannel1")) By("Ensure all nodes are in sync after node 5 evicted") - assertBlockReception(map[string]int{"testchannel1": 12}, network.Orderers, peer, network) + assertBlockReception(map[string]int{"testchannel1": 12}, network.Orderers, network) By("Make sure the peers get the config blocks, again") waitForBlockReceptionByPeer(peer, network, "testchannel1", 12) @@ -535,7 +535,7 @@ var _ = Describe("EndToEnd Smart BFT configuration test", func() { By("Transact again") invokeQuery(network, peer, network.Orderers[2], channel, 30) - assertBlockReception(map[string]int{"testchannel1": 13}, network.Orderers[:4], peer, network) + assertBlockReception(map[string]int{"testchannel1": 13}, network.Orderers[:4], network) // Drain the buffer n := len(orderer5Runner.Err().Contents()) @@ -555,7 +555,7 @@ var _ = Describe("EndToEnd Smart BFT configuration test", func() { }) By("Ensuring all nodes got the block that adds the consenter to the application channel") - assertBlockReception(map[string]int{"testchannel1": 14}, network.Orderers, peer, network) + assertBlockReception(map[string]int{"testchannel1": 14}, network.Orderers, network) By("Transact after orderer5 rejoined the consenters set") invokeQuery(network, peer, network.Orderers[0], channel, 20) @@ -563,7 +563,7 @@ var _ = Describe("EndToEnd Smart BFT configuration test", func() { By("Transact last time") invokeQuery(network, peer, network.Orderers[4], channel, 10) - assertBlockReception(map[string]int{"testchannel1": 16}, network.Orderers, peer, network) + assertBlockReception(map[string]int{"testchannel1": 16}, network.Orderers, network) }) It("smartbft policy update protection works properly", func() { @@ -716,7 +716,7 @@ var _ = Describe("EndToEnd Smart BFT configuration test", func() { By("Joining peers to testchannel1") network.JoinChannel(channel, network.Orderers[0], network.PeersWithChannel(channel)...) - assertBlockReception(map[string]int{"testchannel1": 0}, network.Orderers, peer, network) + assertBlockReception(map[string]int{"testchannel1": 0}, network.Orderers, network) By("Restarting all nodes") for i := 0; i < 4; i++ { @@ -737,7 +737,7 @@ var _ = Describe("EndToEnd Smart BFT configuration test", func() { By("Deploying chaincode") deployChaincode(network, channel, testDir) - assertBlockReception(map[string]int{"testchannel1": 4}, network.Orderers, peer, network) + assertBlockReception(map[string]int{"testchannel1": 4}, network.Orderers, network) By("Taking down a follower node") ordererProcesses[3].Signal(syscall.SIGTERM) @@ -762,7 +762,7 @@ var _ = Describe("EndToEnd Smart BFT configuration test", func() { Eventually(runner.Err(), network.EventuallyTimeout, time.Second).Should(gbytes.Say("Message from 1")) Eventually(runner.Err(), network.EventuallyTimeout, time.Second).Should(gbytes.Say("Message from 1")) - assertBlockReception(map[string]int{"testchannel1": 8}, network.Orderers, peer, network) + assertBlockReception(map[string]int{"testchannel1": 8}, network.Orderers, network) invokeQuery(network, peer, orderer, channel, 50) time.Sleep(time.Second * 2) @@ -776,7 +776,7 @@ var _ = Describe("EndToEnd Smart BFT configuration test", func() { By("Submitting to orderer4") invokeQuery(network, peer, network.Orderers[3], channel, 0) - assertBlockReception(map[string]int{"testchannel1": 14}, network.Orderers, peer, network) + assertBlockReception(map[string]int{"testchannel1": 14}, network.Orderers, network) By("Ensuring follower participates in consensus") Eventually(runner.Err(), network.EventuallyTimeout, time.Second).Should(gbytes.Say("Deciding on seq 14")) @@ -820,7 +820,7 @@ var _ = Describe("EndToEnd Smart BFT configuration test", func() { By("Joining peers to testchannel1") network.JoinChannel(channel, network.Orderers[0], network.PeersWithChannel(channel)...) - assertBlockReception(map[string]int{"testchannel1": 0}, network.Orderers, peer, network) + assertBlockReception(map[string]int{"testchannel1": 0}, network.Orderers, network) By("Restarting all nodes") for i := 0; i < 4; i++ { @@ -841,7 +841,7 @@ var _ = Describe("EndToEnd Smart BFT configuration test", func() { By("Deploying chaincode") deployChaincode(network, channel, testDir) - assertBlockReception(map[string]int{"testchannel1": 4}, network.Orderers, peer, network) + assertBlockReception(map[string]int{"testchannel1": 4}, network.Orderers, network) By("Taking down a follower node") ordererProcesses[3].Signal(syscall.SIGTERM) @@ -867,7 +867,7 @@ var _ = Describe("EndToEnd Smart BFT configuration test", func() { Eventually(runner.Err(), network.EventuallyTimeout, time.Second).Should(gbytes.Say("Message from 1")) Eventually(runner.Err(), network.EventuallyTimeout, time.Second).Should(gbytes.Say("Message from 1")) - assertBlockReception(map[string]int{"testchannel1": 8}, network.Orderers, peer, network) + assertBlockReception(map[string]int{"testchannel1": 8}, network.Orderers, network) invokeQuery(network, peer, orderer, channel, 50) time.Sleep(time.Second * 2) @@ -881,7 +881,7 @@ var _ = Describe("EndToEnd Smart BFT configuration test", func() { By("Submitting to orderer4") invokeQuery(network, peer, network.Orderers[3], channel, 0) - assertBlockReception(map[string]int{"testchannel1": 14}, network.Orderers, peer, network) + assertBlockReception(map[string]int{"testchannel1": 14}, network.Orderers, network) By("Ensuring follower participates in consensus") Eventually(runner.Err(), network.EventuallyTimeout, time.Second).Should(gbytes.Say("Deciding on seq 14")) @@ -925,7 +925,7 @@ var _ = Describe("EndToEnd Smart BFT configuration test", func() { By("Deploying chaincode") deployChaincode(network, channel, testDir) - assertBlockReception(map[string]int{"testchannel1": 4}, network.Orderers, peer, network) + assertBlockReception(map[string]int{"testchannel1": 4}, network.Orderers, network) By("Taking down the leader node") ordererProcesses[0].Signal(syscall.SIGTERM) @@ -968,12 +968,12 @@ var _ = Describe("EndToEnd Smart BFT configuration test", func() { Eventually(runner.Err(), network.EventuallyTimeout, time.Second).Should(gbytes.Say("Node 1 was informed of a new view 1 channel=testchannel1")) By("Waiting for all nodes to have the latest block sequence") - assertBlockReception(map[string]int{"testchannel1": 8}, network.Orderers, peer, network) + assertBlockReception(map[string]int{"testchannel1": 8}, network.Orderers, network) By("Ensuring the follower is functioning properly") invokeQuery(network, peer, orderer, channel, 50) invokeQuery(network, peer, orderer, channel, 40) - assertBlockReception(map[string]int{"testchannel1": 10}, network.Orderers, peer, network) + assertBlockReception(map[string]int{"testchannel1": 10}, network.Orderers, network) }) It("smartbft multiple nodes view change", func() { @@ -1013,7 +1013,7 @@ var _ = Describe("EndToEnd Smart BFT configuration test", func() { By("Deploying chaincode") deployChaincode(network, channel, testDir) - assertBlockReception(map[string]int{"testchannel1": 4}, network.Orderers, peer, network) + assertBlockReception(map[string]int{"testchannel1": 4}, network.Orderers, network) By("Taking down the leader node") ordererProcesses[0].Signal(syscall.SIGTERM) @@ -1163,7 +1163,7 @@ var _ = Describe("EndToEnd Smart BFT configuration test", func() { }) }) - assertBlockReception(map[string]int{"testchannel1": 1 + i}, network.Orderers[:4+i], peer, network) + assertBlockReception(map[string]int{"testchannel1": 1 + i}, network.Orderers[:4+i], network) By("Planting last config block in the orderer's file system") configBlock := nwo.GetConfigBlock(network, peer, orderer, "testchannel1") @@ -1203,7 +1203,7 @@ var _ = Describe("EndToEnd Smart BFT configuration test", func() { Eventually(runner.Err(), network.EventuallyTimeout, time.Second).Should(gbytes.Say("Message from 1 channel=testchannel1")) By("Ensure all orderers are in sync") - assertBlockReception(map[string]int{"testchannel1": 1 + i}, network.Orderers, peer, network) + assertBlockReception(map[string]int{"testchannel1": 1 + i}, network.Orderers, network) } // for loop that adds orderers @@ -1229,7 +1229,7 @@ var _ = Describe("EndToEnd Smart BFT configuration test", func() { orderers.ConsenterMapping = orderers.ConsenterMapping[1:] }) - assertBlockReception(map[string]int{"testchannel1": 8 + i}, network.Orderers[7:], peer, network) + assertBlockReception(map[string]int{"testchannel1": 8 + i}, network.Orderers[7:], network) } }) @@ -1380,12 +1380,12 @@ var _ = Describe("EndToEnd Smart BFT configuration test", func() { By("Deploying chaincode") deployChaincode(network, channel, testDir) - assertBlockReception(map[string]int{"testchannel1": 4}, network.Orderers, peer, network) + assertBlockReception(map[string]int{"testchannel1": 4}, network.Orderers, network) By("Transacting on testchannel1") invokeQuery(network, peer, network.Orderers[0], channel, 90) invokeQuery(network, peer, network.Orderers[0], channel, 80) - assertBlockReception(map[string]int{"testchannel1": 6}, network.Orderers, peer, network) + assertBlockReception(map[string]int{"testchannel1": 6}, network.Orderers, network) By("Adding a new consenter") @@ -1430,7 +1430,7 @@ var _ = Describe("EndToEnd Smart BFT configuration test", func() { }) }) - assertBlockReception(map[string]int{"testchannel1": 7}, network.Orderers[:4], peer, network) + assertBlockReception(map[string]int{"testchannel1": 7}, network.Orderers[:4], network) By("Waiting for followers to see the leader after config update") Eventually(ordererRunners[1].Err(), network.EventuallyTimeout, time.Second).Should(gbytes.Say("Message from 1 channel=testchannel1")) @@ -1488,7 +1488,7 @@ var _ = Describe("EndToEnd Smart BFT configuration test", func() { Eventually(ordererRunners[3].Err(), network.EventuallyTimeout*2, time.Second).Should(gbytes.Say("Changing to follower role, current view: 1, current leader: 2 channel=testchannel1")) Eventually(ordererRunners[4].Err(), network.EventuallyTimeout*2, time.Second).Should(gbytes.Say("Changing to follower role, current view: 1, current leader: 2 channel=testchannel1")) - assertBlockReception(map[string]int{"testchannel1": 7}, network.Orderers[1:], peer, network) + assertBlockReception(map[string]int{"testchannel1": 7}, network.Orderers[1:], network) By("Transacting") invokeQuery(network, peer, network.Orderers[2], channel, 70) @@ -1499,7 +1499,7 @@ var _ = Describe("EndToEnd Smart BFT configuration test", func() { Eventually(ordererRunners[3].Err(), network.EventuallyTimeout, time.Second).Should(gbytes.Say("Skipping verifying prev commit signatures due to verification sequence advancing from 0 to 1 channel=testchannel1")) Eventually(ordererRunners[4].Err(), network.EventuallyTimeout, time.Second).Should(gbytes.Say("Skipping verifying prev commit signatures due to verification sequence advancing from 0 to 1 channel=testchannel1")) - assertBlockReception(map[string]int{"testchannel1": 8}, network.Orderers[1:], peer, network) + assertBlockReception(map[string]int{"testchannel1": 8}, network.Orderers[1:], network) }) It("smartbft forwarding errorous message to leader", func() { @@ -2159,12 +2159,12 @@ var _ = Describe("EndToEnd Smart BFT configuration test", func() { By("Deploying chaincode") deployChaincode(network, channel, testDir) - assertBlockReception(map[string]int{channel: 4}, network.Orderers, peer, network) + assertBlockReception(map[string]int{channel: 4}, network.Orderers, network) By("Transacting on channel") invokeQuery(network, peer, network.Orderers[0], channel, 90) invokeQuery(network, peer, network.Orderers[0], channel, 80) - assertBlockReception(map[string]int{channel: 6}, network.Orderers, peer, network) + assertBlockReception(map[string]int{channel: 6}, network.Orderers, network) }) It("cluster delivery client is creating a BFT delivery client", func() { @@ -2251,12 +2251,12 @@ var _ = Describe("EndToEnd Smart BFT configuration test", func() { By("Deploying chaincode") deployChaincode(network, channel, testDir) - assertBlockReception(map[string]int{channel: 4}, network.Orderers, peer, network) + assertBlockReception(map[string]int{channel: 4}, network.Orderers, network) By("Transacting on channel") invokeQuery(network, peer, network.Orderers[0], channel, 90) invokeQuery(network, peer, network.Orderers[0], channel, 80) - assertBlockReception(map[string]int{channel: 6}, network.Orderers, peer, network) + assertBlockReception(map[string]int{channel: 6}, network.Orderers, network) }) It("remove channel from all orderers and add channel back", func() { @@ -2280,8 +2280,6 @@ var _ = Describe("EndToEnd Smart BFT configuration test", func() { Eventually(proc.Ready(), network.EventuallyTimeout).Should(BeClosed()) } - peer := network.Peer("Org1", "peer0") - sess, err := network.ConfigTxGen(commands.OutputBlock{ ChannelID: cn, Profile: network.Profiles[0].Name, @@ -2318,7 +2316,7 @@ var _ = Describe("EndToEnd Smart BFT configuration test", func() { Eventually(ordererRunners[2].Err(), network.EventuallyTimeout, time.Second).Should(gbytes.Say("Message from 1")) Eventually(ordererRunners[3].Err(), network.EventuallyTimeout, time.Second).Should(gbytes.Say("Message from 1")) - assertBlockReception(map[string]int{cn: 0}, network.Orderers, peer, network) + assertBlockReception(map[string]int{cn: 0}, network.Orderers, network) By("Removing channel from all orderers") for _, o := range network.Orderers { @@ -2373,9 +2371,7 @@ var _ = Describe("EndToEnd Smart BFT configuration test", func() { Eventually(ordererRunners[2].Err(), network.EventuallyTimeout, time.Second).Should(gbytes.Say("Message from 1")) Eventually(ordererRunners[3].Err(), network.EventuallyTimeout, time.Second).Should(gbytes.Say("Message from 1")) - assertBlockReception(map[string]int{ - cn: 0, - }, network.Orderers, peer, network) + assertBlockReception(map[string]int{cn: 0}, network.Orderers, network) By("Submitting tx") env := ordererclient.CreateBroadcastEnvelope(network, network.Orderers[0], cn, []byte("foo"), common.HeaderType_ENDORSER_TRANSACTION) @@ -2395,9 +2391,7 @@ var _ = Describe("EndToEnd Smart BFT configuration test", func() { wg.Wait() By("End broadcast") - assertBlockReception(map[string]int{ - cn: 1, - }, network.Orderers, peer, network) + assertBlockReception(map[string]int{cn: 1}, network.Orderers, network) }) }) }) @@ -2442,11 +2436,11 @@ func queryExpect(network *nwo.Network, peer *nwo.Peer, channel string, key strin } // assertBlockReception asserts that the given orderers have expected heights for the given channel--> height mapping -func assertBlockReception(expectedSequencesPerChannel map[string]int, orderers []*nwo.Orderer, p *nwo.Peer, n *nwo.Network) { +func assertBlockReception(expectedSequencesPerChannel map[string]int, orderers []*nwo.Orderer, n *nwo.Network) { defer GinkgoRecover() assertReception := func(channelName string, blockSeq int) { for _, orderer := range orderers { - waitForBlockReception(orderer, p, n, channelName, blockSeq) + waitForBlockReception(orderer, n, channelName, blockSeq) } } @@ -2455,26 +2449,17 @@ func assertBlockReception(expectedSequencesPerChannel map[string]int, orderers [ } } -func waitForBlockReception(o *nwo.Orderer, submitter *nwo.Peer, network *nwo.Network, channelName string, blockSeq int) { - c := commands.ChannelFetch{ - ChannelID: channelName, - Block: "newest", - OutputFile: "/dev/null", - Orderer: network.OrdererAddress(o, nwo.ListenPort), - } +func waitForBlockReception(o *nwo.Orderer, network *nwo.Network, channelName string, blockSeq int) { Eventually(func() string { - sess, err := network.OrdererAdminSession(o, submitter, c) - Expect(err).NotTo(HaveOccurred()) - Eventually(sess, network.EventuallyTimeout).Should(gexec.Exit()) - if sess.ExitCode() != 0 { - return fmt.Sprintf("exit code is %d: %s", sess.ExitCode(), string(sess.Err.Contents())) + b, err := nwo.Fetch(network, o, channelName, "newest") + if err != nil { + return fmt.Sprintf("error is %s", err.Error()) } - sessErr := string(sess.Err.Contents()) - expected := fmt.Sprintf("Received block: %d", blockSeq) - if strings.Contains(sessErr, expected) { + + if b.GetHeader().GetNumber() == uint64(blockSeq) { return "" } - return sessErr + return "wrong block" }, network.EventuallyTimeout, time.Second).Should(BeEmpty()) } diff --git a/internal/osnadmin/httpclient.go b/internal/osnadmin/httpclient.go index 197da28a07a..435a3b36563 100644 --- a/internal/osnadmin/httpclient.go +++ b/internal/osnadmin/httpclient.go @@ -42,8 +42,7 @@ func httpDoTimeShift(req *http.Request, caCertPool *x509.CertPool, tlsClientCert } func httpGet(url string, caCertPool *x509.CertPool, tlsClientCert tls.Certificate) (*http.Response, error) { - client := httpClient(caCertPool, tlsClientCert, 0) - return client.Get(url) + return httpGetTimeShift(url, caCertPool, tlsClientCert, 0) } func httpGetTimeShift(url string, caCertPool *x509.CertPool, tlsClientCert tls.Certificate, timeShift time.Duration) (*http.Response, error) {