Skip to content

Commit 58d2b88

Browse files
committedMay 9, 2018
[FAB-9984] Discovery cc2cc with collections to protobuf
This change set changes the discovery protobufs to support queries that have collections combined with chaincode to chaincode, i.e chaincode foo calls chaincode bar and chaincode bar performs private data operations. Change-Id: I52d78da97f890e59283fa1935bdd32280279f717 Signed-off-by: yacovm <yacovm@il.ibm.com>
1 parent f65e128 commit 58d2b88

File tree

7 files changed

+135
-110
lines changed

7 files changed

+135
-110
lines changed
 

‎discovery/client/client.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ func (req *Request) AddEndorsersQuery(chaincodes ...string) *Request {
7575
}
7676
for _, cc := range chaincodes {
7777
q.CcQuery.Interests = append(q.CcQuery.Interests, &discovery.ChaincodeInterest{
78-
ChaincodeNames: []string{cc},
78+
Chaincodes: []*discovery.ChaincodeCall{{Name: cc}},
7979
})
8080
}
8181
req.Queries = append(req.Queries, &discovery.Query{

‎discovery/endorsement/endorsement.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,10 @@ type peerPrincipalEvaluator func(member discovery2.NetworkMember, principal *msp
7979

8080
// PeersForEndorsement returns an EndorsementDescriptor for a given set of peers, channel, and chaincode
8181
func (ea *endorsementAnalyzer) PeersForEndorsement(chainID common.ChainID, interest *discovery.ChaincodeInterest) (*discovery.EndorsementDescriptor, error) {
82-
chaincode := interest.ChaincodeNames[0]
83-
ccMD := ea.Metadata(string(chainID), chaincode)
82+
chaincode := interest.Chaincodes[0]
83+
ccMD := ea.Metadata(string(chainID), chaincode.Name)
8484
if ccMD == nil {
85-
return nil, errors.Errorf("No metadata was found for chaincode %s in channel %s", chaincode, string(chainID))
85+
return nil, errors.Errorf("No metadata was found for chaincode %s in channel %s", chaincode.Name, string(chainID))
8686
}
8787
// Filter out peers that don't have the chaincode installed on them
8888
chanMembership := ea.PeersOfChannel(chainID).Filter(peersWithChaincode(ccMD))
@@ -95,7 +95,7 @@ func (ea *endorsementAnalyzer) PeersForEndorsement(chainID common.ChainID, inter
9595
identitiesOfMembers := computeIdentitiesOfMembers(identities, membersById)
9696

9797
// Retrieve the policy for the chaincode
98-
pol := ea.PolicyByChaincode(string(chainID), chaincode)
98+
pol := ea.PolicyByChaincode(string(chainID), chaincode.Name)
9999
if pol == nil {
100100
logger.Debug("Policy for chaincode '", chaincode, "'doesn't exist")
101101
return nil, errors.New("policy not found")
@@ -137,7 +137,7 @@ func (ea *endorsementAnalyzer) PeersForEndorsement(chainID common.ChainID, inter
137137
}
138138

139139
return &discovery.EndorsementDescriptor{
140-
Chaincode: chaincode,
140+
Chaincode: chaincode.Name,
141141
Layouts: layouts,
142142
EndorsersByGroups: endorsersByGroup(criteria),
143143
}, nil

‎discovery/endorsement/endorsement_test.go

+7-7
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ func TestPeersForEndorsement(t *testing.T) {
8787
// Scenario I: Policy isn't found
8888
pf.On("PolicyByChaincode", ccWithMissingPolicy).Return(nil).Once()
8989
analyzer := NewEndorsementAnalyzer(g, pf, &principalEvaluatorMock{}, mf)
90-
desc, err := analyzer.PeersForEndorsement(channel, &discovery2.ChaincodeInterest{ChaincodeNames: []string{ccWithMissingPolicy}})
90+
desc, err := analyzer.PeersForEndorsement(channel, &discovery2.ChaincodeInterest{Chaincodes: []*discovery2.ChaincodeCall{{Name: ccWithMissingPolicy}}})
9191
assert.Nil(t, desc)
9292
assert.Equal(t, "policy not found", err.Error())
9393

@@ -106,7 +106,7 @@ func TestPeersForEndorsement(t *testing.T) {
106106

107107
analyzer = NewEndorsementAnalyzer(g, pf, policy.ToPrincipalEvaluator(pkiID2MSPID), mf)
108108
pf.On("PolicyByChaincode", cc).Return(policy).Once()
109-
desc, err = analyzer.PeersForEndorsement(channel, &discovery2.ChaincodeInterest{ChaincodeNames: []string{cc}})
109+
desc, err = analyzer.PeersForEndorsement(channel, &discovery2.ChaincodeInterest{Chaincodes: []*discovery2.ChaincodeCall{{Name: cc}}})
110110
assert.Nil(t, desc)
111111
assert.Equal(t, err.Error(), "cannot satisfy any principal combination")
112112

@@ -126,7 +126,7 @@ func TestPeersForEndorsement(t *testing.T) {
126126

127127
analyzer = NewEndorsementAnalyzer(g, pf, policy.ToPrincipalEvaluator(pkiID2MSPID), mf)
128128
pf.On("PolicyByChaincode", cc).Return(policy).Once()
129-
desc, err = analyzer.PeersForEndorsement(channel, &discovery2.ChaincodeInterest{ChaincodeNames: []string{cc}})
129+
desc, err = analyzer.PeersForEndorsement(channel, &discovery2.ChaincodeInterest{Chaincodes: []*discovery2.ChaincodeCall{{Name: cc}}})
130130
assert.NoError(t, err)
131131
assert.NotNil(t, desc)
132132
assert.Len(t, desc.Layouts, 1)
@@ -150,7 +150,7 @@ func TestPeersForEndorsement(t *testing.T) {
150150

151151
analyzer = NewEndorsementAnalyzer(g, pf, policy.ToPrincipalEvaluator(pkiID2MSPID), mf)
152152
pf.On("PolicyByChaincode", cc).Return(policy).Once()
153-
desc, err = analyzer.PeersForEndorsement(channel, &discovery2.ChaincodeInterest{ChaincodeNames: []string{cc}})
153+
desc, err = analyzer.PeersForEndorsement(channel, &discovery2.ChaincodeInterest{Chaincodes: []*discovery2.ChaincodeCall{{Name: cc}}})
154154
assert.NoError(t, err)
155155
assert.NotNil(t, desc)
156156
assert.Len(t, desc.Layouts, 2)
@@ -169,7 +169,7 @@ func TestPeersForEndorsement(t *testing.T) {
169169
}).Once()
170170
g.On("PeersOfChannel").Return(chanPeers.toMembers()).Once()
171171
pf.On("PolicyByChaincode", cc).Return(policy).Once()
172-
desc, err = analyzer.PeersForEndorsement(channel, &discovery2.ChaincodeInterest{ChaincodeNames: []string{cc}})
172+
desc, err = analyzer.PeersForEndorsement(channel, &discovery2.ChaincodeInterest{Chaincodes: []*discovery2.ChaincodeCall{{Name: cc}}})
173173
assert.Nil(t, desc)
174174
assert.Equal(t, err.Error(), "cannot satisfy any principal combination")
175175

@@ -182,7 +182,7 @@ func TestPeersForEndorsement(t *testing.T) {
182182
mf.On("Metadata").Return(&chaincode.Metadata{
183183
Name: cc, Version: "1.0",
184184
}).Once()
185-
desc, err = analyzer.PeersForEndorsement(channel, &discovery2.ChaincodeInterest{ChaincodeNames: []string{cc}})
185+
desc, err = analyzer.PeersForEndorsement(channel, &discovery2.ChaincodeInterest{Chaincodes: []*discovery2.ChaincodeCall{{Name: cc}}})
186186
assert.Nil(t, desc)
187187
assert.Equal(t, err.Error(), "cannot satisfy any principal combination")
188188

@@ -191,7 +191,7 @@ func TestPeersForEndorsement(t *testing.T) {
191191
g.On("PeersOfChannel").Return(chanPeers.toMembers()).Once()
192192
pf.On("PolicyByChaincode", cc).Return(policy).Once()
193193
mf.On("Metadata").Return(nil).Once()
194-
desc, err = analyzer.PeersForEndorsement(channel, &discovery2.ChaincodeInterest{ChaincodeNames: []string{cc}})
194+
desc, err = analyzer.PeersForEndorsement(channel, &discovery2.ChaincodeInterest{Chaincodes: []*discovery2.ChaincodeCall{{Name: cc}}})
195195
assert.Nil(t, desc)
196196
assert.Equal(t, err.Error(), "No metadata was found for chaincode chaincode in channel test")
197197
}

‎discovery/service.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ func (s *service) dispatch(q *discovery.Query) *discovery.QueryResult {
121121
func (s *service) chaincodeQuery(q *discovery.Query) *discovery.QueryResult {
122122
var descriptors []*discovery.EndorsementDescriptor
123123
for _, interest := range q.GetCcQuery().Interests {
124-
if len(interest.ChaincodeNames) == 0 {
124+
if len(interest.Chaincodes) == 0 || interest.Chaincodes[0] == nil {
125125
return wrapError(errors.Errorf("must include at least one chaincode"))
126126
}
127127
desc, err := s.PeersForEndorsement(common2.ChainID(q.Channel), interest)

‎discovery/service_test.go

+6-6
Original file line numberDiff line numberDiff line change
@@ -108,10 +108,10 @@ func TestService(t *testing.T) {
108108
CcQuery: &discovery.ChaincodeQuery{
109109
Interests: []*discovery.ChaincodeInterest{
110110
{
111-
ChaincodeNames: []string{"unknownCC"},
111+
Chaincodes: []*discovery.ChaincodeCall{{Name: "unknownCC"}},
112112
},
113113
{
114-
ChaincodeNames: []string{"cc1"},
114+
Chaincodes: []*discovery.ChaincodeCall{{Name: "cc1"}},
115115
},
116116
},
117117
},
@@ -127,13 +127,13 @@ func TestService(t *testing.T) {
127127
CcQuery: &discovery.ChaincodeQuery{
128128
Interests: []*discovery.ChaincodeInterest{
129129
{
130-
ChaincodeNames: []string{"cc1"},
130+
Chaincodes: []*discovery.ChaincodeCall{{Name: "cc1"}},
131131
},
132132
{
133-
ChaincodeNames: []string{"cc2"},
133+
Chaincodes: []*discovery.ChaincodeCall{{Name: "cc2"}},
134134
},
135135
{
136-
ChaincodeNames: []string{"cc3"},
136+
Chaincodes: []*discovery.ChaincodeCall{{Name: "cc3"}},
137137
},
138138
},
139139
},
@@ -446,7 +446,7 @@ func (ms *mockSupport) Peers() discovery2.Members {
446446
}
447447

448448
func (ms *mockSupport) PeersForEndorsement(channel common2.ChainID, interest *discovery.ChaincodeInterest) (*discovery.EndorsementDescriptor, error) {
449-
cc := interest.ChaincodeNames[0]
449+
cc := interest.Chaincodes[0].Name
450450
args := ms.Called(cc)
451451
if args.Get(0) == nil {
452452
return nil, args.Error(1)

‎protos/discovery/protocol.pb.go

+107-87
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎protos/discovery/protocol.proto

+8-3
Original file line numberDiff line numberDiff line change
@@ -142,10 +142,15 @@ message ChaincodeQuery {
142142

143143
// ChaincodeInterest defines an interest about an endorsement
144144
// for a specific single chaincode invocation.
145-
// Multiple chaincode names indicate chaincode to chaincode invocations.
146-
// Collections indicate the chaincode invocation includes collections.
145+
// Multiple chaincodes indicate chaincode to chaincode invocations.
147146
message ChaincodeInterest {
148-
repeated string chaincode_names = 1;
147+
repeated ChaincodeCall chaincodes = 1;
148+
}
149+
150+
// ChaincodeCall defines a call to a chaincode.
151+
// It may have collections that are related to the chaincode
152+
message ChaincodeCall {
153+
string name = 1;
149154
repeated string collection_names = 2;
150155
}
151156

0 commit comments

Comments
 (0)
Please sign in to comment.