Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

delete shadow copy proto-struct #4960

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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions core/chaincode/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2550,7 +2550,7 @@ var _ = Describe("Handler", func() {
})

It("sends an execute message to the chaincode with the correct proposal", func() {
expectedMessage := *incomingMessage
expectedMessage := proto.Clone(incomingMessage).(*pb.ChaincodeMessage)
expectedMessage.Proposal = expectedSignedProp

close(responseNotifier)
Expand All @@ -2559,7 +2559,7 @@ var _ = Describe("Handler", func() {
Eventually(fakeChatStream.SendCallCount).Should(Equal(1))
Consistently(fakeChatStream.SendCallCount).Should(Equal(1))
msg := fakeChatStream.SendArgsForCall(0)
Expect(msg).To(Equal(&expectedMessage))
Expect(msg).To(Equal(expectedMessage))
Expect(msg.Proposal).To(Equal(expectedSignedProp))
})

Expand Down
5 changes: 3 additions & 2 deletions core/common/privdata/simplecollection.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ SPDX-License-Identifier: Apache-2.0
package privdata

import (
"github.com/golang/protobuf/proto"
"github.com/hyperledger/fabric-protos-go/peer"
"github.com/hyperledger/fabric/common/policies"
"github.com/hyperledger/fabric/msp"
Expand All @@ -20,7 +21,7 @@ type SimpleCollection struct {
name string
accessPolicy policies.Policy
memberOrgs map[string]struct{}
conf peer.StaticCollectionConfig
conf *peer.StaticCollectionConfig
}

type SimpleCollectionPersistenceConfigs struct {
Expand Down Expand Up @@ -86,7 +87,7 @@ func (sc *SimpleCollection) Setup(collectionConfig *peer.StaticCollectionConfig,
if collectionConfig == nil {
return errors.New("Nil config passed to collection setup")
}
sc.conf = *collectionConfig
sc.conf = proto.Clone(collectionConfig).(*peer.StaticCollectionConfig)
sc.name = collectionConfig.GetName()

// get the access signature policy envelope
Expand Down
41 changes: 16 additions & 25 deletions core/endorser/endorser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ package endorser_test
import (
"context"
"fmt"
"sort"
"slices"
"strings"

"github.com/golang/protobuf/proto"
"github.com/hyperledger/fabric-lib-go/common/metrics/metricsfakes"
Expand All @@ -29,32 +30,22 @@ import (
"github.com/pkg/errors"
)

type CcInterest pb.ChaincodeInterest

func (a CcInterest) Len() int { return len(a.Chaincodes) }
func (a CcInterest) Swap(i, j int) {
a.Chaincodes[i], a.Chaincodes[j] = a.Chaincodes[j], a.Chaincodes[i]
}

func (a CcInterest) Less(i, j int) bool {
ai := a.Chaincodes[i]
aj := a.Chaincodes[j]

if ai.Name != aj.Name {
return ai.Name < aj.Name
func sortChaincodeCall(a, b *pb.ChaincodeCall) int {
if a.Name != b.Name {
return strings.Compare(a.Name, b.Name)
}

if len(ai.CollectionNames) != len(aj.CollectionNames) {
return len(ai.CollectionNames) < len(aj.CollectionNames)
if len(a.CollectionNames) != len(b.CollectionNames) {
return len(a.CollectionNames) - len(b.CollectionNames)
}

for ii := range ai.CollectionNames {
if ai.CollectionNames[ii] != aj.CollectionNames[ii] {
return ai.CollectionNames[ii] < aj.CollectionNames[ii]
for ii := range a.CollectionNames {
if a.CollectionNames[ii] != b.CollectionNames[ii] {
return strings.Compare(a.CollectionNames[ii], b.CollectionNames[ii])
}
}

return false
return 0
}

var _ = Describe("Endorser", func() {
Expand Down Expand Up @@ -1132,7 +1123,7 @@ var _ = Describe("Endorser", func() {

proposalResponse, err := e.ProcessProposal(context.TODO(), signedProposal)
Expect(err).NotTo(HaveOccurred())
sort.Sort(CcInterest(*proposalResponse.Interest))
slices.SortFunc(proposalResponse.Interest.Chaincodes, sortChaincodeCall)
Expect(proposalResponse.Interest).To(Equal(&pb.ChaincodeInterest{
Chaincodes: []*pb.ChaincodeCall{{
Name: "myCC",
Expand Down Expand Up @@ -1169,7 +1160,7 @@ var _ = Describe("Endorser", func() {

proposalResponse, err := e.ProcessProposal(context.TODO(), signedProposal)
Expect(err).NotTo(HaveOccurred())
sort.Sort(CcInterest(*proposalResponse.Interest))
slices.SortFunc(proposalResponse.Interest.Chaincodes, sortChaincodeCall)
Expect(proposalResponse.Interest).To(Equal(&pb.ChaincodeInterest{
Chaincodes: []*pb.ChaincodeCall{
{
Expand Down Expand Up @@ -1209,7 +1200,7 @@ var _ = Describe("Endorser", func() {

proposalResponse, err := e.ProcessProposal(context.TODO(), signedProposal)
Expect(err).NotTo(HaveOccurred())
sort.Sort(CcInterest(*proposalResponse.Interest))
slices.SortFunc(proposalResponse.Interest.Chaincodes, sortChaincodeCall)
Expect(proposalResponse.Interest).To(Equal(&pb.ChaincodeInterest{
Chaincodes: []*pb.ChaincodeCall{{
Name: "myCC",
Expand Down Expand Up @@ -1248,7 +1239,7 @@ var _ = Describe("Endorser", func() {
proposalResponse, err := e.ProcessProposal(context.TODO(), signedProposal)
Expect(err).NotTo(HaveOccurred())

sort.Sort(CcInterest(*proposalResponse.Interest))
slices.SortFunc(proposalResponse.Interest.Chaincodes, sortChaincodeCall)
Expect(proto.Equal(
proposalResponse.Interest,
&pb.ChaincodeInterest{
Expand Down Expand Up @@ -1293,7 +1284,7 @@ var _ = Describe("Endorser", func() {
proposalResponse, err := e.ProcessProposal(context.TODO(), signedProposal)
Expect(err).NotTo(HaveOccurred())

sort.Sort(CcInterest(*proposalResponse.Interest))
slices.SortFunc(proposalResponse.Interest.Chaincodes, sortChaincodeCall)
Expect(proto.Equal(
proposalResponse.Interest,
&pb.ChaincodeInterest{
Expand Down
9 changes: 2 additions & 7 deletions core/peer/deliverevents.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,7 @@ func (fbrs *filteredBlockResponseSender) SendBlockResponse(
signedData *protoutil.SignedData,
) error {
// Generates filtered block response
b := blockEvent(*block)
filteredBlock, err := b.toFilteredBlock()
filteredBlock, err := toFilteredBlock(block)
if err != nil {
logger.Warningf("Failed to generate filtered block due to: %s", err)
return fbrs.SendStatusResponse(common.Status_BAD_REQUEST)
Expand Down Expand Up @@ -231,10 +230,6 @@ func (bprs *blockAndPrivateDataResponseSender) getPrivateData(
// transactionActions aliasing for peer.TransactionAction pointers slice
type transactionActions []*peer.TransactionAction

// blockEvent an alias for common.Block structure, used to
// extend with auxiliary functionality
type blockEvent common.Block

// DeliverFiltered sends a stream of blocks to a client after commitment
func (s *DeliverServer) DeliverFiltered(srv peer.Deliver_DeliverFilteredServer) error {
logger.Debugf("Starting new DeliverFiltered handler")
Expand Down Expand Up @@ -289,7 +284,7 @@ func (s *DeliverServer) DeliverWithPrivateData(srv peer.Deliver_DeliverWithPriva
return err
}

func (block *blockEvent) toFilteredBlock() (*peer.FilteredBlock, error) {
func toFilteredBlock(block *common.Block) (*peer.FilteredBlock, error) {
filteredBlock := &peer.FilteredBlock{
Number: block.Header.Number,
}
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions discovery/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,9 +157,9 @@ func (req *Request) addQueryMapping(queryType protoext.QueryType, key string) {

// Send sends the request and returns the response, or error on failure
func (c *Client) Send(ctx context.Context, req *Request, auth *discovery.AuthInfo) (Response, error) {
reqToBeSent := *req.Request
reqToBeSent := proto.Clone(req.Request).(*discovery.Request)
reqToBeSent.Authentication = auth
payload, err := proto.Marshal(&reqToBeSent)
payload, err := proto.Marshal(reqToBeSent)
if err != nil {
return nil, errors.Wrap(err, "failed marshaling Request to bytes")
}
Expand Down
8 changes: 4 additions & 4 deletions discovery/cmd/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"fmt"
"testing"

. "github.com/hyperledger/fabric-protos-go/discovery"
discprotos "github.com/hyperledger/fabric-protos-go/discovery"
"github.com/hyperledger/fabric-protos-go/msp"
"github.com/hyperledger/fabric/cmd/common"
discovery "github.com/hyperledger/fabric/discovery/cmd"
Expand Down Expand Up @@ -79,13 +79,13 @@ func TestParseConfigResponse(t *testing.T) {
})

t.Run("Success", func(t *testing.T) {
chanRes.On("Config").Return(&ConfigResult{
chanRes.On("Config").Return(&discprotos.ConfigResult{
Msps: map[string]*msp.FabricMSPConfig{
"Org1MSP": nil,
"Org2MSP": nil,
},
Orderers: map[string]*Endpoints{
"OrdererMSP": {Endpoint: []*Endpoint{
Orderers: map[string]*discprotos.Endpoints{
"OrdererMSP": {Endpoint: []*discprotos.Endpoint{
{Host: "orderer1", Port: 7050},
}},
},
Expand Down
2 changes: 1 addition & 1 deletion discovery/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -593,7 +593,7 @@ type peers []*discovery.Peer
func (ps peers) exists(p *discovery.Peer) error {
var found bool
for _, q := range ps {
if reflect.DeepEqual(*p, *q) {
if proto.Equal(p, q) {
found = true
break
}
Expand Down
45 changes: 22 additions & 23 deletions discovery/test/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,14 @@ import (
"testing"
"time"

discovery_protos "github.com/hyperledger/fabric-protos-go/discovery"

"github.com/golang/protobuf/proto"
"github.com/hyperledger/fabric-lib-go/bccsp/sw"
bccsp "github.com/hyperledger/fabric-lib-go/bccsp/utils"
"github.com/hyperledger/fabric-protos-go/common"
discprotos "github.com/hyperledger/fabric-protos-go/discovery"
"github.com/hyperledger/fabric-protos-go/gossip"
msprotos "github.com/hyperledger/fabric-protos-go/msp"
. "github.com/hyperledger/fabric-protos-go/peer"
"github.com/hyperledger/fabric-protos-go/peer"
"github.com/hyperledger/fabric/common/cauthdsl"
"github.com/hyperledger/fabric/common/configtx"
"github.com/hyperledger/fabric/common/crypto/tlsgen"
Expand Down Expand Up @@ -128,21 +127,21 @@ func TestGreenPath(t *testing.T) {
service.lsccMetadataManager.query.On("GetState", "lscc", "cc2").Return(cc2Bytes, nil)
service.lsccMetadataManager.query.On("GetState", "lscc", "cc2~collection").Return(collectionConfigBytes, nil)

ccWithCollection := &ChaincodeInterest{
Chaincodes: []*ChaincodeCall{
ccWithCollection := &peer.ChaincodeInterest{
Chaincodes: []*peer.ChaincodeCall{
{Name: "cc2", CollectionNames: []string{"col12"}},
},
}
cc2cc := &ChaincodeInterest{
Chaincodes: []*ChaincodeCall{
cc2cc := &peer.ChaincodeInterest{
Chaincodes: []*peer.ChaincodeCall{
{Name: "cc1"}, {Name: "cc2"},
},
}

// Send all queries
req := disc.NewRequest().AddLocalPeersQuery().OfChannel("mychannel")
col1 := &ChaincodeCall{Name: "cc2", CollectionNames: []string{"col1"}}
nonExistentCollection := &ChaincodeCall{Name: "cc2", CollectionNames: []string{"col3"}}
col1 := &peer.ChaincodeCall{Name: "cc2", CollectionNames: []string{"col1"}}
nonExistentCollection := &peer.ChaincodeCall{Name: "cc2", CollectionNames: []string{"col3"}}
_ = nonExistentCollection
req, err := req.AddPeersQuery().AddPeersQuery(col1).AddPeersQuery(nonExistentCollection).AddConfigQuery().AddEndorsersQuery(cc2cc, ccWithCollection)

Expand Down Expand Up @@ -241,8 +240,8 @@ func TestEndorsementComputationFailure(t *testing.T) {

// Now test a collection query that should fail because cc2's endorsement policy is Org1MSP AND org2MSP
// but the collection is configured only to have peers from Org1MSP
ccWithCollection := &ChaincodeInterest{
Chaincodes: []*ChaincodeCall{
ccWithCollection := &peer.ChaincodeInterest{
Chaincodes: []*peer.ChaincodeCall{
{Name: "cc2", CollectionNames: []string{"col1"}},
},
}
Expand All @@ -266,8 +265,8 @@ func TestLedgerFailure(t *testing.T) {
service.lsccMetadataManager.query.On("GetState", "lscc", "cc2").Return(nil, errors.New("IO error"))
service.lsccMetadataManager.query.On("GetState", "lscc", "cc12~collection").Return(collectionConfigBytes, nil)

ccWithCollection := &ChaincodeInterest{
Chaincodes: []*ChaincodeCall{
ccWithCollection := &peer.ChaincodeInterest{
Chaincodes: []*peer.ChaincodeCall{
{Name: "cc1"},
{Name: "cc2", CollectionNames: []string{"col1"}},
},
Expand Down Expand Up @@ -331,7 +330,7 @@ func TestRevocation(t *testing.T) {

type client struct {
*disc.Client
*discovery_protos.AuthInfo
*discprotos.AuthInfo
conn *grpc.ClientConn
}

Expand Down Expand Up @@ -482,7 +481,7 @@ func createClientAndService(t *testing.T, testdir string) (*client, *client, *se
AuthCachePurgeRetentionRatio: 0.5,
}, sup)

discovery_protos.RegisterDiscoveryServer(gRPCServer.Server(), svc)
discprotos.RegisterDiscoveryServer(gRPCServer.Server(), svc)

require.NoError(t, err)
go gRPCServer.Start()
Expand All @@ -503,15 +502,15 @@ func createClientAndService(t *testing.T, testdir string) (*client, *client, *se
require.NoError(t, err)

userSigner := createUserSigner(t)
wrapperUserClient := &client{AuthInfo: &discovery_protos.AuthInfo{
wrapperUserClient := &client{AuthInfo: &discprotos.AuthInfo{
ClientIdentity: userSigner.Creator,
ClientTlsCertHash: util.ComputeSHA256(clientKeyPair.TLSCert.Raw),
}, conn: conn}
var signerCacheSize uint = 10
wrapperUserClient.Client = disc.NewClient(wrapperUserClient.newConnection, userSigner.Sign, signerCacheSize)

adminSigner := createAdminSigner(t)
wrapperAdminClient := &client{AuthInfo: &discovery_protos.AuthInfo{
wrapperAdminClient := &client{AuthInfo: &discprotos.AuthInfo{
ClientIdentity: adminSigner.Creator,
ClientTlsCertHash: util.ComputeSHA256(clientKeyPair.TLSCert.Raw),
}, conn: conn}
Expand Down Expand Up @@ -883,14 +882,14 @@ func aliveMsg(pkiID gcommon.PKIidType) gdisc.NetworkMember {
}

func buildCollectionConfig(col2principals map[string][]*msprotos.MSPPrincipal) []byte {
collections := &CollectionConfigPackage{}
collections := &peer.CollectionConfigPackage{}
for col, principals := range col2principals {
collections.Config = append(collections.Config, &CollectionConfig{
Payload: &CollectionConfig_StaticCollectionConfig{
StaticCollectionConfig: &StaticCollectionConfig{
collections.Config = append(collections.Config, &peer.CollectionConfig{
Payload: &peer.CollectionConfig_StaticCollectionConfig{
StaticCollectionConfig: &peer.StaticCollectionConfig{
Name: col,
MemberOrgsPolicy: &CollectionPolicyConfig{
Payload: &CollectionPolicyConfig_SignaturePolicy{
MemberOrgsPolicy: &peer.CollectionPolicyConfig{
Payload: &peer.CollectionPolicyConfig_SignaturePolicy{
SignaturePolicy: &common.SignaturePolicyEnvelope{
Identities: principals,
},
Expand Down
Loading
Loading