Skip to content

Commit

Permalink
[FAB-9550] Add collections and cc2cc to discovery proto
Browse files Browse the repository at this point in the history
This change set adds the ability to express interest
about collections and cc2cc queries in the discovery protobuf.

Change-Id: I03c133b8ed2cb43419b4304357b5de013d3ef4f5
Signed-off-by: yacovm <yacovm@il.ibm.com>
  • Loading branch information
yacovm committed Apr 22, 2018
1 parent 5f1893b commit e8d83e5
Show file tree
Hide file tree
Showing 5 changed files with 182 additions and 99 deletions.
9 changes: 6 additions & 3 deletions discovery/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,12 @@ func (req *Request) AddConfigQuery() *Request {
func (req *Request) AddEndorsersQuery(chaincodes ...string) *Request {
ch := req.lastChannel
q := &discovery.Query_CcQuery{
CcQuery: &discovery.ChaincodeQuery{
Chaincodes: chaincodes,
},
CcQuery: &discovery.ChaincodeQuery{},
}
for _, cc := range chaincodes {
q.CcQuery.Interests = append(q.CcQuery.Interests, &discovery.ChaincodeInterest{
ChaincodeNames: []string{cc},
})
}
req.Queries = append(req.Queries, &discovery.Query{
Channel: ch,
Expand Down
12 changes: 8 additions & 4 deletions discovery/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,11 +120,15 @@ func (s *service) dispatch(q *discovery.Query) *discovery.QueryResult {

func (s *service) chaincodeQuery(q *discovery.Query) *discovery.QueryResult {
var descriptors []*discovery.EndorsementDescriptor
for _, cc := range q.GetCcQuery().Chaincodes {
desc, err := s.PeersForEndorsement(cc, common2.ChainID(q.Channel))
for _, interest := range q.GetCcQuery().Interests {
if len(interest.ChaincodeNames) == 0 {
return wrapError(errors.Errorf("must include at least one chaincode"))
}
// Until we have cc2cc support, we just take the first chaincode
desc, err := s.PeersForEndorsement(interest.ChaincodeNames[0], common2.ChainID(q.Channel))
if err != nil {
logger.Errorf("Failed constructing descriptor for chaincode %s,: %v", cc, err)
return wrapError(errors.Errorf("failed constructing descriptor for chaincode %s", cc))
logger.Errorf("Failed constructing descriptor for chaincode %s,: %v", interest, err)
return wrapError(errors.Errorf("failed constructing descriptor for %v", interest))
}
descriptors = append(descriptors, desc)
}
Expand Down
48 changes: 39 additions & 9 deletions discovery/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,21 +91,51 @@ func TestService(t *testing.T) {
assert.Contains(t, err.Error(), "failed parsing request")
}

// Scenario V: Request with a CC query where one chaincode is unavailable
// Scenario V: Request a CC query with no chaincodes at all
req.Queries[0].Query = &discovery.Query_CcQuery{
CcQuery: &discovery.ChaincodeQuery{
Chaincodes: []string{"unknownCC", "cc1"},
Interests: []*discovery.ChaincodeInterest{
{},
},
},
}
resp, err = service.Discover(ctx, toSignedRequest(req))
assert.NoError(t, err)
assert.Contains(t, resp.Results[0].GetError().Content, "must include at least one chaincode")

// Scenario VI: Request with a CC query where one chaincode is unavailable
req.Queries[0].Query = &discovery.Query_CcQuery{
CcQuery: &discovery.ChaincodeQuery{
Interests: []*discovery.ChaincodeInterest{
{
ChaincodeNames: []string{"unknownCC"},
},
{
ChaincodeNames: []string{"cc1"},
},
},
},
}

resp, err = service.Discover(ctx, toSignedRequest(req))
assert.NoError(t, err)
assert.Contains(t, resp.Results[0].GetError().Content, "failed constructing descriptor for chaincode unknownCC")
assert.Contains(t, resp.Results[0].GetError().Content, "failed constructing descriptor")
assert.Contains(t, resp.Results[0].GetError().Content, "unknownCC")

// Scenario VI: Request with a CC query where all are available
// Scenario VII: Request with a CC query where all are available
req.Queries[0].Query = &discovery.Query_CcQuery{
CcQuery: &discovery.ChaincodeQuery{
Chaincodes: []string{"cc1", "cc2", "cc3"},
Interests: []*discovery.ChaincodeInterest{
{
ChaincodeNames: []string{"cc1"},
},
{
ChaincodeNames: []string{"cc2"},
},
{
ChaincodeNames: []string{"cc3"},
},
},
},
}
resp, err = service.Discover(ctx, toSignedRequest(req))
Expand All @@ -115,7 +145,7 @@ func TestService(t *testing.T) {
})
assert.Equal(t, expected, resp)

// Scenario VII: Request with a config query
// Scenario VIII: Request with a config query
mockSup.On("Config", mock.Anything).Return(nil, errors.New("failed fetching config")).Once()
req.Queries[0].Query = &discovery.Query_ConfigQuery{
ConfigQuery: &discovery.ConfigQuery{},
Expand All @@ -124,7 +154,7 @@ func TestService(t *testing.T) {
assert.NoError(t, err)
assert.Contains(t, resp.Results[0].GetError().Content, "failed fetching config for channel channelWithAccessGranted")

// Scenario VII: Request with a config query
// Scenario IX: Request with a config query
mockSup.On("Config", mock.Anything).Return(&discovery.ConfigResult{}, nil).Once()
req.Queries[0].Query = &discovery.Query_ConfigQuery{
ConfigQuery: &discovery.ConfigQuery{},
Expand All @@ -133,7 +163,7 @@ func TestService(t *testing.T) {
assert.NoError(t, err)
assert.NotNil(t, resp.Results[0].GetConfigResult())

// Scenario VIII: Request with a membership query
// Scenario X: Request with a membership query
// Peers in membership view: { p0, p1, p2, p3}
// Peers in channel view: {p1, p2, p4}
// So that means that the returned peers for the channel should be the intersection
Expand Down Expand Up @@ -232,7 +262,7 @@ func TestService(t *testing.T) {
assert.NoError(t, err)
}

// Scenario IX: The client is eligible for channel queries but not for channel-less
// Scenario XI: The client is eligible for channel queries but not for channel-less
// since it's not an admin. It sends a query for a channel-less query but puts a channel in the query.
// It should fail because channel-less query types cannot have a channel configured in them.
req.Queries = []*discovery.Query{
Expand Down
Loading

0 comments on commit e8d83e5

Please sign in to comment.