Skip to content

Commit dd9b758

Browse files
committed
delete shadow copy proto-struct
Signed-off-by: Fedor Partanskiy <[email protected]>
1 parent 7b0fb38 commit dd9b758

File tree

18 files changed

+189
-220
lines changed

18 files changed

+189
-220
lines changed

core/chaincode/handler_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2550,7 +2550,7 @@ var _ = Describe("Handler", func() {
25502550
})
25512551

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

25562556
close(responseNotifier)
@@ -2559,7 +2559,7 @@ var _ = Describe("Handler", func() {
25592559
Eventually(fakeChatStream.SendCallCount).Should(Equal(1))
25602560
Consistently(fakeChatStream.SendCallCount).Should(Equal(1))
25612561
msg := fakeChatStream.SendArgsForCall(0)
2562-
Expect(msg).To(Equal(&expectedMessage))
2562+
Expect(msg).To(Equal(expectedMessage))
25632563
Expect(msg.Proposal).To(Equal(expectedSignedProp))
25642564
})
25652565

core/common/privdata/simplecollection.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ SPDX-License-Identifier: Apache-2.0
77
package privdata
88

99
import (
10+
"github.com/golang/protobuf/proto"
1011
"github.com/hyperledger/fabric-protos-go/peer"
1112
"github.com/hyperledger/fabric/common/policies"
1213
"github.com/hyperledger/fabric/msp"
@@ -20,7 +21,7 @@ type SimpleCollection struct {
2021
name string
2122
accessPolicy policies.Policy
2223
memberOrgs map[string]struct{}
23-
conf peer.StaticCollectionConfig
24+
conf *peer.StaticCollectionConfig
2425
}
2526

2627
type SimpleCollectionPersistenceConfigs struct {
@@ -86,7 +87,7 @@ func (sc *SimpleCollection) Setup(collectionConfig *peer.StaticCollectionConfig,
8687
if collectionConfig == nil {
8788
return errors.New("Nil config passed to collection setup")
8889
}
89-
sc.conf = *collectionConfig
90+
sc.conf = proto.Clone(collectionConfig).(*peer.StaticCollectionConfig)
9091
sc.name = collectionConfig.GetName()
9192

9293
// get the access signature policy envelope

core/endorser/endorser_test.go

Lines changed: 16 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ package endorser_test
99
import (
1010
"context"
1111
"fmt"
12-
"sort"
12+
"slices"
13+
"strings"
1314

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

32-
type CcInterest pb.ChaincodeInterest
33-
34-
func (a CcInterest) Len() int { return len(a.Chaincodes) }
35-
func (a CcInterest) Swap(i, j int) {
36-
a.Chaincodes[i], a.Chaincodes[j] = a.Chaincodes[j], a.Chaincodes[i]
37-
}
38-
39-
func (a CcInterest) Less(i, j int) bool {
40-
ai := a.Chaincodes[i]
41-
aj := a.Chaincodes[j]
42-
43-
if ai.Name != aj.Name {
44-
return ai.Name < aj.Name
33+
func sortChaincodeCall(a, b *pb.ChaincodeCall) int {
34+
if a.Name != b.Name {
35+
return strings.Compare(a.Name, b.Name)
4536
}
4637

47-
if len(ai.CollectionNames) != len(aj.CollectionNames) {
48-
return len(ai.CollectionNames) < len(aj.CollectionNames)
38+
if len(a.CollectionNames) != len(b.CollectionNames) {
39+
return len(a.CollectionNames) - len(b.CollectionNames)
4940
}
5041

51-
for ii := range ai.CollectionNames {
52-
if ai.CollectionNames[ii] != aj.CollectionNames[ii] {
53-
return ai.CollectionNames[ii] < aj.CollectionNames[ii]
42+
for ii := range a.CollectionNames {
43+
if a.CollectionNames[ii] != b.CollectionNames[ii] {
44+
return strings.Compare(a.CollectionNames[ii], b.CollectionNames[ii])
5445
}
5546
}
5647

57-
return false
48+
return 0
5849
}
5950

6051
var _ = Describe("Endorser", func() {
@@ -1132,7 +1123,7 @@ var _ = Describe("Endorser", func() {
11321123

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

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

12101201
proposalResponse, err := e.ProcessProposal(context.TODO(), signedProposal)
12111202
Expect(err).NotTo(HaveOccurred())
1212-
sort.Sort(CcInterest(*proposalResponse.Interest))
1203+
slices.SortFunc(proposalResponse.Interest.Chaincodes, sortChaincodeCall)
12131204
Expect(proposalResponse.Interest).To(Equal(&pb.ChaincodeInterest{
12141205
Chaincodes: []*pb.ChaincodeCall{{
12151206
Name: "myCC",
@@ -1248,7 +1239,7 @@ var _ = Describe("Endorser", func() {
12481239
proposalResponse, err := e.ProcessProposal(context.TODO(), signedProposal)
12491240
Expect(err).NotTo(HaveOccurred())
12501241

1251-
sort.Sort(CcInterest(*proposalResponse.Interest))
1242+
slices.SortFunc(proposalResponse.Interest.Chaincodes, sortChaincodeCall)
12521243
Expect(proto.Equal(
12531244
proposalResponse.Interest,
12541245
&pb.ChaincodeInterest{
@@ -1293,7 +1284,7 @@ var _ = Describe("Endorser", func() {
12931284
proposalResponse, err := e.ProcessProposal(context.TODO(), signedProposal)
12941285
Expect(err).NotTo(HaveOccurred())
12951286

1296-
sort.Sort(CcInterest(*proposalResponse.Interest))
1287+
slices.SortFunc(proposalResponse.Interest.Chaincodes, sortChaincodeCall)
12971288
Expect(proto.Equal(
12981289
proposalResponse.Interest,
12991290
&pb.ChaincodeInterest{

core/peer/deliverevents.go

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,7 @@ func (fbrs *filteredBlockResponseSender) SendBlockResponse(
114114
signedData *protoutil.SignedData,
115115
) error {
116116
// Generates filtered block response
117-
b := blockEvent(*block)
118-
filteredBlock, err := b.toFilteredBlock()
117+
filteredBlock, err := toFilteredBlock(block)
119118
if err != nil {
120119
logger.Warningf("Failed to generate filtered block due to: %s", err)
121120
return fbrs.SendStatusResponse(common.Status_BAD_REQUEST)
@@ -231,10 +230,6 @@ func (bprs *blockAndPrivateDataResponseSender) getPrivateData(
231230
// transactionActions aliasing for peer.TransactionAction pointers slice
232231
type transactionActions []*peer.TransactionAction
233232

234-
// blockEvent an alias for common.Block structure, used to
235-
// extend with auxiliary functionality
236-
type blockEvent common.Block
237-
238233
// DeliverFiltered sends a stream of blocks to a client after commitment
239234
func (s *DeliverServer) DeliverFiltered(srv peer.Deliver_DeliverFilteredServer) error {
240235
logger.Debugf("Starting new DeliverFiltered handler")
@@ -289,7 +284,7 @@ func (s *DeliverServer) DeliverWithPrivateData(srv peer.Deliver_DeliverWithPriva
289284
return err
290285
}
291286

292-
func (block *blockEvent) toFilteredBlock() (*peer.FilteredBlock, error) {
287+
func toFilteredBlock(block *common.Block) (*peer.FilteredBlock, error) {
293288
filteredBlock := &peer.FilteredBlock{
294289
Number: block.Header.Number,
295290
}

core/transientstore/persistance.pb.go renamed to core/transientstore/persistence.pb.go

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

discovery/client/client.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,9 +157,9 @@ func (req *Request) addQueryMapping(queryType protoext.QueryType, key string) {
157157

158158
// Send sends the request and returns the response, or error on failure
159159
func (c *Client) Send(ctx context.Context, req *Request, auth *discovery.AuthInfo) (Response, error) {
160-
reqToBeSent := *req.Request
160+
reqToBeSent := proto.Clone(req.Request).(*discovery.Request)
161161
reqToBeSent.Authentication = auth
162-
payload, err := proto.Marshal(&reqToBeSent)
162+
payload, err := proto.Marshal(reqToBeSent)
163163
if err != nil {
164164
return nil, errors.Wrap(err, "failed marshaling Request to bytes")
165165
}

discovery/cmd/config_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import (
1111
"fmt"
1212
"testing"
1313

14-
. "github.com/hyperledger/fabric-protos-go/discovery"
14+
discprotos "github.com/hyperledger/fabric-protos-go/discovery"
1515
"github.com/hyperledger/fabric-protos-go/msp"
1616
"github.com/hyperledger/fabric/cmd/common"
1717
discovery "github.com/hyperledger/fabric/discovery/cmd"
@@ -79,13 +79,13 @@ func TestParseConfigResponse(t *testing.T) {
7979
})
8080

8181
t.Run("Success", func(t *testing.T) {
82-
chanRes.On("Config").Return(&ConfigResult{
82+
chanRes.On("Config").Return(&discprotos.ConfigResult{
8383
Msps: map[string]*msp.FabricMSPConfig{
8484
"Org1MSP": nil,
8585
"Org2MSP": nil,
8686
},
87-
Orderers: map[string]*Endpoints{
88-
"OrdererMSP": {Endpoint: []*Endpoint{
87+
Orderers: map[string]*discprotos.Endpoints{
88+
"OrdererMSP": {Endpoint: []*discprotos.Endpoint{
8989
{Host: "orderer1", Port: 7050},
9090
}},
9191
},

discovery/service_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -593,7 +593,7 @@ type peers []*discovery.Peer
593593
func (ps peers) exists(p *discovery.Peer) error {
594594
var found bool
595595
for _, q := range ps {
596-
if reflect.DeepEqual(*p, *q) {
596+
if proto.Equal(p, q) {
597597
found = true
598598
break
599599
}

discovery/test/integration_test.go

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,14 @@ import (
2222
"testing"
2323
"time"
2424

25-
discovery_protos "github.com/hyperledger/fabric-protos-go/discovery"
26-
2725
"github.com/golang/protobuf/proto"
2826
"github.com/hyperledger/fabric-lib-go/bccsp/sw"
2927
bccsp "github.com/hyperledger/fabric-lib-go/bccsp/utils"
3028
"github.com/hyperledger/fabric-protos-go/common"
29+
discprotos "github.com/hyperledger/fabric-protos-go/discovery"
3130
"github.com/hyperledger/fabric-protos-go/gossip"
3231
msprotos "github.com/hyperledger/fabric-protos-go/msp"
33-
. "github.com/hyperledger/fabric-protos-go/peer"
32+
"github.com/hyperledger/fabric-protos-go/peer"
3433
"github.com/hyperledger/fabric/common/cauthdsl"
3534
"github.com/hyperledger/fabric/common/configtx"
3635
"github.com/hyperledger/fabric/common/crypto/tlsgen"
@@ -128,21 +127,21 @@ func TestGreenPath(t *testing.T) {
128127
service.lsccMetadataManager.query.On("GetState", "lscc", "cc2").Return(cc2Bytes, nil)
129128
service.lsccMetadataManager.query.On("GetState", "lscc", "cc2~collection").Return(collectionConfigBytes, nil)
130129

131-
ccWithCollection := &ChaincodeInterest{
132-
Chaincodes: []*ChaincodeCall{
130+
ccWithCollection := &peer.ChaincodeInterest{
131+
Chaincodes: []*peer.ChaincodeCall{
133132
{Name: "cc2", CollectionNames: []string{"col12"}},
134133
},
135134
}
136-
cc2cc := &ChaincodeInterest{
137-
Chaincodes: []*ChaincodeCall{
135+
cc2cc := &peer.ChaincodeInterest{
136+
Chaincodes: []*peer.ChaincodeCall{
138137
{Name: "cc1"}, {Name: "cc2"},
139138
},
140139
}
141140

142141
// Send all queries
143142
req := disc.NewRequest().AddLocalPeersQuery().OfChannel("mychannel")
144-
col1 := &ChaincodeCall{Name: "cc2", CollectionNames: []string{"col1"}}
145-
nonExistentCollection := &ChaincodeCall{Name: "cc2", CollectionNames: []string{"col3"}}
143+
col1 := &peer.ChaincodeCall{Name: "cc2", CollectionNames: []string{"col1"}}
144+
nonExistentCollection := &peer.ChaincodeCall{Name: "cc2", CollectionNames: []string{"col3"}}
146145
_ = nonExistentCollection
147146
req, err := req.AddPeersQuery().AddPeersQuery(col1).AddPeersQuery(nonExistentCollection).AddConfigQuery().AddEndorsersQuery(cc2cc, ccWithCollection)
148147

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

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

269-
ccWithCollection := &ChaincodeInterest{
270-
Chaincodes: []*ChaincodeCall{
268+
ccWithCollection := &peer.ChaincodeInterest{
269+
Chaincodes: []*peer.ChaincodeCall{
271270
{Name: "cc1"},
272271
{Name: "cc2", CollectionNames: []string{"col1"}},
273272
},
@@ -331,7 +330,7 @@ func TestRevocation(t *testing.T) {
331330

332331
type client struct {
333332
*disc.Client
334-
*discovery_protos.AuthInfo
333+
*discprotos.AuthInfo
335334
conn *grpc.ClientConn
336335
}
337336

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

485-
discovery_protos.RegisterDiscoveryServer(gRPCServer.Server(), svc)
484+
discprotos.RegisterDiscoveryServer(gRPCServer.Server(), svc)
486485

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

505504
userSigner := createUserSigner(t)
506-
wrapperUserClient := &client{AuthInfo: &discovery_protos.AuthInfo{
505+
wrapperUserClient := &client{AuthInfo: &discprotos.AuthInfo{
507506
ClientIdentity: userSigner.Creator,
508507
ClientTlsCertHash: util.ComputeSHA256(clientKeyPair.TLSCert.Raw),
509508
}, conn: conn}
510509
var signerCacheSize uint = 10
511510
wrapperUserClient.Client = disc.NewClient(wrapperUserClient.newConnection, userSigner.Sign, signerCacheSize)
512511

513512
adminSigner := createAdminSigner(t)
514-
wrapperAdminClient := &client{AuthInfo: &discovery_protos.AuthInfo{
513+
wrapperAdminClient := &client{AuthInfo: &discprotos.AuthInfo{
515514
ClientIdentity: adminSigner.Creator,
516515
ClientTlsCertHash: util.ComputeSHA256(clientKeyPair.TLSCert.Raw),
517516
}, conn: conn}
@@ -883,14 +882,14 @@ func aliveMsg(pkiID gcommon.PKIidType) gdisc.NetworkMember {
883882
}
884883

885884
func buildCollectionConfig(col2principals map[string][]*msprotos.MSPPrincipal) []byte {
886-
collections := &CollectionConfigPackage{}
885+
collections := &peer.CollectionConfigPackage{}
887886
for col, principals := range col2principals {
888-
collections.Config = append(collections.Config, &CollectionConfig{
889-
Payload: &CollectionConfig_StaticCollectionConfig{
890-
StaticCollectionConfig: &StaticCollectionConfig{
887+
collections.Config = append(collections.Config, &peer.CollectionConfig{
888+
Payload: &peer.CollectionConfig_StaticCollectionConfig{
889+
StaticCollectionConfig: &peer.StaticCollectionConfig{
891890
Name: col,
892-
MemberOrgsPolicy: &CollectionPolicyConfig{
893-
Payload: &CollectionPolicyConfig_SignaturePolicy{
891+
MemberOrgsPolicy: &peer.CollectionPolicyConfig{
892+
Payload: &peer.CollectionPolicyConfig_SignaturePolicy{
894893
SignaturePolicy: &common.SignaturePolicyEnvelope{
895894
Identities: principals,
896895
},

0 commit comments

Comments
 (0)