Skip to content

Commit

Permalink
[FAB-10547] Pvt Collections in Selection API
Browse files Browse the repository at this point in the history
Modified the SelectionService API to accept
an optional set of private data collections
associated with each chaincode.
Fabric's Discovery Service takes this info
into consideration by filtering out peers that
aren't in the specified collections.

Change-Id: I36f0355a1c44fa14fec1f8d2ab366294f531b498
Signed-off-by: Bob Stasyszyn <[email protected]>
  • Loading branch information
bstasyszyn authored and troyronda committed Jun 6, 2018
1 parent 7d9ebd2 commit ec9053c
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 8 deletions.
14 changes: 13 additions & 1 deletion pkg/client/channel/invoke/txnhandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,19 @@ func (h *ProposalProcessorHandler) Handle(requestContext *RequestContext, client
if requestContext.SelectionFilter != nil {
selectionOpts = append(selectionOpts, selectopts.WithPeerFilter(requestContext.SelectionFilter))
}
endorsers, err := clientContext.Selection.GetEndorsersForChaincode([]string{requestContext.Request.ChaincodeID}, selectionOpts...)

// TODO: Add optional meta-data to RequestContext that specifies invoked chaincodes
// (in CC-to-CC calls) where the policy of the invoked chaincodes need to be taken
// into consideration. Also, associatied private data collections may be specified
// in order to prioritize those endorsers which have read access to the private data
// collections.
chaincodes := []*fab.ChaincodeCall{
{
ID: requestContext.Request.ChaincodeID,
Collections: nil,
},
}
endorsers, err := clientContext.Selection.GetEndorsersForChaincode(chaincodes, selectionOpts...)
if err != nil {
requestContext.Error = errors.WithMessage(err, "Failed to get endorsing peers")
return
Expand Down
2 changes: 1 addition & 1 deletion pkg/client/common/mocks/mockselection.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func NewMockSelectionService(err error, peers ...fab.Peer) *MockSelectionService
}

// GetEndorsersForChaincode mockcore retrieving endorsing peers
func (ds *MockSelectionService) GetEndorsersForChaincode(chaincodeIDs []string, opts ...options.Opt) ([]fab.Peer, error) {
func (ds *MockSelectionService) GetEndorsersForChaincode(chaincodes []*fab.ChaincodeCall, opts ...options.Opt) ([]fab.Peer, error) {

if ds.Error != nil {
return nil, ds.Error
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,13 +103,18 @@ func newService(context context.Client, channelID string, discovery fab.Discover
}

// GetEndorsersForChaincode returns the endorsing peers for the given chaincodes
func (s *SelectionService) GetEndorsersForChaincode(chaincodeIDs []string, opts ...copts.Opt) ([]fab.Peer, error) {
if len(chaincodeIDs) == 0 {
func (s *SelectionService) GetEndorsersForChaincode(chaincodes []*fab.ChaincodeCall, opts ...copts.Opt) ([]fab.Peer, error) {
if len(chaincodes) == 0 {
return nil, errors.New("no chaincode IDs provided")
}

params := options.NewParams(opts)

var chaincodeIDs []string
for _, cc := range chaincodes {
chaincodeIDs = append(chaincodeIDs, cc.ID)
}

resolver, err := s.getPeerGroupResolver(chaincodeIDs)
if err != nil {
return nil, errors.WithMessage(err, fmt.Sprintf("Error getting peer group resolver for chaincodes [%v] on channel [%s]", chaincodeIDs, s.channelID))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -217,8 +217,13 @@ func verify(t *testing.T, service fab.SelectionService, expectedPeerGroups []pgr
logging.SetLevel(module, logging.WARNING)
defer logging.SetLevel(module, level)

var chaincodes []*fab.ChaincodeCall
for _, ccID := range chaincodeIDs {
chaincodes = append(chaincodes, &fab.ChaincodeCall{ID: ccID})
}

for i := 0; i < len(expectedPeerGroups); i++ {
peers, err := service.GetEndorsersForChaincode(chaincodeIDs, getEndorsersOpts...)
peers, err := service.GetEndorsersForChaincode(chaincodes, getEndorsersOpts...)
if err != nil {
t.Fatalf("error getting endorsers: %s", err)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func NewService(discovery fab.DiscoveryService) (fab.SelectionService, error) {
}

// GetEndorsersForChaincode returns a set of endorsing peers
func (s *SelectionService) GetEndorsersForChaincode(chaincodeIDs []string, opts ...copts.Opt) ([]fab.Peer, error) {
func (s *SelectionService) GetEndorsersForChaincode(chaincodes []*fab.ChaincodeCall, opts ...copts.Opt) ([]fab.Peer, error) {
params := options.NewParams(opts)

channelPeers, err := s.discoveryService.GetPeers()
Expand Down
10 changes: 9 additions & 1 deletion pkg/common/providers/fab/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,21 @@ type InfraProvider interface {
Close()
}

// ChaincodeCall contains the ID of the chaincode as well
// as an optional set of private data collections that may be
// accessed by the chaincode.
type ChaincodeCall struct {
ID string
Collections []string
}

// SelectionService selects peers for endorsement and commit events
type SelectionService interface {
// GetEndorsersForChaincode returns a set of peers that should satisfy the endorsement
// policies of all of the given chaincodes.
// A set of options may be provided to the selection service. Note that the type of options
// may vary depending on the specific selection service implementation.
GetEndorsersForChaincode(chaincodeIDs []string, opts ...options.Opt) ([]Peer, error)
GetEndorsersForChaincode(chaincodes []*ChaincodeCall, opts ...options.Opt) ([]Peer, error)
}

// DiscoveryService is used to discover eligible peers on specific channel
Expand Down
2 changes: 1 addition & 1 deletion pkg/fab/mocks/mockselection.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func NewMockSelectionService(err error, peers ...fab.Peer) *MockSelectionService
}

// GetEndorsersForChaincode mockcore retrieving endorsing peers
func (ds *MockSelectionService) GetEndorsersForChaincode(chaincodeIDs []string, opts ...options.Opt) ([]fab.Peer, error) {
func (ds *MockSelectionService) GetEndorsersForChaincode(chaincodes []*fab.ChaincodeCall, opts ...options.Opt) ([]fab.Peer, error) {

if ds.Error != nil {
return nil, ds.Error
Expand Down

0 comments on commit ec9053c

Please sign in to comment.