From 52ecfb6465e8cef898ef3cc35d4981dc0a83e4ce Mon Sep 17 00:00:00 2001 From: Sam Yuan Date: Tue, 4 Apr 2023 23:29:34 +0800 Subject: [PATCH 01/12] impl for get block from orderer Signed-off-by: Sam Yuan --- pkg/channel/getBlock.go | 92 +++++++++++++++++++++++++++++++++++++++++ test/e2e_test.go | 23 ++++++++++- 2 files changed, 113 insertions(+), 2 deletions(-) create mode 100644 pkg/channel/getBlock.go diff --git a/pkg/channel/getBlock.go b/pkg/channel/getBlock.go new file mode 100644 index 0000000..e2453f8 --- /dev/null +++ b/pkg/channel/getBlock.go @@ -0,0 +1,92 @@ +package channel + +import ( + "crypto/sha256" + "crypto/tls" + "fmt" + + "github.com/hyperledger/fabric-admin-sdk/internal/protoutil" + "github.com/hyperledger/fabric-admin-sdk/pkg/identity" + cb "github.com/hyperledger/fabric-protos-go-apiv2/common" + ab "github.com/hyperledger/fabric-protos-go-apiv2/orderer" +) + +var Newest = &ab.SeekPosition{ + Type: &ab.SeekPosition_Newest{ + Newest: &ab.SeekNewest{}, + }, +} + +func GetNewstBlock(Service ab.AtomicBroadcast_DeliverClient, channelID string, Certificate tls.Certificate, signer identity.SigningIdentity, bestEffort bool) (*cb.Block, error) { + var tlsCertHash []byte + hasher := sha256.New() + hasher.Write([]byte(Certificate.Certificate[0])) + tlsCertHash = hasher.Sum(nil) + err := seekNewest(Service, channelID, tlsCertHash, signer, bestEffort) + if err != nil { + return nil, err + } + return readBlock(Service) +} + +func readBlock(Service ab.AtomicBroadcast_DeliverClient) (*cb.Block, error) { + msg, err := Service.Recv() + if err != nil { + return nil, err + } + switch t := msg.Type.(type) { + case *ab.DeliverResponse_Status: + //logger.Infof("Expect block, but got status: %v", t) + return nil, fmt.Errorf("can't read the block: %v", t) + case *ab.DeliverResponse_Block: + //logger.Infof("Received block: %v", t.Block.Header.Number) + if resp, err := Service.Recv(); err != nil { // Flush the success message + fmt.Printf("Failed to flush success message: %s", err) + } else if status := resp.GetStatus(); status != cb.Status_SUCCESS { + fmt.Printf("Expect status to be SUCCESS, got: %s", status) + } + + return t.Block, nil + default: + return nil, fmt.Errorf("response error: unknown type %T", t) + } +} + +func seekNewest(Service ab.AtomicBroadcast_DeliverClient, channelID string, tlsCertHash []byte, signer identity.SigningIdentity, bestEffort bool) error { + env := seekHelper(channelID, Newest, tlsCertHash, signer, bestEffort) + return Service.Send(env) +} + +func seekHelper( + channelID string, + position *ab.SeekPosition, + tlsCertHash []byte, + signer identity.SigningIdentity, + bestEffort bool, +) *cb.Envelope { + seekInfo := &ab.SeekInfo{ + Start: position, + Stop: position, + Behavior: ab.SeekInfo_BLOCK_UNTIL_READY, + } + + if bestEffort { + seekInfo.ErrorResponse = ab.SeekInfo_BEST_EFFORT + } + + env, err := protoutil.CreateSignedEnvelopeWithTLSBinding( + cb.HeaderType_DELIVER_SEEK_INFO, + channelID, + signer, + seekInfo, + int32(0), + uint64(0), + tlsCertHash, + ) + if err != nil { + fmt.Printf("Error signing envelope: %s", err) + return nil + } + + return env +} diff --git a/test/e2e_test.go b/test/e2e_test.go index 3ac8b85..108880f 100644 --- a/test/e2e_test.go +++ b/test/e2e_test.go @@ -21,6 +21,7 @@ import ( "github.com/hyperledger/fabric-admin-sdk/pkg/identity" "github.com/hyperledger/fabric-gateway/pkg/client" gatewaypb "github.com/hyperledger/fabric-protos-go-apiv2/gateway" + "github.com/hyperledger/fabric-protos-go-apiv2/orderer" "github.com/hyperledger/fabric-protos-go-apiv2/peer" . "github.com/onsi/ginkgo/v2" @@ -166,6 +167,24 @@ var _ = Describe("e2e", func() { Expect(err).NotTo(HaveOccurred()) Expect(resp.StatusCode).Should(Equal(http.StatusCreated)) + //osnURL + order := network.Node{ + Addr: osnURL, + TLSCACert: clientCert, + } + err = order.LoadConfig() + Expect(err).NotTo(HaveOccurred()) + ordererConnection, err := network.DialConnection(order) + Expect(err).NotTo(HaveOccurred()) + AtomicBroadcastClient := orderer.NewAtomicBroadcastClient(ordererConnection) + ctx, cancel := context.WithTimeout(specCtx, 2*time.Minute) + defer cancel() + DeliverClient, err := AtomicBroadcastClient.Deliver(ctx) + Expect(err).NotTo(HaveOccurred()) + ordererBlock, err := channel.GetNewstBlock(DeliverClient, channelName, tlsClientCert, org1MSP, true) + Expect(err).NotTo(HaveOccurred()) + Expect(ordererBlock).NotTo(BeNil()) + //join peer1 err = channel.JoinChannel( block, org1MSP, peer1Endorser, @@ -245,7 +264,7 @@ var _ = Describe("e2e", func() { Expect(result).NotTo(BeEmpty()) }) - time.Sleep(time.Duration(20) * time.Second) + //time.Sleep(time.Duration(20) * time.Second) PolicyStr := "AND ('Org1MSP.peer','Org2MSP.peer')" applicationPolicy, err := chaincode.NewApplicationPolicy(PolicyStr, "") Expect(err).NotTo(HaveOccurred()) @@ -289,7 +308,7 @@ var _ = Describe("e2e", func() { Expect(err).NotTo(HaveOccurred(), "check commit readiness") Expect(readinessResult.GetApprovals()).To(Equal((map[string]bool{org1MspID: true, org2MspID: true}))) - time.Sleep(time.Duration(20) * time.Second) + //time.Sleep(time.Duration(20) * time.Second) // Commit chaincode commitCtx, commitCancel := context.WithTimeout(specCtx, 30*time.Second) From 92294896621d1c55d0c3ca9ef73d4dc526e889f0 Mon Sep 17 00:00:00 2001 From: Sam Yuan Date: Tue, 4 Apr 2023 23:35:25 +0800 Subject: [PATCH 02/12] fix up Signed-off-by: Sam Yuan --- test/e2e_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/e2e_test.go b/test/e2e_test.go index 108880f..c5f0b13 100644 --- a/test/e2e_test.go +++ b/test/e2e_test.go @@ -169,7 +169,7 @@ var _ = Describe("e2e", func() { //osnURL order := network.Node{ - Addr: osnURL, + Addr: "localhost:7053", TLSCACert: clientCert, } err = order.LoadConfig() From 64b26df63dcac5338767573c69315a298c9733f8 Mon Sep 17 00:00:00 2001 From: Sam Yuan Date: Tue, 4 Apr 2023 23:39:11 +0800 Subject: [PATCH 03/12] fix up Signed-off-by: Sam Yuan --- test/e2e_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/e2e_test.go b/test/e2e_test.go index c5f0b13..4950da2 100644 --- a/test/e2e_test.go +++ b/test/e2e_test.go @@ -169,7 +169,7 @@ var _ = Describe("e2e", func() { //osnURL order := network.Node{ - Addr: "localhost:7053", + Addr: "localhost:7050", TLSCACert: clientCert, } err = order.LoadConfig() From fc733d9c2721d42f0affe92100c75fe329be5056 Mon Sep 17 00:00:00 2001 From: Sam Yuan Date: Tue, 4 Apr 2023 23:42:49 +0800 Subject: [PATCH 04/12] fix up Signed-off-by: Sam Yuan --- test/e2e_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/e2e_test.go b/test/e2e_test.go index 4950da2..41278b0 100644 --- a/test/e2e_test.go +++ b/test/e2e_test.go @@ -264,7 +264,7 @@ var _ = Describe("e2e", func() { Expect(result).NotTo(BeEmpty()) }) - //time.Sleep(time.Duration(20) * time.Second) + time.Sleep(time.Duration(20) * time.Second) PolicyStr := "AND ('Org1MSP.peer','Org2MSP.peer')" applicationPolicy, err := chaincode.NewApplicationPolicy(PolicyStr, "") Expect(err).NotTo(HaveOccurred()) @@ -308,7 +308,7 @@ var _ = Describe("e2e", func() { Expect(err).NotTo(HaveOccurred(), "check commit readiness") Expect(readinessResult.GetApprovals()).To(Equal((map[string]bool{org1MspID: true, org2MspID: true}))) - //time.Sleep(time.Duration(20) * time.Second) + time.Sleep(time.Duration(20) * time.Second) // Commit chaincode commitCtx, commitCancel := context.WithTimeout(specCtx, 30*time.Second) From 4a195b12baa999c654c430d8e4dc246d009708ec Mon Sep 17 00:00:00 2001 From: Sam Yuan Date: Thu, 13 Apr 2023 21:54:04 +0800 Subject: [PATCH 05/12] fix up Signed-off-by: Sam Yuan --- pkg/channel/getBlock.go | 88 +++++++++++++++++++++++++++++++++++++---- test/e2e_test.go | 2 +- 2 files changed, 81 insertions(+), 9 deletions(-) diff --git a/pkg/channel/getBlock.go b/pkg/channel/getBlock.go index e2453f8..ef1672f 100644 --- a/pkg/channel/getBlock.go +++ b/pkg/channel/getBlock.go @@ -9,26 +9,55 @@ import ( "github.com/hyperledger/fabric-admin-sdk/pkg/identity" cb "github.com/hyperledger/fabric-protos-go-apiv2/common" ab "github.com/hyperledger/fabric-protos-go-apiv2/orderer" + "google.golang.org/protobuf/proto" ) -var Newest = &ab.SeekPosition{ +var newest = &ab.SeekPosition{ Type: &ab.SeekPosition_Newest{ Newest: &ab.SeekNewest{}, }, } -func GetNewstBlock(Service ab.AtomicBroadcast_DeliverClient, channelID string, Certificate tls.Certificate, signer identity.SigningIdentity, bestEffort bool) (*cb.Block, error) { +func GetConfigBlockFromOrderer(Service ab.AtomicBroadcast_DeliverClient, channelID string, Certificate tls.Certificate, signer identity.SigningIdentity, bestEffort bool) (*cb.Block, error) { + iBlock, err := GetNewstBlock(Service, channelID, Certificate, signer, bestEffort) + if err != nil { + return nil, err + } + lc, err := GetLastConfigIndexFromBlock(iBlock) + if err != nil { + return nil, err + } + return GetSpecifiedBlock(Service, channelID, Certificate, signer, bestEffort, lc) +} + +func GetSpecifiedBlock(Service ab.AtomicBroadcast_DeliverClient, channelID string, Certificate tls.Certificate, signer identity.SigningIdentity, bestEffort bool, num uint64) (*cb.Block, error) { + seekPosition := &ab.SeekPosition{ + Type: &ab.SeekPosition_Specified{ + Specified: &ab.SeekSpecified{ + Number: num, + }, + }, + } + return getBlockBySeekPosition(Service, channelID, Certificate, signer, bestEffort, seekPosition) +} + +func getBlockBySeekPosition(Service ab.AtomicBroadcast_DeliverClient, channelID string, Certificate tls.Certificate, signer identity.SigningIdentity, bestEffort bool, seekPosition *ab.SeekPosition) (*cb.Block, error) { var tlsCertHash []byte hasher := sha256.New() hasher.Write([]byte(Certificate.Certificate[0])) tlsCertHash = hasher.Sum(nil) - err := seekNewest(Service, channelID, tlsCertHash, signer, bestEffort) + env := seekHelper(channelID, seekPosition, tlsCertHash, signer, bestEffort) + err := Service.Send(env) if err != nil { return nil, err } return readBlock(Service) } +func GetNewstBlock(Service ab.AtomicBroadcast_DeliverClient, channelID string, Certificate tls.Certificate, signer identity.SigningIdentity, bestEffort bool) (*cb.Block, error) { + return getBlockBySeekPosition(Service, channelID, Certificate, signer, bestEffort, newest) +} + func readBlock(Service ab.AtomicBroadcast_DeliverClient) (*cb.Block, error) { msg, err := Service.Recv() if err != nil { @@ -52,11 +81,6 @@ func readBlock(Service ab.AtomicBroadcast_DeliverClient) (*cb.Block, error) { } } -func seekNewest(Service ab.AtomicBroadcast_DeliverClient, channelID string, tlsCertHash []byte, signer identity.SigningIdentity, bestEffort bool) error { - env := seekHelper(channelID, Newest, tlsCertHash, signer, bestEffort) - return Service.Send(env) -} - func seekHelper( channelID string, position *ab.SeekPosition, @@ -90,3 +114,51 @@ func seekHelper( return env } + +// GetLastConfigIndexFromBlock retrieves the index of the last config block as +// encoded in the block metadata +func GetLastConfigIndexFromBlock(block *cb.Block) (uint64, error) { + m, err := GetMetadataFromBlock(block, cb.BlockMetadataIndex_SIGNATURES) + if err != nil { + return 0, fmt.Errorf("failed to retrieve metadata %w", err) + } + // TODO FAB-15864 Remove this fallback when we can stop supporting upgrade from pre-1.4.1 orderer + if len(m.Value) == 0 { + // TODO cb.BlockMetadataIndex_LAST_CONFIG + m, err := GetMetadataFromBlock(block, 1) + if err != nil { + return 0, fmt.Errorf("failed to retrieve metadata %w", err) + } + lc := &cb.LastConfig{} + err = proto.Unmarshal(m.Value, lc) + if err != nil { + return 0, fmt.Errorf("error unmarshalling LastConfig %w", err) + } + return lc.Index, nil + } + + obm := &cb.OrdererBlockMetadata{} + err = proto.Unmarshal(m.Value, obm) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal orderer block metadata %w", err) + } + return obm.LastConfig.Index, nil +} + +// GetMetadataFromBlock retrieves metadata at the specified index. +func GetMetadataFromBlock(block *cb.Block, index cb.BlockMetadataIndex) (*cb.Metadata, error) { + if block.Metadata == nil { + return nil, fmt.Errorf("no metadata in block") + } + + if len(block.Metadata.Metadata) <= int(index) { + return nil, fmt.Errorf("no metadata at index [%s]", index) + } + + md := &cb.Metadata{} + err := proto.Unmarshal(block.Metadata.Metadata[index], md) + if err != nil { + return nil, fmt.Errorf("error unmarshalling metadata at index [%s] %w", index, err) + } + return md, nil +} diff --git a/test/e2e_test.go b/test/e2e_test.go index 41278b0..5c56cad 100644 --- a/test/e2e_test.go +++ b/test/e2e_test.go @@ -181,7 +181,7 @@ var _ = Describe("e2e", func() { defer cancel() DeliverClient, err := AtomicBroadcastClient.Deliver(ctx) Expect(err).NotTo(HaveOccurred()) - ordererBlock, err := channel.GetNewstBlock(DeliverClient, channelName, tlsClientCert, org1MSP, true) + ordererBlock, err := channel.GetConfigBlockFromOrderer(DeliverClient, channelName, tlsClientCert, org1MSP, true) Expect(err).NotTo(HaveOccurred()) Expect(ordererBlock).NotTo(BeNil()) From 880216fea6d40774be6465560e4bc436c9de03f6 Mon Sep 17 00:00:00 2001 From: Sam Yuan Date: Wed, 26 Apr 2023 19:30:11 +0800 Subject: [PATCH 06/12] Update pkg/channel/getBlock.go Co-authored-by: Mark S. Lewis Signed-off-by: Sam Yuan --- pkg/channel/getBlock.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/channel/getBlock.go b/pkg/channel/getBlock.go index ef1672f..2ecacdb 100644 --- a/pkg/channel/getBlock.go +++ b/pkg/channel/getBlock.go @@ -30,7 +30,7 @@ func GetConfigBlockFromOrderer(Service ab.AtomicBroadcast_DeliverClient, channel return GetSpecifiedBlock(Service, channelID, Certificate, signer, bestEffort, lc) } -func GetSpecifiedBlock(Service ab.AtomicBroadcast_DeliverClient, channelID string, Certificate tls.Certificate, signer identity.SigningIdentity, bestEffort bool, num uint64) (*cb.Block, error) { +func getSpecifiedBlock(Service ab.AtomicBroadcast_DeliverClient, channelID string, Certificate tls.Certificate, signer identity.SigningIdentity, bestEffort bool, num uint64) (*cb.Block, error) { seekPosition := &ab.SeekPosition{ Type: &ab.SeekPosition_Specified{ Specified: &ab.SeekSpecified{ From 4939b27b0946addd56d1a3d7079049c2b9807173 Mon Sep 17 00:00:00 2001 From: Sam Yuan Date: Wed, 26 Apr 2023 19:30:43 +0800 Subject: [PATCH 07/12] Update pkg/channel/getBlock.go Co-authored-by: Mark S. Lewis Signed-off-by: Sam Yuan --- pkg/channel/getBlock.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/channel/getBlock.go b/pkg/channel/getBlock.go index 2ecacdb..f89eccb 100644 --- a/pkg/channel/getBlock.go +++ b/pkg/channel/getBlock.go @@ -54,7 +54,7 @@ func getBlockBySeekPosition(Service ab.AtomicBroadcast_DeliverClient, channelID return readBlock(Service) } -func GetNewstBlock(Service ab.AtomicBroadcast_DeliverClient, channelID string, Certificate tls.Certificate, signer identity.SigningIdentity, bestEffort bool) (*cb.Block, error) { +func getNewestBlock(Service ab.AtomicBroadcast_DeliverClient, channelID string, Certificate tls.Certificate, signer identity.SigningIdentity, bestEffort bool) (*cb.Block, error) { return getBlockBySeekPosition(Service, channelID, Certificate, signer, bestEffort, newest) } From f2966626d131c8efb4af8165e2d7dcf73b3140ab Mon Sep 17 00:00:00 2001 From: Sam Yuan Date: Wed, 26 Apr 2023 19:31:19 +0800 Subject: [PATCH 08/12] Update pkg/channel/getBlock.go Co-authored-by: Mark S. Lewis Signed-off-by: Sam Yuan --- pkg/channel/getBlock.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/channel/getBlock.go b/pkg/channel/getBlock.go index f89eccb..baed7a1 100644 --- a/pkg/channel/getBlock.go +++ b/pkg/channel/getBlock.go @@ -117,7 +117,7 @@ func seekHelper( // GetLastConfigIndexFromBlock retrieves the index of the last config block as // encoded in the block metadata -func GetLastConfigIndexFromBlock(block *cb.Block) (uint64, error) { +func getLastConfigIndexFromBlock(block *cb.Block) (uint64, error) { m, err := GetMetadataFromBlock(block, cb.BlockMetadataIndex_SIGNATURES) if err != nil { return 0, fmt.Errorf("failed to retrieve metadata %w", err) From c4fbfc045cdd139bc239bae4e781f2399f8e6fff Mon Sep 17 00:00:00 2001 From: Sam Yuan Date: Wed, 26 Apr 2023 19:32:22 +0800 Subject: [PATCH 09/12] Update pkg/channel/getBlock.go Co-authored-by: Mark S. Lewis Signed-off-by: Sam Yuan --- pkg/channel/getBlock.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/pkg/channel/getBlock.go b/pkg/channel/getBlock.go index baed7a1..eacb6aa 100644 --- a/pkg/channel/getBlock.go +++ b/pkg/channel/getBlock.go @@ -18,7 +18,12 @@ var newest = &ab.SeekPosition{ }, } -func GetConfigBlockFromOrderer(Service ab.AtomicBroadcast_DeliverClient, channelID string, Certificate tls.Certificate, signer identity.SigningIdentity, bestEffort bool) (*cb.Block, error) { +func GetConfigBlockFromOrderer(ctx context.Context, connection grpc.ClientConnInterface, id identity.SigningIdentity, channelID string, certificate tls.Certificate) (*cb.Block, error) { + abClient := ab.NewAtomicBroadcastClient(connection) + deliverClient, err := abClient.Deliver(ctx) + if err != nil { + return nil, err + } iBlock, err := GetNewstBlock(Service, channelID, Certificate, signer, bestEffort) if err != nil { return nil, err From 4d662a9997468c69b7747de8077672c32b3915ea Mon Sep 17 00:00:00 2001 From: Sam Yuan Date: Wed, 26 Apr 2023 19:33:20 +0800 Subject: [PATCH 10/12] Update pkg/channel/getBlock.go Co-authored-by: Mark S. Lewis Signed-off-by: Sam Yuan --- pkg/channel/getBlock.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/channel/getBlock.go b/pkg/channel/getBlock.go index eacb6aa..324a92c 100644 --- a/pkg/channel/getBlock.go +++ b/pkg/channel/getBlock.go @@ -151,7 +151,7 @@ func getLastConfigIndexFromBlock(block *cb.Block) (uint64, error) { } // GetMetadataFromBlock retrieves metadata at the specified index. -func GetMetadataFromBlock(block *cb.Block, index cb.BlockMetadataIndex) (*cb.Metadata, error) { +func getMetadataFromBlock(block *cb.Block, index cb.BlockMetadataIndex) (*cb.Metadata, error) { if block.Metadata == nil { return nil, fmt.Errorf("no metadata in block") } From c951592a81386b8f7d1b5c716b11982c497c7e1a Mon Sep 17 00:00:00 2001 From: Sam Yuan Date: Wed, 26 Apr 2023 19:33:51 +0800 Subject: [PATCH 11/12] Update test/e2e_test.go Co-authored-by: Mark S. Lewis Signed-off-by: Sam Yuan --- test/e2e_test.go | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/test/e2e_test.go b/test/e2e_test.go index 5c56cad..c7ace34 100644 --- a/test/e2e_test.go +++ b/test/e2e_test.go @@ -176,12 +176,9 @@ var _ = Describe("e2e", func() { Expect(err).NotTo(HaveOccurred()) ordererConnection, err := network.DialConnection(order) Expect(err).NotTo(HaveOccurred()) - AtomicBroadcastClient := orderer.NewAtomicBroadcastClient(ordererConnection) ctx, cancel := context.WithTimeout(specCtx, 2*time.Minute) defer cancel() - DeliverClient, err := AtomicBroadcastClient.Deliver(ctx) - Expect(err).NotTo(HaveOccurred()) - ordererBlock, err := channel.GetConfigBlockFromOrderer(DeliverClient, channelName, tlsClientCert, org1MSP, true) + ordererBlock, err := channel.GetConfigBlockFromOrderer(ctx, ordererConnection, org1MSP, channelName, tlsClientCert) Expect(err).NotTo(HaveOccurred()) Expect(ordererBlock).NotTo(BeNil()) From e643d16a99118ff8a79552c3233b790b0c6c6792 Mon Sep 17 00:00:00 2001 From: Sam Yuan Date: Wed, 26 Apr 2023 20:04:16 +0800 Subject: [PATCH 12/12] fix up Signed-off-by: Sam Yuan --- pkg/channel/getBlock.go | 12 +++++++----- test/e2e_test.go | 1 - 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/pkg/channel/getBlock.go b/pkg/channel/getBlock.go index 324a92c..bf2bb80 100644 --- a/pkg/channel/getBlock.go +++ b/pkg/channel/getBlock.go @@ -1,6 +1,7 @@ package channel import ( + "context" "crypto/sha256" "crypto/tls" "fmt" @@ -9,6 +10,7 @@ import ( "github.com/hyperledger/fabric-admin-sdk/pkg/identity" cb "github.com/hyperledger/fabric-protos-go-apiv2/common" ab "github.com/hyperledger/fabric-protos-go-apiv2/orderer" + "google.golang.org/grpc" "google.golang.org/protobuf/proto" ) @@ -24,15 +26,15 @@ func GetConfigBlockFromOrderer(ctx context.Context, connection grpc.ClientConnIn if err != nil { return nil, err } - iBlock, err := GetNewstBlock(Service, channelID, Certificate, signer, bestEffort) + iBlock, err := getNewestBlock(deliverClient, channelID, certificate, id, true) if err != nil { return nil, err } - lc, err := GetLastConfigIndexFromBlock(iBlock) + lc, err := getLastConfigIndexFromBlock(iBlock) if err != nil { return nil, err } - return GetSpecifiedBlock(Service, channelID, Certificate, signer, bestEffort, lc) + return getSpecifiedBlock(deliverClient, channelID, certificate, id, true, lc) } func getSpecifiedBlock(Service ab.AtomicBroadcast_DeliverClient, channelID string, Certificate tls.Certificate, signer identity.SigningIdentity, bestEffort bool, num uint64) (*cb.Block, error) { @@ -123,14 +125,14 @@ func seekHelper( // GetLastConfigIndexFromBlock retrieves the index of the last config block as // encoded in the block metadata func getLastConfigIndexFromBlock(block *cb.Block) (uint64, error) { - m, err := GetMetadataFromBlock(block, cb.BlockMetadataIndex_SIGNATURES) + m, err := getMetadataFromBlock(block, cb.BlockMetadataIndex_SIGNATURES) if err != nil { return 0, fmt.Errorf("failed to retrieve metadata %w", err) } // TODO FAB-15864 Remove this fallback when we can stop supporting upgrade from pre-1.4.1 orderer if len(m.Value) == 0 { // TODO cb.BlockMetadataIndex_LAST_CONFIG - m, err := GetMetadataFromBlock(block, 1) + m, err := getMetadataFromBlock(block, 1) if err != nil { return 0, fmt.Errorf("failed to retrieve metadata %w", err) } diff --git a/test/e2e_test.go b/test/e2e_test.go index c7ace34..3f44bdb 100644 --- a/test/e2e_test.go +++ b/test/e2e_test.go @@ -21,7 +21,6 @@ import ( "github.com/hyperledger/fabric-admin-sdk/pkg/identity" "github.com/hyperledger/fabric-gateway/pkg/client" gatewaypb "github.com/hyperledger/fabric-protos-go-apiv2/gateway" - "github.com/hyperledger/fabric-protos-go-apiv2/orderer" "github.com/hyperledger/fabric-protos-go-apiv2/peer" . "github.com/onsi/ginkgo/v2"