Skip to content

Commit 4e17f53

Browse files
committed
collACL: add simpleCollectionStore to txContext
We need to add simpleCollectionStore interface in the transactionContext so that we can check whether the creator has access to the collection or not. FAB-13038 #done Change-Id: I5b150bb751bd22451b546b8c1028e54f1f1ca884 Signed-off-by: senthil <cendhu@gmail.com>
1 parent a770740 commit 4e17f53

File tree

5 files changed

+32
-6
lines changed

5 files changed

+32
-6
lines changed

core/chaincode/handler.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,12 @@ import (
2020
commonledger "github.com/hyperledger/fabric/common/ledger"
2121
"github.com/hyperledger/fabric/core/aclmgmt/resources"
2222
"github.com/hyperledger/fabric/core/common/ccprovider"
23+
"github.com/hyperledger/fabric/core/common/privdata"
2324
"github.com/hyperledger/fabric/core/common/sysccprovider"
2425
"github.com/hyperledger/fabric/core/container/ccintf"
2526
"github.com/hyperledger/fabric/core/ledger"
2627
"github.com/hyperledger/fabric/core/ledger/ledgerconfig"
28+
"github.com/hyperledger/fabric/core/peer"
2729
pb "github.com/hyperledger/fabric/protos/peer"
2830
"github.com/pkg/errors"
2931
)
@@ -1123,6 +1125,7 @@ func (h *Handler) Execute(txParams *ccprovider.TransactionParams, cccid *ccprovi
11231125
chaincodeLogger.Debugf("Entry")
11241126
defer chaincodeLogger.Debugf("Exit")
11251127

1128+
txParams.CollectionStore = h.getCollectionStore(msg.ChannelId)
11261129
txctx, err := h.TXContexts.Create(txParams)
11271130
if err != nil {
11281131
return nil, err
@@ -1159,6 +1162,14 @@ func (h *Handler) setChaincodeProposal(signedProp *pb.SignedProposal, prop *pb.P
11591162
return nil
11601163
}
11611164

1165+
func (h *Handler) getCollectionStore(channelID string) privdata.CollectionStore {
1166+
csStoreSupport := &peer.CollectionSupport{
1167+
PeerLedger: h.LedgerGetter.GetLedger(channelID),
1168+
}
1169+
return privdata.NewSimpleCollectionStore(csStoreSupport)
1170+
1171+
}
1172+
11621173
func (h *Handler) State() State { return h.state }
11631174
func (h *Handler) Close() { h.TXContexts.Close() }
11641175

core/chaincode/transaction_context.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"sync"
1111

1212
commonledger "github.com/hyperledger/fabric/common/ledger"
13+
"github.com/hyperledger/fabric/core/common/privdata"
1314
"github.com/hyperledger/fabric/core/ledger"
1415
pb "github.com/hyperledger/fabric/protos/peer"
1516
)
@@ -21,6 +22,7 @@ type TransactionContext struct {
2122
ResponseNotifier chan *pb.ChaincodeMessage
2223
TXSimulator ledger.TxSimulator
2324
HistoryQueryExecutor ledger.HistoryQueryExecutor
25+
CollectionStore privdata.CollectionStore
2426

2527
// tracks open iterators used for range queries
2628
queryMutex sync.Mutex

core/chaincode/transaction_contexts.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,10 @@ func (c *TransactionContexts) Create(txParams *ccprovider.TransactionParams) (*T
6666
ResponseNotifier: make(chan *pb.ChaincodeMessage, 1),
6767
TXSimulator: txParams.TXSimulator,
6868
HistoryQueryExecutor: txParams.HistoryQueryExecutor,
69-
queryIteratorMap: map[string]commonledger.ResultsIterator{},
70-
pendingQueryResults: map[string]*PendingQueryResult{},
69+
CollectionStore: txParams.CollectionStore,
70+
71+
queryIteratorMap: map[string]commonledger.ResultsIterator{},
72+
pendingQueryResults: map[string]*PendingQueryResult{},
7173
}
7274
c.contexts[ctxID] = txctx
7375

core/common/ccprovider/ccprovider.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import (
1818
"github.com/golang/protobuf/proto"
1919
"github.com/hyperledger/fabric/common/chaincode"
2020
"github.com/hyperledger/fabric/common/flogging"
21+
"github.com/hyperledger/fabric/core/common/privdata"
2122
"github.com/hyperledger/fabric/core/ledger"
2223
pb "github.com/hyperledger/fabric/protos/peer"
2324
"github.com/pkg/errors"
@@ -509,6 +510,7 @@ type TransactionParams struct {
509510
Proposal *pb.Proposal
510511
TXSimulator ledger.TxSimulator
511512
HistoryQueryExecutor ledger.HistoryQueryExecutor
513+
CollectionStore privdata.CollectionStore
512514

513515
// this is additional data passed to the chaincode
514516
ProposalDecorations map[string][]byte

core/peer/peer.go

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -401,7 +401,7 @@ func createChain(cid string, ledger ledger.PeerLedger, cb *common.Block, ccp ccp
401401
if err != nil {
402402
return errors.Wrapf(err, "[channel %s] failed opening transient store", bundle.ConfigtxValidator().ChainID())
403403
}
404-
csStoreSupport := &collectionSupport{
404+
csStoreSupport := &CollectionSupport{
405405
PeerLedger: ledger,
406406
}
407407
simpleCollectionStore := privdata.NewSimpleCollectionStore(csStoreSupport)
@@ -703,15 +703,24 @@ func NewPeerServer(listenAddress string, serverConfig comm.ServerConfig) (*comm.
703703
return peerServer, nil
704704
}
705705

706-
type collectionSupport struct {
706+
// TODO: Remove CollectionSupport and respective methonds on them.
707+
// CollectionSupport is created per chain and is passed to the simple
708+
// collection store and the gossip. As it is created per chain, there
709+
// is no need to pass the channelID for both GetQueryExecutorForLedger()
710+
// and GetIdentityDeserializer(). Note that the cid passed to
711+
// GetQueryExecutorForLedger is never used. Instead, we can directly
712+
// pass the ledger.PeerLedger and msp.IdentityDeserializer to the
713+
// simpleCollectionStore and pass only the msp.IdentityDeserializer to
714+
// the gossip in createChain() -- FAB-13037
715+
type CollectionSupport struct {
707716
ledger.PeerLedger
708717
}
709718

710-
func (cs *collectionSupport) GetQueryExecutorForLedger(cid string) (ledger.QueryExecutor, error) {
719+
func (cs *CollectionSupport) GetQueryExecutorForLedger(cid string) (ledger.QueryExecutor, error) {
711720
return cs.NewQueryExecutor()
712721
}
713722

714-
func (*collectionSupport) GetIdentityDeserializer(chainID string) msp.IdentityDeserializer {
723+
func (*CollectionSupport) GetIdentityDeserializer(chainID string) msp.IdentityDeserializer {
715724
return mspmgmt.GetManagerForChain(chainID)
716725
}
717726

0 commit comments

Comments
 (0)