From 9b7d4022545c21e5c3ac72bdf1d769a93e33a465 Mon Sep 17 00:00:00 2001 From: yacovm Date: Mon, 21 Aug 2017 19:55:06 +0300 Subject: [PATCH] [FAB-5863] Collection-related APIs This commit defines 2 APIs: - An API that declares the needed methods that the coordinator would invoke on gossip, in gossip/api/subchannel.go - An API that the coordinator would use to fetch policies for sub-channels, in core/common/privdata/policies.go Change-Id: I6e7b7176e2c3b29e069b998214c6aaddd0a37008 Signed-off-by: yacovm --- core/common/privdata/policies.go | 43 +++++++++++++++ gossip/api/subchannel.go | 24 +++++++++ protos/gossip/message.pb.go | 4 +- protos/ledger/rwset/rwset.pb.go | 93 ++++++++++++++++++++++---------- protos/ledger/rwset/rwset.proto | 8 +++ 5 files changed, 143 insertions(+), 29 deletions(-) create mode 100644 core/common/privdata/policies.go create mode 100644 gossip/api/subchannel.go diff --git a/core/common/privdata/policies.go b/core/common/privdata/policies.go new file mode 100644 index 00000000000..90df00ea26d --- /dev/null +++ b/core/common/privdata/policies.go @@ -0,0 +1,43 @@ +/* +Copyright IBM Corp. All Rights Reserved. + +SPDX-License-Identifier: Apache-2.0 +*/ + +package privdata + +import "github.com/hyperledger/fabric/protos/ledger/rwset" + +// SerializedPolicy defines a persisted policy +type SerializedPolicy interface { + // Channel returns the channel this SerializedPolicy corresponds to + Channel() string + // Raw returns the policy in its raw form + Raw() []byte +} + +// SerializedIdentity defines an identity of a network participant +type SerializedIdentity []byte + +// PolicyStore defines an object that retrieves stored SerializedPolicies +// based on the collection's properties +type PolicyStore interface { + // GetPolicy retrieves the collection policy from in the following way: + // If the TxID exists in the ledger, the policy that is returned is the latest policy + // which was committed into the ledger before this txID was committed. + // Else - it's the latest policy for the collection. + CollectionPolicy(rwset.CollectionCriteria) SerializedPolicy +} + +// Filter defines a rule that filters out SerializedIdentities +// that the policy doesn't hold for them. +// Returns: True, if the policy holds for the given SerializedIdentity, +// False otherwise +type Filter func(SerializedIdentity) bool + +// PolicyParser parses SerializedPolicies and returns a Filter +type PolicyParser interface { + // Parse parses a given SerializedPolicy and returns a Filter + // that is derived from it + Parse(SerializedPolicy) Filter +} diff --git a/gossip/api/subchannel.go b/gossip/api/subchannel.go new file mode 100644 index 00000000000..c80bc5ac545 --- /dev/null +++ b/gossip/api/subchannel.go @@ -0,0 +1,24 @@ +/* +Copyright IBM Corp. All Rights Reserved. + +SPDX-License-Identifier: Apache-2.0 +*/ + +package api + +import "github.com/hyperledger/fabric/gossip/common" + +// RoutingFilter defines which peers should receive a certain message, +// or which peers are eligible of receiving a certain message +type RoutingFilter func(peerIdentity PeerIdentityType) bool + +// CollectionCriteria describes a certain sub-channel, or a part of it +type CollectionCriteria []byte + +// RoutingFilterFactory defines an object that given a CollectionCriteria and a channel, +// it can ascertain which peers should be aware of the data related to the +// CollectionCriteria. +type RoutingFilterFactory interface { + // Peers returns a RoutingFilter for given chainID and CollectionCriteria + Peers(common.ChainID, CollectionCriteria) RoutingFilter +} diff --git a/protos/gossip/message.pb.go b/protos/gossip/message.pb.go index f13133579ae..c40e025b75c 100644 --- a/protos/gossip/message.pb.go +++ b/protos/gossip/message.pb.go @@ -1525,7 +1525,9 @@ func (m *RemotePvtDataResponse) GetPayloads() []*PrivatePayload { // inside the block type PvtDataPayload struct { TxSeqInBlock uint64 `protobuf:"varint,1,opt,name=tx_seq_in_block,json=txSeqInBlock" json:"tx_seq_in_block,omitempty"` - Payload []byte `protobuf:"bytes,2,opt,name=payload,proto3" json:"payload,omitempty"` + // Encodes marhslaed bytes of rwset.TxPvtReadWriteSet + // defined in rwset.proto + Payload []byte `protobuf:"bytes,2,opt,name=payload,proto3" json:"payload,omitempty"` } func (m *PvtDataPayload) Reset() { *m = PvtDataPayload{} } diff --git a/protos/ledger/rwset/rwset.pb.go b/protos/ledger/rwset/rwset.pb.go index afec652cb16..17ab8c832d5 100644 --- a/protos/ledger/rwset/rwset.pb.go +++ b/protos/ledger/rwset/rwset.pb.go @@ -14,6 +14,7 @@ It has these top-level messages: TxPvtReadWriteSet NsPvtReadWriteSet CollectionPvtReadWriteSet + CollectionCriteria */ package rwset @@ -218,6 +219,38 @@ func (m *CollectionPvtReadWriteSet) GetRwset() []byte { return nil } +type CollectionCriteria struct { + Channel string `protobuf:"bytes,1,opt,name=channel" json:"channel,omitempty"` + TxId string `protobuf:"bytes,2,opt,name=tx_id,json=txId" json:"tx_id,omitempty"` + Collection string `protobuf:"bytes,3,opt,name=collection" json:"collection,omitempty"` +} + +func (m *CollectionCriteria) Reset() { *m = CollectionCriteria{} } +func (m *CollectionCriteria) String() string { return proto.CompactTextString(m) } +func (*CollectionCriteria) ProtoMessage() {} +func (*CollectionCriteria) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{6} } + +func (m *CollectionCriteria) GetChannel() string { + if m != nil { + return m.Channel + } + return "" +} + +func (m *CollectionCriteria) GetTxId() string { + if m != nil { + return m.TxId + } + return "" +} + +func (m *CollectionCriteria) GetCollection() string { + if m != nil { + return m.Collection + } + return "" +} + func init() { proto.RegisterType((*TxReadWriteSet)(nil), "rwset.TxReadWriteSet") proto.RegisterType((*NsReadWriteSet)(nil), "rwset.NsReadWriteSet") @@ -225,38 +258,42 @@ func init() { proto.RegisterType((*TxPvtReadWriteSet)(nil), "rwset.TxPvtReadWriteSet") proto.RegisterType((*NsPvtReadWriteSet)(nil), "rwset.NsPvtReadWriteSet") proto.RegisterType((*CollectionPvtReadWriteSet)(nil), "rwset.CollectionPvtReadWriteSet") + proto.RegisterType((*CollectionCriteria)(nil), "rwset.CollectionCriteria") proto.RegisterEnum("rwset.TxReadWriteSet_DataModel", TxReadWriteSet_DataModel_name, TxReadWriteSet_DataModel_value) } func init() { proto.RegisterFile("ledger/rwset/rwset.proto", fileDescriptor0) } var fileDescriptor0 = []byte{ - // 421 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x09, 0x6e, 0x88, 0x02, 0xff, 0xac, 0x93, 0x4f, 0x6f, 0xd3, 0x30, - 0x18, 0xc6, 0x71, 0xab, 0x16, 0xf2, 0x36, 0x0a, 0xd4, 0xb4, 0x22, 0x48, 0x95, 0x28, 0x05, 0x89, - 0x8a, 0x43, 0x02, 0xe5, 0xc6, 0x81, 0x03, 0x70, 0x40, 0x42, 0x54, 0xc8, 0x54, 0x4c, 0xea, 0x0e, - 0x91, 0x9b, 0x78, 0x4d, 0xa4, 0xfc, 0x53, 0xec, 0x75, 0xdd, 0x07, 0xd8, 0x79, 0xbb, 0xed, 0xbc, - 0x6f, 0x3a, 0xd5, 0x4e, 0xd3, 0x24, 0xdd, 0xbf, 0xc3, 0x2e, 0x51, 0xfc, 0xfa, 0x79, 0xf2, 0xfc, - 0xec, 0x37, 0x2f, 0x98, 0x21, 0xf3, 0x96, 0x2c, 0xb3, 0xb3, 0x13, 0xce, 0x84, 0x7a, 0x5a, 0x69, - 0x96, 0x88, 0x04, 0xb7, 0xe4, 0x62, 0x74, 0x89, 0xc0, 0x98, 0xad, 0x09, 0xa3, 0xde, 0x41, 0x16, - 0x08, 0xf6, 0x8f, 0x09, 0xfc, 0x0d, 0xc0, 0xa3, 0x82, 0x3a, 0x51, 0xe2, 0xb1, 0xd0, 0x44, 0x43, - 0x34, 0x36, 0x26, 0x6f, 0x2c, 0xe5, 0xad, 0x4a, 0xad, 0x9f, 0x54, 0xd0, 0x3f, 0x1b, 0x19, 0xd1, - 0xbc, 0xed, 0x2b, 0xfe, 0x04, 0xcf, 0x62, 0xee, 0x48, 0xbd, 0xd9, 0x18, 0x36, 0xc7, 0x9d, 0x49, - 0x3f, 0x77, 0x4f, 0x79, 0xd9, 0x4d, 0x9e, 0xc6, 0x9c, 0x48, 0x88, 0x97, 0xa0, 0x15, 0x5f, 0xc2, - 0x6d, 0x68, 0xfc, 0xfe, 0xff, 0xe2, 0xc9, 0xe8, 0x0a, 0x81, 0x51, 0x35, 0xe0, 0x01, 0x68, 0x31, - 0x8d, 0x18, 0x4f, 0xa9, 0xcb, 0x24, 0x98, 0x46, 0x76, 0x05, 0xdc, 0x83, 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 0x19, 0x08, 0xff, 0x78, 0x61, 0xb9, 0x49, 0x64, 0x97, 0x2c, 0xb6, 0xb2, 0xd8, 0xca, 0x62, - 0x97, 0x47, 0x77, 0xd1, 0x96, 0xc5, 0x2f, 0xd7, 0x01, 0x00, 0x00, 0xff, 0xff, 0x2b, 0x8a, 0xfa, - 0x65, 0xd1, 0x03, 0x00, 0x00, + // 466 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x09, 0x6e, 0x88, 0x02, 0xff, 0xac, 0x54, 0xcf, 0x6f, 0xd3, 0x30, + 0x14, 0xc6, 0x2b, 0xdd, 0xc8, 0x5b, 0x15, 0x98, 0xb7, 0x89, 0x20, 0x4d, 0x50, 0x0a, 0x12, 0x15, + 0x87, 0x04, 0xc6, 0x8d, 0x03, 0x07, 0xc6, 0x01, 0x84, 0x98, 0x90, 0x99, 0x40, 0x1a, 0x87, 0xc8, + 0xb5, 0x4d, 0x13, 0xa9, 0x75, 0x22, 0xdb, 0x94, 0xf2, 0x07, 0x70, 0x86, 0x1b, 0x67, 0xfe, 0x53, + 0xd4, 0xe7, 0xb4, 0xf9, 0x31, 0x7e, 0x1d, 0xb8, 0x44, 0xf1, 0xf3, 0xf7, 0xbd, 0xef, 0xf3, 0xfb, + 0xe2, 0x40, 0x34, 0x53, 0x72, 0xaa, 0x4c, 0x62, 0x3e, 0x59, 0xe5, 0xfc, 0x33, 0x2e, 0x4d, 0xe1, + 0x0a, 0xda, 0xc7, 0xc5, 0xe8, 0x3b, 0x81, 0xf0, 0x6c, 0xc9, 0x14, 0x97, 0xef, 0x4c, 0xee, 0xd4, + 0x1b, 0xe5, 0xe8, 0x13, 0x00, 0xc9, 0x1d, 0x4f, 0xe7, 0x85, 0x54, 0xb3, 0x88, 0x0c, 0xc9, 0x38, + 0x3c, 0xbe, 0x15, 0x7b, 0x6e, 0x1b, 0x1a, 0x3f, 0xe3, 0x8e, 0xbf, 0x5a, 0xc1, 0x58, 0x20, 0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 0x10, 0xd8, 0xbb, 0x80, 0xf8, 0x4b, 0x96, 0x0c, 0x0e, 0x1a, 0x73, 0xeb, + 0xea, 0x0e, 0x2f, 0x44, 0xd6, 0xd5, 0xa7, 0xa2, 0xb5, 0x85, 0x3e, 0xce, 0xe1, 0xc6, 0x6f, 0x09, + 0xff, 0x1e, 0xd4, 0x2f, 0xbf, 0xb2, 0x91, 0x00, 0x5a, 0xf7, 0x3e, 0x59, 0x35, 0x35, 0x39, 0xa7, + 0x11, 0xec, 0x88, 0x8c, 0x6b, 0x5d, 0x8d, 0x3c, 0x60, 0xeb, 0x25, 0xdd, 0x87, 0xbe, 0x5b, 0xa6, + 0xb9, 0xc4, 0x2e, 0x01, 0xbb, 0xec, 0x96, 0x2f, 0x24, 0xbd, 0x09, 0x50, 0x8b, 0x61, 0xb8, 0x01, + 0x6b, 0x54, 0x9e, 0xa6, 0x70, 0xbf, 0x30, 0xd3, 0x38, 0xfb, 0x5c, 0x2a, 0xe3, 0xef, 0x75, 0xfc, + 0x81, 0x4f, 0x4c, 0x2e, 0xfc, 0x95, 0xb6, 0x71, 0x55, 0x44, 0x4b, 0xe7, 0x0f, 0xa7, 0xb9, 0xcb, + 0x3e, 0x4e, 0x62, 0x51, 0xcc, 0x93, 0x06, 0x25, 0xf1, 0x94, 0xc4, 0x53, 0x92, 0xe6, 0xff, 0x61, + 0xb2, 0x8d, 0xc5, 0x47, 0x3f, 0x03, 0x00, 0x00, 0xff, 0xff, 0xae, 0xa7, 0x5f, 0x87, 0x36, 0x04, + 0x00, 0x00, } diff --git a/protos/ledger/rwset/rwset.proto b/protos/ledger/rwset/rwset.proto index e923047a983..cc2fc4b271e 100644 --- a/protos/ledger/rwset/rwset.proto +++ b/protos/ledger/rwset/rwset.proto @@ -62,4 +62,12 @@ message NsPvtReadWriteSet { message CollectionPvtReadWriteSet { string collection_name = 1; bytes rwset = 2; // Data model specific serialized proto message (e.g., kvrwset.KVRWSet for KV and Document data models) +} + +// CollectionProperty defines an element of a private data that corresponds +// to a certain transaction and collection +message CollectionCriteria { + string channel = 1; + string tx_id = 2; + string collection = 3; } \ No newline at end of file