Skip to content

Commit 6cc7444

Browse files
committed
[FAB-5870] Configuration proto for a collection
Defined collection configuration protos (passed at chaincode initialisation time). Change-Id: I0c9cdb332bd9dadd46b51fe2b57d2102b02d50ee Signed-off-by: Mathias Bjoerkqvist <mbj@zurich.ibm.com>
1 parent 887da22 commit 6cc7444

File tree

16 files changed

+522
-207
lines changed

16 files changed

+522
-207
lines changed

core/common/privdata/policies.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ package privdata
88

99
import (
1010
"github.com/hyperledger/fabric/protos/common"
11-
"github.com/hyperledger/fabric/protos/ledger/rwset"
1211
)
1312

1413
// SerializedPolicy defines a persisted policy
@@ -26,7 +25,7 @@ type PolicyStore interface {
2625
// If the TxID exists in the ledger, the policy that is returned is the latest policy
2726
// which was committed into the ledger before this txID was committed.
2827
// Else - it's the latest policy for the collection.
29-
CollectionPolicy(rwset.CollectionCriteria) SerializedPolicy
28+
CollectionPolicy(common.CollectionCriteria) SerializedPolicy
3029
}
3130

3231
// Filter defines a rule that filters peers according to data signed by them.

core/peer/peer.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ import (
3131
"github.com/hyperledger/fabric/msp"
3232
mspmgmt "github.com/hyperledger/fabric/msp/mgmt"
3333
"github.com/hyperledger/fabric/protos/common"
34-
"github.com/hyperledger/fabric/protos/ledger/rwset"
3534
pb "github.com/hyperledger/fabric/protos/peer"
3635
"github.com/hyperledger/fabric/protos/utils"
3736
"github.com/pkg/errors"
@@ -641,7 +640,7 @@ func (*noopPolicyParser) Parse(privdata.SerializedPolicy) privdata.Filter {
641640
type noopPolicyStore struct {
642641
}
643642

644-
func (*noopPolicyStore) CollectionPolicy(rwset.CollectionCriteria) privdata.SerializedPolicy {
643+
func (*noopPolicyStore) CollectionPolicy(common.CollectionCriteria) privdata.SerializedPolicy {
645644
return &serializedPolicy{}
646645
}
647646

gossip/privdata/coordinator.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -497,7 +497,7 @@ func (c *coordinator) listMissingPrivateData(block *common.Block, ownedRWsets ma
497497

498498
// isEligible checks if this peer is eligible for a collection in a given namespace
499499
func (c *coordinator) isEligible(chdr *common.ChannelHeader, namespace string, col string) bool {
500-
cp := rwset.CollectionCriteria{
500+
cp := common.CollectionCriteria{
501501
Channel: chdr.ChannelId,
502502
Namespace: namespace,
503503
Collection: col,
@@ -580,7 +580,7 @@ func (c *coordinator) GetPvtDataAndBlockByNum(seqNum uint64, peerAuthInfo common
580580

581581
for _, ns := range item.WriteSet.NsPvtRwset {
582582
for _, col := range ns.CollectionPvtRwset {
583-
cc := rwset.CollectionCriteria{
583+
cc := common.CollectionCriteria{
584584
Channel: chdr.ChannelId,
585585
TxId: chdr.TxId,
586586
Namespace: ns.Namespace,

gossip/privdata/coordinator_test.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -225,24 +225,24 @@ func (f *fetcherMock) fetch(req *proto.RemotePvtDataRequest) ([]*proto.PvtDataEl
225225
func createPolicyStore(expectedSignedData common.SignedData) *policyStore {
226226
return &policyStore{
227227
expectedSignedData: expectedSignedData,
228-
policies: make(map[serializedPolicy]rwset.CollectionCriteria),
229-
store: make(map[rwset.CollectionCriteria]serializedPolicy),
228+
policies: make(map[serializedPolicy]common.CollectionCriteria),
229+
store: make(map[common.CollectionCriteria]serializedPolicy),
230230
}
231231
}
232232

233233
type policyStore struct {
234234
expectedSignedData common.SignedData
235235
acceptsAll bool
236-
store map[rwset.CollectionCriteria]serializedPolicy
237-
policies map[serializedPolicy]rwset.CollectionCriteria
236+
store map[common.CollectionCriteria]serializedPolicy
237+
policies map[serializedPolicy]common.CollectionCriteria
238238
}
239239

240240
func (ps *policyStore) thatAcceptsAll() *policyStore {
241241
ps.acceptsAll = true
242242
return ps
243243
}
244244

245-
func (ps *policyStore) thatAccepts(cc rwset.CollectionCriteria) *policyStore {
245+
func (ps *policyStore) thatAccepts(cc common.CollectionCriteria) *policyStore {
246246
sp := serializedPolicy{
247247
ps: ps,
248248
n: util.RandomUInt64(),
@@ -252,7 +252,7 @@ func (ps *policyStore) thatAccepts(cc rwset.CollectionCriteria) *policyStore {
252252
return ps
253253
}
254254

255-
func (ps *policyStore) CollectionPolicy(cc rwset.CollectionCriteria) privdata.SerializedPolicy {
255+
func (ps *policyStore) CollectionPolicy(cc common.CollectionCriteria) privdata.SerializedPolicy {
256256
if sp, exists := ps.store[cc]; exists {
257257
return &sp
258258
}
@@ -779,7 +779,7 @@ func TestCoordinatorStoreBlock(t *testing.T) {
779779
// private data from the transient store or peers, and in fact- if it attempts to fetch the data it's not eligible
780780
// for from the transient store or from peers - the test would fail because the Mock wasn't initialized.
781781
block = bf.AddTxn("tx3", "ns3", hash, "c3", "c2", "c1").AddTxn("tx1", "ns1", hash, "c1").create()
782-
ps = createPolicyStore(peerSelfSignedData).thatAccepts(rwset.CollectionCriteria{
782+
ps = createPolicyStore(peerSelfSignedData).thatAccepts(common.CollectionCriteria{
783783
TxId: "tx3",
784784
Collection: "c3",
785785
Namespace: "ns3",
@@ -837,7 +837,7 @@ func TestCoordinatorGetBlocks(t *testing.T) {
837837

838838
// Green path - block and private data is returned, but the requester isn't eligible for all the private data,
839839
// but only to a subset of it.
840-
ps = createPolicyStore(sd).thatAccepts(rwset.CollectionCriteria{
840+
ps = createPolicyStore(sd).thatAccepts(common.CollectionCriteria{
841841
Namespace: "ns1",
842842
Collection: "c2",
843843
TxId: "tx1",

gossip/privdata/distributor.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ func (d *distributorImpl) Distribute(txID string, privData *rwset.TxPvtReadWrite
6363
namespace := pvtRwset.Namespace
6464
for _, collection := range pvtRwset.CollectionPvtRwset {
6565
collectionName := collection.CollectionName
66-
policyFilter := pp.Parse(ps.CollectionPolicy(rwset.CollectionCriteria{
66+
policyFilter := pp.Parse(ps.CollectionPolicy(common.CollectionCriteria{
6767
Namespace: namespace,
6868
Collection: collectionName,
6969
TxId: txID,

gossip/privdata/pull.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ import (
2222
"github.com/hyperledger/fabric/gossip/util"
2323
fcommon "github.com/hyperledger/fabric/protos/common"
2424
proto "github.com/hyperledger/fabric/protos/gossip"
25-
"github.com/hyperledger/fabric/protos/ledger/rwset"
2625
"github.com/op/go-logging"
2726
"github.com/pkg/errors"
2827
)
@@ -133,7 +132,7 @@ func (p *puller) createResponse(message proto.ReceivedMessage) []*proto.PvtDataE
133132
}()
134133
msg := message.GetGossipMessage()
135134
for _, dig := range msg.GetPrivateReq().Digests {
136-
pol := p.ps.CollectionPolicy(rwset.CollectionCriteria{
135+
pol := p.ps.CollectionPolicy(fcommon.CollectionCriteria{
137136
Channel: p.channel,
138137
Collection: dig.Collection,
139138
TxId: dig.TxId,
@@ -358,7 +357,7 @@ func (dig2Filter digestToFilterMapping) String() string {
358357
func (p *puller) computeFilters(req *proto.RemotePvtDataRequest) (digestToFilterMapping, error) {
359358
filters := make(map[proto.PvtDataDigest]filter.RoutingFilter)
360359
for _, digest := range req.Digests {
361-
pol := p.ps.CollectionPolicy(rwset.CollectionCriteria{
360+
pol := p.ps.CollectionPolicy(fcommon.CollectionCriteria{
362361
Channel: p.channel,
363362
TxId: digest.TxId,
364363
Collection: digest.Collection,

gossip/privdata/pull_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ import (
2222
"github.com/hyperledger/fabric/gossip/util"
2323
fcommon "github.com/hyperledger/fabric/protos/common"
2424
proto "github.com/hyperledger/fabric/protos/gossip"
25-
"github.com/hyperledger/fabric/protos/ledger/rwset"
2625
"github.com/op/go-logging"
2726
"github.com/pkg/errors"
2827
"github.com/stretchr/testify/assert"
@@ -79,7 +78,7 @@ func (ps *mockPolicyStore) withPolicy(collection string) *mockSerializedPolicy {
7978
return sp
8079
}
8180

82-
func (ps mockPolicyStore) CollectionPolicy(cc rwset.CollectionCriteria) privdata.SerializedPolicy {
81+
func (ps mockPolicyStore) CollectionPolicy(cc fcommon.CollectionCriteria) privdata.SerializedPolicy {
8382
return ps.m[cc.Collection]
8483
}
8584

0 commit comments

Comments
 (0)