Skip to content

Commit 4a3c528

Browse files
author
Matthias Neugschwandtner
committed
[FAB-5868] Specify collection interface
This generic collection interface is implemented by different kinds of collection types. The collection's access policy interface is consumed by gossip to govern access to private read-write sets. The collection store acts as a collection factory and serves collection objects based on collection criteria. The nop-collection is an implementation of both interfaces, i.e. a collection type, that allows all organizations to pull a private read-write set and a collection store that just returns an instance of this collection type. Change-Id: I9a589c1609a719a593918896623586583568a262 Signed-off-by: Matthias Neugschwandtner <eug@zurich.ibm.com>
1 parent 6cc7444 commit 4a3c528

File tree

10 files changed

+306
-263
lines changed

10 files changed

+306
-263
lines changed

core/common/privdata/collection.go

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
/*
2+
Copyright IBM Corp. All Rights Reserved.
3+
4+
SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
package privdata
8+
9+
import (
10+
"github.com/hyperledger/fabric/protos/common"
11+
)
12+
13+
// Collection defines a common interface for collections
14+
type Collection interface {
15+
// SetTxContext configures the tx-specific ephemeral collection info, such
16+
// as txid, nonce, creator -- for future use
17+
// SetTxContext(parameters ...interface{})
18+
19+
// GetCollectionID returns this collection's ID
20+
GetCollectionID() string
21+
22+
// GetEndorsementPolicy returns the endorsement policy for validation -- for
23+
// future use
24+
// GetEndorsementPolicy() string
25+
26+
// GetMemberOrgs returns the collection's members as MSP IDs. This serves as
27+
// a human-readable way of quickly identifying who is part of a collection.
28+
GetMemberOrgs() []string
29+
}
30+
31+
// CollectionAccess encapsulates functions for the access policy of a collection
32+
type CollectionAccessPolicy interface {
33+
// GetAccessFilter returns a member filter function for a collection
34+
GetAccessFilter() Filter
35+
36+
// RequiredExternalPeerCount returns the minimum number of external peers
37+
// required to hold private data
38+
RequiredExternalPeerCount() int
39+
40+
// RequiredExternalPeerCount returns the minimum number of internal peers
41+
// required to hold private data
42+
RequiredInternalPeerCount() int
43+
}
44+
45+
// Filter defines a rule that filters peers according to data signed by them.
46+
// The Identity in the SignedData is a SerializedIdentity of a peer.
47+
// The Data is a message the peer signed, and the Signature is the corresponding
48+
// Signature on that Data.
49+
// Returns: True, if the policy holds for the given signed data.
50+
// False otherwise
51+
type Filter func(common.SignedData) bool
52+
53+
// CollectionStore retrieves stored collections based on the collection's
54+
// properties. It works as a collection object factory and takes care of
55+
// returning a collection object of an appropriate collection type.
56+
type CollectionStore interface {
57+
// GetCollection retrieves the collection in the following way:
58+
// If the TxID exists in the ledger, the collection that is returned has the
59+
// latest configuration that was committed into the ledger before this txID
60+
// was committed.
61+
// Else - it's the latest configuration for the collection.
62+
GetCollection(common.CollectionCriteria) Collection
63+
64+
// GetCollectionAccessPolicy retrieves a collection's access policy
65+
GetCollectionAccessPolicy(common.CollectionCriteria) CollectionAccessPolicy
66+
}

core/common/privdata/nopcollection.go

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/*
2+
Copyright IBM Corp. All Rights Reserved.
3+
4+
SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
package privdata
8+
9+
import (
10+
"github.com/hyperledger/fabric/protos/common"
11+
)
12+
13+
// NopCollection implements an allow-all collection which all orgs are a member of
14+
type NopCollection struct {
15+
}
16+
17+
func (nc *NopCollection) GetCollectionID() string {
18+
return ""
19+
}
20+
21+
func (nc *NopCollection) GetEndorsementPolicy() string {
22+
return ""
23+
}
24+
25+
func (nc *NopCollection) GetMemberOrgs() []string {
26+
return nil
27+
}
28+
29+
func (nc *NopCollection) RequiredExternalPeerCount() int {
30+
return 0
31+
}
32+
33+
func (nc *NopCollection) RequiredInternalPeerCount() int {
34+
return 0
35+
}
36+
37+
func (nc *NopCollection) GetAccessFilter() Filter {
38+
// return true for all
39+
return func(common.SignedData) bool {
40+
return true
41+
}
42+
}
43+
44+
type NopCollectionStore struct {
45+
}
46+
47+
func (*NopCollectionStore) GetCollection(common.CollectionCriteria) Collection {
48+
return &NopCollection{}
49+
}
50+
51+
func (*NopCollectionStore) GetCollectionAccessPolicy(common.CollectionCriteria) CollectionAccessPolicy {
52+
return &NopCollection{}
53+
}

core/common/privdata/policies.go

Lines changed: 0 additions & 44 deletions
This file was deleted.

core/peer/peer.go

Lines changed: 1 addition & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -303,8 +303,7 @@ func createChain(cid string, ledger ledger.PeerLedger, cb *common.Block) error {
303303
Validator: validator,
304304
Committer: c,
305305
Store: store,
306-
Pp: &noopPolicyParser{},
307-
Ps: &noopPolicyStore{},
306+
Cs: &privdata.NopCollectionStore{},
308307
})
309308

310309
chains.Lock()
@@ -625,32 +624,3 @@ func CreatePeerServer(listenAddress string,
625624
func GetPeerServer() comm.GRPCServer {
626625
return peerServer
627626
}
628-
629-
// TODO: This is a temporary implementation until the PolicyParser would be implemented
630-
type noopPolicyParser struct {
631-
}
632-
633-
func (*noopPolicyParser) Parse(privdata.SerializedPolicy) privdata.Filter {
634-
return func(common.SignedData) bool {
635-
return true
636-
}
637-
}
638-
639-
// TODO: This is a temporary implementation until the PolicyStore would be implemented
640-
type noopPolicyStore struct {
641-
}
642-
643-
func (*noopPolicyStore) CollectionPolicy(common.CollectionCriteria) privdata.SerializedPolicy {
644-
return &serializedPolicy{}
645-
}
646-
647-
type serializedPolicy struct {
648-
}
649-
650-
func (*serializedPolicy) Channel() string {
651-
panic("implement me")
652-
}
653-
654-
func (*serializedPolicy) Raw() []byte {
655-
panic("implement me")
656-
}

gossip/privdata/coordinator.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,7 @@ type Fetcher interface {
7171
}
7272

7373
type Support struct {
74-
privdata.PolicyParser
75-
privdata.PolicyStore
74+
privdata.CollectionStore
7675
txvalidator.Validator
7776
committer.Committer
7877
TransientStore
@@ -503,12 +502,12 @@ func (c *coordinator) isEligible(chdr *common.ChannelHeader, namespace string, c
503502
Collection: col,
504503
TxId: chdr.TxId,
505504
}
506-
sp := c.PolicyStore.CollectionPolicy(cp)
505+
sp := c.CollectionStore.GetCollectionAccessPolicy(cp)
507506
if sp == nil {
508507
logger.Warning("Failed obtaining policy for", cp, "skipping collection")
509508
return false
510509
}
511-
filt := c.PolicyParser.Parse(sp)
510+
filt := sp.GetAccessFilter()
512511
if filt == nil {
513512
logger.Warning("Failed parsing policy for", cp, "skipping collection")
514513
return false
@@ -586,12 +585,12 @@ func (c *coordinator) GetPvtDataAndBlockByNum(seqNum uint64, peerAuthInfo common
586585
Namespace: ns.Namespace,
587586
Collection: col.CollectionName,
588587
}
589-
sp := c.PolicyStore.CollectionPolicy(cc)
588+
sp := c.CollectionStore.GetCollectionAccessPolicy(cc)
590589
if sp == nil {
591590
logger.Warning("Failed obtaining policy for", cc)
592591
continue
593592
}
594-
isAuthorized := c.PolicyParser.Parse(sp)
593+
isAuthorized := sp.GetAccessFilter()
595594
if isAuthorized == nil {
596595
logger.Warning("Failed obtaining filter for", cc)
597596
continue

0 commit comments

Comments
 (0)