Skip to content

Commit

Permalink
[FAB-9984] Discovery cc2cc with collections to protobuf
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
yacovm committed May 9, 2018
1 parent f65e128 commit 58d2b88
Show file tree
Hide file tree
Showing 7 changed files with 135 additions and 110 deletions.
2 changes: 1 addition & 1 deletion discovery/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ func (req *Request) AddEndorsersQuery(chaincodes ...string) *Request {
}
for _, cc := range chaincodes {
q.CcQuery.Interests = append(q.CcQuery.Interests, &discovery.ChaincodeInterest{
ChaincodeNames: []string{cc},
Chaincodes: []*discovery.ChaincodeCall{{Name: cc}},
})
}
req.Queries = append(req.Queries, &discovery.Query{
Expand Down
10 changes: 5 additions & 5 deletions discovery/endorsement/endorsement.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,10 @@ type peerPrincipalEvaluator func(member discovery2.NetworkMember, principal *msp

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

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

return &discovery.EndorsementDescriptor{
Chaincode: chaincode,
Chaincode: chaincode.Name,
Layouts: layouts,
EndorsersByGroups: endorsersByGroup(criteria),
}, nil
Expand Down
14 changes: 7 additions & 7 deletions discovery/endorsement/endorsement_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ func TestPeersForEndorsement(t *testing.T) {
// Scenario I: Policy isn't found
pf.On("PolicyByChaincode", ccWithMissingPolicy).Return(nil).Once()
analyzer := NewEndorsementAnalyzer(g, pf, &principalEvaluatorMock{}, mf)
desc, err := analyzer.PeersForEndorsement(channel, &discovery2.ChaincodeInterest{ChaincodeNames: []string{ccWithMissingPolicy}})
desc, err := analyzer.PeersForEndorsement(channel, &discovery2.ChaincodeInterest{Chaincodes: []*discovery2.ChaincodeCall{{Name: ccWithMissingPolicy}}})
assert.Nil(t, desc)
assert.Equal(t, "policy not found", err.Error())

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

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

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

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

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

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

Expand All @@ -191,7 +191,7 @@ func TestPeersForEndorsement(t *testing.T) {
g.On("PeersOfChannel").Return(chanPeers.toMembers()).Once()
pf.On("PolicyByChaincode", cc).Return(policy).Once()
mf.On("Metadata").Return(nil).Once()
desc, err = analyzer.PeersForEndorsement(channel, &discovery2.ChaincodeInterest{ChaincodeNames: []string{cc}})
desc, err = analyzer.PeersForEndorsement(channel, &discovery2.ChaincodeInterest{Chaincodes: []*discovery2.ChaincodeCall{{Name: cc}}})
assert.Nil(t, desc)
assert.Equal(t, err.Error(), "No metadata was found for chaincode chaincode in channel test")
}
Expand Down
2 changes: 1 addition & 1 deletion discovery/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ func (s *service) dispatch(q *discovery.Query) *discovery.QueryResult {
func (s *service) chaincodeQuery(q *discovery.Query) *discovery.QueryResult {
var descriptors []*discovery.EndorsementDescriptor
for _, interest := range q.GetCcQuery().Interests {
if len(interest.ChaincodeNames) == 0 {
if len(interest.Chaincodes) == 0 || interest.Chaincodes[0] == nil {
return wrapError(errors.Errorf("must include at least one chaincode"))
}
desc, err := s.PeersForEndorsement(common2.ChainID(q.Channel), interest)
Expand Down
12 changes: 6 additions & 6 deletions discovery/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,10 @@ func TestService(t *testing.T) {
CcQuery: &discovery.ChaincodeQuery{
Interests: []*discovery.ChaincodeInterest{
{
ChaincodeNames: []string{"unknownCC"},
Chaincodes: []*discovery.ChaincodeCall{{Name: "unknownCC"}},
},
{
ChaincodeNames: []string{"cc1"},
Chaincodes: []*discovery.ChaincodeCall{{Name: "cc1"}},
},
},
},
Expand All @@ -127,13 +127,13 @@ func TestService(t *testing.T) {
CcQuery: &discovery.ChaincodeQuery{
Interests: []*discovery.ChaincodeInterest{
{
ChaincodeNames: []string{"cc1"},
Chaincodes: []*discovery.ChaincodeCall{{Name: "cc1"}},
},
{
ChaincodeNames: []string{"cc2"},
Chaincodes: []*discovery.ChaincodeCall{{Name: "cc2"}},
},
{
ChaincodeNames: []string{"cc3"},
Chaincodes: []*discovery.ChaincodeCall{{Name: "cc3"}},
},
},
},
Expand Down Expand Up @@ -446,7 +446,7 @@ func (ms *mockSupport) Peers() discovery2.Members {
}

func (ms *mockSupport) PeersForEndorsement(channel common2.ChainID, interest *discovery.ChaincodeInterest) (*discovery.EndorsementDescriptor, error) {
cc := interest.ChaincodeNames[0]
cc := interest.Chaincodes[0].Name
args := ms.Called(cc)
if args.Get(0) == nil {
return nil, args.Error(1)
Expand Down
Loading

0 comments on commit 58d2b88

Please sign in to comment.