Skip to content

Commit e8d83e5

Browse files
committed
[FAB-9550] Add collections and cc2cc to discovery proto
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>
1 parent 5f1893b commit e8d83e5

File tree

5 files changed

+182
-99
lines changed

5 files changed

+182
-99
lines changed

discovery/client/client.go

+6-3
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,12 @@ func (req *Request) AddConfigQuery() *Request {
7171
func (req *Request) AddEndorsersQuery(chaincodes ...string) *Request {
7272
ch := req.lastChannel
7373
q := &discovery.Query_CcQuery{
74-
CcQuery: &discovery.ChaincodeQuery{
75-
Chaincodes: chaincodes,
76-
},
74+
CcQuery: &discovery.ChaincodeQuery{},
75+
}
76+
for _, cc := range chaincodes {
77+
q.CcQuery.Interests = append(q.CcQuery.Interests, &discovery.ChaincodeInterest{
78+
ChaincodeNames: []string{cc},
79+
})
7780
}
7881
req.Queries = append(req.Queries, &discovery.Query{
7982
Channel: ch,

discovery/service.go

+8-4
Original file line numberDiff line numberDiff line change
@@ -120,11 +120,15 @@ func (s *service) dispatch(q *discovery.Query) *discovery.QueryResult {
120120

121121
func (s *service) chaincodeQuery(q *discovery.Query) *discovery.QueryResult {
122122
var descriptors []*discovery.EndorsementDescriptor
123-
for _, cc := range q.GetCcQuery().Chaincodes {
124-
desc, err := s.PeersForEndorsement(cc, common2.ChainID(q.Channel))
123+
for _, interest := range q.GetCcQuery().Interests {
124+
if len(interest.ChaincodeNames) == 0 {
125+
return wrapError(errors.Errorf("must include at least one chaincode"))
126+
}
127+
// Until we have cc2cc support, we just take the first chaincode
128+
desc, err := s.PeersForEndorsement(interest.ChaincodeNames[0], common2.ChainID(q.Channel))
125129
if err != nil {
126-
logger.Errorf("Failed constructing descriptor for chaincode %s,: %v", cc, err)
127-
return wrapError(errors.Errorf("failed constructing descriptor for chaincode %s", cc))
130+
logger.Errorf("Failed constructing descriptor for chaincode %s,: %v", interest, err)
131+
return wrapError(errors.Errorf("failed constructing descriptor for %v", interest))
128132
}
129133
descriptors = append(descriptors, desc)
130134
}

discovery/service_test.go

+39-9
Original file line numberDiff line numberDiff line change
@@ -91,21 +91,51 @@ func TestService(t *testing.T) {
9191
assert.Contains(t, err.Error(), "failed parsing request")
9292
}
9393

94-
// Scenario V: Request with a CC query where one chaincode is unavailable
94+
// Scenario V: Request a CC query with no chaincodes at all
9595
req.Queries[0].Query = &discovery.Query_CcQuery{
9696
CcQuery: &discovery.ChaincodeQuery{
97-
Chaincodes: []string{"unknownCC", "cc1"},
97+
Interests: []*discovery.ChaincodeInterest{
98+
{},
99+
},
100+
},
101+
}
102+
resp, err = service.Discover(ctx, toSignedRequest(req))
103+
assert.NoError(t, err)
104+
assert.Contains(t, resp.Results[0].GetError().Content, "must include at least one chaincode")
105+
106+
// Scenario VI: Request with a CC query where one chaincode is unavailable
107+
req.Queries[0].Query = &discovery.Query_CcQuery{
108+
CcQuery: &discovery.ChaincodeQuery{
109+
Interests: []*discovery.ChaincodeInterest{
110+
{
111+
ChaincodeNames: []string{"unknownCC"},
112+
},
113+
{
114+
ChaincodeNames: []string{"cc1"},
115+
},
116+
},
98117
},
99118
}
100119

101120
resp, err = service.Discover(ctx, toSignedRequest(req))
102121
assert.NoError(t, err)
103-
assert.Contains(t, resp.Results[0].GetError().Content, "failed constructing descriptor for chaincode unknownCC")
122+
assert.Contains(t, resp.Results[0].GetError().Content, "failed constructing descriptor")
123+
assert.Contains(t, resp.Results[0].GetError().Content, "unknownCC")
104124

105-
// Scenario VI: Request with a CC query where all are available
125+
// Scenario VII: Request with a CC query where all are available
106126
req.Queries[0].Query = &discovery.Query_CcQuery{
107127
CcQuery: &discovery.ChaincodeQuery{
108-
Chaincodes: []string{"cc1", "cc2", "cc3"},
128+
Interests: []*discovery.ChaincodeInterest{
129+
{
130+
ChaincodeNames: []string{"cc1"},
131+
},
132+
{
133+
ChaincodeNames: []string{"cc2"},
134+
},
135+
{
136+
ChaincodeNames: []string{"cc3"},
137+
},
138+
},
109139
},
110140
}
111141
resp, err = service.Discover(ctx, toSignedRequest(req))
@@ -115,7 +145,7 @@ func TestService(t *testing.T) {
115145
})
116146
assert.Equal(t, expected, resp)
117147

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

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

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

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

0 commit comments

Comments
 (0)